qla_os.c 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. /*
  20. * Driver version
  21. */
  22. char qla2x00_version_str[40];
  23. static int apidev_major;
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * CT6 CTX allocation cache
  30. */
  31. static struct kmem_cache *ctx_cachep;
  32. int ql2xlogintimeout = 20;
  33. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  34. MODULE_PARM_DESC(ql2xlogintimeout,
  35. "Login timeout value in seconds.");
  36. int qlport_down_retry;
  37. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  38. MODULE_PARM_DESC(qlport_down_retry,
  39. "Maximum number of command retries to a port that returns "
  40. "a PORT-DOWN status.");
  41. int ql2xplogiabsentdevice;
  42. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  43. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  44. "Option to enable PLOGI to devices that are not present after "
  45. "a Fabric scan. This is needed for several broken switches. "
  46. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  47. int ql2xloginretrycount = 0;
  48. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  49. MODULE_PARM_DESC(ql2xloginretrycount,
  50. "Specify an alternate value for the NVRAM login retry count.");
  51. int ql2xallocfwdump = 1;
  52. module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
  53. MODULE_PARM_DESC(ql2xallocfwdump,
  54. "Option to enable allocation of memory for a firmware dump "
  55. "during HBA initialization. Memory allocation requirements "
  56. "vary by ISP type. Default is 1 - allocate memory.");
  57. int ql2xextended_error_logging;
  58. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  59. MODULE_PARM_DESC(ql2xextended_error_logging,
  60. "Option to enable extended error logging, "
  61. "Default is 0 - no logging. 1 - log errors.");
  62. int ql2xshiftctondsd = 6;
  63. module_param(ql2xshiftctondsd, int, S_IRUGO|S_IRUSR);
  64. MODULE_PARM_DESC(ql2xshiftctondsd,
  65. "Set to control shifting of command type processing "
  66. "based on total number of SG elements.");
  67. static void qla2x00_free_device(scsi_qla_host_t *);
  68. int ql2xfdmienable=1;
  69. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  70. MODULE_PARM_DESC(ql2xfdmienable,
  71. "Enables FDMI registrations. "
  72. "0 - no FDMI. Default is 1 - perform FDMI.");
  73. #define MAX_Q_DEPTH 32
  74. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  75. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  76. MODULE_PARM_DESC(ql2xmaxqdepth,
  77. "Maximum queue depth to report for target devices.");
  78. /* Do not change the value of this after module load */
  79. int ql2xenabledif = 1;
  80. module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
  81. MODULE_PARM_DESC(ql2xenabledif,
  82. " Enable T10-CRC-DIF "
  83. " Default is 0 - No DIF Support. 1 - Enable it");
  84. int ql2xenablehba_err_chk;
  85. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  86. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  87. " Enable T10-CRC-DIF Error isolation by HBA"
  88. " Default is 0 - Error isolation disabled, 1 - Enable it");
  89. int ql2xiidmaenable=1;
  90. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  91. MODULE_PARM_DESC(ql2xiidmaenable,
  92. "Enables iIDMA settings "
  93. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  94. int ql2xmaxqueues = 1;
  95. module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
  96. MODULE_PARM_DESC(ql2xmaxqueues,
  97. "Enables MQ settings "
  98. "Default is 1 for single queue. Set it to number "
  99. "of queues in MQ mode.");
  100. int ql2xmultique_tag;
  101. module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
  102. MODULE_PARM_DESC(ql2xmultique_tag,
  103. "Enables CPU affinity settings for the driver "
  104. "Default is 0 for no affinity of request and response IO. "
  105. "Set it to 1 to turn on the cpu affinity.");
  106. int ql2xfwloadbin;
  107. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  108. MODULE_PARM_DESC(ql2xfwloadbin,
  109. "Option to specify location from which to load ISP firmware:\n"
  110. " 2 -- load firmware via the request_firmware() (hotplug)\n"
  111. " interface.\n"
  112. " 1 -- load firmware from flash.\n"
  113. " 0 -- use default semantics.\n");
  114. int ql2xetsenable;
  115. module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
  116. MODULE_PARM_DESC(ql2xetsenable,
  117. "Enables firmware ETS burst."
  118. "Default is 0 - skip ETS enablement.");
  119. int ql2xdbwr = 1;
  120. module_param(ql2xdbwr, int, S_IRUGO|S_IRUSR);
  121. MODULE_PARM_DESC(ql2xdbwr,
  122. "Option to specify scheme for request queue posting\n"
  123. " 0 -- Regular doorbell.\n"
  124. " 1 -- CAMRAM doorbell (faster).\n");
  125. int ql2xdontresethba;
  126. module_param(ql2xdontresethba, int, S_IRUGO|S_IRUSR);
  127. MODULE_PARM_DESC(ql2xdontresethba,
  128. "Option to specify reset behaviour\n"
  129. " 0 (Default) -- Reset on failure.\n"
  130. " 1 -- Do not reset on failure.\n");
  131. int ql2xtargetreset = 1;
  132. module_param(ql2xtargetreset, int, S_IRUGO|S_IRUSR);
  133. MODULE_PARM_DESC(ql2xtargetreset,
  134. "Enable target reset."
  135. "Default is 1 - use hw defaults.");
  136. int ql2xgffidenable;
  137. module_param(ql2xgffidenable, int, S_IRUGO|S_IRUSR);
  138. MODULE_PARM_DESC(ql2xgffidenable,
  139. "Enables GFF_ID checks of port type. "
  140. "Default is 0 - Do not use GFF_ID information.");
  141. int ql2xasynctmfenable;
  142. module_param(ql2xasynctmfenable, int, S_IRUGO|S_IRUSR);
  143. MODULE_PARM_DESC(ql2xasynctmfenable,
  144. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  145. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  146. /*
  147. * SCSI host template entry points
  148. */
  149. static int qla2xxx_slave_configure(struct scsi_device * device);
  150. static int qla2xxx_slave_alloc(struct scsi_device *);
  151. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  152. static void qla2xxx_scan_start(struct Scsi_Host *);
  153. static void qla2xxx_slave_destroy(struct scsi_device *);
  154. static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
  155. void (*fn)(struct scsi_cmnd *));
  156. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  157. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  158. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  159. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  160. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  161. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  162. static int qla2x00_change_queue_type(struct scsi_device *, int);
  163. struct scsi_host_template qla2xxx_driver_template = {
  164. .module = THIS_MODULE,
  165. .name = QLA2XXX_DRIVER_NAME,
  166. .queuecommand = qla2xxx_queuecommand,
  167. .eh_abort_handler = qla2xxx_eh_abort,
  168. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  169. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  170. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  171. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  172. .slave_configure = qla2xxx_slave_configure,
  173. .slave_alloc = qla2xxx_slave_alloc,
  174. .slave_destroy = qla2xxx_slave_destroy,
  175. .scan_finished = qla2xxx_scan_finished,
  176. .scan_start = qla2xxx_scan_start,
  177. .change_queue_depth = qla2x00_change_queue_depth,
  178. .change_queue_type = qla2x00_change_queue_type,
  179. .this_id = -1,
  180. .cmd_per_lun = 3,
  181. .use_clustering = ENABLE_CLUSTERING,
  182. .sg_tablesize = SG_ALL,
  183. .max_sectors = 0xFFFF,
  184. .shost_attrs = qla2x00_host_attrs,
  185. };
  186. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  187. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  188. /* TODO Convert to inlines
  189. *
  190. * Timer routines
  191. */
  192. __inline__ void
  193. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  194. {
  195. init_timer(&vha->timer);
  196. vha->timer.expires = jiffies + interval * HZ;
  197. vha->timer.data = (unsigned long)vha;
  198. vha->timer.function = (void (*)(unsigned long))func;
  199. add_timer(&vha->timer);
  200. vha->timer_active = 1;
  201. }
  202. static inline void
  203. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  204. {
  205. /* Currently used for 82XX only. */
  206. if (vha->device_flags & DFLG_DEV_FAILED)
  207. return;
  208. mod_timer(&vha->timer, jiffies + interval * HZ);
  209. }
  210. static __inline__ void
  211. qla2x00_stop_timer(scsi_qla_host_t *vha)
  212. {
  213. del_timer_sync(&vha->timer);
  214. vha->timer_active = 0;
  215. }
  216. static int qla2x00_do_dpc(void *data);
  217. static void qla2x00_rst_aen(scsi_qla_host_t *);
  218. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  219. struct req_que **, struct rsp_que **);
  220. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  221. static void qla2x00_mem_free(struct qla_hw_data *);
  222. static void qla2x00_sp_free_dma(srb_t *);
  223. /* -------------------------------------------------------------------------- */
  224. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  225. {
  226. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  227. GFP_KERNEL);
  228. if (!ha->req_q_map) {
  229. qla_printk(KERN_WARNING, ha,
  230. "Unable to allocate memory for request queue ptrs\n");
  231. goto fail_req_map;
  232. }
  233. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  234. GFP_KERNEL);
  235. if (!ha->rsp_q_map) {
  236. qla_printk(KERN_WARNING, ha,
  237. "Unable to allocate memory for response queue ptrs\n");
  238. goto fail_rsp_map;
  239. }
  240. set_bit(0, ha->rsp_qid_map);
  241. set_bit(0, ha->req_qid_map);
  242. return 1;
  243. fail_rsp_map:
  244. kfree(ha->req_q_map);
  245. ha->req_q_map = NULL;
  246. fail_req_map:
  247. return -ENOMEM;
  248. }
  249. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  250. {
  251. if (req && req->ring)
  252. dma_free_coherent(&ha->pdev->dev,
  253. (req->length + 1) * sizeof(request_t),
  254. req->ring, req->dma);
  255. kfree(req);
  256. req = NULL;
  257. }
  258. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  259. {
  260. if (rsp && rsp->ring)
  261. dma_free_coherent(&ha->pdev->dev,
  262. (rsp->length + 1) * sizeof(response_t),
  263. rsp->ring, rsp->dma);
  264. kfree(rsp);
  265. rsp = NULL;
  266. }
  267. static void qla2x00_free_queues(struct qla_hw_data *ha)
  268. {
  269. struct req_que *req;
  270. struct rsp_que *rsp;
  271. int cnt;
  272. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  273. req = ha->req_q_map[cnt];
  274. qla2x00_free_req_que(ha, req);
  275. }
  276. kfree(ha->req_q_map);
  277. ha->req_q_map = NULL;
  278. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  279. rsp = ha->rsp_q_map[cnt];
  280. qla2x00_free_rsp_que(ha, rsp);
  281. }
  282. kfree(ha->rsp_q_map);
  283. ha->rsp_q_map = NULL;
  284. }
  285. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  286. {
  287. uint16_t options = 0;
  288. int ques, req, ret;
  289. struct qla_hw_data *ha = vha->hw;
  290. if (!(ha->fw_attributes & BIT_6)) {
  291. qla_printk(KERN_INFO, ha,
  292. "Firmware is not multi-queue capable\n");
  293. goto fail;
  294. }
  295. if (ql2xmultique_tag) {
  296. /* create a request queue for IO */
  297. options |= BIT_7;
  298. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  299. QLA_DEFAULT_QUE_QOS);
  300. if (!req) {
  301. qla_printk(KERN_WARNING, ha,
  302. "Can't create request queue\n");
  303. goto fail;
  304. }
  305. ha->wq = create_workqueue("qla2xxx_wq");
  306. vha->req = ha->req_q_map[req];
  307. options |= BIT_1;
  308. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  309. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  310. if (!ret) {
  311. qla_printk(KERN_WARNING, ha,
  312. "Response Queue create failed\n");
  313. goto fail2;
  314. }
  315. }
  316. ha->flags.cpu_affinity_enabled = 1;
  317. DEBUG2(qla_printk(KERN_INFO, ha,
  318. "CPU affinity mode enabled, no. of response"
  319. " queues:%d, no. of request queues:%d\n",
  320. ha->max_rsp_queues, ha->max_req_queues));
  321. }
  322. return 0;
  323. fail2:
  324. qla25xx_delete_queues(vha);
  325. destroy_workqueue(ha->wq);
  326. ha->wq = NULL;
  327. fail:
  328. ha->mqenable = 0;
  329. kfree(ha->req_q_map);
  330. kfree(ha->rsp_q_map);
  331. ha->max_req_queues = ha->max_rsp_queues = 1;
  332. return 1;
  333. }
  334. static char *
  335. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  336. {
  337. struct qla_hw_data *ha = vha->hw;
  338. static char *pci_bus_modes[] = {
  339. "33", "66", "100", "133",
  340. };
  341. uint16_t pci_bus;
  342. strcpy(str, "PCI");
  343. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  344. if (pci_bus) {
  345. strcat(str, "-X (");
  346. strcat(str, pci_bus_modes[pci_bus]);
  347. } else {
  348. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  349. strcat(str, " (");
  350. strcat(str, pci_bus_modes[pci_bus]);
  351. }
  352. strcat(str, " MHz)");
  353. return (str);
  354. }
  355. static char *
  356. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  357. {
  358. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  359. struct qla_hw_data *ha = vha->hw;
  360. uint32_t pci_bus;
  361. int pcie_reg;
  362. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  363. if (pcie_reg) {
  364. char lwstr[6];
  365. uint16_t pcie_lstat, lspeed, lwidth;
  366. pcie_reg += 0x12;
  367. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  368. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  369. lwidth = (pcie_lstat &
  370. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  371. strcpy(str, "PCIe (");
  372. if (lspeed == 1)
  373. strcat(str, "2.5GT/s ");
  374. else if (lspeed == 2)
  375. strcat(str, "5.0GT/s ");
  376. else
  377. strcat(str, "<unknown> ");
  378. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  379. strcat(str, lwstr);
  380. return str;
  381. }
  382. strcpy(str, "PCI");
  383. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  384. if (pci_bus == 0 || pci_bus == 8) {
  385. strcat(str, " (");
  386. strcat(str, pci_bus_modes[pci_bus >> 3]);
  387. } else {
  388. strcat(str, "-X ");
  389. if (pci_bus & BIT_2)
  390. strcat(str, "Mode 2");
  391. else
  392. strcat(str, "Mode 1");
  393. strcat(str, " (");
  394. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  395. }
  396. strcat(str, " MHz)");
  397. return str;
  398. }
  399. static char *
  400. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  401. {
  402. char un_str[10];
  403. struct qla_hw_data *ha = vha->hw;
  404. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  405. ha->fw_minor_version,
  406. ha->fw_subminor_version);
  407. if (ha->fw_attributes & BIT_9) {
  408. strcat(str, "FLX");
  409. return (str);
  410. }
  411. switch (ha->fw_attributes & 0xFF) {
  412. case 0x7:
  413. strcat(str, "EF");
  414. break;
  415. case 0x17:
  416. strcat(str, "TP");
  417. break;
  418. case 0x37:
  419. strcat(str, "IP");
  420. break;
  421. case 0x77:
  422. strcat(str, "VI");
  423. break;
  424. default:
  425. sprintf(un_str, "(%x)", ha->fw_attributes);
  426. strcat(str, un_str);
  427. break;
  428. }
  429. if (ha->fw_attributes & 0x100)
  430. strcat(str, "X");
  431. return (str);
  432. }
  433. static char *
  434. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  435. {
  436. struct qla_hw_data *ha = vha->hw;
  437. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  438. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  439. return str;
  440. }
  441. static inline srb_t *
  442. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  443. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  444. {
  445. srb_t *sp;
  446. struct qla_hw_data *ha = vha->hw;
  447. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  448. if (!sp)
  449. return sp;
  450. atomic_set(&sp->ref_count, 1);
  451. sp->fcport = fcport;
  452. sp->cmd = cmd;
  453. sp->flags = 0;
  454. CMD_SP(cmd) = (void *)sp;
  455. cmd->scsi_done = done;
  456. sp->ctx = NULL;
  457. return sp;
  458. }
  459. static int
  460. qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  461. {
  462. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  463. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  464. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  465. struct qla_hw_data *ha = vha->hw;
  466. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  467. srb_t *sp;
  468. int rval;
  469. spin_unlock_irq(vha->host->host_lock);
  470. if (ha->flags.eeh_busy) {
  471. if (ha->flags.pci_channel_io_perm_failure)
  472. cmd->result = DID_NO_CONNECT << 16;
  473. else
  474. cmd->result = DID_REQUEUE << 16;
  475. goto qc24_fail_command;
  476. }
  477. rval = fc_remote_port_chkready(rport);
  478. if (rval) {
  479. cmd->result = rval;
  480. goto qc24_fail_command;
  481. }
  482. if (!vha->flags.difdix_supported &&
  483. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  484. DEBUG2(qla_printk(KERN_ERR, ha,
  485. "DIF Cap Not Reg, fail DIF capable cmd's:%x\n",
  486. cmd->cmnd[0]));
  487. cmd->result = DID_NO_CONNECT << 16;
  488. goto qc24_fail_command;
  489. }
  490. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  491. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  492. atomic_read(&fcport->state) == FCS_DEVICE_LOST ||
  493. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  494. cmd->result = DID_NO_CONNECT << 16;
  495. goto qc24_fail_command;
  496. }
  497. goto qc24_target_busy;
  498. }
  499. sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
  500. if (!sp)
  501. goto qc24_host_busy_lock;
  502. rval = ha->isp_ops->start_scsi(sp);
  503. if (rval != QLA_SUCCESS)
  504. goto qc24_host_busy_free_sp;
  505. spin_lock_irq(vha->host->host_lock);
  506. return 0;
  507. qc24_host_busy_free_sp:
  508. qla2x00_sp_free_dma(sp);
  509. mempool_free(sp, ha->srb_mempool);
  510. qc24_host_busy_lock:
  511. spin_lock_irq(vha->host->host_lock);
  512. return SCSI_MLQUEUE_HOST_BUSY;
  513. qc24_target_busy:
  514. spin_lock_irq(vha->host->host_lock);
  515. return SCSI_MLQUEUE_TARGET_BUSY;
  516. qc24_fail_command:
  517. spin_lock_irq(vha->host->host_lock);
  518. done(cmd);
  519. return 0;
  520. }
  521. /*
  522. * qla2x00_eh_wait_on_command
  523. * Waits for the command to be returned by the Firmware for some
  524. * max time.
  525. *
  526. * Input:
  527. * cmd = Scsi Command to wait on.
  528. *
  529. * Return:
  530. * Not Found : 0
  531. * Found : 1
  532. */
  533. static int
  534. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  535. {
  536. #define ABORT_POLLING_PERIOD 1000
  537. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  538. unsigned long wait_iter = ABORT_WAIT_ITER;
  539. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  540. struct qla_hw_data *ha = vha->hw;
  541. int ret = QLA_SUCCESS;
  542. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  543. DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
  544. return ret;
  545. }
  546. while (CMD_SP(cmd) && wait_iter--) {
  547. msleep(ABORT_POLLING_PERIOD);
  548. }
  549. if (CMD_SP(cmd))
  550. ret = QLA_FUNCTION_FAILED;
  551. return ret;
  552. }
  553. /*
  554. * qla2x00_wait_for_hba_online
  555. * Wait till the HBA is online after going through
  556. * <= MAX_RETRIES_OF_ISP_ABORT or
  557. * finally HBA is disabled ie marked offline
  558. *
  559. * Input:
  560. * ha - pointer to host adapter structure
  561. *
  562. * Note:
  563. * Does context switching-Release SPIN_LOCK
  564. * (if any) before calling this routine.
  565. *
  566. * Return:
  567. * Success (Adapter is online) : 0
  568. * Failed (Adapter is offline/disabled) : 1
  569. */
  570. int
  571. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  572. {
  573. int return_status;
  574. unsigned long wait_online;
  575. struct qla_hw_data *ha = vha->hw;
  576. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  577. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  578. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  579. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  580. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  581. ha->dpc_active) && time_before(jiffies, wait_online)) {
  582. msleep(1000);
  583. }
  584. if (base_vha->flags.online)
  585. return_status = QLA_SUCCESS;
  586. else
  587. return_status = QLA_FUNCTION_FAILED;
  588. return (return_status);
  589. }
  590. /*
  591. * qla2x00_wait_for_reset_ready
  592. * Wait till the HBA is online after going through
  593. * <= MAX_RETRIES_OF_ISP_ABORT or
  594. * finally HBA is disabled ie marked offline or flash
  595. * operations are in progress.
  596. *
  597. * Input:
  598. * ha - pointer to host adapter structure
  599. *
  600. * Note:
  601. * Does context switching-Release SPIN_LOCK
  602. * (if any) before calling this routine.
  603. *
  604. * Return:
  605. * Success (Adapter is online/no flash ops) : 0
  606. * Failed (Adapter is offline/disabled/flash ops in progress) : 1
  607. */
  608. static int
  609. qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
  610. {
  611. int return_status;
  612. unsigned long wait_online;
  613. struct qla_hw_data *ha = vha->hw;
  614. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  615. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  616. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  617. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  618. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  619. ha->optrom_state != QLA_SWAITING ||
  620. ha->dpc_active) && time_before(jiffies, wait_online))
  621. msleep(1000);
  622. if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
  623. return_status = QLA_SUCCESS;
  624. else
  625. return_status = QLA_FUNCTION_FAILED;
  626. DEBUG2(printk("%s return_status=%d\n", __func__, return_status));
  627. return return_status;
  628. }
  629. int
  630. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  631. {
  632. int return_status;
  633. unsigned long wait_reset;
  634. struct qla_hw_data *ha = vha->hw;
  635. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  636. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  637. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  638. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  639. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  640. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  641. msleep(1000);
  642. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  643. ha->flags.chip_reset_done)
  644. break;
  645. }
  646. if (ha->flags.chip_reset_done)
  647. return_status = QLA_SUCCESS;
  648. else
  649. return_status = QLA_FUNCTION_FAILED;
  650. return return_status;
  651. }
  652. /*
  653. * qla2x00_wait_for_loop_ready
  654. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  655. * to be in LOOP_READY state.
  656. * Input:
  657. * ha - pointer to host adapter structure
  658. *
  659. * Note:
  660. * Does context switching-Release SPIN_LOCK
  661. * (if any) before calling this routine.
  662. *
  663. *
  664. * Return:
  665. * Success (LOOP_READY) : 0
  666. * Failed (LOOP_NOT_READY) : 1
  667. */
  668. static inline int
  669. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  670. {
  671. int return_status = QLA_SUCCESS;
  672. unsigned long loop_timeout ;
  673. struct qla_hw_data *ha = vha->hw;
  674. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  675. /* wait for 5 min at the max for loop to be ready */
  676. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  677. while ((!atomic_read(&base_vha->loop_down_timer) &&
  678. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  679. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  680. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  681. return_status = QLA_FUNCTION_FAILED;
  682. break;
  683. }
  684. msleep(1000);
  685. if (time_after_eq(jiffies, loop_timeout)) {
  686. return_status = QLA_FUNCTION_FAILED;
  687. break;
  688. }
  689. }
  690. return (return_status);
  691. }
  692. static void
  693. sp_get(struct srb *sp)
  694. {
  695. atomic_inc(&sp->ref_count);
  696. }
  697. /**************************************************************************
  698. * qla2xxx_eh_abort
  699. *
  700. * Description:
  701. * The abort function will abort the specified command.
  702. *
  703. * Input:
  704. * cmd = Linux SCSI command packet to be aborted.
  705. *
  706. * Returns:
  707. * Either SUCCESS or FAILED.
  708. *
  709. * Note:
  710. * Only return FAILED if command not returned by firmware.
  711. **************************************************************************/
  712. static int
  713. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  714. {
  715. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  716. srb_t *sp;
  717. int ret;
  718. unsigned int id, lun;
  719. unsigned long flags;
  720. int wait = 0;
  721. struct qla_hw_data *ha = vha->hw;
  722. fc_block_scsi_eh(cmd);
  723. if (!CMD_SP(cmd))
  724. return SUCCESS;
  725. id = cmd->device->id;
  726. lun = cmd->device->lun;
  727. spin_lock_irqsave(&ha->hardware_lock, flags);
  728. sp = (srb_t *) CMD_SP(cmd);
  729. if (!sp) {
  730. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  731. return SUCCESS;
  732. }
  733. DEBUG2(printk("%s(%ld): aborting sp %p from RISC.",
  734. __func__, vha->host_no, sp));
  735. /* Get a reference to the sp and drop the lock.*/
  736. sp_get(sp);
  737. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  738. if (ha->isp_ops->abort_command(sp)) {
  739. DEBUG2(printk("%s(%ld): abort_command "
  740. "mbx failed.\n", __func__, vha->host_no));
  741. ret = FAILED;
  742. } else {
  743. DEBUG3(printk("%s(%ld): abort_command "
  744. "mbx success.\n", __func__, vha->host_no));
  745. wait = 1;
  746. }
  747. qla2x00_sp_compl(ha, sp);
  748. /* Wait for the command to be returned. */
  749. if (wait) {
  750. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  751. qla_printk(KERN_ERR, ha,
  752. "scsi(%ld:%d:%d): Abort handler timed out -- %x.\n",
  753. vha->host_no, id, lun, ret);
  754. ret = FAILED;
  755. }
  756. }
  757. qla_printk(KERN_INFO, ha,
  758. "scsi(%ld:%d:%d): Abort command issued -- %d %x.\n",
  759. vha->host_no, id, lun, wait, ret);
  760. return ret;
  761. }
  762. int
  763. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  764. unsigned int l, enum nexus_wait_type type)
  765. {
  766. int cnt, match, status;
  767. unsigned long flags;
  768. struct qla_hw_data *ha = vha->hw;
  769. struct req_que *req;
  770. srb_t *sp;
  771. status = QLA_SUCCESS;
  772. spin_lock_irqsave(&ha->hardware_lock, flags);
  773. req = vha->req;
  774. for (cnt = 1; status == QLA_SUCCESS &&
  775. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  776. sp = req->outstanding_cmds[cnt];
  777. if (!sp)
  778. continue;
  779. if ((sp->ctx) && !IS_PROT_IO(sp))
  780. continue;
  781. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  782. continue;
  783. match = 0;
  784. switch (type) {
  785. case WAIT_HOST:
  786. match = 1;
  787. break;
  788. case WAIT_TARGET:
  789. match = sp->cmd->device->id == t;
  790. break;
  791. case WAIT_LUN:
  792. match = (sp->cmd->device->id == t &&
  793. sp->cmd->device->lun == l);
  794. break;
  795. }
  796. if (!match)
  797. continue;
  798. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  799. status = qla2x00_eh_wait_on_command(sp->cmd);
  800. spin_lock_irqsave(&ha->hardware_lock, flags);
  801. }
  802. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  803. return status;
  804. }
  805. static char *reset_errors[] = {
  806. "HBA not online",
  807. "HBA not ready",
  808. "Task management failed",
  809. "Waiting for command completions",
  810. };
  811. static int
  812. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  813. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  814. {
  815. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  816. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  817. int err;
  818. fc_block_scsi_eh(cmd);
  819. if (!fcport)
  820. return FAILED;
  821. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
  822. vha->host_no, cmd->device->id, cmd->device->lun, name);
  823. err = 0;
  824. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  825. goto eh_reset_failed;
  826. err = 1;
  827. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
  828. goto eh_reset_failed;
  829. err = 2;
  830. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  831. != QLA_SUCCESS)
  832. goto eh_reset_failed;
  833. err = 3;
  834. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  835. cmd->device->lun, type) != QLA_SUCCESS)
  836. goto eh_reset_failed;
  837. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
  838. vha->host_no, cmd->device->id, cmd->device->lun, name);
  839. return SUCCESS;
  840. eh_reset_failed:
  841. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
  842. , vha->host_no, cmd->device->id, cmd->device->lun, name,
  843. reset_errors[err]);
  844. return FAILED;
  845. }
  846. static int
  847. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  848. {
  849. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  850. struct qla_hw_data *ha = vha->hw;
  851. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  852. ha->isp_ops->lun_reset);
  853. }
  854. static int
  855. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  856. {
  857. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  858. struct qla_hw_data *ha = vha->hw;
  859. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  860. ha->isp_ops->target_reset);
  861. }
  862. /**************************************************************************
  863. * qla2xxx_eh_bus_reset
  864. *
  865. * Description:
  866. * The bus reset function will reset the bus and abort any executing
  867. * commands.
  868. *
  869. * Input:
  870. * cmd = Linux SCSI command packet of the command that cause the
  871. * bus reset.
  872. *
  873. * Returns:
  874. * SUCCESS/FAILURE (defined as macro in scsi.h).
  875. *
  876. **************************************************************************/
  877. static int
  878. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  879. {
  880. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  881. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  882. int ret = FAILED;
  883. unsigned int id, lun;
  884. fc_block_scsi_eh(cmd);
  885. id = cmd->device->id;
  886. lun = cmd->device->lun;
  887. if (!fcport)
  888. return ret;
  889. qla_printk(KERN_INFO, vha->hw,
  890. "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
  891. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  892. DEBUG2(printk("%s failed:board disabled\n",__func__));
  893. goto eh_bus_reset_done;
  894. }
  895. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  896. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  897. ret = SUCCESS;
  898. }
  899. if (ret == FAILED)
  900. goto eh_bus_reset_done;
  901. /* Flush outstanding commands. */
  902. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  903. QLA_SUCCESS)
  904. ret = FAILED;
  905. eh_bus_reset_done:
  906. qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
  907. (ret == FAILED) ? "failed" : "succeded");
  908. return ret;
  909. }
  910. /**************************************************************************
  911. * qla2xxx_eh_host_reset
  912. *
  913. * Description:
  914. * The reset function will reset the Adapter.
  915. *
  916. * Input:
  917. * cmd = Linux SCSI command packet of the command that cause the
  918. * adapter reset.
  919. *
  920. * Returns:
  921. * Either SUCCESS or FAILED.
  922. *
  923. * Note:
  924. **************************************************************************/
  925. static int
  926. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  927. {
  928. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  929. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  930. struct qla_hw_data *ha = vha->hw;
  931. int ret = FAILED;
  932. unsigned int id, lun;
  933. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  934. fc_block_scsi_eh(cmd);
  935. id = cmd->device->id;
  936. lun = cmd->device->lun;
  937. if (!fcport)
  938. return ret;
  939. qla_printk(KERN_INFO, ha,
  940. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
  941. if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
  942. goto eh_host_reset_lock;
  943. /*
  944. * Fixme-may be dpc thread is active and processing
  945. * loop_resync,so wait a while for it to
  946. * be completed and then issue big hammer.Otherwise
  947. * it may cause I/O failure as big hammer marks the
  948. * devices as lost kicking of the port_down_timer
  949. * while dpc is stuck for the mailbox to complete.
  950. */
  951. qla2x00_wait_for_loop_ready(vha);
  952. if (vha != base_vha) {
  953. if (qla2x00_vp_abort_isp(vha))
  954. goto eh_host_reset_lock;
  955. } else {
  956. if (IS_QLA82XX(vha->hw)) {
  957. if (!qla82xx_fcoe_ctx_reset(vha)) {
  958. /* Ctx reset success */
  959. ret = SUCCESS;
  960. goto eh_host_reset_lock;
  961. }
  962. /* fall thru if ctx reset failed */
  963. }
  964. if (ha->wq)
  965. flush_workqueue(ha->wq);
  966. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  967. if (ha->isp_ops->abort_isp(base_vha)) {
  968. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  969. /* failed. schedule dpc to try */
  970. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  971. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  972. goto eh_host_reset_lock;
  973. }
  974. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  975. }
  976. /* Waiting for command to be returned to OS.*/
  977. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  978. QLA_SUCCESS)
  979. ret = SUCCESS;
  980. eh_host_reset_lock:
  981. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  982. (ret == FAILED) ? "failed" : "succeded");
  983. return ret;
  984. }
  985. /*
  986. * qla2x00_loop_reset
  987. * Issue loop reset.
  988. *
  989. * Input:
  990. * ha = adapter block pointer.
  991. *
  992. * Returns:
  993. * 0 = success
  994. */
  995. int
  996. qla2x00_loop_reset(scsi_qla_host_t *vha)
  997. {
  998. int ret;
  999. struct fc_port *fcport;
  1000. struct qla_hw_data *ha = vha->hw;
  1001. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1002. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1003. if (fcport->port_type != FCT_TARGET)
  1004. continue;
  1005. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1006. if (ret != QLA_SUCCESS) {
  1007. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  1008. "target_reset=%d d_id=%x.\n", __func__,
  1009. vha->host_no, ret, fcport->d_id.b24));
  1010. }
  1011. }
  1012. }
  1013. if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
  1014. ret = qla2x00_full_login_lip(vha);
  1015. if (ret != QLA_SUCCESS) {
  1016. DEBUG2_3(printk("%s(%ld): failed: "
  1017. "full_login_lip=%d.\n", __func__, vha->host_no,
  1018. ret));
  1019. }
  1020. atomic_set(&vha->loop_state, LOOP_DOWN);
  1021. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1022. qla2x00_mark_all_devices_lost(vha, 0);
  1023. qla2x00_wait_for_loop_ready(vha);
  1024. }
  1025. if (ha->flags.enable_lip_reset) {
  1026. ret = qla2x00_lip_reset(vha);
  1027. if (ret != QLA_SUCCESS) {
  1028. DEBUG2_3(printk("%s(%ld): failed: "
  1029. "lip_reset=%d.\n", __func__, vha->host_no, ret));
  1030. } else
  1031. qla2x00_wait_for_loop_ready(vha);
  1032. }
  1033. /* Issue marker command only when we are going to start the I/O */
  1034. vha->marker_needed = 1;
  1035. return QLA_SUCCESS;
  1036. }
  1037. void
  1038. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1039. {
  1040. int que, cnt;
  1041. unsigned long flags;
  1042. srb_t *sp;
  1043. struct srb_ctx *ctx;
  1044. struct qla_hw_data *ha = vha->hw;
  1045. struct req_que *req;
  1046. spin_lock_irqsave(&ha->hardware_lock, flags);
  1047. for (que = 0; que < ha->max_req_queues; que++) {
  1048. req = ha->req_q_map[que];
  1049. if (!req)
  1050. continue;
  1051. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  1052. sp = req->outstanding_cmds[cnt];
  1053. if (sp) {
  1054. req->outstanding_cmds[cnt] = NULL;
  1055. if (!sp->ctx ||
  1056. (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
  1057. IS_PROT_IO(sp)) {
  1058. sp->cmd->result = res;
  1059. qla2x00_sp_compl(ha, sp);
  1060. } else {
  1061. ctx = sp->ctx;
  1062. if (ctx->type == SRB_LOGIN_CMD ||
  1063. ctx->type == SRB_LOGOUT_CMD) {
  1064. ctx->u.iocb_cmd->free(sp);
  1065. } else {
  1066. struct fc_bsg_job *bsg_job =
  1067. ctx->u.bsg_job;
  1068. if (bsg_job->request->msgcode
  1069. == FC_BSG_HST_CT)
  1070. kfree(sp->fcport);
  1071. bsg_job->req->errors = 0;
  1072. bsg_job->reply->result = res;
  1073. bsg_job->job_done(bsg_job);
  1074. kfree(sp->ctx);
  1075. mempool_free(sp,
  1076. ha->srb_mempool);
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1083. }
  1084. static int
  1085. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1086. {
  1087. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1088. if (!rport || fc_remote_port_chkready(rport))
  1089. return -ENXIO;
  1090. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1091. return 0;
  1092. }
  1093. static int
  1094. qla2xxx_slave_configure(struct scsi_device *sdev)
  1095. {
  1096. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1097. struct req_que *req = vha->req;
  1098. if (sdev->tagged_supported)
  1099. scsi_activate_tcq(sdev, req->max_q_depth);
  1100. else
  1101. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1102. return 0;
  1103. }
  1104. static void
  1105. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1106. {
  1107. sdev->hostdata = NULL;
  1108. }
  1109. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1110. {
  1111. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1112. if (!scsi_track_queue_full(sdev, qdepth))
  1113. return;
  1114. DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
  1115. "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
  1116. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1117. sdev->queue_depth));
  1118. }
  1119. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1120. {
  1121. fc_port_t *fcport = sdev->hostdata;
  1122. struct scsi_qla_host *vha = fcport->vha;
  1123. struct qla_hw_data *ha = vha->hw;
  1124. struct req_que *req = NULL;
  1125. req = vha->req;
  1126. if (!req)
  1127. return;
  1128. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1129. return;
  1130. if (sdev->ordered_tags)
  1131. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1132. else
  1133. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1134. DEBUG2(qla_printk(KERN_INFO, ha,
  1135. "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
  1136. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1137. sdev->queue_depth));
  1138. }
  1139. static int
  1140. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1141. {
  1142. switch (reason) {
  1143. case SCSI_QDEPTH_DEFAULT:
  1144. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1145. break;
  1146. case SCSI_QDEPTH_QFULL:
  1147. qla2x00_handle_queue_full(sdev, qdepth);
  1148. break;
  1149. case SCSI_QDEPTH_RAMP_UP:
  1150. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1151. break;
  1152. default:
  1153. return -EOPNOTSUPP;
  1154. }
  1155. return sdev->queue_depth;
  1156. }
  1157. static int
  1158. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1159. {
  1160. if (sdev->tagged_supported) {
  1161. scsi_set_tag_type(sdev, tag_type);
  1162. if (tag_type)
  1163. scsi_activate_tcq(sdev, sdev->queue_depth);
  1164. else
  1165. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1166. } else
  1167. tag_type = 0;
  1168. return tag_type;
  1169. }
  1170. /**
  1171. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1172. * @ha: HA context
  1173. *
  1174. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1175. * supported addressing method.
  1176. */
  1177. static void
  1178. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1179. {
  1180. /* Assume a 32bit DMA mask. */
  1181. ha->flags.enable_64bit_addressing = 0;
  1182. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1183. /* Any upper-dword bits set? */
  1184. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1185. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1186. /* Ok, a 64bit DMA mask is applicable. */
  1187. ha->flags.enable_64bit_addressing = 1;
  1188. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1189. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1190. return;
  1191. }
  1192. }
  1193. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1194. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1195. }
  1196. static void
  1197. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1198. {
  1199. unsigned long flags = 0;
  1200. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1201. spin_lock_irqsave(&ha->hardware_lock, flags);
  1202. ha->interrupts_on = 1;
  1203. /* enable risc and host interrupts */
  1204. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1205. RD_REG_WORD(&reg->ictrl);
  1206. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1207. }
  1208. static void
  1209. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1210. {
  1211. unsigned long flags = 0;
  1212. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1213. spin_lock_irqsave(&ha->hardware_lock, flags);
  1214. ha->interrupts_on = 0;
  1215. /* disable risc and host interrupts */
  1216. WRT_REG_WORD(&reg->ictrl, 0);
  1217. RD_REG_WORD(&reg->ictrl);
  1218. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1219. }
  1220. static void
  1221. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1222. {
  1223. unsigned long flags = 0;
  1224. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1225. spin_lock_irqsave(&ha->hardware_lock, flags);
  1226. ha->interrupts_on = 1;
  1227. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1228. RD_REG_DWORD(&reg->ictrl);
  1229. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1230. }
  1231. static void
  1232. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1233. {
  1234. unsigned long flags = 0;
  1235. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1236. if (IS_NOPOLLING_TYPE(ha))
  1237. return;
  1238. spin_lock_irqsave(&ha->hardware_lock, flags);
  1239. ha->interrupts_on = 0;
  1240. WRT_REG_DWORD(&reg->ictrl, 0);
  1241. RD_REG_DWORD(&reg->ictrl);
  1242. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1243. }
  1244. static struct isp_operations qla2100_isp_ops = {
  1245. .pci_config = qla2100_pci_config,
  1246. .reset_chip = qla2x00_reset_chip,
  1247. .chip_diag = qla2x00_chip_diag,
  1248. .config_rings = qla2x00_config_rings,
  1249. .reset_adapter = qla2x00_reset_adapter,
  1250. .nvram_config = qla2x00_nvram_config,
  1251. .update_fw_options = qla2x00_update_fw_options,
  1252. .load_risc = qla2x00_load_risc,
  1253. .pci_info_str = qla2x00_pci_info_str,
  1254. .fw_version_str = qla2x00_fw_version_str,
  1255. .intr_handler = qla2100_intr_handler,
  1256. .enable_intrs = qla2x00_enable_intrs,
  1257. .disable_intrs = qla2x00_disable_intrs,
  1258. .abort_command = qla2x00_abort_command,
  1259. .target_reset = qla2x00_abort_target,
  1260. .lun_reset = qla2x00_lun_reset,
  1261. .fabric_login = qla2x00_login_fabric,
  1262. .fabric_logout = qla2x00_fabric_logout,
  1263. .calc_req_entries = qla2x00_calc_iocbs_32,
  1264. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1265. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1266. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1267. .read_nvram = qla2x00_read_nvram_data,
  1268. .write_nvram = qla2x00_write_nvram_data,
  1269. .fw_dump = qla2100_fw_dump,
  1270. .beacon_on = NULL,
  1271. .beacon_off = NULL,
  1272. .beacon_blink = NULL,
  1273. .read_optrom = qla2x00_read_optrom_data,
  1274. .write_optrom = qla2x00_write_optrom_data,
  1275. .get_flash_version = qla2x00_get_flash_version,
  1276. .start_scsi = qla2x00_start_scsi,
  1277. .abort_isp = qla2x00_abort_isp,
  1278. };
  1279. static struct isp_operations qla2300_isp_ops = {
  1280. .pci_config = qla2300_pci_config,
  1281. .reset_chip = qla2x00_reset_chip,
  1282. .chip_diag = qla2x00_chip_diag,
  1283. .config_rings = qla2x00_config_rings,
  1284. .reset_adapter = qla2x00_reset_adapter,
  1285. .nvram_config = qla2x00_nvram_config,
  1286. .update_fw_options = qla2x00_update_fw_options,
  1287. .load_risc = qla2x00_load_risc,
  1288. .pci_info_str = qla2x00_pci_info_str,
  1289. .fw_version_str = qla2x00_fw_version_str,
  1290. .intr_handler = qla2300_intr_handler,
  1291. .enable_intrs = qla2x00_enable_intrs,
  1292. .disable_intrs = qla2x00_disable_intrs,
  1293. .abort_command = qla2x00_abort_command,
  1294. .target_reset = qla2x00_abort_target,
  1295. .lun_reset = qla2x00_lun_reset,
  1296. .fabric_login = qla2x00_login_fabric,
  1297. .fabric_logout = qla2x00_fabric_logout,
  1298. .calc_req_entries = qla2x00_calc_iocbs_32,
  1299. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1300. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1301. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1302. .read_nvram = qla2x00_read_nvram_data,
  1303. .write_nvram = qla2x00_write_nvram_data,
  1304. .fw_dump = qla2300_fw_dump,
  1305. .beacon_on = qla2x00_beacon_on,
  1306. .beacon_off = qla2x00_beacon_off,
  1307. .beacon_blink = qla2x00_beacon_blink,
  1308. .read_optrom = qla2x00_read_optrom_data,
  1309. .write_optrom = qla2x00_write_optrom_data,
  1310. .get_flash_version = qla2x00_get_flash_version,
  1311. .start_scsi = qla2x00_start_scsi,
  1312. .abort_isp = qla2x00_abort_isp,
  1313. };
  1314. static struct isp_operations qla24xx_isp_ops = {
  1315. .pci_config = qla24xx_pci_config,
  1316. .reset_chip = qla24xx_reset_chip,
  1317. .chip_diag = qla24xx_chip_diag,
  1318. .config_rings = qla24xx_config_rings,
  1319. .reset_adapter = qla24xx_reset_adapter,
  1320. .nvram_config = qla24xx_nvram_config,
  1321. .update_fw_options = qla24xx_update_fw_options,
  1322. .load_risc = qla24xx_load_risc,
  1323. .pci_info_str = qla24xx_pci_info_str,
  1324. .fw_version_str = qla24xx_fw_version_str,
  1325. .intr_handler = qla24xx_intr_handler,
  1326. .enable_intrs = qla24xx_enable_intrs,
  1327. .disable_intrs = qla24xx_disable_intrs,
  1328. .abort_command = qla24xx_abort_command,
  1329. .target_reset = qla24xx_abort_target,
  1330. .lun_reset = qla24xx_lun_reset,
  1331. .fabric_login = qla24xx_login_fabric,
  1332. .fabric_logout = qla24xx_fabric_logout,
  1333. .calc_req_entries = NULL,
  1334. .build_iocbs = NULL,
  1335. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1336. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1337. .read_nvram = qla24xx_read_nvram_data,
  1338. .write_nvram = qla24xx_write_nvram_data,
  1339. .fw_dump = qla24xx_fw_dump,
  1340. .beacon_on = qla24xx_beacon_on,
  1341. .beacon_off = qla24xx_beacon_off,
  1342. .beacon_blink = qla24xx_beacon_blink,
  1343. .read_optrom = qla24xx_read_optrom_data,
  1344. .write_optrom = qla24xx_write_optrom_data,
  1345. .get_flash_version = qla24xx_get_flash_version,
  1346. .start_scsi = qla24xx_start_scsi,
  1347. .abort_isp = qla2x00_abort_isp,
  1348. };
  1349. static struct isp_operations qla25xx_isp_ops = {
  1350. .pci_config = qla25xx_pci_config,
  1351. .reset_chip = qla24xx_reset_chip,
  1352. .chip_diag = qla24xx_chip_diag,
  1353. .config_rings = qla24xx_config_rings,
  1354. .reset_adapter = qla24xx_reset_adapter,
  1355. .nvram_config = qla24xx_nvram_config,
  1356. .update_fw_options = qla24xx_update_fw_options,
  1357. .load_risc = qla24xx_load_risc,
  1358. .pci_info_str = qla24xx_pci_info_str,
  1359. .fw_version_str = qla24xx_fw_version_str,
  1360. .intr_handler = qla24xx_intr_handler,
  1361. .enable_intrs = qla24xx_enable_intrs,
  1362. .disable_intrs = qla24xx_disable_intrs,
  1363. .abort_command = qla24xx_abort_command,
  1364. .target_reset = qla24xx_abort_target,
  1365. .lun_reset = qla24xx_lun_reset,
  1366. .fabric_login = qla24xx_login_fabric,
  1367. .fabric_logout = qla24xx_fabric_logout,
  1368. .calc_req_entries = NULL,
  1369. .build_iocbs = NULL,
  1370. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1371. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1372. .read_nvram = qla25xx_read_nvram_data,
  1373. .write_nvram = qla25xx_write_nvram_data,
  1374. .fw_dump = qla25xx_fw_dump,
  1375. .beacon_on = qla24xx_beacon_on,
  1376. .beacon_off = qla24xx_beacon_off,
  1377. .beacon_blink = qla24xx_beacon_blink,
  1378. .read_optrom = qla25xx_read_optrom_data,
  1379. .write_optrom = qla24xx_write_optrom_data,
  1380. .get_flash_version = qla24xx_get_flash_version,
  1381. .start_scsi = qla24xx_dif_start_scsi,
  1382. .abort_isp = qla2x00_abort_isp,
  1383. };
  1384. static struct isp_operations qla81xx_isp_ops = {
  1385. .pci_config = qla25xx_pci_config,
  1386. .reset_chip = qla24xx_reset_chip,
  1387. .chip_diag = qla24xx_chip_diag,
  1388. .config_rings = qla24xx_config_rings,
  1389. .reset_adapter = qla24xx_reset_adapter,
  1390. .nvram_config = qla81xx_nvram_config,
  1391. .update_fw_options = qla81xx_update_fw_options,
  1392. .load_risc = qla81xx_load_risc,
  1393. .pci_info_str = qla24xx_pci_info_str,
  1394. .fw_version_str = qla24xx_fw_version_str,
  1395. .intr_handler = qla24xx_intr_handler,
  1396. .enable_intrs = qla24xx_enable_intrs,
  1397. .disable_intrs = qla24xx_disable_intrs,
  1398. .abort_command = qla24xx_abort_command,
  1399. .target_reset = qla24xx_abort_target,
  1400. .lun_reset = qla24xx_lun_reset,
  1401. .fabric_login = qla24xx_login_fabric,
  1402. .fabric_logout = qla24xx_fabric_logout,
  1403. .calc_req_entries = NULL,
  1404. .build_iocbs = NULL,
  1405. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1406. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1407. .read_nvram = NULL,
  1408. .write_nvram = NULL,
  1409. .fw_dump = qla81xx_fw_dump,
  1410. .beacon_on = qla24xx_beacon_on,
  1411. .beacon_off = qla24xx_beacon_off,
  1412. .beacon_blink = qla24xx_beacon_blink,
  1413. .read_optrom = qla25xx_read_optrom_data,
  1414. .write_optrom = qla24xx_write_optrom_data,
  1415. .get_flash_version = qla24xx_get_flash_version,
  1416. .start_scsi = qla24xx_dif_start_scsi,
  1417. .abort_isp = qla2x00_abort_isp,
  1418. };
  1419. static struct isp_operations qla82xx_isp_ops = {
  1420. .pci_config = qla82xx_pci_config,
  1421. .reset_chip = qla82xx_reset_chip,
  1422. .chip_diag = qla24xx_chip_diag,
  1423. .config_rings = qla82xx_config_rings,
  1424. .reset_adapter = qla24xx_reset_adapter,
  1425. .nvram_config = qla81xx_nvram_config,
  1426. .update_fw_options = qla24xx_update_fw_options,
  1427. .load_risc = qla82xx_load_risc,
  1428. .pci_info_str = qla82xx_pci_info_str,
  1429. .fw_version_str = qla24xx_fw_version_str,
  1430. .intr_handler = qla82xx_intr_handler,
  1431. .enable_intrs = qla82xx_enable_intrs,
  1432. .disable_intrs = qla82xx_disable_intrs,
  1433. .abort_command = qla24xx_abort_command,
  1434. .target_reset = qla24xx_abort_target,
  1435. .lun_reset = qla24xx_lun_reset,
  1436. .fabric_login = qla24xx_login_fabric,
  1437. .fabric_logout = qla24xx_fabric_logout,
  1438. .calc_req_entries = NULL,
  1439. .build_iocbs = NULL,
  1440. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1441. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1442. .read_nvram = qla24xx_read_nvram_data,
  1443. .write_nvram = qla24xx_write_nvram_data,
  1444. .fw_dump = qla24xx_fw_dump,
  1445. .beacon_on = qla24xx_beacon_on,
  1446. .beacon_off = qla24xx_beacon_off,
  1447. .beacon_blink = qla24xx_beacon_blink,
  1448. .read_optrom = qla82xx_read_optrom_data,
  1449. .write_optrom = qla82xx_write_optrom_data,
  1450. .get_flash_version = qla24xx_get_flash_version,
  1451. .start_scsi = qla82xx_start_scsi,
  1452. .abort_isp = qla82xx_abort_isp,
  1453. };
  1454. static inline void
  1455. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1456. {
  1457. ha->device_type = DT_EXTENDED_IDS;
  1458. switch (ha->pdev->device) {
  1459. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1460. ha->device_type |= DT_ISP2100;
  1461. ha->device_type &= ~DT_EXTENDED_IDS;
  1462. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1463. break;
  1464. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1465. ha->device_type |= DT_ISP2200;
  1466. ha->device_type &= ~DT_EXTENDED_IDS;
  1467. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1468. break;
  1469. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1470. ha->device_type |= DT_ISP2300;
  1471. ha->device_type |= DT_ZIO_SUPPORTED;
  1472. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1473. break;
  1474. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1475. ha->device_type |= DT_ISP2312;
  1476. ha->device_type |= DT_ZIO_SUPPORTED;
  1477. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1478. break;
  1479. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1480. ha->device_type |= DT_ISP2322;
  1481. ha->device_type |= DT_ZIO_SUPPORTED;
  1482. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1483. ha->pdev->subsystem_device == 0x0170)
  1484. ha->device_type |= DT_OEM_001;
  1485. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1486. break;
  1487. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1488. ha->device_type |= DT_ISP6312;
  1489. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1490. break;
  1491. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1492. ha->device_type |= DT_ISP6322;
  1493. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1494. break;
  1495. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1496. ha->device_type |= DT_ISP2422;
  1497. ha->device_type |= DT_ZIO_SUPPORTED;
  1498. ha->device_type |= DT_FWI2;
  1499. ha->device_type |= DT_IIDMA;
  1500. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1501. break;
  1502. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1503. ha->device_type |= DT_ISP2432;
  1504. ha->device_type |= DT_ZIO_SUPPORTED;
  1505. ha->device_type |= DT_FWI2;
  1506. ha->device_type |= DT_IIDMA;
  1507. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1508. break;
  1509. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1510. ha->device_type |= DT_ISP8432;
  1511. ha->device_type |= DT_ZIO_SUPPORTED;
  1512. ha->device_type |= DT_FWI2;
  1513. ha->device_type |= DT_IIDMA;
  1514. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1515. break;
  1516. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1517. ha->device_type |= DT_ISP5422;
  1518. ha->device_type |= DT_FWI2;
  1519. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1520. break;
  1521. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1522. ha->device_type |= DT_ISP5432;
  1523. ha->device_type |= DT_FWI2;
  1524. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1525. break;
  1526. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1527. ha->device_type |= DT_ISP2532;
  1528. ha->device_type |= DT_ZIO_SUPPORTED;
  1529. ha->device_type |= DT_FWI2;
  1530. ha->device_type |= DT_IIDMA;
  1531. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1532. break;
  1533. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1534. ha->device_type |= DT_ISP8001;
  1535. ha->device_type |= DT_ZIO_SUPPORTED;
  1536. ha->device_type |= DT_FWI2;
  1537. ha->device_type |= DT_IIDMA;
  1538. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1539. break;
  1540. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  1541. ha->device_type |= DT_ISP8021;
  1542. ha->device_type |= DT_ZIO_SUPPORTED;
  1543. ha->device_type |= DT_FWI2;
  1544. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1545. /* Initialize 82XX ISP flags */
  1546. qla82xx_init_flags(ha);
  1547. break;
  1548. }
  1549. if (IS_QLA82XX(ha))
  1550. ha->port_no = !(ha->portnum & 1);
  1551. else
  1552. /* Get adapter physical port no from interrupt pin register. */
  1553. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1554. if (ha->port_no & 1)
  1555. ha->flags.port0 = 1;
  1556. else
  1557. ha->flags.port0 = 0;
  1558. }
  1559. static int
  1560. qla2x00_iospace_config(struct qla_hw_data *ha)
  1561. {
  1562. resource_size_t pio;
  1563. uint16_t msix;
  1564. int cpus;
  1565. if (IS_QLA82XX(ha))
  1566. return qla82xx_iospace_config(ha);
  1567. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1568. QLA2XXX_DRIVER_NAME)) {
  1569. qla_printk(KERN_WARNING, ha,
  1570. "Failed to reserve PIO/MMIO regions (%s)\n",
  1571. pci_name(ha->pdev));
  1572. goto iospace_error_exit;
  1573. }
  1574. if (!(ha->bars & 1))
  1575. goto skip_pio;
  1576. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1577. pio = pci_resource_start(ha->pdev, 0);
  1578. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1579. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1580. qla_printk(KERN_WARNING, ha,
  1581. "Invalid PCI I/O region size (%s)...\n",
  1582. pci_name(ha->pdev));
  1583. pio = 0;
  1584. }
  1585. } else {
  1586. qla_printk(KERN_WARNING, ha,
  1587. "region #0 not a PIO resource (%s)...\n",
  1588. pci_name(ha->pdev));
  1589. pio = 0;
  1590. }
  1591. ha->pio_address = pio;
  1592. skip_pio:
  1593. /* Use MMIO operations for all accesses. */
  1594. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1595. qla_printk(KERN_ERR, ha,
  1596. "region #1 not an MMIO resource (%s), aborting\n",
  1597. pci_name(ha->pdev));
  1598. goto iospace_error_exit;
  1599. }
  1600. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1601. qla_printk(KERN_ERR, ha,
  1602. "Invalid PCI mem region size (%s), aborting\n",
  1603. pci_name(ha->pdev));
  1604. goto iospace_error_exit;
  1605. }
  1606. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1607. if (!ha->iobase) {
  1608. qla_printk(KERN_ERR, ha,
  1609. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1610. goto iospace_error_exit;
  1611. }
  1612. /* Determine queue resources */
  1613. ha->max_req_queues = ha->max_rsp_queues = 1;
  1614. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1615. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1616. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1617. goto mqiobase_exit;
  1618. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1619. pci_resource_len(ha->pdev, 3));
  1620. if (ha->mqiobase) {
  1621. /* Read MSIX vector size of the board */
  1622. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1623. ha->msix_count = msix;
  1624. /* Max queues are bounded by available msix vectors */
  1625. /* queue 0 uses two msix vectors */
  1626. if (ql2xmultique_tag) {
  1627. cpus = num_online_cpus();
  1628. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1629. (cpus + 1) : (ha->msix_count - 1);
  1630. ha->max_req_queues = 2;
  1631. } else if (ql2xmaxqueues > 1) {
  1632. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1633. QLA_MQ_SIZE : ql2xmaxqueues;
  1634. DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
  1635. " of request queues:%d\n", ha->max_req_queues));
  1636. }
  1637. qla_printk(KERN_INFO, ha,
  1638. "MSI-X vector count: %d\n", msix);
  1639. } else
  1640. qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
  1641. mqiobase_exit:
  1642. ha->msix_count = ha->max_rsp_queues + 1;
  1643. return (0);
  1644. iospace_error_exit:
  1645. return (-ENOMEM);
  1646. }
  1647. static void
  1648. qla2xxx_scan_start(struct Scsi_Host *shost)
  1649. {
  1650. scsi_qla_host_t *vha = shost_priv(shost);
  1651. if (vha->hw->flags.running_gold_fw)
  1652. return;
  1653. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1654. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1655. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1656. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1657. }
  1658. static int
  1659. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1660. {
  1661. scsi_qla_host_t *vha = shost_priv(shost);
  1662. if (!vha->host)
  1663. return 1;
  1664. if (time > vha->hw->loop_reset_delay * HZ)
  1665. return 1;
  1666. return atomic_read(&vha->loop_state) == LOOP_READY;
  1667. }
  1668. /*
  1669. * PCI driver interface
  1670. */
  1671. static int __devinit
  1672. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1673. {
  1674. int ret = -ENODEV;
  1675. struct Scsi_Host *host;
  1676. scsi_qla_host_t *base_vha = NULL;
  1677. struct qla_hw_data *ha;
  1678. char pci_info[30];
  1679. char fw_str[30];
  1680. struct scsi_host_template *sht;
  1681. int bars, max_id, mem_only = 0;
  1682. uint16_t req_length = 0, rsp_length = 0;
  1683. struct req_que *req = NULL;
  1684. struct rsp_que *rsp = NULL;
  1685. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1686. sht = &qla2xxx_driver_template;
  1687. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1688. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1689. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1690. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1691. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1692. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1693. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  1694. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
  1695. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1696. mem_only = 1;
  1697. }
  1698. if (mem_only) {
  1699. if (pci_enable_device_mem(pdev))
  1700. goto probe_out;
  1701. } else {
  1702. if (pci_enable_device(pdev))
  1703. goto probe_out;
  1704. }
  1705. /* This may fail but that's ok */
  1706. pci_enable_pcie_error_reporting(pdev);
  1707. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1708. if (!ha) {
  1709. DEBUG(printk("Unable to allocate memory for ha\n"));
  1710. goto probe_out;
  1711. }
  1712. ha->pdev = pdev;
  1713. /* Clear our data area */
  1714. ha->bars = bars;
  1715. ha->mem_only = mem_only;
  1716. spin_lock_init(&ha->hardware_lock);
  1717. spin_lock_init(&ha->vport_slock);
  1718. /* Set ISP-type information. */
  1719. qla2x00_set_isp_flags(ha);
  1720. /* Set EEH reset type to fundamental if required by hba */
  1721. if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
  1722. pdev->needs_freset = 1;
  1723. }
  1724. /* Configure PCI I/O space */
  1725. ret = qla2x00_iospace_config(ha);
  1726. if (ret)
  1727. goto probe_hw_failed;
  1728. qla_printk(KERN_INFO, ha,
  1729. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1730. ha->iobase);
  1731. ha->prev_topology = 0;
  1732. ha->init_cb_size = sizeof(init_cb_t);
  1733. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1734. ha->optrom_size = OPTROM_SIZE_2300;
  1735. /* Assign ISP specific operations. */
  1736. max_id = MAX_TARGETS_2200;
  1737. if (IS_QLA2100(ha)) {
  1738. max_id = MAX_TARGETS_2100;
  1739. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1740. req_length = REQUEST_ENTRY_CNT_2100;
  1741. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1742. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1743. ha->gid_list_info_size = 4;
  1744. ha->flash_conf_off = ~0;
  1745. ha->flash_data_off = ~0;
  1746. ha->nvram_conf_off = ~0;
  1747. ha->nvram_data_off = ~0;
  1748. ha->isp_ops = &qla2100_isp_ops;
  1749. } else if (IS_QLA2200(ha)) {
  1750. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1751. req_length = REQUEST_ENTRY_CNT_2200;
  1752. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1753. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1754. ha->gid_list_info_size = 4;
  1755. ha->flash_conf_off = ~0;
  1756. ha->flash_data_off = ~0;
  1757. ha->nvram_conf_off = ~0;
  1758. ha->nvram_data_off = ~0;
  1759. ha->isp_ops = &qla2100_isp_ops;
  1760. } else if (IS_QLA23XX(ha)) {
  1761. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1762. req_length = REQUEST_ENTRY_CNT_2200;
  1763. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1764. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1765. ha->gid_list_info_size = 6;
  1766. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1767. ha->optrom_size = OPTROM_SIZE_2322;
  1768. ha->flash_conf_off = ~0;
  1769. ha->flash_data_off = ~0;
  1770. ha->nvram_conf_off = ~0;
  1771. ha->nvram_data_off = ~0;
  1772. ha->isp_ops = &qla2300_isp_ops;
  1773. } else if (IS_QLA24XX_TYPE(ha)) {
  1774. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1775. req_length = REQUEST_ENTRY_CNT_24XX;
  1776. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1777. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1778. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1779. ha->gid_list_info_size = 8;
  1780. ha->optrom_size = OPTROM_SIZE_24XX;
  1781. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1782. ha->isp_ops = &qla24xx_isp_ops;
  1783. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1784. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1785. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1786. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1787. } else if (IS_QLA25XX(ha)) {
  1788. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1789. req_length = REQUEST_ENTRY_CNT_24XX;
  1790. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1791. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1792. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1793. ha->gid_list_info_size = 8;
  1794. ha->optrom_size = OPTROM_SIZE_25XX;
  1795. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1796. ha->isp_ops = &qla25xx_isp_ops;
  1797. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1798. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1799. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1800. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1801. } else if (IS_QLA81XX(ha)) {
  1802. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1803. req_length = REQUEST_ENTRY_CNT_24XX;
  1804. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1805. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1806. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1807. ha->gid_list_info_size = 8;
  1808. ha->optrom_size = OPTROM_SIZE_81XX;
  1809. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1810. ha->isp_ops = &qla81xx_isp_ops;
  1811. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1812. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1813. ha->nvram_conf_off = ~0;
  1814. ha->nvram_data_off = ~0;
  1815. } else if (IS_QLA82XX(ha)) {
  1816. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1817. req_length = REQUEST_ENTRY_CNT_82XX;
  1818. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  1819. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1820. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1821. ha->gid_list_info_size = 8;
  1822. ha->optrom_size = OPTROM_SIZE_82XX;
  1823. ha->isp_ops = &qla82xx_isp_ops;
  1824. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1825. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1826. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1827. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1828. }
  1829. mutex_init(&ha->vport_lock);
  1830. init_completion(&ha->mbx_cmd_comp);
  1831. complete(&ha->mbx_cmd_comp);
  1832. init_completion(&ha->mbx_intr_comp);
  1833. init_completion(&ha->dcbx_comp);
  1834. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1835. qla2x00_config_dma_addressing(ha);
  1836. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1837. if (!ret) {
  1838. qla_printk(KERN_WARNING, ha,
  1839. "[ERROR] Failed to allocate memory for adapter\n");
  1840. goto probe_hw_failed;
  1841. }
  1842. req->max_q_depth = MAX_Q_DEPTH;
  1843. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1844. req->max_q_depth = ql2xmaxqdepth;
  1845. base_vha = qla2x00_create_host(sht, ha);
  1846. if (!base_vha) {
  1847. qla_printk(KERN_WARNING, ha,
  1848. "[ERROR] Failed to allocate memory for scsi_host\n");
  1849. ret = -ENOMEM;
  1850. qla2x00_mem_free(ha);
  1851. qla2x00_free_req_que(ha, req);
  1852. qla2x00_free_rsp_que(ha, rsp);
  1853. goto probe_hw_failed;
  1854. }
  1855. pci_set_drvdata(pdev, base_vha);
  1856. host = base_vha->host;
  1857. base_vha->req = req;
  1858. host->can_queue = req->length + 128;
  1859. if (IS_QLA2XXX_MIDTYPE(ha))
  1860. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1861. else
  1862. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1863. base_vha->vp_idx;
  1864. /* Set the SG table size based on ISP type */
  1865. if (!IS_FWI2_CAPABLE(ha)) {
  1866. if (IS_QLA2100(ha))
  1867. host->sg_tablesize = 32;
  1868. } else {
  1869. if (!IS_QLA82XX(ha))
  1870. host->sg_tablesize = QLA_SG_ALL;
  1871. }
  1872. host->max_id = max_id;
  1873. host->this_id = 255;
  1874. host->cmd_per_lun = 3;
  1875. host->unique_id = host->host_no;
  1876. if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif)
  1877. host->max_cmd_len = 32;
  1878. else
  1879. host->max_cmd_len = MAX_CMDSZ;
  1880. host->max_channel = MAX_BUSES - 1;
  1881. host->max_lun = MAX_LUNS;
  1882. host->transportt = qla2xxx_transport_template;
  1883. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  1884. /* Set up the irqs */
  1885. ret = qla2x00_request_irqs(ha, rsp);
  1886. if (ret)
  1887. goto probe_init_failed;
  1888. pci_save_state(pdev);
  1889. /* Alloc arrays of request and response ring ptrs */
  1890. que_init:
  1891. if (!qla2x00_alloc_queues(ha)) {
  1892. qla_printk(KERN_WARNING, ha,
  1893. "[ERROR] Failed to allocate memory for queue"
  1894. " pointers\n");
  1895. goto probe_init_failed;
  1896. }
  1897. ha->rsp_q_map[0] = rsp;
  1898. ha->req_q_map[0] = req;
  1899. rsp->req = req;
  1900. req->rsp = rsp;
  1901. set_bit(0, ha->req_qid_map);
  1902. set_bit(0, ha->rsp_qid_map);
  1903. /* FWI2-capable only. */
  1904. req->req_q_in = &ha->iobase->isp24.req_q_in;
  1905. req->req_q_out = &ha->iobase->isp24.req_q_out;
  1906. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  1907. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  1908. if (ha->mqenable) {
  1909. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  1910. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  1911. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  1912. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  1913. }
  1914. if (IS_QLA82XX(ha)) {
  1915. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  1916. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  1917. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  1918. }
  1919. if (qla2x00_initialize_adapter(base_vha)) {
  1920. qla_printk(KERN_WARNING, ha,
  1921. "Failed to initialize adapter\n");
  1922. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1923. "Adapter flags %x.\n",
  1924. base_vha->host_no, base_vha->device_flags));
  1925. if (IS_QLA82XX(ha)) {
  1926. qla82xx_idc_lock(ha);
  1927. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  1928. QLA82XX_DEV_FAILED);
  1929. qla82xx_idc_unlock(ha);
  1930. qla_printk(KERN_INFO, ha, "HW State: FAILED\n");
  1931. }
  1932. ret = -ENODEV;
  1933. goto probe_failed;
  1934. }
  1935. if (ha->mqenable) {
  1936. if (qla25xx_setup_mode(base_vha)) {
  1937. qla_printk(KERN_WARNING, ha,
  1938. "Can't create queues, falling back to single"
  1939. " queue mode\n");
  1940. goto que_init;
  1941. }
  1942. }
  1943. if (ha->flags.running_gold_fw)
  1944. goto skip_dpc;
  1945. /*
  1946. * Startup the kernel thread for this host adapter
  1947. */
  1948. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1949. "%s_dpc", base_vha->host_str);
  1950. if (IS_ERR(ha->dpc_thread)) {
  1951. qla_printk(KERN_WARNING, ha,
  1952. "Unable to start DPC thread!\n");
  1953. ret = PTR_ERR(ha->dpc_thread);
  1954. goto probe_failed;
  1955. }
  1956. skip_dpc:
  1957. list_add_tail(&base_vha->list, &ha->vp_list);
  1958. base_vha->host->irq = ha->pdev->irq;
  1959. /* Initialized the timer */
  1960. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1961. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1962. base_vha->host_no, ha));
  1963. if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
  1964. if (ha->fw_attributes & BIT_4) {
  1965. base_vha->flags.difdix_supported = 1;
  1966. DEBUG18(qla_printk(KERN_INFO, ha,
  1967. "Registering for DIF/DIX type 1 and 3"
  1968. " protection.\n"));
  1969. scsi_host_set_prot(host,
  1970. SHOST_DIF_TYPE1_PROTECTION
  1971. | SHOST_DIF_TYPE2_PROTECTION
  1972. | SHOST_DIF_TYPE3_PROTECTION
  1973. | SHOST_DIX_TYPE1_PROTECTION
  1974. | SHOST_DIX_TYPE2_PROTECTION
  1975. | SHOST_DIX_TYPE3_PROTECTION);
  1976. scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
  1977. } else
  1978. base_vha->flags.difdix_supported = 0;
  1979. }
  1980. ha->isp_ops->enable_intrs(ha);
  1981. ret = scsi_add_host(host, &pdev->dev);
  1982. if (ret)
  1983. goto probe_failed;
  1984. base_vha->flags.init_done = 1;
  1985. base_vha->flags.online = 1;
  1986. scsi_scan_host(host);
  1987. qla2x00_alloc_sysfs_attr(base_vha);
  1988. qla2x00_init_host_attr(base_vha);
  1989. qla2x00_dfs_setup(base_vha);
  1990. qla_printk(KERN_INFO, ha, "\n"
  1991. " QLogic Fibre Channel HBA Driver: %s\n"
  1992. " QLogic %s - %s\n"
  1993. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1994. qla2x00_version_str, ha->model_number,
  1995. ha->model_desc ? ha->model_desc : "", pdev->device,
  1996. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1997. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1998. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1999. return 0;
  2000. probe_init_failed:
  2001. qla2x00_free_req_que(ha, req);
  2002. qla2x00_free_rsp_que(ha, rsp);
  2003. ha->max_req_queues = ha->max_rsp_queues = 0;
  2004. probe_failed:
  2005. if (base_vha->timer_active)
  2006. qla2x00_stop_timer(base_vha);
  2007. base_vha->flags.online = 0;
  2008. if (ha->dpc_thread) {
  2009. struct task_struct *t = ha->dpc_thread;
  2010. ha->dpc_thread = NULL;
  2011. kthread_stop(t);
  2012. }
  2013. qla2x00_free_device(base_vha);
  2014. scsi_host_put(base_vha->host);
  2015. probe_hw_failed:
  2016. if (IS_QLA82XX(ha)) {
  2017. qla82xx_idc_lock(ha);
  2018. qla82xx_clear_drv_active(ha);
  2019. qla82xx_idc_unlock(ha);
  2020. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2021. if (!ql2xdbwr)
  2022. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2023. } else {
  2024. if (ha->iobase)
  2025. iounmap(ha->iobase);
  2026. }
  2027. pci_release_selected_regions(ha->pdev, ha->bars);
  2028. kfree(ha);
  2029. ha = NULL;
  2030. probe_out:
  2031. pci_disable_device(pdev);
  2032. return ret;
  2033. }
  2034. static void
  2035. qla2x00_shutdown(struct pci_dev *pdev)
  2036. {
  2037. scsi_qla_host_t *vha;
  2038. struct qla_hw_data *ha;
  2039. vha = pci_get_drvdata(pdev);
  2040. ha = vha->hw;
  2041. /* Turn-off FCE trace */
  2042. if (ha->flags.fce_enabled) {
  2043. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2044. ha->flags.fce_enabled = 0;
  2045. }
  2046. /* Turn-off EFT trace */
  2047. if (ha->eft)
  2048. qla2x00_disable_eft_trace(vha);
  2049. /* Stop currently executing firmware. */
  2050. qla2x00_try_to_stop_firmware(vha);
  2051. /* Turn adapter off line */
  2052. vha->flags.online = 0;
  2053. /* turn-off interrupts on the card */
  2054. if (ha->interrupts_on) {
  2055. vha->flags.init_done = 0;
  2056. ha->isp_ops->disable_intrs(ha);
  2057. }
  2058. qla2x00_free_irqs(vha);
  2059. qla2x00_free_fw_dump(ha);
  2060. }
  2061. static void
  2062. qla2x00_remove_one(struct pci_dev *pdev)
  2063. {
  2064. scsi_qla_host_t *base_vha, *vha;
  2065. struct qla_hw_data *ha;
  2066. unsigned long flags;
  2067. base_vha = pci_get_drvdata(pdev);
  2068. ha = base_vha->hw;
  2069. spin_lock_irqsave(&ha->vport_slock, flags);
  2070. list_for_each_entry(vha, &ha->vp_list, list) {
  2071. atomic_inc(&vha->vref_count);
  2072. if (vha && vha->fc_vport) {
  2073. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2074. fc_vport_terminate(vha->fc_vport);
  2075. spin_lock_irqsave(&ha->vport_slock, flags);
  2076. }
  2077. atomic_dec(&vha->vref_count);
  2078. }
  2079. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2080. set_bit(UNLOADING, &base_vha->dpc_flags);
  2081. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2082. qla2x00_dfs_remove(base_vha);
  2083. qla84xx_put_chip(base_vha);
  2084. /* Disable timer */
  2085. if (base_vha->timer_active)
  2086. qla2x00_stop_timer(base_vha);
  2087. base_vha->flags.online = 0;
  2088. /* Flush the work queue and remove it */
  2089. if (ha->wq) {
  2090. flush_workqueue(ha->wq);
  2091. destroy_workqueue(ha->wq);
  2092. ha->wq = NULL;
  2093. }
  2094. /* Kill the kernel thread for this host */
  2095. if (ha->dpc_thread) {
  2096. struct task_struct *t = ha->dpc_thread;
  2097. /*
  2098. * qla2xxx_wake_dpc checks for ->dpc_thread
  2099. * so we need to zero it out.
  2100. */
  2101. ha->dpc_thread = NULL;
  2102. kthread_stop(t);
  2103. }
  2104. qla2x00_free_sysfs_attr(base_vha);
  2105. fc_remove_host(base_vha->host);
  2106. scsi_remove_host(base_vha->host);
  2107. qla2x00_free_device(base_vha);
  2108. scsi_host_put(base_vha->host);
  2109. if (IS_QLA82XX(ha)) {
  2110. qla82xx_idc_lock(ha);
  2111. qla82xx_clear_drv_active(ha);
  2112. qla82xx_idc_unlock(ha);
  2113. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2114. if (!ql2xdbwr)
  2115. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2116. } else {
  2117. if (ha->iobase)
  2118. iounmap(ha->iobase);
  2119. if (ha->mqiobase)
  2120. iounmap(ha->mqiobase);
  2121. }
  2122. pci_release_selected_regions(ha->pdev, ha->bars);
  2123. kfree(ha);
  2124. ha = NULL;
  2125. pci_disable_pcie_error_reporting(pdev);
  2126. pci_disable_device(pdev);
  2127. pci_set_drvdata(pdev, NULL);
  2128. }
  2129. static void
  2130. qla2x00_free_device(scsi_qla_host_t *vha)
  2131. {
  2132. struct qla_hw_data *ha = vha->hw;
  2133. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2134. /* Disable timer */
  2135. if (vha->timer_active)
  2136. qla2x00_stop_timer(vha);
  2137. /* Kill the kernel thread for this host */
  2138. if (ha->dpc_thread) {
  2139. struct task_struct *t = ha->dpc_thread;
  2140. /*
  2141. * qla2xxx_wake_dpc checks for ->dpc_thread
  2142. * so we need to zero it out.
  2143. */
  2144. ha->dpc_thread = NULL;
  2145. kthread_stop(t);
  2146. }
  2147. qla25xx_delete_queues(vha);
  2148. if (ha->flags.fce_enabled)
  2149. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2150. if (ha->eft)
  2151. qla2x00_disable_eft_trace(vha);
  2152. /* Stop currently executing firmware. */
  2153. qla2x00_try_to_stop_firmware(vha);
  2154. vha->flags.online = 0;
  2155. /* turn-off interrupts on the card */
  2156. if (ha->interrupts_on) {
  2157. vha->flags.init_done = 0;
  2158. ha->isp_ops->disable_intrs(ha);
  2159. }
  2160. qla2x00_free_irqs(vha);
  2161. qla2x00_free_fcports(vha);
  2162. qla2x00_mem_free(ha);
  2163. qla2x00_free_queues(ha);
  2164. }
  2165. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2166. {
  2167. fc_port_t *fcport, *tfcport;
  2168. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2169. list_del(&fcport->list);
  2170. kfree(fcport);
  2171. fcport = NULL;
  2172. }
  2173. }
  2174. static inline void
  2175. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2176. int defer)
  2177. {
  2178. struct fc_rport *rport;
  2179. scsi_qla_host_t *base_vha;
  2180. if (!fcport->rport)
  2181. return;
  2182. rport = fcport->rport;
  2183. if (defer) {
  2184. base_vha = pci_get_drvdata(vha->hw->pdev);
  2185. spin_lock_irq(vha->host->host_lock);
  2186. fcport->drport = rport;
  2187. spin_unlock_irq(vha->host->host_lock);
  2188. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2189. qla2xxx_wake_dpc(base_vha);
  2190. } else
  2191. fc_remote_port_delete(rport);
  2192. }
  2193. /*
  2194. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2195. *
  2196. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2197. *
  2198. * Return: None.
  2199. *
  2200. * Context:
  2201. */
  2202. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2203. int do_login, int defer)
  2204. {
  2205. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2206. vha->vp_idx == fcport->vp_idx) {
  2207. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2208. qla2x00_schedule_rport_del(vha, fcport, defer);
  2209. }
  2210. /*
  2211. * We may need to retry the login, so don't change the state of the
  2212. * port but do the retries.
  2213. */
  2214. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2215. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2216. if (!do_login)
  2217. return;
  2218. if (fcport->login_retry == 0) {
  2219. fcport->login_retry = vha->hw->login_retry_count;
  2220. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2221. DEBUG(printk("scsi(%ld): Port login retry: "
  2222. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  2223. "id = 0x%04x retry cnt=%d\n",
  2224. vha->host_no,
  2225. fcport->port_name[0],
  2226. fcport->port_name[1],
  2227. fcport->port_name[2],
  2228. fcport->port_name[3],
  2229. fcport->port_name[4],
  2230. fcport->port_name[5],
  2231. fcport->port_name[6],
  2232. fcport->port_name[7],
  2233. fcport->loop_id,
  2234. fcport->login_retry));
  2235. }
  2236. }
  2237. /*
  2238. * qla2x00_mark_all_devices_lost
  2239. * Updates fcport state when device goes offline.
  2240. *
  2241. * Input:
  2242. * ha = adapter block pointer.
  2243. * fcport = port structure pointer.
  2244. *
  2245. * Return:
  2246. * None.
  2247. *
  2248. * Context:
  2249. */
  2250. void
  2251. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2252. {
  2253. fc_port_t *fcport;
  2254. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2255. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
  2256. continue;
  2257. /*
  2258. * No point in marking the device as lost, if the device is
  2259. * already DEAD.
  2260. */
  2261. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2262. continue;
  2263. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2264. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2265. if (defer)
  2266. qla2x00_schedule_rport_del(vha, fcport, defer);
  2267. else if (vha->vp_idx == fcport->vp_idx)
  2268. qla2x00_schedule_rport_del(vha, fcport, defer);
  2269. }
  2270. }
  2271. }
  2272. /*
  2273. * qla2x00_mem_alloc
  2274. * Allocates adapter memory.
  2275. *
  2276. * Returns:
  2277. * 0 = success.
  2278. * !0 = failure.
  2279. */
  2280. static int
  2281. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2282. struct req_que **req, struct rsp_que **rsp)
  2283. {
  2284. char name[16];
  2285. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2286. &ha->init_cb_dma, GFP_KERNEL);
  2287. if (!ha->init_cb)
  2288. goto fail;
  2289. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  2290. &ha->gid_list_dma, GFP_KERNEL);
  2291. if (!ha->gid_list)
  2292. goto fail_free_init_cb;
  2293. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2294. if (!ha->srb_mempool)
  2295. goto fail_free_gid_list;
  2296. if (IS_QLA82XX(ha)) {
  2297. /* Allocate cache for CT6 Ctx. */
  2298. if (!ctx_cachep) {
  2299. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2300. sizeof(struct ct6_dsd), 0,
  2301. SLAB_HWCACHE_ALIGN, NULL);
  2302. if (!ctx_cachep)
  2303. goto fail_free_gid_list;
  2304. }
  2305. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2306. ctx_cachep);
  2307. if (!ha->ctx_mempool)
  2308. goto fail_free_srb_mempool;
  2309. }
  2310. /* Get memory for cached NVRAM */
  2311. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2312. if (!ha->nvram)
  2313. goto fail_free_ctx_mempool;
  2314. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2315. ha->pdev->device);
  2316. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2317. DMA_POOL_SIZE, 8, 0);
  2318. if (!ha->s_dma_pool)
  2319. goto fail_free_nvram;
  2320. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2321. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2322. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2323. if (!ha->dl_dma_pool) {
  2324. qla_printk(KERN_WARNING, ha,
  2325. "Memory Allocation failed - dl_dma_pool\n");
  2326. goto fail_s_dma_pool;
  2327. }
  2328. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2329. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2330. if (!ha->fcp_cmnd_dma_pool) {
  2331. qla_printk(KERN_WARNING, ha,
  2332. "Memory Allocation failed - fcp_cmnd_dma_pool\n");
  2333. goto fail_dl_dma_pool;
  2334. }
  2335. }
  2336. /* Allocate memory for SNS commands */
  2337. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2338. /* Get consistent memory allocated for SNS commands */
  2339. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  2340. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  2341. if (!ha->sns_cmd)
  2342. goto fail_dma_pool;
  2343. } else {
  2344. /* Get consistent memory allocated for MS IOCB */
  2345. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2346. &ha->ms_iocb_dma);
  2347. if (!ha->ms_iocb)
  2348. goto fail_dma_pool;
  2349. /* Get consistent memory allocated for CT SNS commands */
  2350. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  2351. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  2352. if (!ha->ct_sns)
  2353. goto fail_free_ms_iocb;
  2354. }
  2355. /* Allocate memory for request ring */
  2356. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  2357. if (!*req) {
  2358. DEBUG(printk("Unable to allocate memory for req\n"));
  2359. goto fail_req;
  2360. }
  2361. (*req)->length = req_len;
  2362. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2363. ((*req)->length + 1) * sizeof(request_t),
  2364. &(*req)->dma, GFP_KERNEL);
  2365. if (!(*req)->ring) {
  2366. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  2367. goto fail_req_ring;
  2368. }
  2369. /* Allocate memory for response ring */
  2370. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  2371. if (!*rsp) {
  2372. qla_printk(KERN_WARNING, ha,
  2373. "Unable to allocate memory for rsp\n");
  2374. goto fail_rsp;
  2375. }
  2376. (*rsp)->hw = ha;
  2377. (*rsp)->length = rsp_len;
  2378. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2379. ((*rsp)->length + 1) * sizeof(response_t),
  2380. &(*rsp)->dma, GFP_KERNEL);
  2381. if (!(*rsp)->ring) {
  2382. qla_printk(KERN_WARNING, ha,
  2383. "Unable to allocate memory for rsp_ring\n");
  2384. goto fail_rsp_ring;
  2385. }
  2386. (*req)->rsp = *rsp;
  2387. (*rsp)->req = *req;
  2388. /* Allocate memory for NVRAM data for vports */
  2389. if (ha->nvram_npiv_size) {
  2390. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2391. ha->nvram_npiv_size, GFP_KERNEL);
  2392. if (!ha->npiv_info) {
  2393. qla_printk(KERN_WARNING, ha,
  2394. "Unable to allocate memory for npiv info\n");
  2395. goto fail_npiv_info;
  2396. }
  2397. } else
  2398. ha->npiv_info = NULL;
  2399. /* Get consistent memory allocated for EX-INIT-CB. */
  2400. if (IS_QLA8XXX_TYPE(ha)) {
  2401. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2402. &ha->ex_init_cb_dma);
  2403. if (!ha->ex_init_cb)
  2404. goto fail_ex_init_cb;
  2405. }
  2406. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  2407. /* Get consistent memory allocated for Async Port-Database. */
  2408. if (!IS_FWI2_CAPABLE(ha)) {
  2409. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2410. &ha->async_pd_dma);
  2411. if (!ha->async_pd)
  2412. goto fail_async_pd;
  2413. }
  2414. INIT_LIST_HEAD(&ha->vp_list);
  2415. return 1;
  2416. fail_async_pd:
  2417. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  2418. fail_ex_init_cb:
  2419. kfree(ha->npiv_info);
  2420. fail_npiv_info:
  2421. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2422. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2423. (*rsp)->ring = NULL;
  2424. (*rsp)->dma = 0;
  2425. fail_rsp_ring:
  2426. kfree(*rsp);
  2427. fail_rsp:
  2428. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2429. sizeof(request_t), (*req)->ring, (*req)->dma);
  2430. (*req)->ring = NULL;
  2431. (*req)->dma = 0;
  2432. fail_req_ring:
  2433. kfree(*req);
  2434. fail_req:
  2435. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2436. ha->ct_sns, ha->ct_sns_dma);
  2437. ha->ct_sns = NULL;
  2438. ha->ct_sns_dma = 0;
  2439. fail_free_ms_iocb:
  2440. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2441. ha->ms_iocb = NULL;
  2442. ha->ms_iocb_dma = 0;
  2443. fail_dma_pool:
  2444. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2445. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2446. ha->fcp_cmnd_dma_pool = NULL;
  2447. }
  2448. fail_dl_dma_pool:
  2449. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2450. dma_pool_destroy(ha->dl_dma_pool);
  2451. ha->dl_dma_pool = NULL;
  2452. }
  2453. fail_s_dma_pool:
  2454. dma_pool_destroy(ha->s_dma_pool);
  2455. ha->s_dma_pool = NULL;
  2456. fail_free_nvram:
  2457. kfree(ha->nvram);
  2458. ha->nvram = NULL;
  2459. fail_free_ctx_mempool:
  2460. mempool_destroy(ha->ctx_mempool);
  2461. ha->ctx_mempool = NULL;
  2462. fail_free_srb_mempool:
  2463. mempool_destroy(ha->srb_mempool);
  2464. ha->srb_mempool = NULL;
  2465. fail_free_gid_list:
  2466. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2467. ha->gid_list_dma);
  2468. ha->gid_list = NULL;
  2469. ha->gid_list_dma = 0;
  2470. fail_free_init_cb:
  2471. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2472. ha->init_cb_dma);
  2473. ha->init_cb = NULL;
  2474. ha->init_cb_dma = 0;
  2475. fail:
  2476. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2477. return -ENOMEM;
  2478. }
  2479. /*
  2480. * qla2x00_free_fw_dump
  2481. * Frees fw dump stuff.
  2482. *
  2483. * Input:
  2484. * ha = adapter block pointer.
  2485. */
  2486. static void
  2487. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  2488. {
  2489. if (ha->fce)
  2490. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2491. ha->fce_dma);
  2492. if (ha->fw_dump) {
  2493. if (ha->eft)
  2494. dma_free_coherent(&ha->pdev->dev,
  2495. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2496. vfree(ha->fw_dump);
  2497. }
  2498. ha->fce = NULL;
  2499. ha->fce_dma = 0;
  2500. ha->eft = NULL;
  2501. ha->eft_dma = 0;
  2502. ha->fw_dump = NULL;
  2503. ha->fw_dumped = 0;
  2504. ha->fw_dump_reading = 0;
  2505. }
  2506. /*
  2507. * qla2x00_mem_free
  2508. * Frees all adapter allocated memory.
  2509. *
  2510. * Input:
  2511. * ha = adapter block pointer.
  2512. */
  2513. static void
  2514. qla2x00_mem_free(struct qla_hw_data *ha)
  2515. {
  2516. qla2x00_free_fw_dump(ha);
  2517. if (ha->srb_mempool)
  2518. mempool_destroy(ha->srb_mempool);
  2519. if (ha->dcbx_tlv)
  2520. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  2521. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  2522. if (ha->xgmac_data)
  2523. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  2524. ha->xgmac_data, ha->xgmac_data_dma);
  2525. if (ha->sns_cmd)
  2526. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2527. ha->sns_cmd, ha->sns_cmd_dma);
  2528. if (ha->ct_sns)
  2529. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2530. ha->ct_sns, ha->ct_sns_dma);
  2531. if (ha->sfp_data)
  2532. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2533. if (ha->edc_data)
  2534. dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
  2535. if (ha->ms_iocb)
  2536. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2537. if (ha->ex_init_cb)
  2538. dma_pool_free(ha->s_dma_pool,
  2539. ha->ex_init_cb, ha->ex_init_cb_dma);
  2540. if (ha->async_pd)
  2541. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  2542. if (ha->s_dma_pool)
  2543. dma_pool_destroy(ha->s_dma_pool);
  2544. if (ha->gid_list)
  2545. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2546. ha->gid_list_dma);
  2547. if (IS_QLA82XX(ha)) {
  2548. if (!list_empty(&ha->gbl_dsd_list)) {
  2549. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  2550. /* clean up allocated prev pool */
  2551. list_for_each_entry_safe(dsd_ptr,
  2552. tdsd_ptr, &ha->gbl_dsd_list, list) {
  2553. dma_pool_free(ha->dl_dma_pool,
  2554. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  2555. list_del(&dsd_ptr->list);
  2556. kfree(dsd_ptr);
  2557. }
  2558. }
  2559. }
  2560. if (ha->dl_dma_pool)
  2561. dma_pool_destroy(ha->dl_dma_pool);
  2562. if (ha->fcp_cmnd_dma_pool)
  2563. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2564. if (ha->ctx_mempool)
  2565. mempool_destroy(ha->ctx_mempool);
  2566. if (ha->init_cb)
  2567. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2568. ha->init_cb, ha->init_cb_dma);
  2569. vfree(ha->optrom_buffer);
  2570. kfree(ha->nvram);
  2571. kfree(ha->npiv_info);
  2572. ha->srb_mempool = NULL;
  2573. ha->ctx_mempool = NULL;
  2574. ha->sns_cmd = NULL;
  2575. ha->sns_cmd_dma = 0;
  2576. ha->ct_sns = NULL;
  2577. ha->ct_sns_dma = 0;
  2578. ha->ms_iocb = NULL;
  2579. ha->ms_iocb_dma = 0;
  2580. ha->init_cb = NULL;
  2581. ha->init_cb_dma = 0;
  2582. ha->ex_init_cb = NULL;
  2583. ha->ex_init_cb_dma = 0;
  2584. ha->async_pd = NULL;
  2585. ha->async_pd_dma = 0;
  2586. ha->s_dma_pool = NULL;
  2587. ha->dl_dma_pool = NULL;
  2588. ha->fcp_cmnd_dma_pool = NULL;
  2589. ha->gid_list = NULL;
  2590. ha->gid_list_dma = 0;
  2591. }
  2592. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2593. struct qla_hw_data *ha)
  2594. {
  2595. struct Scsi_Host *host;
  2596. struct scsi_qla_host *vha = NULL;
  2597. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2598. if (host == NULL) {
  2599. printk(KERN_WARNING
  2600. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2601. goto fail;
  2602. }
  2603. /* Clear our data area */
  2604. vha = shost_priv(host);
  2605. memset(vha, 0, sizeof(scsi_qla_host_t));
  2606. vha->host = host;
  2607. vha->host_no = host->host_no;
  2608. vha->hw = ha;
  2609. INIT_LIST_HEAD(&vha->vp_fcports);
  2610. INIT_LIST_HEAD(&vha->work_list);
  2611. INIT_LIST_HEAD(&vha->list);
  2612. spin_lock_init(&vha->work_lock);
  2613. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2614. return vha;
  2615. fail:
  2616. return vha;
  2617. }
  2618. static struct qla_work_evt *
  2619. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  2620. {
  2621. struct qla_work_evt *e;
  2622. uint8_t bail;
  2623. QLA_VHA_MARK_BUSY(vha, bail);
  2624. if (bail)
  2625. return NULL;
  2626. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  2627. if (!e) {
  2628. QLA_VHA_MARK_NOT_BUSY(vha);
  2629. return NULL;
  2630. }
  2631. INIT_LIST_HEAD(&e->list);
  2632. e->type = type;
  2633. e->flags = QLA_EVT_FLAG_FREE;
  2634. return e;
  2635. }
  2636. static int
  2637. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  2638. {
  2639. unsigned long flags;
  2640. spin_lock_irqsave(&vha->work_lock, flags);
  2641. list_add_tail(&e->list, &vha->work_list);
  2642. spin_unlock_irqrestore(&vha->work_lock, flags);
  2643. qla2xxx_wake_dpc(vha);
  2644. return QLA_SUCCESS;
  2645. }
  2646. int
  2647. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2648. u32 data)
  2649. {
  2650. struct qla_work_evt *e;
  2651. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  2652. if (!e)
  2653. return QLA_FUNCTION_FAILED;
  2654. e->u.aen.code = code;
  2655. e->u.aen.data = data;
  2656. return qla2x00_post_work(vha, e);
  2657. }
  2658. int
  2659. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2660. {
  2661. struct qla_work_evt *e;
  2662. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  2663. if (!e)
  2664. return QLA_FUNCTION_FAILED;
  2665. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2666. return qla2x00_post_work(vha, e);
  2667. }
  2668. #define qla2x00_post_async_work(name, type) \
  2669. int qla2x00_post_async_##name##_work( \
  2670. struct scsi_qla_host *vha, \
  2671. fc_port_t *fcport, uint16_t *data) \
  2672. { \
  2673. struct qla_work_evt *e; \
  2674. \
  2675. e = qla2x00_alloc_work(vha, type); \
  2676. if (!e) \
  2677. return QLA_FUNCTION_FAILED; \
  2678. \
  2679. e->u.logio.fcport = fcport; \
  2680. if (data) { \
  2681. e->u.logio.data[0] = data[0]; \
  2682. e->u.logio.data[1] = data[1]; \
  2683. } \
  2684. return qla2x00_post_work(vha, e); \
  2685. }
  2686. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  2687. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  2688. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  2689. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  2690. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  2691. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  2692. int
  2693. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  2694. {
  2695. struct qla_work_evt *e;
  2696. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  2697. if (!e)
  2698. return QLA_FUNCTION_FAILED;
  2699. e->u.uevent.code = code;
  2700. return qla2x00_post_work(vha, e);
  2701. }
  2702. static void
  2703. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  2704. {
  2705. char event_string[40];
  2706. char *envp[] = { event_string, NULL };
  2707. switch (code) {
  2708. case QLA_UEVENT_CODE_FW_DUMP:
  2709. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2710. vha->host_no);
  2711. break;
  2712. default:
  2713. /* do nothing */
  2714. break;
  2715. }
  2716. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  2717. }
  2718. void
  2719. qla2x00_do_work(struct scsi_qla_host *vha)
  2720. {
  2721. struct qla_work_evt *e, *tmp;
  2722. unsigned long flags;
  2723. LIST_HEAD(work);
  2724. spin_lock_irqsave(&vha->work_lock, flags);
  2725. list_splice_init(&vha->work_list, &work);
  2726. spin_unlock_irqrestore(&vha->work_lock, flags);
  2727. list_for_each_entry_safe(e, tmp, &work, list) {
  2728. list_del_init(&e->list);
  2729. switch (e->type) {
  2730. case QLA_EVT_AEN:
  2731. fc_host_post_event(vha->host, fc_get_event_number(),
  2732. e->u.aen.code, e->u.aen.data);
  2733. break;
  2734. case QLA_EVT_IDC_ACK:
  2735. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2736. break;
  2737. case QLA_EVT_ASYNC_LOGIN:
  2738. qla2x00_async_login(vha, e->u.logio.fcport,
  2739. e->u.logio.data);
  2740. break;
  2741. case QLA_EVT_ASYNC_LOGIN_DONE:
  2742. qla2x00_async_login_done(vha, e->u.logio.fcport,
  2743. e->u.logio.data);
  2744. break;
  2745. case QLA_EVT_ASYNC_LOGOUT:
  2746. qla2x00_async_logout(vha, e->u.logio.fcport);
  2747. break;
  2748. case QLA_EVT_ASYNC_LOGOUT_DONE:
  2749. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  2750. e->u.logio.data);
  2751. break;
  2752. case QLA_EVT_ASYNC_ADISC:
  2753. qla2x00_async_adisc(vha, e->u.logio.fcport,
  2754. e->u.logio.data);
  2755. break;
  2756. case QLA_EVT_ASYNC_ADISC_DONE:
  2757. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  2758. e->u.logio.data);
  2759. break;
  2760. case QLA_EVT_UEVENT:
  2761. qla2x00_uevent_emit(vha, e->u.uevent.code);
  2762. break;
  2763. }
  2764. if (e->flags & QLA_EVT_FLAG_FREE)
  2765. kfree(e);
  2766. /* For each work completed decrement vha ref count */
  2767. QLA_VHA_MARK_NOT_BUSY(vha);
  2768. }
  2769. }
  2770. /* Relogins all the fcports of a vport
  2771. * Context: dpc thread
  2772. */
  2773. void qla2x00_relogin(struct scsi_qla_host *vha)
  2774. {
  2775. fc_port_t *fcport;
  2776. int status;
  2777. uint16_t next_loopid = 0;
  2778. struct qla_hw_data *ha = vha->hw;
  2779. uint16_t data[2];
  2780. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2781. /*
  2782. * If the port is not ONLINE then try to login
  2783. * to it if we haven't run out of retries.
  2784. */
  2785. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  2786. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  2787. fcport->login_retry--;
  2788. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2789. if (fcport->flags & FCF_FCP2_DEVICE)
  2790. ha->isp_ops->fabric_logout(vha,
  2791. fcport->loop_id,
  2792. fcport->d_id.b.domain,
  2793. fcport->d_id.b.area,
  2794. fcport->d_id.b.al_pa);
  2795. if (IS_ALOGIO_CAPABLE(ha)) {
  2796. fcport->flags |= FCF_ASYNC_SENT;
  2797. data[0] = 0;
  2798. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  2799. status = qla2x00_post_async_login_work(
  2800. vha, fcport, data);
  2801. if (status == QLA_SUCCESS)
  2802. continue;
  2803. /* Attempt a retry. */
  2804. status = 1;
  2805. } else
  2806. status = qla2x00_fabric_login(vha,
  2807. fcport, &next_loopid);
  2808. } else
  2809. status = qla2x00_local_device_login(vha,
  2810. fcport);
  2811. if (status == QLA_SUCCESS) {
  2812. fcport->old_loop_id = fcport->loop_id;
  2813. DEBUG(printk("scsi(%ld): port login OK: logged "
  2814. "in ID 0x%x\n", vha->host_no, fcport->loop_id));
  2815. qla2x00_update_fcport(vha, fcport);
  2816. } else if (status == 1) {
  2817. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2818. /* retry the login again */
  2819. DEBUG(printk("scsi(%ld): Retrying"
  2820. " %d login again loop_id 0x%x\n",
  2821. vha->host_no, fcport->login_retry,
  2822. fcport->loop_id));
  2823. } else {
  2824. fcport->login_retry = 0;
  2825. }
  2826. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2827. fcport->loop_id = FC_NO_LOOP_ID;
  2828. }
  2829. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2830. break;
  2831. }
  2832. }
  2833. /**************************************************************************
  2834. * qla2x00_do_dpc
  2835. * This kernel thread is a task that is schedule by the interrupt handler
  2836. * to perform the background processing for interrupts.
  2837. *
  2838. * Notes:
  2839. * This task always run in the context of a kernel thread. It
  2840. * is kick-off by the driver's detect code and starts up
  2841. * up one per adapter. It immediately goes to sleep and waits for
  2842. * some fibre event. When either the interrupt handler or
  2843. * the timer routine detects a event it will one of the task
  2844. * bits then wake us up.
  2845. **************************************************************************/
  2846. static int
  2847. qla2x00_do_dpc(void *data)
  2848. {
  2849. int rval;
  2850. scsi_qla_host_t *base_vha;
  2851. struct qla_hw_data *ha;
  2852. ha = (struct qla_hw_data *)data;
  2853. base_vha = pci_get_drvdata(ha->pdev);
  2854. set_user_nice(current, -20);
  2855. while (!kthread_should_stop()) {
  2856. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  2857. set_current_state(TASK_INTERRUPTIBLE);
  2858. schedule();
  2859. __set_current_state(TASK_RUNNING);
  2860. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  2861. /* Initialization not yet finished. Don't do anything yet. */
  2862. if (!base_vha->flags.init_done)
  2863. continue;
  2864. if (ha->flags.eeh_busy) {
  2865. DEBUG17(qla_printk(KERN_WARNING, ha,
  2866. "qla2x00_do_dpc: dpc_flags: %lx\n",
  2867. base_vha->dpc_flags));
  2868. continue;
  2869. }
  2870. DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
  2871. ha->dpc_active = 1;
  2872. if (ha->flags.mbox_busy) {
  2873. ha->dpc_active = 0;
  2874. continue;
  2875. }
  2876. qla2x00_do_work(base_vha);
  2877. if (IS_QLA82XX(ha)) {
  2878. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  2879. &base_vha->dpc_flags)) {
  2880. qla82xx_idc_lock(ha);
  2881. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2882. QLA82XX_DEV_FAILED);
  2883. qla82xx_idc_unlock(ha);
  2884. qla_printk(KERN_INFO, ha,
  2885. "HW State: FAILED\n");
  2886. qla82xx_device_state_handler(base_vha);
  2887. continue;
  2888. }
  2889. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  2890. &base_vha->dpc_flags)) {
  2891. DEBUG(printk(KERN_INFO
  2892. "scsi(%ld): dpc: sched "
  2893. "qla82xx_fcoe_ctx_reset ha = %p\n",
  2894. base_vha->host_no, ha));
  2895. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2896. &base_vha->dpc_flags))) {
  2897. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  2898. /* FCoE-ctx reset failed.
  2899. * Escalate to chip-reset
  2900. */
  2901. set_bit(ISP_ABORT_NEEDED,
  2902. &base_vha->dpc_flags);
  2903. }
  2904. clear_bit(ABORT_ISP_ACTIVE,
  2905. &base_vha->dpc_flags);
  2906. }
  2907. DEBUG(printk("scsi(%ld): dpc:"
  2908. " qla82xx_fcoe_ctx_reset end\n",
  2909. base_vha->host_no));
  2910. }
  2911. }
  2912. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  2913. &base_vha->dpc_flags)) {
  2914. DEBUG(printk("scsi(%ld): dpc: sched "
  2915. "qla2x00_abort_isp ha = %p\n",
  2916. base_vha->host_no, ha));
  2917. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2918. &base_vha->dpc_flags))) {
  2919. if (ha->isp_ops->abort_isp(base_vha)) {
  2920. /* failed. retry later */
  2921. set_bit(ISP_ABORT_NEEDED,
  2922. &base_vha->dpc_flags);
  2923. }
  2924. clear_bit(ABORT_ISP_ACTIVE,
  2925. &base_vha->dpc_flags);
  2926. }
  2927. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  2928. base_vha->host_no));
  2929. }
  2930. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  2931. qla2x00_update_fcports(base_vha);
  2932. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2933. }
  2934. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  2935. &base_vha->dpc_flags) &&
  2936. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  2937. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  2938. base_vha->host_no));
  2939. qla2x00_rst_aen(base_vha);
  2940. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  2941. }
  2942. /* Retry each device up to login retry count */
  2943. if ((test_and_clear_bit(RELOGIN_NEEDED,
  2944. &base_vha->dpc_flags)) &&
  2945. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  2946. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  2947. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2948. base_vha->host_no));
  2949. qla2x00_relogin(base_vha);
  2950. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2951. base_vha->host_no));
  2952. }
  2953. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  2954. &base_vha->dpc_flags)) {
  2955. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2956. base_vha->host_no));
  2957. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2958. &base_vha->dpc_flags))) {
  2959. rval = qla2x00_loop_resync(base_vha);
  2960. clear_bit(LOOP_RESYNC_ACTIVE,
  2961. &base_vha->dpc_flags);
  2962. }
  2963. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2964. base_vha->host_no));
  2965. }
  2966. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  2967. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  2968. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  2969. qla2xxx_flash_npiv_conf(base_vha);
  2970. }
  2971. if (!ha->interrupts_on)
  2972. ha->isp_ops->enable_intrs(ha);
  2973. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  2974. &base_vha->dpc_flags))
  2975. ha->isp_ops->beacon_blink(base_vha);
  2976. qla2x00_do_dpc_all_vps(base_vha);
  2977. ha->dpc_active = 0;
  2978. } /* End of while(1) */
  2979. DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
  2980. /*
  2981. * Make sure that nobody tries to wake us up again.
  2982. */
  2983. ha->dpc_active = 0;
  2984. /* Cleanup any residual CTX SRBs. */
  2985. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2986. return 0;
  2987. }
  2988. void
  2989. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  2990. {
  2991. struct qla_hw_data *ha = vha->hw;
  2992. struct task_struct *t = ha->dpc_thread;
  2993. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  2994. wake_up_process(t);
  2995. }
  2996. /*
  2997. * qla2x00_rst_aen
  2998. * Processes asynchronous reset.
  2999. *
  3000. * Input:
  3001. * ha = adapter block pointer.
  3002. */
  3003. static void
  3004. qla2x00_rst_aen(scsi_qla_host_t *vha)
  3005. {
  3006. if (vha->flags.online && !vha->flags.reset_active &&
  3007. !atomic_read(&vha->loop_down_timer) &&
  3008. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  3009. do {
  3010. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3011. /*
  3012. * Issue marker command only when we are going to start
  3013. * the I/O.
  3014. */
  3015. vha->marker_needed = 1;
  3016. } while (!atomic_read(&vha->loop_down_timer) &&
  3017. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  3018. }
  3019. }
  3020. static void
  3021. qla2x00_sp_free_dma(srb_t *sp)
  3022. {
  3023. struct scsi_cmnd *cmd = sp->cmd;
  3024. struct qla_hw_data *ha = sp->fcport->vha->hw;
  3025. if (sp->flags & SRB_DMA_VALID) {
  3026. scsi_dma_unmap(cmd);
  3027. sp->flags &= ~SRB_DMA_VALID;
  3028. }
  3029. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  3030. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  3031. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  3032. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  3033. }
  3034. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  3035. /* List assured to be having elements */
  3036. qla2x00_clean_dsd_pool(ha, sp);
  3037. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  3038. }
  3039. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  3040. dma_pool_free(ha->dl_dma_pool, sp->ctx,
  3041. ((struct crc_context *)sp->ctx)->crc_ctx_dma);
  3042. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  3043. }
  3044. CMD_SP(cmd) = NULL;
  3045. }
  3046. static void
  3047. qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
  3048. {
  3049. struct scsi_cmnd *cmd = sp->cmd;
  3050. qla2x00_sp_free_dma(sp);
  3051. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  3052. struct ct6_dsd *ctx = sp->ctx;
  3053. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
  3054. ctx->fcp_cmnd_dma);
  3055. list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
  3056. ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
  3057. ha->gbl_dsd_avail += ctx->dsd_use_cnt;
  3058. mempool_free(sp->ctx, ha->ctx_mempool);
  3059. sp->ctx = NULL;
  3060. }
  3061. mempool_free(sp, ha->srb_mempool);
  3062. cmd->scsi_done(cmd);
  3063. }
  3064. void
  3065. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  3066. {
  3067. if (atomic_read(&sp->ref_count) == 0) {
  3068. DEBUG2(qla_printk(KERN_WARNING, ha,
  3069. "SP reference-count to ZERO -- sp=%p\n", sp));
  3070. DEBUG2(BUG());
  3071. return;
  3072. }
  3073. if (!atomic_dec_and_test(&sp->ref_count))
  3074. return;
  3075. qla2x00_sp_final_compl(ha, sp);
  3076. }
  3077. /**************************************************************************
  3078. * qla2x00_timer
  3079. *
  3080. * Description:
  3081. * One second timer
  3082. *
  3083. * Context: Interrupt
  3084. ***************************************************************************/
  3085. void
  3086. qla2x00_timer(scsi_qla_host_t *vha)
  3087. {
  3088. unsigned long cpu_flags = 0;
  3089. int start_dpc = 0;
  3090. int index;
  3091. srb_t *sp;
  3092. uint16_t w;
  3093. struct qla_hw_data *ha = vha->hw;
  3094. struct req_que *req;
  3095. if (ha->flags.eeh_busy) {
  3096. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3097. return;
  3098. }
  3099. if (IS_QLA82XX(ha))
  3100. qla82xx_watchdog(vha);
  3101. /* Hardware read to raise pending EEH errors during mailbox waits. */
  3102. if (!pci_channel_offline(ha->pdev))
  3103. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  3104. /* Loop down handler. */
  3105. if (atomic_read(&vha->loop_down_timer) > 0 &&
  3106. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  3107. && vha->flags.online) {
  3108. if (atomic_read(&vha->loop_down_timer) ==
  3109. vha->loop_down_abort_time) {
  3110. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  3111. "queues before time expire\n",
  3112. vha->host_no));
  3113. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  3114. atomic_set(&vha->loop_state, LOOP_DEAD);
  3115. /*
  3116. * Schedule an ISP abort to return any FCP2-device
  3117. * commands.
  3118. */
  3119. /* NPIV - scan physical port only */
  3120. if (!vha->vp_idx) {
  3121. spin_lock_irqsave(&ha->hardware_lock,
  3122. cpu_flags);
  3123. req = ha->req_q_map[0];
  3124. for (index = 1;
  3125. index < MAX_OUTSTANDING_COMMANDS;
  3126. index++) {
  3127. fc_port_t *sfcp;
  3128. sp = req->outstanding_cmds[index];
  3129. if (!sp)
  3130. continue;
  3131. if (sp->ctx && !IS_PROT_IO(sp))
  3132. continue;
  3133. sfcp = sp->fcport;
  3134. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  3135. continue;
  3136. set_bit(ISP_ABORT_NEEDED,
  3137. &vha->dpc_flags);
  3138. break;
  3139. }
  3140. spin_unlock_irqrestore(&ha->hardware_lock,
  3141. cpu_flags);
  3142. }
  3143. start_dpc++;
  3144. }
  3145. /* if the loop has been down for 4 minutes, reinit adapter */
  3146. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  3147. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  3148. DEBUG(printk("scsi(%ld): Loop down - "
  3149. "aborting ISP.\n",
  3150. vha->host_no));
  3151. qla_printk(KERN_WARNING, ha,
  3152. "Loop down - aborting ISP.\n");
  3153. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  3154. }
  3155. }
  3156. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  3157. vha->host_no,
  3158. atomic_read(&vha->loop_down_timer)));
  3159. }
  3160. /* Check if beacon LED needs to be blinked */
  3161. if (ha->beacon_blink_led == 1) {
  3162. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  3163. start_dpc++;
  3164. }
  3165. /* Process any deferred work. */
  3166. if (!list_empty(&vha->work_list))
  3167. start_dpc++;
  3168. /* Schedule the DPC routine if needed */
  3169. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  3170. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  3171. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  3172. start_dpc ||
  3173. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  3174. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  3175. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  3176. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  3177. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  3178. test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
  3179. qla2xxx_wake_dpc(vha);
  3180. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3181. }
  3182. /* Firmware interface routines. */
  3183. #define FW_BLOBS 8
  3184. #define FW_ISP21XX 0
  3185. #define FW_ISP22XX 1
  3186. #define FW_ISP2300 2
  3187. #define FW_ISP2322 3
  3188. #define FW_ISP24XX 4
  3189. #define FW_ISP25XX 5
  3190. #define FW_ISP81XX 6
  3191. #define FW_ISP82XX 7
  3192. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  3193. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  3194. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  3195. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  3196. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  3197. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  3198. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  3199. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  3200. static DEFINE_MUTEX(qla_fw_lock);
  3201. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  3202. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  3203. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  3204. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  3205. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  3206. { .name = FW_FILE_ISP24XX, },
  3207. { .name = FW_FILE_ISP25XX, },
  3208. { .name = FW_FILE_ISP81XX, },
  3209. { .name = FW_FILE_ISP82XX, },
  3210. };
  3211. struct fw_blob *
  3212. qla2x00_request_firmware(scsi_qla_host_t *vha)
  3213. {
  3214. struct qla_hw_data *ha = vha->hw;
  3215. struct fw_blob *blob;
  3216. blob = NULL;
  3217. if (IS_QLA2100(ha)) {
  3218. blob = &qla_fw_blobs[FW_ISP21XX];
  3219. } else if (IS_QLA2200(ha)) {
  3220. blob = &qla_fw_blobs[FW_ISP22XX];
  3221. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  3222. blob = &qla_fw_blobs[FW_ISP2300];
  3223. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  3224. blob = &qla_fw_blobs[FW_ISP2322];
  3225. } else if (IS_QLA24XX_TYPE(ha)) {
  3226. blob = &qla_fw_blobs[FW_ISP24XX];
  3227. } else if (IS_QLA25XX(ha)) {
  3228. blob = &qla_fw_blobs[FW_ISP25XX];
  3229. } else if (IS_QLA81XX(ha)) {
  3230. blob = &qla_fw_blobs[FW_ISP81XX];
  3231. } else if (IS_QLA82XX(ha)) {
  3232. blob = &qla_fw_blobs[FW_ISP82XX];
  3233. }
  3234. mutex_lock(&qla_fw_lock);
  3235. if (blob->fw)
  3236. goto out;
  3237. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  3238. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  3239. "(%s).\n", vha->host_no, blob->name));
  3240. blob->fw = NULL;
  3241. blob = NULL;
  3242. goto out;
  3243. }
  3244. out:
  3245. mutex_unlock(&qla_fw_lock);
  3246. return blob;
  3247. }
  3248. static void
  3249. qla2x00_release_firmware(void)
  3250. {
  3251. int idx;
  3252. mutex_lock(&qla_fw_lock);
  3253. for (idx = 0; idx < FW_BLOBS; idx++)
  3254. if (qla_fw_blobs[idx].fw)
  3255. release_firmware(qla_fw_blobs[idx].fw);
  3256. mutex_unlock(&qla_fw_lock);
  3257. }
  3258. static pci_ers_result_t
  3259. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  3260. {
  3261. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  3262. struct qla_hw_data *ha = vha->hw;
  3263. DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
  3264. state));
  3265. switch (state) {
  3266. case pci_channel_io_normal:
  3267. ha->flags.eeh_busy = 0;
  3268. return PCI_ERS_RESULT_CAN_RECOVER;
  3269. case pci_channel_io_frozen:
  3270. ha->flags.eeh_busy = 1;
  3271. /* For ISP82XX complete any pending mailbox cmd */
  3272. if (IS_QLA82XX(ha)) {
  3273. ha->flags.fw_hung = 1;
  3274. if (ha->flags.mbox_busy) {
  3275. ha->flags.mbox_int = 1;
  3276. DEBUG2(qla_printk(KERN_ERR, ha,
  3277. "Due to pci channel io frozen, doing premature "
  3278. "completion of mbx command\n"));
  3279. complete(&ha->mbx_intr_comp);
  3280. }
  3281. }
  3282. qla2x00_free_irqs(vha);
  3283. pci_disable_device(pdev);
  3284. /* Return back all IOs */
  3285. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3286. return PCI_ERS_RESULT_NEED_RESET;
  3287. case pci_channel_io_perm_failure:
  3288. ha->flags.pci_channel_io_perm_failure = 1;
  3289. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  3290. return PCI_ERS_RESULT_DISCONNECT;
  3291. }
  3292. return PCI_ERS_RESULT_NEED_RESET;
  3293. }
  3294. static pci_ers_result_t
  3295. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  3296. {
  3297. int risc_paused = 0;
  3298. uint32_t stat;
  3299. unsigned long flags;
  3300. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3301. struct qla_hw_data *ha = base_vha->hw;
  3302. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3303. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  3304. if (IS_QLA82XX(ha))
  3305. return PCI_ERS_RESULT_RECOVERED;
  3306. spin_lock_irqsave(&ha->hardware_lock, flags);
  3307. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  3308. stat = RD_REG_DWORD(&reg->hccr);
  3309. if (stat & HCCR_RISC_PAUSE)
  3310. risc_paused = 1;
  3311. } else if (IS_QLA23XX(ha)) {
  3312. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  3313. if (stat & HSR_RISC_PAUSED)
  3314. risc_paused = 1;
  3315. } else if (IS_FWI2_CAPABLE(ha)) {
  3316. stat = RD_REG_DWORD(&reg24->host_status);
  3317. if (stat & HSRX_RISC_PAUSED)
  3318. risc_paused = 1;
  3319. }
  3320. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3321. if (risc_paused) {
  3322. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  3323. "Dumping firmware!\n");
  3324. ha->isp_ops->fw_dump(base_vha, 0);
  3325. return PCI_ERS_RESULT_NEED_RESET;
  3326. } else
  3327. return PCI_ERS_RESULT_RECOVERED;
  3328. }
  3329. uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  3330. {
  3331. uint32_t rval = QLA_FUNCTION_FAILED;
  3332. uint32_t drv_active = 0;
  3333. struct qla_hw_data *ha = base_vha->hw;
  3334. int fn;
  3335. struct pci_dev *other_pdev = NULL;
  3336. DEBUG17(qla_printk(KERN_INFO, ha,
  3337. "scsi(%ld): In qla82xx_error_recovery\n", base_vha->host_no));
  3338. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3339. if (base_vha->flags.online) {
  3340. /* Abort all outstanding commands,
  3341. * so as to be requeued later */
  3342. qla2x00_abort_isp_cleanup(base_vha);
  3343. }
  3344. fn = PCI_FUNC(ha->pdev->devfn);
  3345. while (fn > 0) {
  3346. fn--;
  3347. DEBUG17(qla_printk(KERN_INFO, ha,
  3348. "Finding pci device at function = 0x%x\n", fn));
  3349. other_pdev =
  3350. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  3351. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  3352. fn));
  3353. if (!other_pdev)
  3354. continue;
  3355. if (atomic_read(&other_pdev->enable_cnt)) {
  3356. DEBUG17(qla_printk(KERN_INFO, ha,
  3357. "Found PCI func availabe and enabled at 0x%x\n",
  3358. fn));
  3359. pci_dev_put(other_pdev);
  3360. break;
  3361. }
  3362. pci_dev_put(other_pdev);
  3363. }
  3364. if (!fn) {
  3365. /* Reset owner */
  3366. DEBUG17(qla_printk(KERN_INFO, ha,
  3367. "This devfn is reset owner = 0x%x\n", ha->pdev->devfn));
  3368. qla82xx_idc_lock(ha);
  3369. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3370. QLA82XX_DEV_INITIALIZING);
  3371. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  3372. QLA82XX_IDC_VERSION);
  3373. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  3374. DEBUG17(qla_printk(KERN_INFO, ha,
  3375. "drv_active = 0x%x\n", drv_active));
  3376. qla82xx_idc_unlock(ha);
  3377. /* Reset if device is not already reset
  3378. * drv_active would be 0 if a reset has already been done
  3379. */
  3380. if (drv_active)
  3381. rval = qla82xx_start_firmware(base_vha);
  3382. else
  3383. rval = QLA_SUCCESS;
  3384. qla82xx_idc_lock(ha);
  3385. if (rval != QLA_SUCCESS) {
  3386. qla_printk(KERN_INFO, ha, "HW State: FAILED\n");
  3387. qla82xx_clear_drv_active(ha);
  3388. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3389. QLA82XX_DEV_FAILED);
  3390. } else {
  3391. qla_printk(KERN_INFO, ha, "HW State: READY\n");
  3392. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3393. QLA82XX_DEV_READY);
  3394. qla82xx_idc_unlock(ha);
  3395. ha->flags.fw_hung = 0;
  3396. rval = qla82xx_restart_isp(base_vha);
  3397. qla82xx_idc_lock(ha);
  3398. /* Clear driver state register */
  3399. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  3400. qla82xx_set_drv_active(base_vha);
  3401. }
  3402. qla82xx_idc_unlock(ha);
  3403. } else {
  3404. DEBUG17(qla_printk(KERN_INFO, ha,
  3405. "This devfn is not reset owner = 0x%x\n", ha->pdev->devfn));
  3406. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  3407. QLA82XX_DEV_READY)) {
  3408. ha->flags.fw_hung = 0;
  3409. rval = qla82xx_restart_isp(base_vha);
  3410. qla82xx_idc_lock(ha);
  3411. qla82xx_set_drv_active(base_vha);
  3412. qla82xx_idc_unlock(ha);
  3413. }
  3414. }
  3415. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3416. return rval;
  3417. }
  3418. static pci_ers_result_t
  3419. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  3420. {
  3421. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  3422. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3423. struct qla_hw_data *ha = base_vha->hw;
  3424. struct rsp_que *rsp;
  3425. int rc, retries = 10;
  3426. DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
  3427. /* Workaround: qla2xxx driver which access hardware earlier
  3428. * needs error state to be pci_channel_io_online.
  3429. * Otherwise mailbox command timesout.
  3430. */
  3431. pdev->error_state = pci_channel_io_normal;
  3432. pci_restore_state(pdev);
  3433. /* pci_restore_state() clears the saved_state flag of the device
  3434. * save restored state which resets saved_state flag
  3435. */
  3436. pci_save_state(pdev);
  3437. if (ha->mem_only)
  3438. rc = pci_enable_device_mem(pdev);
  3439. else
  3440. rc = pci_enable_device(pdev);
  3441. if (rc) {
  3442. qla_printk(KERN_WARNING, ha,
  3443. "Can't re-enable PCI device after reset.\n");
  3444. goto exit_slot_reset;
  3445. }
  3446. rsp = ha->rsp_q_map[0];
  3447. if (qla2x00_request_irqs(ha, rsp))
  3448. goto exit_slot_reset;
  3449. if (ha->isp_ops->pci_config(base_vha))
  3450. goto exit_slot_reset;
  3451. if (IS_QLA82XX(ha)) {
  3452. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  3453. ret = PCI_ERS_RESULT_RECOVERED;
  3454. goto exit_slot_reset;
  3455. } else
  3456. goto exit_slot_reset;
  3457. }
  3458. while (ha->flags.mbox_busy && retries--)
  3459. msleep(1000);
  3460. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3461. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  3462. ret = PCI_ERS_RESULT_RECOVERED;
  3463. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3464. exit_slot_reset:
  3465. DEBUG17(qla_printk(KERN_WARNING, ha,
  3466. "slot_reset-return:ret=%x\n", ret));
  3467. return ret;
  3468. }
  3469. static void
  3470. qla2xxx_pci_resume(struct pci_dev *pdev)
  3471. {
  3472. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3473. struct qla_hw_data *ha = base_vha->hw;
  3474. int ret;
  3475. DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
  3476. ret = qla2x00_wait_for_hba_online(base_vha);
  3477. if (ret != QLA_SUCCESS) {
  3478. qla_printk(KERN_ERR, ha,
  3479. "the device failed to resume I/O "
  3480. "from slot/link_reset");
  3481. }
  3482. pci_cleanup_aer_uncorrect_error_status(pdev);
  3483. ha->flags.eeh_busy = 0;
  3484. }
  3485. static struct pci_error_handlers qla2xxx_err_handler = {
  3486. .error_detected = qla2xxx_pci_error_detected,
  3487. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  3488. .slot_reset = qla2xxx_pci_slot_reset,
  3489. .resume = qla2xxx_pci_resume,
  3490. };
  3491. static struct pci_device_id qla2xxx_pci_tbl[] = {
  3492. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  3493. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  3494. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  3495. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  3496. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  3497. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  3498. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  3499. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  3500. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  3501. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  3502. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  3503. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  3504. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  3505. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  3506. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  3507. { 0 },
  3508. };
  3509. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  3510. static struct pci_driver qla2xxx_pci_driver = {
  3511. .name = QLA2XXX_DRIVER_NAME,
  3512. .driver = {
  3513. .owner = THIS_MODULE,
  3514. },
  3515. .id_table = qla2xxx_pci_tbl,
  3516. .probe = qla2x00_probe_one,
  3517. .remove = qla2x00_remove_one,
  3518. .shutdown = qla2x00_shutdown,
  3519. .err_handler = &qla2xxx_err_handler,
  3520. };
  3521. static struct file_operations apidev_fops = {
  3522. .owner = THIS_MODULE,
  3523. .llseek = noop_llseek,
  3524. };
  3525. /**
  3526. * qla2x00_module_init - Module initialization.
  3527. **/
  3528. static int __init
  3529. qla2x00_module_init(void)
  3530. {
  3531. int ret = 0;
  3532. /* Allocate cache for SRBs. */
  3533. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  3534. SLAB_HWCACHE_ALIGN, NULL);
  3535. if (srb_cachep == NULL) {
  3536. printk(KERN_ERR
  3537. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  3538. return -ENOMEM;
  3539. }
  3540. /* Derive version string. */
  3541. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  3542. if (ql2xextended_error_logging)
  3543. strcat(qla2x00_version_str, "-debug");
  3544. qla2xxx_transport_template =
  3545. fc_attach_transport(&qla2xxx_transport_functions);
  3546. if (!qla2xxx_transport_template) {
  3547. kmem_cache_destroy(srb_cachep);
  3548. return -ENODEV;
  3549. }
  3550. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  3551. if (apidev_major < 0) {
  3552. printk(KERN_WARNING "qla2xxx: Unable to register char device "
  3553. "%s\n", QLA2XXX_APIDEV);
  3554. }
  3555. qla2xxx_transport_vport_template =
  3556. fc_attach_transport(&qla2xxx_transport_vport_functions);
  3557. if (!qla2xxx_transport_vport_template) {
  3558. kmem_cache_destroy(srb_cachep);
  3559. fc_release_transport(qla2xxx_transport_template);
  3560. return -ENODEV;
  3561. }
  3562. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  3563. qla2x00_version_str);
  3564. ret = pci_register_driver(&qla2xxx_pci_driver);
  3565. if (ret) {
  3566. kmem_cache_destroy(srb_cachep);
  3567. fc_release_transport(qla2xxx_transport_template);
  3568. fc_release_transport(qla2xxx_transport_vport_template);
  3569. }
  3570. return ret;
  3571. }
  3572. /**
  3573. * qla2x00_module_exit - Module cleanup.
  3574. **/
  3575. static void __exit
  3576. qla2x00_module_exit(void)
  3577. {
  3578. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  3579. pci_unregister_driver(&qla2xxx_pci_driver);
  3580. qla2x00_release_firmware();
  3581. kmem_cache_destroy(srb_cachep);
  3582. if (ctx_cachep)
  3583. kmem_cache_destroy(ctx_cachep);
  3584. fc_release_transport(qla2xxx_transport_template);
  3585. fc_release_transport(qla2xxx_transport_vport_template);
  3586. }
  3587. module_init(qla2x00_module_init);
  3588. module_exit(qla2x00_module_exit);
  3589. MODULE_AUTHOR("QLogic Corporation");
  3590. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  3591. MODULE_LICENSE("GPL");
  3592. MODULE_VERSION(QLA2XXX_VERSION);
  3593. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  3594. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  3595. MODULE_FIRMWARE(FW_FILE_ISP2300);
  3596. MODULE_FIRMWARE(FW_FILE_ISP2322);
  3597. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  3598. MODULE_FIRMWARE(FW_FILE_ISP25XX);