qla1280.c 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543
  1. /******************************************************************************
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
  5. * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
  6. * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
  7. * Copyright (C) 2003-2004 Christoph Hellwig
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. ******************************************************************************/
  20. #define QLA1280_VERSION "3.26"
  21. /*****************************************************************************
  22. Revision History:
  23. Rev 3.26, January 16, 2006 Jes Sorensen
  24. - Ditch all < 2.6 support
  25. Rev 3.25.1, February 10, 2005 Christoph Hellwig
  26. - use pci_map_single to map non-S/G requests
  27. - remove qla1280_proc_info
  28. Rev 3.25, September 28, 2004, Christoph Hellwig
  29. - add support for ISP1020/1040
  30. - don't include "scsi.h" anymore for 2.6.x
  31. Rev 3.24.4 June 7, 2004 Christoph Hellwig
  32. - restructure firmware loading, cleanup initialization code
  33. - prepare support for ISP1020/1040 chips
  34. Rev 3.24.3 January 19, 2004, Jes Sorensen
  35. - Handle PCI DMA mask settings correctly
  36. - Correct order of error handling in probe_one, free_irq should not
  37. be called if request_irq failed
  38. Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
  39. - Big endian fixes (James)
  40. - Remove bogus IOCB content on zero data transfer commands (Andrew)
  41. Rev 3.24.1 January 5, 2004, Jes Sorensen
  42. - Initialize completion queue to avoid OOPS on probe
  43. - Handle interrupts during mailbox testing
  44. Rev 3.24 November 17, 2003, Christoph Hellwig
  45. - use struct list_head for completion queue
  46. - avoid old Scsi_FOO typedefs
  47. - cleanup 2.4 compat glue a bit
  48. - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
  49. - make initialization for memory mapped vs port I/O more similar
  50. - remove broken pci config space manipulation
  51. - kill more cruft
  52. - this is an almost perfect 2.6 scsi driver now! ;)
  53. Rev 3.23.39 December 17, 2003, Jes Sorensen
  54. - Delete completion queue from srb if mailbox command failed to
  55. to avoid qla1280_done completeting qla1280_error_action's
  56. obsolete context
  57. - Reduce arguments for qla1280_done
  58. Rev 3.23.38 October 18, 2003, Christoph Hellwig
  59. - Convert to new-style hotplugable driver for 2.6
  60. - Fix missing scsi_unregister/scsi_host_put on HBA removal
  61. - Kill some more cruft
  62. Rev 3.23.37 October 1, 2003, Jes Sorensen
  63. - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
  64. random CONFIG option
  65. - Clean up locking in probe path
  66. Rev 3.23.36 October 1, 2003, Christoph Hellwig
  67. - queuecommand only ever receives new commands - clear flags
  68. - Reintegrate lost fixes from Linux 2.5
  69. Rev 3.23.35 August 14, 2003, Jes Sorensen
  70. - Build against 2.6
  71. Rev 3.23.34 July 23, 2003, Jes Sorensen
  72. - Remove pointless TRUE/FALSE macros
  73. - Clean up vchan handling
  74. Rev 3.23.33 July 3, 2003, Jes Sorensen
  75. - Don't define register access macros before define determining MMIO.
  76. This just happend to work out on ia64 but not elsewhere.
  77. - Don't try and read from the card while it is in reset as
  78. it won't respond and causes an MCA
  79. Rev 3.23.32 June 23, 2003, Jes Sorensen
  80. - Basic support for boot time arguments
  81. Rev 3.23.31 June 8, 2003, Jes Sorensen
  82. - Reduce boot time messages
  83. Rev 3.23.30 June 6, 2003, Jes Sorensen
  84. - Do not enable sync/wide/ppr before it has been determined
  85. that the target device actually supports it
  86. - Enable DMA arbitration for multi channel controllers
  87. Rev 3.23.29 June 3, 2003, Jes Sorensen
  88. - Port to 2.5.69
  89. Rev 3.23.28 June 3, 2003, Jes Sorensen
  90. - Eliminate duplicate marker commands on bus resets
  91. - Handle outstanding commands appropriately on bus/device resets
  92. Rev 3.23.27 May 28, 2003, Jes Sorensen
  93. - Remove bogus input queue code, let the Linux SCSI layer do the work
  94. - Clean up NVRAM handling, only read it once from the card
  95. - Add a number of missing default nvram parameters
  96. Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
  97. - Use completion queue for mailbox commands instead of busy wait
  98. Rev 3.23.25 Beta May 27, 2003, James Bottomley
  99. - Migrate to use new error handling code
  100. Rev 3.23.24 Beta May 21, 2003, James Bottomley
  101. - Big endian support
  102. - Cleanup data direction code
  103. Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
  104. - Switch to using MMIO instead of PIO
  105. Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
  106. - Fix PCI parity problem with 12160 during reset.
  107. Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
  108. - Use pci_map_page()/pci_unmap_page() instead of map_single version.
  109. Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
  110. - Remove < 2.4.x support
  111. - Introduce HOST_LOCK to make the spin lock changes portable.
  112. - Remove a bunch of idiotic and unnecessary typedef's
  113. - Kill all leftovers of target-mode support which never worked anyway
  114. Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
  115. - Do qla1280_pci_config() before calling request_irq() and
  116. request_region()
  117. - Use pci_dma_hi32() to handle upper word of DMA addresses instead
  118. of large shifts
  119. - Hand correct arguments to free_irq() in case of failure
  120. Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
  121. - Run source through Lindent and clean up the output
  122. Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
  123. - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
  124. Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
  125. - Rely on mailbox commands generating interrupts - do not
  126. run qla1280_isr() from ql1280_mailbox_command()
  127. - Remove device_reg_t
  128. - Integrate ql12160_set_target_parameters() with 1280 version
  129. - Make qla1280_setup() non static
  130. - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
  131. sent to the card - this command pauses the firmare!!!
  132. Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
  133. - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
  134. - Remove a pile of pointless and confusing (srb_t **) and
  135. (scsi_lu_t *) typecasts
  136. - Explicit mark that we do not use the new error handling (for now)
  137. - Remove scsi_qla_host_t and use 'struct' instead
  138. - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
  139. pci_64bit_slot flags which weren't used for anything anyway
  140. - Grab host->host_lock while calling qla1280_isr() from abort()
  141. - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
  142. do not need to save/restore flags in the interrupt handler
  143. - Enable interrupts early (before any mailbox access) in preparation
  144. for cleaning up the mailbox handling
  145. Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
  146. - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
  147. it with proper use of dprintk().
  148. - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
  149. a debug level argument to determine if data is to be printed
  150. - Add KERN_* info to printk()
  151. Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
  152. - Significant cosmetic cleanups
  153. - Change debug code to use dprintk() and remove #if mess
  154. Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
  155. - More cosmetic cleanups, fix places treating return as function
  156. - use cpu_relax() in qla1280_debounce_register()
  157. Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
  158. - Make it compile under 2.5.5
  159. Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
  160. - Do no typecast short * to long * in QL1280BoardTbl, this
  161. broke miserably on big endian boxes
  162. Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
  163. - Remove pre 2.2 hack for checking for reentrance in interrupt handler
  164. - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
  165. unsigned int to match the types from struct scsi_cmnd
  166. Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
  167. - Remove bogus timer_t typedef from qla1280.h
  168. - Remove obsolete pre 2.2 PCI setup code, use proper #define's
  169. for PCI_ values, call pci_set_master()
  170. - Fix memleak of qla1280_buffer on module unload
  171. - Only compile module parsing code #ifdef MODULE - should be
  172. changed to use individual MODULE_PARM's later
  173. - Remove dummy_buffer that was never modified nor printed
  174. - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
  175. #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
  176. - Remove \r from print statements, this is Linux, not DOS
  177. - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
  178. dummy macros
  179. - Remove C++ compile hack in header file as Linux driver are not
  180. supposed to be compiled as C++
  181. - Kill MS_64BITS macro as it makes the code more readable
  182. - Remove unnecessary flags.in_interrupts bit
  183. Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
  184. - Dont' check for set flags on q->q_flag one by one in qla1280_next()
  185. - Check whether the interrupt was generated by the QLA1280 before
  186. doing any processing
  187. - qla1280_status_entry(): Only zero out part of sense_buffer that
  188. is not being copied into
  189. - Remove more superflouous typecasts
  190. - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
  191. Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
  192. - Don't walk the entire list in qla1280_putq_t() just to directly
  193. grab the pointer to the last element afterwards
  194. Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
  195. - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
  196. Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
  197. - Set dev->max_sectors to 1024
  198. Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
  199. - Provide compat macros for pci_enable_device(), pci_find_subsys()
  200. and scsi_set_pci_device()
  201. - Call scsi_set_pci_device() for all devices
  202. - Reduce size of kernel version dependent device probe code
  203. - Move duplicate probe/init code to separate function
  204. - Handle error if qla1280_mem_alloc() fails
  205. - Kill OFFSET() macro and use Linux's PCI definitions instead
  206. - Kill private structure defining PCI config space (struct config_reg)
  207. - Only allocate I/O port region if not in MMIO mode
  208. - Remove duplicate (unused) sanity check of sife of srb_t
  209. Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
  210. - Change home-brew memset() implementations to use memset()
  211. - Remove all references to COMTRACE() - accessing a PC's COM2 serial
  212. port directly is not legal under Linux.
  213. Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
  214. - Remove pre 2.2 kernel support
  215. - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
  216. - Fix MMIO access to use readl/writel instead of directly
  217. dereferencing pointers
  218. - Nuke MSDOS debugging code
  219. - Change true/false data types to int from uint8_t
  220. - Use int for counters instead of uint8_t etc.
  221. - Clean up size & byte order conversion macro usage
  222. Rev 3.23 Beta January 11, 2001 BN Qlogic
  223. - Added check of device_id when handling non
  224. QLA12160s during detect().
  225. Rev 3.22 Beta January 5, 2001 BN Qlogic
  226. - Changed queue_task() to schedule_task()
  227. for kernels 2.4.0 and higher.
  228. Note: 2.4.0-testxx kernels released prior to
  229. the actual 2.4.0 kernel release on January 2001
  230. will get compile/link errors with schedule_task().
  231. Please update your kernel to released 2.4.0 level,
  232. or comment lines in this file flagged with 3.22
  233. to resolve compile/link error of schedule_task().
  234. - Added -DCONFIG_SMP in addition to -D__SMP__
  235. in Makefile for 2.4.0 builds of driver as module.
  236. Rev 3.21 Beta January 4, 2001 BN Qlogic
  237. - Changed criteria of 64/32 Bit mode of HBA
  238. operation according to BITS_PER_LONG rather
  239. than HBA's NVRAM setting of >4Gig memory bit;
  240. so that the HBA auto-configures without the need
  241. to setup each system individually.
  242. Rev 3.20 Beta December 5, 2000 BN Qlogic
  243. - Added priority handling to IA-64 onboard SCSI
  244. ISP12160 chip for kernels greater than 2.3.18.
  245. - Added irqrestore for qla1280_intr_handler.
  246. - Enabled /proc/scsi/qla1280 interface.
  247. - Clear /proc/scsi/qla1280 counters in detect().
  248. Rev 3.19 Beta October 13, 2000 BN Qlogic
  249. - Declare driver_template for new kernel
  250. (2.4.0 and greater) scsi initialization scheme.
  251. - Update /proc/scsi entry for 2.3.18 kernels and
  252. above as qla1280
  253. Rev 3.18 Beta October 10, 2000 BN Qlogic
  254. - Changed scan order of adapters to map
  255. the QLA12160 followed by the QLA1280.
  256. Rev 3.17 Beta September 18, 2000 BN Qlogic
  257. - Removed warnings for 32 bit 2.4.x compiles
  258. - Corrected declared size for request and response
  259. DMA addresses that are kept in each ha
  260. Rev. 3.16 Beta August 25, 2000 BN Qlogic
  261. - Corrected 64 bit addressing issue on IA-64
  262. where the upper 32 bits were not properly
  263. passed to the RISC engine.
  264. Rev. 3.15 Beta August 22, 2000 BN Qlogic
  265. - Modified qla1280_setup_chip to properly load
  266. ISP firmware for greater that 4 Gig memory on IA-64
  267. Rev. 3.14 Beta August 16, 2000 BN Qlogic
  268. - Added setting of dma_mask to full 64 bit
  269. if flags.enable_64bit_addressing is set in NVRAM
  270. Rev. 3.13 Beta August 16, 2000 BN Qlogic
  271. - Use new PCI DMA mapping APIs for 2.4.x kernel
  272. Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
  273. - Added check of pci_enable_device to detect() for 2.3.x
  274. - Use pci_resource_start() instead of
  275. pdev->resource[0].start in detect() for 2.3.x
  276. - Updated driver version
  277. Rev. 3.11 July 14, 2000 BN Qlogic
  278. - Updated SCSI Firmware to following versions:
  279. qla1x80: 8.13.08
  280. qla1x160: 10.04.08
  281. - Updated driver version to 3.11
  282. Rev. 3.10 June 23, 2000 BN Qlogic
  283. - Added filtering of AMI SubSys Vendor ID devices
  284. Rev. 3.9
  285. - DEBUG_QLA1280 undefined and new version BN Qlogic
  286. Rev. 3.08b May 9, 2000 MD Dell
  287. - Added logic to check against AMI subsystem vendor ID
  288. Rev. 3.08 May 4, 2000 DG Qlogic
  289. - Added logic to check for PCI subsystem ID.
  290. Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
  291. - Updated SCSI Firmware to following versions:
  292. qla12160: 10.01.19
  293. qla1280: 8.09.00
  294. Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
  295. - Internal revision; not released
  296. Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
  297. - Edit correction for virt_to_bus and PROC.
  298. Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
  299. - Merge changes from ia64 port.
  300. Rev. 3.03 Mar 28, 2000 BN Qlogic
  301. - Increase version to reflect new code drop with compile fix
  302. of issue with inclusion of linux/spinlock for 2.3 kernels
  303. Rev. 3.02 Mar 15, 2000 BN Qlogic
  304. - Merge qla1280_proc_info from 2.10 code base
  305. Rev. 3.01 Feb 10, 2000 BN Qlogic
  306. - Corrected code to compile on a 2.2.x kernel.
  307. Rev. 3.00 Jan 17, 2000 DG Qlogic
  308. - Added 64-bit support.
  309. Rev. 2.07 Nov 9, 1999 DG Qlogic
  310. - Added new routine to set target parameters for ISP12160.
  311. Rev. 2.06 Sept 10, 1999 DG Qlogic
  312. - Added support for ISP12160 Ultra 3 chip.
  313. Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
  314. - Modified code to remove errors generated when compiling with
  315. Cygnus IA64 Compiler.
  316. - Changed conversion of pointers to unsigned longs instead of integers.
  317. - Changed type of I/O port variables from uint32_t to unsigned long.
  318. - Modified OFFSET macro to work with 64-bit as well as 32-bit.
  319. - Changed sprintf and printk format specifiers for pointers to %p.
  320. - Changed some int to long type casts where needed in sprintf & printk.
  321. - Added l modifiers to sprintf and printk format specifiers for longs.
  322. - Removed unused local variables.
  323. Rev. 1.20 June 8, 1999 DG, Qlogic
  324. Changes to support RedHat release 6.0 (kernel 2.2.5).
  325. - Added SCSI exclusive access lock (io_request_lock) when accessing
  326. the adapter.
  327. - Added changes for the new LINUX interface template. Some new error
  328. handling routines have been added to the template, but for now we
  329. will use the old ones.
  330. - Initial Beta Release.
  331. *****************************************************************************/
  332. #include <linux/config.h>
  333. #include <linux/module.h>
  334. #include <linux/version.h>
  335. #include <linux/types.h>
  336. #include <linux/string.h>
  337. #include <linux/errno.h>
  338. #include <linux/kernel.h>
  339. #include <linux/ioport.h>
  340. #include <linux/delay.h>
  341. #include <linux/timer.h>
  342. #include <linux/sched.h>
  343. #include <linux/pci.h>
  344. #include <linux/proc_fs.h>
  345. #include <linux/stat.h>
  346. #include <linux/slab.h>
  347. #include <linux/pci_ids.h>
  348. #include <linux/interrupt.h>
  349. #include <linux/init.h>
  350. #include <linux/dma-mapping.h>
  351. #include <asm/io.h>
  352. #include <asm/irq.h>
  353. #include <asm/byteorder.h>
  354. #include <asm/processor.h>
  355. #include <asm/types.h>
  356. #include <asm/system.h>
  357. #include <scsi/scsi.h>
  358. #include <scsi/scsi_cmnd.h>
  359. #include <scsi/scsi_device.h>
  360. #include <scsi/scsi_host.h>
  361. #include <scsi/scsi_tcq.h>
  362. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  363. #include <asm/sn/io.h>
  364. #endif
  365. #if LINUX_VERSION_CODE < 0x020600
  366. #error "Kernels older than 2.6.0 are no longer supported"
  367. #endif
  368. /*
  369. * Compile time Options:
  370. * 0 - Disable and 1 - Enable
  371. */
  372. #define DEBUG_QLA1280_INTR 0
  373. #define DEBUG_PRINT_NVRAM 0
  374. #define DEBUG_QLA1280 0
  375. /*
  376. * The SGI VISWS is broken and doesn't support MMIO ;-(
  377. */
  378. #ifdef CONFIG_X86_VISWS
  379. #define MEMORY_MAPPED_IO 0
  380. #else
  381. #define MEMORY_MAPPED_IO 1
  382. #endif
  383. #define UNIQUE_FW_NAME
  384. #include "qla1280.h"
  385. #include "ql12160_fw.h" /* ISP RISC codes */
  386. #include "ql1280_fw.h"
  387. #include "ql1040_fw.h"
  388. /*
  389. * Missing PCI ID's
  390. */
  391. #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
  392. #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
  393. #endif
  394. #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
  395. #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
  396. #endif
  397. #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
  398. #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
  399. #endif
  400. #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
  401. #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
  402. #endif
  403. #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
  404. #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
  405. #endif
  406. #ifndef PCI_VENDOR_ID_AMI
  407. #define PCI_VENDOR_ID_AMI 0x101e
  408. #endif
  409. #ifndef BITS_PER_LONG
  410. #error "BITS_PER_LONG not defined!"
  411. #endif
  412. #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
  413. #define QLA_64BIT_PTR 1
  414. #endif
  415. #ifdef QLA_64BIT_PTR
  416. #define pci_dma_hi32(a) ((a >> 16) >> 16)
  417. #else
  418. #define pci_dma_hi32(a) 0
  419. #endif
  420. #define pci_dma_lo32(a) (a & 0xffffffff)
  421. #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
  422. #if defined(__ia64__) && !defined(ia64_platform_is)
  423. #define ia64_platform_is(foo) (!strcmp(x, platform_name))
  424. #endif
  425. #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
  426. #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
  427. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
  428. #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
  429. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
  430. static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
  431. static void qla1280_remove_one(struct pci_dev *);
  432. /*
  433. * QLogic Driver Support Function Prototypes.
  434. */
  435. static void qla1280_done(struct scsi_qla_host *);
  436. static int qla1280_get_token(char *);
  437. static int qla1280_setup(char *s) __init;
  438. /*
  439. * QLogic ISP1280 Hardware Support Function Prototypes.
  440. */
  441. static int qla1280_load_firmware(struct scsi_qla_host *);
  442. static int qla1280_init_rings(struct scsi_qla_host *);
  443. static int qla1280_nvram_config(struct scsi_qla_host *);
  444. static int qla1280_mailbox_command(struct scsi_qla_host *,
  445. uint8_t, uint16_t *);
  446. static int qla1280_bus_reset(struct scsi_qla_host *, int);
  447. static int qla1280_device_reset(struct scsi_qla_host *, int, int);
  448. static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
  449. static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
  450. static int qla1280_abort_isp(struct scsi_qla_host *);
  451. #ifdef QLA_64BIT_PTR
  452. static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
  453. #else
  454. static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
  455. #endif
  456. static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
  457. static void qla1280_poll(struct scsi_qla_host *);
  458. static void qla1280_reset_adapter(struct scsi_qla_host *);
  459. static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
  460. static void qla1280_isp_cmd(struct scsi_qla_host *);
  461. static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
  462. static void qla1280_rst_aen(struct scsi_qla_host *);
  463. static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
  464. struct list_head *);
  465. static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
  466. struct list_head *);
  467. static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
  468. static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
  469. static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
  470. static request_t *qla1280_req_pkt(struct scsi_qla_host *);
  471. static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
  472. unsigned int);
  473. static void qla1280_get_target_parameters(struct scsi_qla_host *,
  474. struct scsi_device *);
  475. static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
  476. static struct qla_driver_setup driver_setup;
  477. /*
  478. * convert scsi data direction to request_t control flags
  479. */
  480. static inline uint16_t
  481. qla1280_data_direction(struct scsi_cmnd *cmnd)
  482. {
  483. switch(cmnd->sc_data_direction) {
  484. case DMA_FROM_DEVICE:
  485. return BIT_5;
  486. case DMA_TO_DEVICE:
  487. return BIT_6;
  488. case DMA_BIDIRECTIONAL:
  489. return BIT_5 | BIT_6;
  490. /*
  491. * We could BUG() on default here if one of the four cases aren't
  492. * met, but then again if we receive something like that from the
  493. * SCSI layer we have more serious problems. This shuts up GCC.
  494. */
  495. case DMA_NONE:
  496. default:
  497. return 0;
  498. }
  499. }
  500. #if DEBUG_QLA1280
  501. static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
  502. static void __qla1280_dump_buffer(char *, int);
  503. #endif
  504. /*
  505. * insmod needs to find the variable and make it point to something
  506. */
  507. #ifdef MODULE
  508. static char *qla1280;
  509. /* insmod qla1280 options=verbose" */
  510. module_param(qla1280, charp, 0);
  511. #else
  512. __setup("qla1280=", qla1280_setup);
  513. #endif
  514. /*
  515. * We use the scsi_pointer structure that's included with each scsi_command
  516. * to overlay our struct srb over it. qla1280_init() checks that a srb is not
  517. * bigger than a scsi_pointer.
  518. */
  519. #define CMD_SP(Cmnd) &Cmnd->SCp
  520. #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
  521. #define CMD_CDBP(Cmnd) Cmnd->cmnd
  522. #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
  523. #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
  524. #define CMD_RESULT(Cmnd) Cmnd->result
  525. #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
  526. #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
  527. #define CMD_HOST(Cmnd) Cmnd->device->host
  528. #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
  529. #define SCSI_TCN_32(Cmnd) Cmnd->device->id
  530. #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
  531. /*****************************************/
  532. /* ISP Boards supported by this driver */
  533. /*****************************************/
  534. struct qla_boards {
  535. unsigned char name[9]; /* Board ID String */
  536. int numPorts; /* Number of SCSI ports */
  537. unsigned short *fwcode; /* pointer to FW array */
  538. unsigned short *fwlen; /* number of words in array */
  539. unsigned short *fwstart; /* start address for F/W */
  540. unsigned char *fwver; /* Ptr to F/W version array */
  541. };
  542. /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
  543. static struct pci_device_id qla1280_pci_tbl[] = {
  544. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
  545. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  546. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
  547. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  548. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
  549. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  550. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
  551. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  552. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
  553. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  554. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
  555. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
  556. {0,}
  557. };
  558. MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
  559. static struct qla_boards ql1280_board_tbl[] = {
  560. /* Name , Number of ports, FW details */
  561. {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
  562. &fw12160i_addr01, &fw12160i_version_str[0]},
  563. {"QLA1040", 1, &risc_code01[0], &risc_code_length01,
  564. &risc_code_addr01, &firmware_version[0]},
  565. {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
  566. &fw1280ei_addr01, &fw1280ei_version_str[0]},
  567. {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
  568. &fw1280ei_addr01, &fw1280ei_version_str[0]},
  569. {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
  570. &fw1280ei_addr01, &fw1280ei_version_str[0]},
  571. {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
  572. &fw12160i_addr01, &fw12160i_version_str[0]},
  573. {" ", 0}
  574. };
  575. static int qla1280_verbose = 1;
  576. #if DEBUG_QLA1280
  577. static int ql_debug_level = 1;
  578. #define dprintk(level, format, a...) \
  579. do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
  580. #define qla1280_dump_buffer(level, buf, size) \
  581. if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
  582. #define qla1280_print_scsi_cmd(level, cmd) \
  583. if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
  584. #else
  585. #define ql_debug_level 0
  586. #define dprintk(level, format, a...) do{}while(0)
  587. #define qla1280_dump_buffer(a, b, c) do{}while(0)
  588. #define qla1280_print_scsi_cmd(a, b) do{}while(0)
  589. #endif
  590. #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
  591. #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
  592. #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
  593. #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
  594. static int qla1280_read_nvram(struct scsi_qla_host *ha)
  595. {
  596. uint16_t *wptr;
  597. uint8_t chksum;
  598. int cnt, i;
  599. struct nvram *nv;
  600. ENTER("qla1280_read_nvram");
  601. if (driver_setup.no_nvram)
  602. return 1;
  603. printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
  604. wptr = (uint16_t *)&ha->nvram;
  605. nv = &ha->nvram;
  606. chksum = 0;
  607. for (cnt = 0; cnt < 3; cnt++) {
  608. *wptr = qla1280_get_nvram_word(ha, cnt);
  609. chksum += *wptr & 0xff;
  610. chksum += (*wptr >> 8) & 0xff;
  611. wptr++;
  612. }
  613. if (nv->id0 != 'I' || nv->id1 != 'S' ||
  614. nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
  615. dprintk(2, "Invalid nvram ID or version!\n");
  616. chksum = 1;
  617. } else {
  618. for (; cnt < sizeof(struct nvram); cnt++) {
  619. *wptr = qla1280_get_nvram_word(ha, cnt);
  620. chksum += *wptr & 0xff;
  621. chksum += (*wptr >> 8) & 0xff;
  622. wptr++;
  623. }
  624. }
  625. dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
  626. " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
  627. nv->version);
  628. if (chksum) {
  629. if (!driver_setup.no_nvram)
  630. printk(KERN_WARNING "scsi(%ld): Unable to identify or "
  631. "validate NVRAM checksum, using default "
  632. "settings\n", ha->host_no);
  633. ha->nvram_valid = 0;
  634. } else
  635. ha->nvram_valid = 1;
  636. /* The firmware interface is, um, interesting, in that the
  637. * actual firmware image on the chip is little endian, thus,
  638. * the process of taking that image to the CPU would end up
  639. * little endian. However, the firmare interface requires it
  640. * to be read a word (two bytes) at a time.
  641. *
  642. * The net result of this would be that the word (and
  643. * doubleword) quantites in the firmware would be correct, but
  644. * the bytes would be pairwise reversed. Since most of the
  645. * firmware quantites are, in fact, bytes, we do an extra
  646. * le16_to_cpu() in the firmware read routine.
  647. *
  648. * The upshot of all this is that the bytes in the firmware
  649. * are in the correct places, but the 16 and 32 bit quantites
  650. * are still in little endian format. We fix that up below by
  651. * doing extra reverses on them */
  652. nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
  653. nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
  654. for(i = 0; i < MAX_BUSES; i++) {
  655. nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
  656. nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
  657. }
  658. dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
  659. LEAVE("qla1280_read_nvram");
  660. return chksum;
  661. }
  662. /**************************************************************************
  663. * qla1280_info
  664. * Return a string describing the driver.
  665. **************************************************************************/
  666. static const char *
  667. qla1280_info(struct Scsi_Host *host)
  668. {
  669. static char qla1280_scsi_name_buffer[125];
  670. char *bp;
  671. struct scsi_qla_host *ha;
  672. struct qla_boards *bdp;
  673. bp = &qla1280_scsi_name_buffer[0];
  674. ha = (struct scsi_qla_host *)host->hostdata;
  675. bdp = &ql1280_board_tbl[ha->devnum];
  676. memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
  677. sprintf (bp,
  678. "QLogic %s PCI to SCSI Host Adapter\n"
  679. " Firmware version: %2d.%02d.%02d, Driver version %s",
  680. &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
  681. QLA1280_VERSION);
  682. return bp;
  683. }
  684. /**************************************************************************
  685. * qla1200_queuecommand
  686. * Queue a command to the controller.
  687. *
  688. * Note:
  689. * The mid-level driver tries to ensures that queuecommand never gets invoked
  690. * concurrently with itself or the interrupt handler (although the
  691. * interrupt handler may call this routine as part of request-completion
  692. * handling). Unfortunely, it sometimes calls the scheduler in interrupt
  693. * context which is a big NO! NO!.
  694. **************************************************************************/
  695. static int
  696. qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
  697. {
  698. struct Scsi_Host *host = cmd->device->host;
  699. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  700. struct srb *sp = (struct srb *)&cmd->SCp;
  701. int status;
  702. cmd->scsi_done = fn;
  703. sp->cmd = cmd;
  704. sp->flags = 0;
  705. qla1280_print_scsi_cmd(5, cmd);
  706. #ifdef QLA_64BIT_PTR
  707. /*
  708. * Using 64 bit commands if the PCI bridge doesn't support it is a
  709. * bit wasteful, however this should really only happen if one's
  710. * PCI controller is completely broken, like the BCM1250. For
  711. * sane hardware this is not an issue.
  712. */
  713. status = qla1280_64bit_start_scsi(ha, sp);
  714. #else
  715. status = qla1280_32bit_start_scsi(ha, sp);
  716. #endif
  717. return status;
  718. }
  719. enum action {
  720. ABORT_COMMAND,
  721. ABORT_DEVICE,
  722. DEVICE_RESET,
  723. BUS_RESET,
  724. ADAPTER_RESET,
  725. FAIL
  726. };
  727. /* timer action for error action processor */
  728. static void qla1280_error_wait_timeout(unsigned long __data)
  729. {
  730. struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
  731. struct srb *sp = (struct srb *)CMD_SP(cmd);
  732. complete(sp->wait);
  733. }
  734. static void qla1280_mailbox_timeout(unsigned long __data)
  735. {
  736. struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
  737. struct device_reg __iomem *reg;
  738. reg = ha->iobase;
  739. ha->mailbox_out[0] = RD_REG_WORD(&reg->mailbox0);
  740. printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
  741. "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
  742. RD_REG_WORD(&reg->ictrl), RD_REG_WORD(&reg->istatus));
  743. complete(ha->mailbox_wait);
  744. }
  745. /**************************************************************************
  746. * qla1200_error_action
  747. * The function will attempt to perform a specified error action and
  748. * wait for the results (or time out).
  749. *
  750. * Input:
  751. * cmd = Linux SCSI command packet of the command that cause the
  752. * bus reset.
  753. * action = error action to take (see action_t)
  754. *
  755. * Returns:
  756. * SUCCESS or FAILED
  757. *
  758. * Note:
  759. * Resetting the bus always succeeds - is has to, otherwise the
  760. * kernel will panic! Try a surgical technique - sending a BUS
  761. * DEVICE RESET message - on the offending target before pulling
  762. * the SCSI bus reset line.
  763. **************************************************************************/
  764. static int
  765. qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
  766. {
  767. struct scsi_qla_host *ha;
  768. int bus, target, lun;
  769. struct srb *sp;
  770. uint16_t data;
  771. unsigned char *handle;
  772. int result, i;
  773. DECLARE_COMPLETION(wait);
  774. struct timer_list timer;
  775. ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
  776. dprintk(4, "error_action %i, istatus 0x%04x\n", action,
  777. RD_REG_WORD(&ha->iobase->istatus));
  778. dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
  779. RD_REG_WORD(&ha->iobase->host_cmd),
  780. RD_REG_WORD(&ha->iobase->ictrl), jiffies);
  781. ENTER("qla1280_error_action");
  782. if (qla1280_verbose)
  783. printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
  784. "Handle=0x%p, action=0x%x\n",
  785. ha->host_no, cmd, CMD_HANDLE(cmd), action);
  786. if (cmd == NULL) {
  787. printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
  788. "si_Cmnd pointer, failing.\n");
  789. LEAVE("qla1280_error_action");
  790. return FAILED;
  791. }
  792. ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
  793. sp = (struct srb *)CMD_SP(cmd);
  794. handle = CMD_HANDLE(cmd);
  795. /* Check for pending interrupts. */
  796. data = qla1280_debounce_register(&ha->iobase->istatus);
  797. /*
  798. * The io_request_lock is held when the reset handler is called, hence
  799. * the interrupt handler cannot be running in parallel as it also
  800. * grabs the lock. /Jes
  801. */
  802. if (data & RISC_INT)
  803. qla1280_isr(ha, &ha->done_q);
  804. /*
  805. * Determine the suggested action that the mid-level driver wants
  806. * us to perform.
  807. */
  808. if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
  809. if(action == ABORT_COMMAND) {
  810. /* we never got this command */
  811. printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
  812. return SUCCESS; /* no action - we don't have command */
  813. }
  814. } else {
  815. sp->wait = &wait;
  816. }
  817. bus = SCSI_BUS_32(cmd);
  818. target = SCSI_TCN_32(cmd);
  819. lun = SCSI_LUN_32(cmd);
  820. /* Overloading result. Here it means the success or fail of the
  821. * *issue* of the action. When we return from the routine, it must
  822. * mean the actual success or fail of the action */
  823. result = FAILED;
  824. switch (action) {
  825. case FAIL:
  826. break;
  827. case ABORT_COMMAND:
  828. if ((sp->flags & SRB_ABORT_PENDING)) {
  829. printk(KERN_WARNING
  830. "scsi(): Command has a pending abort "
  831. "message - ABORT_PENDING.\n");
  832. /* This should technically be impossible since we
  833. * now wait for abort completion */
  834. break;
  835. }
  836. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  837. if (sp == ha->outstanding_cmds[i]) {
  838. dprintk(1, "qla1280: RISC aborting command\n");
  839. if (qla1280_abort_command(ha, sp, i) == 0)
  840. result = SUCCESS;
  841. else {
  842. /*
  843. * Since we don't know what might
  844. * have happend to the command, it
  845. * is unsafe to remove it from the
  846. * device's queue at this point.
  847. * Wait and let the escalation
  848. * process take care of it.
  849. */
  850. printk(KERN_WARNING
  851. "scsi(%li:%i:%i:%i): Unable"
  852. " to abort command!\n",
  853. ha->host_no, bus, target, lun);
  854. }
  855. }
  856. }
  857. break;
  858. case ABORT_DEVICE:
  859. if (qla1280_verbose)
  860. printk(KERN_INFO
  861. "scsi(%ld:%d:%d:%d): Queueing abort device "
  862. "command.\n", ha->host_no, bus, target, lun);
  863. if (qla1280_abort_device(ha, bus, target, lun) == 0)
  864. result = SUCCESS;
  865. break;
  866. case DEVICE_RESET:
  867. if (qla1280_verbose)
  868. printk(KERN_INFO
  869. "scsi(%ld:%d:%d:%d): Queueing device reset "
  870. "command.\n", ha->host_no, bus, target, lun);
  871. if (qla1280_device_reset(ha, bus, target) == 0)
  872. result = SUCCESS;
  873. break;
  874. case BUS_RESET:
  875. if (qla1280_verbose)
  876. printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
  877. "DEVICE RESET\n", ha->host_no, bus);
  878. if (qla1280_bus_reset(ha, bus == 0))
  879. result = SUCCESS;
  880. break;
  881. case ADAPTER_RESET:
  882. default:
  883. if (qla1280_verbose) {
  884. printk(KERN_INFO
  885. "scsi(%ld): Issued ADAPTER RESET\n",
  886. ha->host_no);
  887. printk(KERN_INFO "scsi(%ld): I/O processing will "
  888. "continue automatically\n", ha->host_no);
  889. }
  890. ha->flags.reset_active = 1;
  891. /*
  892. * We restarted all of the commands automatically, so the
  893. * mid-level code can expect completions momentitarily.
  894. */
  895. if (qla1280_abort_isp(ha) == 0)
  896. result = SUCCESS;
  897. ha->flags.reset_active = 0;
  898. }
  899. if (!list_empty(&ha->done_q))
  900. qla1280_done(ha);
  901. /* If we didn't manage to issue the action, or we have no
  902. * command to wait for, exit here */
  903. if (result == FAILED || handle == NULL ||
  904. handle == (unsigned char *)INVALID_HANDLE) {
  905. /*
  906. * Clear completion queue to avoid qla1280_done() trying
  907. * to complete the command at a later stage after we
  908. * have exited the current context
  909. */
  910. sp->wait = NULL;
  911. goto leave;
  912. }
  913. /* set up a timer just in case we're really jammed */
  914. init_timer(&timer);
  915. timer.expires = jiffies + 4*HZ;
  916. timer.data = (unsigned long)cmd;
  917. timer.function = qla1280_error_wait_timeout;
  918. add_timer(&timer);
  919. /* wait for the action to complete (or the timer to expire) */
  920. spin_unlock_irq(ha->host->host_lock);
  921. wait_for_completion(&wait);
  922. del_timer_sync(&timer);
  923. spin_lock_irq(ha->host->host_lock);
  924. sp->wait = NULL;
  925. /* the only action we might get a fail for is abort */
  926. if (action == ABORT_COMMAND) {
  927. if(sp->flags & SRB_ABORTED)
  928. result = SUCCESS;
  929. else
  930. result = FAILED;
  931. }
  932. leave:
  933. dprintk(1, "RESET returning %d\n", result);
  934. LEAVE("qla1280_error_action");
  935. return result;
  936. }
  937. /**************************************************************************
  938. * qla1280_abort
  939. * Abort the specified SCSI command(s).
  940. **************************************************************************/
  941. static int
  942. qla1280_eh_abort(struct scsi_cmnd * cmd)
  943. {
  944. int rc;
  945. spin_lock_irq(cmd->device->host->host_lock);
  946. rc = qla1280_error_action(cmd, ABORT_COMMAND);
  947. spin_unlock_irq(cmd->device->host->host_lock);
  948. return rc;
  949. }
  950. /**************************************************************************
  951. * qla1280_device_reset
  952. * Reset the specified SCSI device
  953. **************************************************************************/
  954. static int
  955. qla1280_eh_device_reset(struct scsi_cmnd *cmd)
  956. {
  957. int rc;
  958. spin_lock_irq(cmd->device->host->host_lock);
  959. rc = qla1280_error_action(cmd, DEVICE_RESET);
  960. spin_unlock_irq(cmd->device->host->host_lock);
  961. return rc;
  962. }
  963. /**************************************************************************
  964. * qla1280_bus_reset
  965. * Reset the specified bus.
  966. **************************************************************************/
  967. static int
  968. qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
  969. {
  970. int rc;
  971. spin_lock_irq(cmd->device->host->host_lock);
  972. rc = qla1280_error_action(cmd, BUS_RESET);
  973. spin_unlock_irq(cmd->device->host->host_lock);
  974. return rc;
  975. }
  976. /**************************************************************************
  977. * qla1280_adapter_reset
  978. * Reset the specified adapter (both channels)
  979. **************************************************************************/
  980. static int
  981. qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
  982. {
  983. int rc;
  984. spin_lock_irq(cmd->device->host->host_lock);
  985. rc = qla1280_error_action(cmd, ADAPTER_RESET);
  986. spin_unlock_irq(cmd->device->host->host_lock);
  987. return rc;
  988. }
  989. static int
  990. qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  991. sector_t capacity, int geom[])
  992. {
  993. int heads, sectors, cylinders;
  994. heads = 64;
  995. sectors = 32;
  996. cylinders = (unsigned long)capacity / (heads * sectors);
  997. if (cylinders > 1024) {
  998. heads = 255;
  999. sectors = 63;
  1000. cylinders = (unsigned long)capacity / (heads * sectors);
  1001. /* if (cylinders > 1023)
  1002. cylinders = 1023; */
  1003. }
  1004. geom[0] = heads;
  1005. geom[1] = sectors;
  1006. geom[2] = cylinders;
  1007. return 0;
  1008. }
  1009. /* disable risc and host interrupts */
  1010. static inline void
  1011. qla1280_disable_intrs(struct scsi_qla_host *ha)
  1012. {
  1013. WRT_REG_WORD(&ha->iobase->ictrl, 0);
  1014. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  1015. }
  1016. /* enable risc and host interrupts */
  1017. static inline void
  1018. qla1280_enable_intrs(struct scsi_qla_host *ha)
  1019. {
  1020. WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
  1021. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  1022. }
  1023. /**************************************************************************
  1024. * qla1280_intr_handler
  1025. * Handles the H/W interrupt
  1026. **************************************************************************/
  1027. static irqreturn_t
  1028. qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  1029. {
  1030. struct scsi_qla_host *ha;
  1031. struct device_reg __iomem *reg;
  1032. u16 data;
  1033. int handled = 0;
  1034. ENTER_INTR ("qla1280_intr_handler");
  1035. ha = (struct scsi_qla_host *)dev_id;
  1036. spin_lock(ha->host->host_lock);
  1037. ha->isr_count++;
  1038. reg = ha->iobase;
  1039. qla1280_disable_intrs(ha);
  1040. data = qla1280_debounce_register(&reg->istatus);
  1041. /* Check for pending interrupts. */
  1042. if (data & RISC_INT) {
  1043. qla1280_isr(ha, &ha->done_q);
  1044. handled = 1;
  1045. }
  1046. if (!list_empty(&ha->done_q))
  1047. qla1280_done(ha);
  1048. spin_unlock(ha->host->host_lock);
  1049. qla1280_enable_intrs(ha);
  1050. LEAVE_INTR("qla1280_intr_handler");
  1051. return IRQ_RETVAL(handled);
  1052. }
  1053. static int
  1054. qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
  1055. {
  1056. uint8_t mr;
  1057. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1058. struct nvram *nv;
  1059. int status, lun;
  1060. nv = &ha->nvram;
  1061. mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
  1062. /* Set Target Parameters. */
  1063. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1064. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1065. mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
  1066. mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
  1067. mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
  1068. mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
  1069. mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
  1070. mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
  1071. mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
  1072. mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
  1073. if (IS_ISP1x160(ha)) {
  1074. mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
  1075. mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
  1076. mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
  1077. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
  1078. mr |= BIT_6;
  1079. } else {
  1080. mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
  1081. }
  1082. mb[3] |= nv->bus[bus].target[target].sync_period;
  1083. status = qla1280_mailbox_command(ha, mr, mb);
  1084. /* Set Device Queue Parameters. */
  1085. for (lun = 0; lun < MAX_LUNS; lun++) {
  1086. mb[0] = MBC_SET_DEVICE_QUEUE;
  1087. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1088. mb[1] |= lun;
  1089. mb[2] = nv->bus[bus].max_queue_depth;
  1090. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1091. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1092. }
  1093. if (status)
  1094. printk(KERN_WARNING "scsi(%ld:%i:%i): "
  1095. "qla1280_set_target_parameters() failed\n",
  1096. ha->host_no, bus, target);
  1097. return status;
  1098. }
  1099. /**************************************************************************
  1100. * qla1280_slave_configure
  1101. *
  1102. * Description:
  1103. * Determines the queue depth for a given device. There are two ways
  1104. * a queue depth can be obtained for a tagged queueing device. One
  1105. * way is the default queue depth which is determined by whether
  1106. * If it is defined, then it is used
  1107. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  1108. * default queue depth (dependent on the number of hardware SCBs).
  1109. **************************************************************************/
  1110. static int
  1111. qla1280_slave_configure(struct scsi_device *device)
  1112. {
  1113. struct scsi_qla_host *ha;
  1114. int default_depth = 3;
  1115. int bus = device->channel;
  1116. int target = device->id;
  1117. int status = 0;
  1118. struct nvram *nv;
  1119. unsigned long flags;
  1120. ha = (struct scsi_qla_host *)device->host->hostdata;
  1121. nv = &ha->nvram;
  1122. if (qla1280_check_for_dead_scsi_bus(ha, bus))
  1123. return 1;
  1124. if (device->tagged_supported &&
  1125. (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
  1126. scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
  1127. ha->bus_settings[bus].hiwat);
  1128. } else {
  1129. scsi_adjust_queue_depth(device, 0, default_depth);
  1130. }
  1131. nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
  1132. nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
  1133. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
  1134. if (driver_setup.no_sync ||
  1135. (driver_setup.sync_mask &&
  1136. (~driver_setup.sync_mask & (1 << target))))
  1137. nv->bus[bus].target[target].parameter.enable_sync = 0;
  1138. if (driver_setup.no_wide ||
  1139. (driver_setup.wide_mask &&
  1140. (~driver_setup.wide_mask & (1 << target))))
  1141. nv->bus[bus].target[target].parameter.enable_wide = 0;
  1142. if (IS_ISP1x160(ha)) {
  1143. if (driver_setup.no_ppr ||
  1144. (driver_setup.ppr_mask &&
  1145. (~driver_setup.ppr_mask & (1 << target))))
  1146. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
  1147. }
  1148. spin_lock_irqsave(ha->host->host_lock, flags);
  1149. if (nv->bus[bus].target[target].parameter.enable_sync)
  1150. status = qla1280_set_target_parameters(ha, bus, target);
  1151. qla1280_get_target_parameters(ha, device);
  1152. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1153. return status;
  1154. }
  1155. /*
  1156. * qla1280_done
  1157. * Process completed commands.
  1158. *
  1159. * Input:
  1160. * ha = adapter block pointer.
  1161. */
  1162. static void
  1163. qla1280_done(struct scsi_qla_host *ha)
  1164. {
  1165. struct srb *sp;
  1166. struct list_head *done_q;
  1167. int bus, target, lun;
  1168. struct scsi_cmnd *cmd;
  1169. ENTER("qla1280_done");
  1170. done_q = &ha->done_q;
  1171. while (!list_empty(done_q)) {
  1172. sp = list_entry(done_q->next, struct srb, list);
  1173. list_del(&sp->list);
  1174. cmd = sp->cmd;
  1175. bus = SCSI_BUS_32(cmd);
  1176. target = SCSI_TCN_32(cmd);
  1177. lun = SCSI_LUN_32(cmd);
  1178. switch ((CMD_RESULT(cmd) >> 16)) {
  1179. case DID_RESET:
  1180. /* Issue marker command. */
  1181. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  1182. break;
  1183. case DID_ABORT:
  1184. sp->flags &= ~SRB_ABORT_PENDING;
  1185. sp->flags |= SRB_ABORTED;
  1186. if (sp->flags & SRB_TIMEOUT)
  1187. CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
  1188. break;
  1189. default:
  1190. break;
  1191. }
  1192. /* Release memory used for this I/O */
  1193. if (cmd->use_sg) {
  1194. pci_unmap_sg(ha->pdev, cmd->request_buffer,
  1195. cmd->use_sg, cmd->sc_data_direction);
  1196. } else if (cmd->request_bufflen) {
  1197. pci_unmap_single(ha->pdev, sp->saved_dma_handle,
  1198. cmd->request_bufflen,
  1199. cmd->sc_data_direction);
  1200. }
  1201. /* Call the mid-level driver interrupt handler */
  1202. CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
  1203. ha->actthreads--;
  1204. (*(cmd)->scsi_done)(cmd);
  1205. if(sp->wait != NULL)
  1206. complete(sp->wait);
  1207. }
  1208. LEAVE("qla1280_done");
  1209. }
  1210. /*
  1211. * Translates a ISP error to a Linux SCSI error
  1212. */
  1213. static int
  1214. qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
  1215. {
  1216. int host_status = DID_ERROR;
  1217. uint16_t comp_status = le16_to_cpu(sts->comp_status);
  1218. uint16_t state_flags = le16_to_cpu(sts->state_flags);
  1219. uint16_t residual_length = le32_to_cpu(sts->residual_length);
  1220. uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
  1221. #if DEBUG_QLA1280_INTR
  1222. static char *reason[] = {
  1223. "DID_OK",
  1224. "DID_NO_CONNECT",
  1225. "DID_BUS_BUSY",
  1226. "DID_TIME_OUT",
  1227. "DID_BAD_TARGET",
  1228. "DID_ABORT",
  1229. "DID_PARITY",
  1230. "DID_ERROR",
  1231. "DID_RESET",
  1232. "DID_BAD_INTR"
  1233. };
  1234. #endif /* DEBUG_QLA1280_INTR */
  1235. ENTER("qla1280_return_status");
  1236. #if DEBUG_QLA1280_INTR
  1237. /*
  1238. dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
  1239. comp_status);
  1240. */
  1241. #endif
  1242. switch (comp_status) {
  1243. case CS_COMPLETE:
  1244. host_status = DID_OK;
  1245. break;
  1246. case CS_INCOMPLETE:
  1247. if (!(state_flags & SF_GOT_BUS))
  1248. host_status = DID_NO_CONNECT;
  1249. else if (!(state_flags & SF_GOT_TARGET))
  1250. host_status = DID_BAD_TARGET;
  1251. else if (!(state_flags & SF_SENT_CDB))
  1252. host_status = DID_ERROR;
  1253. else if (!(state_flags & SF_TRANSFERRED_DATA))
  1254. host_status = DID_ERROR;
  1255. else if (!(state_flags & SF_GOT_STATUS))
  1256. host_status = DID_ERROR;
  1257. else if (!(state_flags & SF_GOT_SENSE))
  1258. host_status = DID_ERROR;
  1259. break;
  1260. case CS_RESET:
  1261. host_status = DID_RESET;
  1262. break;
  1263. case CS_ABORTED:
  1264. host_status = DID_ABORT;
  1265. break;
  1266. case CS_TIMEOUT:
  1267. host_status = DID_TIME_OUT;
  1268. break;
  1269. case CS_DATA_OVERRUN:
  1270. dprintk(2, "Data overrun 0x%x\n", residual_length);
  1271. dprintk(2, "qla1280_return_status: response packet data\n");
  1272. qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
  1273. host_status = DID_ERROR;
  1274. break;
  1275. case CS_DATA_UNDERRUN:
  1276. if ((cp->request_bufflen - residual_length) <
  1277. cp->underflow) {
  1278. printk(KERN_WARNING
  1279. "scsi: Underflow detected - retrying "
  1280. "command.\n");
  1281. host_status = DID_ERROR;
  1282. } else
  1283. host_status = DID_OK;
  1284. break;
  1285. default:
  1286. host_status = DID_ERROR;
  1287. break;
  1288. }
  1289. #if DEBUG_QLA1280_INTR
  1290. dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
  1291. reason[host_status], scsi_status);
  1292. #endif
  1293. LEAVE("qla1280_return_status");
  1294. return (scsi_status & 0xff) | (host_status << 16);
  1295. }
  1296. /****************************************************************************/
  1297. /* QLogic ISP1280 Hardware Support Functions. */
  1298. /****************************************************************************/
  1299. /*
  1300. * qla1280_initialize_adapter
  1301. * Initialize board.
  1302. *
  1303. * Input:
  1304. * ha = adapter block pointer.
  1305. *
  1306. * Returns:
  1307. * 0 = success
  1308. */
  1309. static int __devinit
  1310. qla1280_initialize_adapter(struct scsi_qla_host *ha)
  1311. {
  1312. struct device_reg __iomem *reg;
  1313. int status;
  1314. int bus;
  1315. unsigned long flags;
  1316. ENTER("qla1280_initialize_adapter");
  1317. /* Clear adapter flags. */
  1318. ha->flags.online = 0;
  1319. ha->flags.disable_host_adapter = 0;
  1320. ha->flags.reset_active = 0;
  1321. ha->flags.abort_isp_active = 0;
  1322. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1323. if (ia64_platform_is("sn2")) {
  1324. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1325. "dual channel lockup workaround\n", ha->host_no);
  1326. ha->flags.use_pci_vchannel = 1;
  1327. driver_setup.no_nvram = 1;
  1328. }
  1329. #endif
  1330. /* TODO: implement support for the 1040 nvram format */
  1331. if (IS_ISP1040(ha))
  1332. driver_setup.no_nvram = 1;
  1333. dprintk(1, "Configure PCI space for adapter...\n");
  1334. reg = ha->iobase;
  1335. /* Insure mailbox registers are free. */
  1336. WRT_REG_WORD(&reg->semaphore, 0);
  1337. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  1338. WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
  1339. RD_REG_WORD(&reg->host_cmd);
  1340. if (qla1280_read_nvram(ha)) {
  1341. dprintk(2, "qla1280_initialize_adapter: failed to read "
  1342. "NVRAM\n");
  1343. }
  1344. /*
  1345. * It's necessary to grab the spin here as qla1280_mailbox_command
  1346. * needs to be able to drop the lock unconditionally to wait
  1347. * for completion.
  1348. */
  1349. spin_lock_irqsave(ha->host->host_lock, flags);
  1350. status = qla1280_load_firmware(ha);
  1351. if (status) {
  1352. printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
  1353. ha->host_no);
  1354. goto out;
  1355. }
  1356. /* Setup adapter based on NVRAM parameters. */
  1357. dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
  1358. qla1280_nvram_config(ha);
  1359. if (ha->flags.disable_host_adapter) {
  1360. status = 1;
  1361. goto out;
  1362. }
  1363. status = qla1280_init_rings(ha);
  1364. if (status)
  1365. goto out;
  1366. /* Issue SCSI reset, if we can't reset twice then bus is dead */
  1367. for (bus = 0; bus < ha->ports; bus++) {
  1368. if (!ha->bus_settings[bus].disable_scsi_reset &&
  1369. qla1280_bus_reset(ha, bus) &&
  1370. qla1280_bus_reset(ha, bus))
  1371. ha->bus_settings[bus].scsi_bus_dead = 1;
  1372. }
  1373. ha->flags.online = 1;
  1374. out:
  1375. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1376. if (status)
  1377. dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
  1378. LEAVE("qla1280_initialize_adapter");
  1379. return status;
  1380. }
  1381. /*
  1382. * Chip diagnostics
  1383. * Test chip for proper operation.
  1384. *
  1385. * Input:
  1386. * ha = adapter block pointer.
  1387. *
  1388. * Returns:
  1389. * 0 = success.
  1390. */
  1391. static int
  1392. qla1280_chip_diag(struct scsi_qla_host *ha)
  1393. {
  1394. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1395. struct device_reg __iomem *reg = ha->iobase;
  1396. int status = 0;
  1397. int cnt;
  1398. uint16_t data;
  1399. dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", &reg->id_l);
  1400. dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
  1401. /* Soft reset chip and wait for it to finish. */
  1402. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  1403. /*
  1404. * We can't do a traditional PCI write flush here by reading
  1405. * back the register. The card will not respond once the reset
  1406. * is in action and we end up with a machine check exception
  1407. * instead. Nothing to do but wait and hope for the best.
  1408. * A portable pci_write_flush(pdev) call would be very useful here.
  1409. */
  1410. udelay(20);
  1411. data = qla1280_debounce_register(&reg->ictrl);
  1412. /*
  1413. * Yet another QLogic gem ;-(
  1414. */
  1415. for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
  1416. udelay(5);
  1417. data = RD_REG_WORD(&reg->ictrl);
  1418. }
  1419. if (!cnt)
  1420. goto fail;
  1421. /* Reset register cleared by chip reset. */
  1422. dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
  1423. WRT_REG_WORD(&reg->cfg_1, 0);
  1424. /* Reset RISC and disable BIOS which
  1425. allows RISC to execute out of RAM. */
  1426. WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC |
  1427. HC_RELEASE_RISC | HC_DISABLE_BIOS);
  1428. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1429. data = qla1280_debounce_register(&reg->mailbox0);
  1430. /*
  1431. * I *LOVE* this code!
  1432. */
  1433. for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
  1434. udelay(5);
  1435. data = RD_REG_WORD(&reg->mailbox0);
  1436. }
  1437. if (!cnt)
  1438. goto fail;
  1439. /* Check product ID of chip */
  1440. dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
  1441. if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
  1442. (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
  1443. RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
  1444. RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
  1445. RD_REG_WORD(&reg->mailbox4) != PROD_ID_4) {
  1446. printk(KERN_INFO "qla1280: Wrong product ID = "
  1447. "0x%x,0x%x,0x%x,0x%x\n",
  1448. RD_REG_WORD(&reg->mailbox1),
  1449. RD_REG_WORD(&reg->mailbox2),
  1450. RD_REG_WORD(&reg->mailbox3),
  1451. RD_REG_WORD(&reg->mailbox4));
  1452. goto fail;
  1453. }
  1454. /*
  1455. * Enable ints early!!!
  1456. */
  1457. qla1280_enable_intrs(ha);
  1458. dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
  1459. /* Wrap Incoming Mailboxes Test. */
  1460. mb[0] = MBC_MAILBOX_REGISTER_TEST;
  1461. mb[1] = 0xAAAA;
  1462. mb[2] = 0x5555;
  1463. mb[3] = 0xAA55;
  1464. mb[4] = 0x55AA;
  1465. mb[5] = 0xA5A5;
  1466. mb[6] = 0x5A5A;
  1467. mb[7] = 0x2525;
  1468. status = qla1280_mailbox_command(ha, 0xff, mb);
  1469. if (status)
  1470. goto fail;
  1471. if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
  1472. mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
  1473. mb[7] != 0x2525) {
  1474. printk(KERN_INFO "qla1280: Failed mbox check\n");
  1475. goto fail;
  1476. }
  1477. dprintk(3, "qla1280_chip_diag: exiting normally\n");
  1478. return 0;
  1479. fail:
  1480. dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
  1481. return status;
  1482. }
  1483. static int
  1484. qla1280_load_firmware_pio(struct scsi_qla_host *ha)
  1485. {
  1486. uint16_t risc_address, *risc_code_address, risc_code_size;
  1487. uint16_t mb[MAILBOX_REGISTER_COUNT], i;
  1488. int err;
  1489. /* Load RISC code. */
  1490. risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
  1491. risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
  1492. risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
  1493. for (i = 0; i < risc_code_size; i++) {
  1494. mb[0] = MBC_WRITE_RAM_WORD;
  1495. mb[1] = risc_address + i;
  1496. mb[2] = risc_code_address[i];
  1497. err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
  1498. if (err) {
  1499. printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
  1500. ha->host_no);
  1501. return err;
  1502. }
  1503. }
  1504. return 0;
  1505. }
  1506. #define DUMP_IT_BACK 0 /* for debug of RISC loading */
  1507. static int
  1508. qla1280_load_firmware_dma(struct scsi_qla_host *ha)
  1509. {
  1510. uint16_t risc_address, *risc_code_address, risc_code_size;
  1511. uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
  1512. int err = 0, num, i;
  1513. #if DUMP_IT_BACK
  1514. uint8_t *sp, *tbuf;
  1515. dma_addr_t p_tbuf;
  1516. tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
  1517. if (!tbuf)
  1518. return -ENOMEM;
  1519. #endif
  1520. /* Load RISC code. */
  1521. risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
  1522. risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
  1523. risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
  1524. dprintk(1, "%s: DMA RISC code (%i) words\n",
  1525. __FUNCTION__, risc_code_size);
  1526. num = 0;
  1527. while (risc_code_size > 0) {
  1528. int warn __attribute__((unused)) = 0;
  1529. cnt = 2000 >> 1;
  1530. if (cnt > risc_code_size)
  1531. cnt = risc_code_size;
  1532. dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
  1533. "%d,%d(0x%x)\n",
  1534. risc_code_address, cnt, num, risc_address);
  1535. for(i = 0; i < cnt; i++)
  1536. ((__le16 *)ha->request_ring)[i] =
  1537. cpu_to_le16(risc_code_address[i]);
  1538. mb[0] = MBC_LOAD_RAM;
  1539. mb[1] = risc_address;
  1540. mb[4] = cnt;
  1541. mb[3] = ha->request_dma & 0xffff;
  1542. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1543. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1544. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1545. dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
  1546. __FUNCTION__, mb[0],
  1547. (void *)(long)ha->request_dma,
  1548. mb[6], mb[7], mb[2], mb[3]);
  1549. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1550. BIT_1 | BIT_0, mb);
  1551. if (err) {
  1552. printk(KERN_ERR "scsi(%li): Failed to load partial "
  1553. "segment of f\n", ha->host_no);
  1554. goto out;
  1555. }
  1556. #if DUMP_IT_BACK
  1557. mb[0] = MBC_DUMP_RAM;
  1558. mb[1] = risc_address;
  1559. mb[4] = cnt;
  1560. mb[3] = p_tbuf & 0xffff;
  1561. mb[2] = (p_tbuf >> 16) & 0xffff;
  1562. mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
  1563. mb[6] = pci_dma_hi32(p_tbuf) >> 16;
  1564. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1565. BIT_1 | BIT_0, mb);
  1566. if (err) {
  1567. printk(KERN_ERR
  1568. "Failed to dump partial segment of f/w\n");
  1569. goto out;
  1570. }
  1571. sp = (uint8_t *)ha->request_ring;
  1572. for (i = 0; i < (cnt << 1); i++) {
  1573. if (tbuf[i] != sp[i] && warn++ < 10) {
  1574. printk(KERN_ERR "%s: FW compare error @ "
  1575. "byte(0x%x) loop#=%x\n",
  1576. __FUNCTION__, i, num);
  1577. printk(KERN_ERR "%s: FWbyte=%x "
  1578. "FWfromChip=%x\n",
  1579. __FUNCTION__, sp[i], tbuf[i]);
  1580. /*break; */
  1581. }
  1582. }
  1583. #endif
  1584. risc_address += cnt;
  1585. risc_code_size = risc_code_size - cnt;
  1586. risc_code_address = risc_code_address + cnt;
  1587. num++;
  1588. }
  1589. out:
  1590. #if DUMP_IT_BACK
  1591. pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
  1592. #endif
  1593. return err;
  1594. }
  1595. static int
  1596. qla1280_start_firmware(struct scsi_qla_host *ha)
  1597. {
  1598. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1599. int err;
  1600. dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
  1601. __FUNCTION__);
  1602. /* Verify checksum of loaded RISC code. */
  1603. mb[0] = MBC_VERIFY_CHECKSUM;
  1604. /* mb[1] = ql12_risc_code_addr01; */
  1605. mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
  1606. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1607. if (err) {
  1608. printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
  1609. return err;
  1610. }
  1611. /* Start firmware execution. */
  1612. dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
  1613. mb[0] = MBC_EXECUTE_FIRMWARE;
  1614. mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
  1615. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1616. if (err) {
  1617. printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
  1618. ha->host_no);
  1619. }
  1620. return err;
  1621. }
  1622. static int
  1623. qla1280_load_firmware(struct scsi_qla_host *ha)
  1624. {
  1625. int err;
  1626. err = qla1280_chip_diag(ha);
  1627. if (err)
  1628. goto out;
  1629. if (IS_ISP1040(ha))
  1630. err = qla1280_load_firmware_pio(ha);
  1631. else
  1632. err = qla1280_load_firmware_dma(ha);
  1633. if (err)
  1634. goto out;
  1635. err = qla1280_start_firmware(ha);
  1636. out:
  1637. return err;
  1638. }
  1639. /*
  1640. * Initialize rings
  1641. *
  1642. * Input:
  1643. * ha = adapter block pointer.
  1644. * ha->request_ring = request ring virtual address
  1645. * ha->response_ring = response ring virtual address
  1646. * ha->request_dma = request ring physical address
  1647. * ha->response_dma = response ring physical address
  1648. *
  1649. * Returns:
  1650. * 0 = success.
  1651. */
  1652. static int
  1653. qla1280_init_rings(struct scsi_qla_host *ha)
  1654. {
  1655. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1656. int status = 0;
  1657. ENTER("qla1280_init_rings");
  1658. /* Clear outstanding commands array. */
  1659. memset(ha->outstanding_cmds, 0,
  1660. sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
  1661. /* Initialize request queue. */
  1662. ha->request_ring_ptr = ha->request_ring;
  1663. ha->req_ring_index = 0;
  1664. ha->req_q_cnt = REQUEST_ENTRY_CNT;
  1665. /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
  1666. mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
  1667. mb[1] = REQUEST_ENTRY_CNT;
  1668. mb[3] = ha->request_dma & 0xffff;
  1669. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1670. mb[4] = 0;
  1671. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1672. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1673. if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
  1674. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1675. &mb[0]))) {
  1676. /* Initialize response queue. */
  1677. ha->response_ring_ptr = ha->response_ring;
  1678. ha->rsp_ring_index = 0;
  1679. /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
  1680. mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
  1681. mb[1] = RESPONSE_ENTRY_CNT;
  1682. mb[3] = ha->response_dma & 0xffff;
  1683. mb[2] = (ha->response_dma >> 16) & 0xffff;
  1684. mb[5] = 0;
  1685. mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
  1686. mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
  1687. status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
  1688. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1689. &mb[0]);
  1690. }
  1691. if (status)
  1692. dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
  1693. LEAVE("qla1280_init_rings");
  1694. return status;
  1695. }
  1696. static void
  1697. qla1280_print_settings(struct nvram *nv)
  1698. {
  1699. dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
  1700. nv->bus[0].config_1.initiator_id);
  1701. dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
  1702. nv->bus[1].config_1.initiator_id);
  1703. dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
  1704. nv->bus[0].bus_reset_delay);
  1705. dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
  1706. nv->bus[1].bus_reset_delay);
  1707. dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
  1708. dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
  1709. dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
  1710. dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
  1711. dprintk(1, "qla1280 : async data setup time[0]=%d\n",
  1712. nv->bus[0].config_2.async_data_setup_time);
  1713. dprintk(1, "qla1280 : async data setup time[1]=%d\n",
  1714. nv->bus[1].config_2.async_data_setup_time);
  1715. dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
  1716. nv->bus[0].config_2.req_ack_active_negation);
  1717. dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
  1718. nv->bus[1].config_2.req_ack_active_negation);
  1719. dprintk(1, "qla1280 : data line active negation[0]=%d\n",
  1720. nv->bus[0].config_2.data_line_active_negation);
  1721. dprintk(1, "qla1280 : data line active negation[1]=%d\n",
  1722. nv->bus[1].config_2.data_line_active_negation);
  1723. dprintk(1, "qla1280 : disable loading risc code=%d\n",
  1724. nv->cntr_flags_1.disable_loading_risc_code);
  1725. dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
  1726. nv->cntr_flags_1.enable_64bit_addressing);
  1727. dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
  1728. nv->bus[0].selection_timeout);
  1729. dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
  1730. nv->bus[1].selection_timeout);
  1731. dprintk(1, "qla1280 : max queue depth[0]=%d\n",
  1732. nv->bus[0].max_queue_depth);
  1733. dprintk(1, "qla1280 : max queue depth[1]=%d\n",
  1734. nv->bus[1].max_queue_depth);
  1735. }
  1736. static void
  1737. qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
  1738. {
  1739. struct nvram *nv = &ha->nvram;
  1740. nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
  1741. nv->bus[bus].target[target].parameter.auto_request_sense = 1;
  1742. nv->bus[bus].target[target].parameter.tag_queuing = 1;
  1743. nv->bus[bus].target[target].parameter.enable_sync = 1;
  1744. #if 1 /* Some SCSI Processors do not seem to like this */
  1745. nv->bus[bus].target[target].parameter.enable_wide = 1;
  1746. #endif
  1747. nv->bus[bus].target[target].execution_throttle =
  1748. nv->bus[bus].max_queue_depth - 1;
  1749. nv->bus[bus].target[target].parameter.parity_checking = 1;
  1750. nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
  1751. if (IS_ISP1x160(ha)) {
  1752. nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
  1753. nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
  1754. nv->bus[bus].target[target].sync_period = 9;
  1755. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
  1756. nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
  1757. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
  1758. } else {
  1759. nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
  1760. nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
  1761. nv->bus[bus].target[target].sync_period = 10;
  1762. }
  1763. }
  1764. static void
  1765. qla1280_set_defaults(struct scsi_qla_host *ha)
  1766. {
  1767. struct nvram *nv = &ha->nvram;
  1768. int bus, target;
  1769. dprintk(1, "Using defaults for NVRAM: \n");
  1770. memset(nv, 0, sizeof(struct nvram));
  1771. /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
  1772. nv->firmware_feature.f.enable_fast_posting = 1;
  1773. nv->firmware_feature.f.disable_synchronous_backoff = 1;
  1774. nv->termination.scsi_bus_0_control = 3;
  1775. nv->termination.scsi_bus_1_control = 3;
  1776. nv->termination.auto_term_support = 1;
  1777. /*
  1778. * Set default FIFO magic - What appropriate values would be here
  1779. * is unknown. This is what I have found testing with 12160s.
  1780. *
  1781. * Now, I would love the magic decoder ring for this one, the
  1782. * header file provided by QLogic seems to be bogus or incomplete
  1783. * at best.
  1784. */
  1785. nv->isp_config.burst_enable = 1;
  1786. if (IS_ISP1040(ha))
  1787. nv->isp_config.fifo_threshold |= 3;
  1788. else
  1789. nv->isp_config.fifo_threshold |= 4;
  1790. if (IS_ISP1x160(ha))
  1791. nv->isp_parameter = 0x01; /* fast memory enable */
  1792. for (bus = 0; bus < MAX_BUSES; bus++) {
  1793. nv->bus[bus].config_1.initiator_id = 7;
  1794. nv->bus[bus].config_2.req_ack_active_negation = 1;
  1795. nv->bus[bus].config_2.data_line_active_negation = 1;
  1796. nv->bus[bus].selection_timeout = 250;
  1797. nv->bus[bus].max_queue_depth = 256;
  1798. if (IS_ISP1040(ha)) {
  1799. nv->bus[bus].bus_reset_delay = 3;
  1800. nv->bus[bus].config_2.async_data_setup_time = 6;
  1801. nv->bus[bus].retry_delay = 1;
  1802. } else {
  1803. nv->bus[bus].bus_reset_delay = 5;
  1804. nv->bus[bus].config_2.async_data_setup_time = 8;
  1805. }
  1806. for (target = 0; target < MAX_TARGETS; target++)
  1807. qla1280_set_target_defaults(ha, bus, target);
  1808. }
  1809. }
  1810. static int
  1811. qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
  1812. {
  1813. struct nvram *nv = &ha->nvram;
  1814. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1815. int status, lun;
  1816. uint16_t flag;
  1817. /* Set Target Parameters. */
  1818. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1819. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1820. /*
  1821. * Do not enable sync and ppr for the initial INQUIRY run. We
  1822. * enable this later if we determine the target actually
  1823. * supports it.
  1824. */
  1825. mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
  1826. | TP_WIDE | TP_PARITY | TP_DISCONNECT);
  1827. if (IS_ISP1x160(ha))
  1828. mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
  1829. else
  1830. mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
  1831. mb[3] |= nv->bus[bus].target[target].sync_period;
  1832. status = qla1280_mailbox_command(ha, 0x0f, mb);
  1833. /* Save Tag queuing enable flag. */
  1834. flag = (BIT_0 << target) & mb[0];
  1835. if (nv->bus[bus].target[target].parameter.tag_queuing)
  1836. ha->bus_settings[bus].qtag_enables |= flag;
  1837. /* Save Device enable flag. */
  1838. if (IS_ISP1x160(ha)) {
  1839. if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
  1840. ha->bus_settings[bus].device_enables |= flag;
  1841. ha->bus_settings[bus].lun_disables |= 0;
  1842. } else {
  1843. if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
  1844. ha->bus_settings[bus].device_enables |= flag;
  1845. /* Save LUN disable flag. */
  1846. if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
  1847. ha->bus_settings[bus].lun_disables |= flag;
  1848. }
  1849. /* Set Device Queue Parameters. */
  1850. for (lun = 0; lun < MAX_LUNS; lun++) {
  1851. mb[0] = MBC_SET_DEVICE_QUEUE;
  1852. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1853. mb[1] |= lun;
  1854. mb[2] = nv->bus[bus].max_queue_depth;
  1855. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1856. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1857. }
  1858. return status;
  1859. }
  1860. static int
  1861. qla1280_config_bus(struct scsi_qla_host *ha, int bus)
  1862. {
  1863. struct nvram *nv = &ha->nvram;
  1864. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1865. int target, status;
  1866. /* SCSI Reset Disable. */
  1867. ha->bus_settings[bus].disable_scsi_reset =
  1868. nv->bus[bus].config_1.scsi_reset_disable;
  1869. /* Initiator ID. */
  1870. ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
  1871. mb[0] = MBC_SET_INITIATOR_ID;
  1872. mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
  1873. ha->bus_settings[bus].id;
  1874. status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1875. /* Reset Delay. */
  1876. ha->bus_settings[bus].bus_reset_delay =
  1877. nv->bus[bus].bus_reset_delay;
  1878. /* Command queue depth per device. */
  1879. ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
  1880. /* Set target parameters. */
  1881. for (target = 0; target < MAX_TARGETS; target++)
  1882. status |= qla1280_config_target(ha, bus, target);
  1883. return status;
  1884. }
  1885. static int
  1886. qla1280_nvram_config(struct scsi_qla_host *ha)
  1887. {
  1888. struct device_reg __iomem *reg = ha->iobase;
  1889. struct nvram *nv = &ha->nvram;
  1890. int bus, target, status = 0;
  1891. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1892. ENTER("qla1280_nvram_config");
  1893. if (ha->nvram_valid) {
  1894. /* Always force AUTO sense for LINUX SCSI */
  1895. for (bus = 0; bus < MAX_BUSES; bus++)
  1896. for (target = 0; target < MAX_TARGETS; target++) {
  1897. nv->bus[bus].target[target].parameter.
  1898. auto_request_sense = 1;
  1899. }
  1900. } else {
  1901. qla1280_set_defaults(ha);
  1902. }
  1903. qla1280_print_settings(nv);
  1904. /* Disable RISC load of firmware. */
  1905. ha->flags.disable_risc_code_load =
  1906. nv->cntr_flags_1.disable_loading_risc_code;
  1907. if (IS_ISP1040(ha)) {
  1908. uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
  1909. hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK;
  1910. cfg1 = RD_REG_WORD(&reg->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
  1911. cdma_conf = RD_REG_WORD(&reg->cdma_cfg);
  1912. ddma_conf = RD_REG_WORD(&reg->ddma_cfg);
  1913. /* Busted fifo, says mjacob. */
  1914. if (hwrev != ISP_CFG0_1040A)
  1915. cfg1 |= nv->isp_config.fifo_threshold << 4;
  1916. cfg1 |= nv->isp_config.burst_enable << 2;
  1917. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1918. WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
  1919. WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
  1920. } else {
  1921. uint16_t cfg1, term;
  1922. /* Set ISP hardware DMA burst */
  1923. cfg1 = nv->isp_config.fifo_threshold << 4;
  1924. cfg1 |= nv->isp_config.burst_enable << 2;
  1925. /* Enable DMA arbitration on dual channel controllers */
  1926. if (ha->ports > 1)
  1927. cfg1 |= BIT_13;
  1928. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1929. /* Set SCSI termination. */
  1930. WRT_REG_WORD(&reg->gpio_enable,
  1931. BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1932. term = nv->termination.scsi_bus_1_control;
  1933. term |= nv->termination.scsi_bus_0_control << 2;
  1934. term |= nv->termination.auto_term_support << 7;
  1935. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1936. WRT_REG_WORD(&reg->gpio_data, term);
  1937. }
  1938. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1939. /* ISP parameter word. */
  1940. mb[0] = MBC_SET_SYSTEM_PARAMETER;
  1941. mb[1] = nv->isp_parameter;
  1942. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1943. if (IS_ISP1x40(ha)) {
  1944. /* clock rate - for qla1240 and older, only */
  1945. mb[0] = MBC_SET_CLOCK_RATE;
  1946. mb[1] = 40;
  1947. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1948. }
  1949. /* Firmware feature word. */
  1950. mb[0] = MBC_SET_FIRMWARE_FEATURES;
  1951. mb[1] = nv->firmware_feature.f.enable_fast_posting;
  1952. mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
  1953. mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
  1954. #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
  1955. if (ia64_platform_is("sn2")) {
  1956. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1957. "workaround\n", ha->host_no);
  1958. mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
  1959. }
  1960. #endif
  1961. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1962. /* Retry count and delay. */
  1963. mb[0] = MBC_SET_RETRY_COUNT;
  1964. mb[1] = nv->bus[0].retry_count;
  1965. mb[2] = nv->bus[0].retry_delay;
  1966. mb[6] = nv->bus[1].retry_count;
  1967. mb[7] = nv->bus[1].retry_delay;
  1968. status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
  1969. BIT_1 | BIT_0, &mb[0]);
  1970. /* ASYNC data setup time. */
  1971. mb[0] = MBC_SET_ASYNC_DATA_SETUP;
  1972. mb[1] = nv->bus[0].config_2.async_data_setup_time;
  1973. mb[2] = nv->bus[1].config_2.async_data_setup_time;
  1974. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  1975. /* Active negation states. */
  1976. mb[0] = MBC_SET_ACTIVE_NEGATION;
  1977. mb[1] = 0;
  1978. if (nv->bus[0].config_2.req_ack_active_negation)
  1979. mb[1] |= BIT_5;
  1980. if (nv->bus[0].config_2.data_line_active_negation)
  1981. mb[1] |= BIT_4;
  1982. mb[2] = 0;
  1983. if (nv->bus[1].config_2.req_ack_active_negation)
  1984. mb[2] |= BIT_5;
  1985. if (nv->bus[1].config_2.data_line_active_negation)
  1986. mb[2] |= BIT_4;
  1987. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  1988. mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
  1989. mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
  1990. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1991. /* thingy */
  1992. mb[0] = MBC_SET_PCI_CONTROL;
  1993. mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
  1994. mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
  1995. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  1996. mb[0] = MBC_SET_TAG_AGE_LIMIT;
  1997. mb[1] = 8;
  1998. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1999. /* Selection timeout. */
  2000. mb[0] = MBC_SET_SELECTION_TIMEOUT;
  2001. mb[1] = nv->bus[0].selection_timeout;
  2002. mb[2] = nv->bus[1].selection_timeout;
  2003. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2004. for (bus = 0; bus < ha->ports; bus++)
  2005. status |= qla1280_config_bus(ha, bus);
  2006. if (status)
  2007. dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
  2008. LEAVE("qla1280_nvram_config");
  2009. return status;
  2010. }
  2011. /*
  2012. * Get NVRAM data word
  2013. * Calculates word position in NVRAM and calls request routine to
  2014. * get the word from NVRAM.
  2015. *
  2016. * Input:
  2017. * ha = adapter block pointer.
  2018. * address = NVRAM word address.
  2019. *
  2020. * Returns:
  2021. * data word.
  2022. */
  2023. static uint16_t
  2024. qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
  2025. {
  2026. uint32_t nv_cmd;
  2027. uint16_t data;
  2028. nv_cmd = address << 16;
  2029. nv_cmd |= NV_READ_OP;
  2030. data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
  2031. dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
  2032. "0x%x", data);
  2033. return data;
  2034. }
  2035. /*
  2036. * NVRAM request
  2037. * Sends read command to NVRAM and gets data from NVRAM.
  2038. *
  2039. * Input:
  2040. * ha = adapter block pointer.
  2041. * nv_cmd = Bit 26 = start bit
  2042. * Bit 25, 24 = opcode
  2043. * Bit 23-16 = address
  2044. * Bit 15-0 = write data
  2045. *
  2046. * Returns:
  2047. * data word.
  2048. */
  2049. static uint16_t
  2050. qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
  2051. {
  2052. struct device_reg __iomem *reg = ha->iobase;
  2053. int cnt;
  2054. uint16_t data = 0;
  2055. uint16_t reg_data;
  2056. /* Send command to NVRAM. */
  2057. nv_cmd <<= 5;
  2058. for (cnt = 0; cnt < 11; cnt++) {
  2059. if (nv_cmd & BIT_31)
  2060. qla1280_nv_write(ha, NV_DATA_OUT);
  2061. else
  2062. qla1280_nv_write(ha, 0);
  2063. nv_cmd <<= 1;
  2064. }
  2065. /* Read data from NVRAM. */
  2066. for (cnt = 0; cnt < 16; cnt++) {
  2067. WRT_REG_WORD(&reg->nvram, (NV_SELECT | NV_CLOCK));
  2068. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2069. NVRAM_DELAY();
  2070. data <<= 1;
  2071. reg_data = RD_REG_WORD(&reg->nvram);
  2072. if (reg_data & NV_DATA_IN)
  2073. data |= BIT_0;
  2074. WRT_REG_WORD(&reg->nvram, NV_SELECT);
  2075. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2076. NVRAM_DELAY();
  2077. }
  2078. /* Deselect chip. */
  2079. WRT_REG_WORD(&reg->nvram, NV_DESELECT);
  2080. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2081. NVRAM_DELAY();
  2082. return data;
  2083. }
  2084. static void
  2085. qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
  2086. {
  2087. struct device_reg __iomem *reg = ha->iobase;
  2088. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2089. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2090. NVRAM_DELAY();
  2091. WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
  2092. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2093. NVRAM_DELAY();
  2094. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2095. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2096. NVRAM_DELAY();
  2097. }
  2098. /*
  2099. * Mailbox Command
  2100. * Issue mailbox command and waits for completion.
  2101. *
  2102. * Input:
  2103. * ha = adapter block pointer.
  2104. * mr = mailbox registers to load.
  2105. * mb = data pointer for mailbox registers.
  2106. *
  2107. * Output:
  2108. * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
  2109. *
  2110. * Returns:
  2111. * 0 = success
  2112. */
  2113. static int
  2114. qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
  2115. {
  2116. struct device_reg __iomem *reg = ha->iobase;
  2117. #if 0
  2118. LIST_HEAD(done_q);
  2119. #endif
  2120. int status = 0;
  2121. int cnt;
  2122. uint16_t *optr, *iptr;
  2123. uint16_t __iomem *mptr;
  2124. uint16_t data;
  2125. DECLARE_COMPLETION(wait);
  2126. struct timer_list timer;
  2127. ENTER("qla1280_mailbox_command");
  2128. if (ha->mailbox_wait) {
  2129. printk(KERN_ERR "Warning mailbox wait already in use!\n");
  2130. }
  2131. ha->mailbox_wait = &wait;
  2132. /*
  2133. * We really should start out by verifying that the mailbox is
  2134. * available before starting sending the command data
  2135. */
  2136. /* Load mailbox registers. */
  2137. mptr = (uint16_t __iomem *) &reg->mailbox0;
  2138. iptr = mb;
  2139. for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
  2140. if (mr & BIT_0) {
  2141. WRT_REG_WORD(mptr, (*iptr));
  2142. }
  2143. mr >>= 1;
  2144. mptr++;
  2145. iptr++;
  2146. }
  2147. /* Issue set host interrupt command. */
  2148. /* set up a timer just in case we're really jammed */
  2149. init_timer(&timer);
  2150. timer.expires = jiffies + 20*HZ;
  2151. timer.data = (unsigned long)ha;
  2152. timer.function = qla1280_mailbox_timeout;
  2153. add_timer(&timer);
  2154. spin_unlock_irq(ha->host->host_lock);
  2155. WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
  2156. data = qla1280_debounce_register(&reg->istatus);
  2157. wait_for_completion(&wait);
  2158. del_timer_sync(&timer);
  2159. spin_lock_irq(ha->host->host_lock);
  2160. ha->mailbox_wait = NULL;
  2161. /* Check for mailbox command timeout. */
  2162. if (ha->mailbox_out[0] != MBS_CMD_CMP) {
  2163. printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
  2164. "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
  2165. "0x%04x\n",
  2166. mb[0], ha->mailbox_out[0], RD_REG_WORD(&reg->istatus));
  2167. printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
  2168. RD_REG_WORD(&reg->mailbox0), RD_REG_WORD(&reg->mailbox1),
  2169. RD_REG_WORD(&reg->mailbox2), RD_REG_WORD(&reg->mailbox3));
  2170. printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
  2171. RD_REG_WORD(&reg->mailbox4), RD_REG_WORD(&reg->mailbox5),
  2172. RD_REG_WORD(&reg->mailbox6), RD_REG_WORD(&reg->mailbox7));
  2173. status = 1;
  2174. }
  2175. /* Load return mailbox registers. */
  2176. optr = mb;
  2177. iptr = (uint16_t *) &ha->mailbox_out[0];
  2178. mr = MAILBOX_REGISTER_COUNT;
  2179. memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
  2180. #if 0
  2181. /* Go check for any response interrupts pending. */
  2182. qla1280_isr(ha, &done_q);
  2183. #endif
  2184. if (ha->flags.reset_marker)
  2185. qla1280_rst_aen(ha);
  2186. #if 0
  2187. if (!list_empty(&done_q))
  2188. qla1280_done(ha, &done_q);
  2189. #endif
  2190. if (status)
  2191. dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
  2192. "0x%x ****\n", mb[0]);
  2193. LEAVE("qla1280_mailbox_command");
  2194. return status;
  2195. }
  2196. /*
  2197. * qla1280_poll
  2198. * Polls ISP for interrupts.
  2199. *
  2200. * Input:
  2201. * ha = adapter block pointer.
  2202. */
  2203. static void
  2204. qla1280_poll(struct scsi_qla_host *ha)
  2205. {
  2206. struct device_reg __iomem *reg = ha->iobase;
  2207. uint16_t data;
  2208. LIST_HEAD(done_q);
  2209. /* ENTER("qla1280_poll"); */
  2210. /* Check for pending interrupts. */
  2211. data = RD_REG_WORD(&reg->istatus);
  2212. if (data & RISC_INT)
  2213. qla1280_isr(ha, &done_q);
  2214. if (!ha->mailbox_wait) {
  2215. if (ha->flags.reset_marker)
  2216. qla1280_rst_aen(ha);
  2217. }
  2218. if (!list_empty(&done_q))
  2219. qla1280_done(ha);
  2220. /* LEAVE("qla1280_poll"); */
  2221. }
  2222. /*
  2223. * qla1280_bus_reset
  2224. * Issue SCSI bus reset.
  2225. *
  2226. * Input:
  2227. * ha = adapter block pointer.
  2228. * bus = SCSI bus number.
  2229. *
  2230. * Returns:
  2231. * 0 = success
  2232. */
  2233. static int
  2234. qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
  2235. {
  2236. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2237. uint16_t reset_delay;
  2238. int status;
  2239. dprintk(3, "qla1280_bus_reset: entered\n");
  2240. if (qla1280_verbose)
  2241. printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
  2242. ha->host_no, bus);
  2243. reset_delay = ha->bus_settings[bus].bus_reset_delay;
  2244. mb[0] = MBC_BUS_RESET;
  2245. mb[1] = reset_delay;
  2246. mb[2] = (uint16_t) bus;
  2247. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2248. if (status) {
  2249. if (ha->bus_settings[bus].failed_reset_count > 2)
  2250. ha->bus_settings[bus].scsi_bus_dead = 1;
  2251. ha->bus_settings[bus].failed_reset_count++;
  2252. } else {
  2253. spin_unlock_irq(ha->host->host_lock);
  2254. ssleep(reset_delay);
  2255. spin_lock_irq(ha->host->host_lock);
  2256. ha->bus_settings[bus].scsi_bus_dead = 0;
  2257. ha->bus_settings[bus].failed_reset_count = 0;
  2258. ha->bus_settings[bus].reset_marker = 0;
  2259. /* Issue marker command. */
  2260. qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
  2261. }
  2262. /*
  2263. * We should probably call qla1280_set_target_parameters()
  2264. * here as well for all devices on the bus.
  2265. */
  2266. if (status)
  2267. dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
  2268. else
  2269. dprintk(3, "qla1280_bus_reset: exiting normally\n");
  2270. return status;
  2271. }
  2272. /*
  2273. * qla1280_device_reset
  2274. * Issue bus device reset message to the target.
  2275. *
  2276. * Input:
  2277. * ha = adapter block pointer.
  2278. * bus = SCSI BUS number.
  2279. * target = SCSI ID.
  2280. *
  2281. * Returns:
  2282. * 0 = success
  2283. */
  2284. static int
  2285. qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
  2286. {
  2287. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2288. int status;
  2289. ENTER("qla1280_device_reset");
  2290. mb[0] = MBC_ABORT_TARGET;
  2291. mb[1] = (bus ? (target | BIT_7) : target) << 8;
  2292. mb[2] = 1;
  2293. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2294. /* Issue marker command. */
  2295. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  2296. if (status)
  2297. dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
  2298. LEAVE("qla1280_device_reset");
  2299. return status;
  2300. }
  2301. /*
  2302. * qla1280_abort_device
  2303. * Issue an abort message to the device
  2304. *
  2305. * Input:
  2306. * ha = adapter block pointer.
  2307. * bus = SCSI BUS.
  2308. * target = SCSI ID.
  2309. * lun = SCSI LUN.
  2310. *
  2311. * Returns:
  2312. * 0 = success
  2313. */
  2314. static int
  2315. qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
  2316. {
  2317. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2318. int status;
  2319. ENTER("qla1280_abort_device");
  2320. mb[0] = MBC_ABORT_DEVICE;
  2321. mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
  2322. status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  2323. /* Issue marker command. */
  2324. qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
  2325. if (status)
  2326. dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
  2327. LEAVE("qla1280_abort_device");
  2328. return status;
  2329. }
  2330. /*
  2331. * qla1280_abort_command
  2332. * Abort command aborts a specified IOCB.
  2333. *
  2334. * Input:
  2335. * ha = adapter block pointer.
  2336. * sp = SB structure pointer.
  2337. *
  2338. * Returns:
  2339. * 0 = success
  2340. */
  2341. static int
  2342. qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
  2343. {
  2344. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2345. unsigned int bus, target, lun;
  2346. int status;
  2347. ENTER("qla1280_abort_command");
  2348. bus = SCSI_BUS_32(sp->cmd);
  2349. target = SCSI_TCN_32(sp->cmd);
  2350. lun = SCSI_LUN_32(sp->cmd);
  2351. sp->flags |= SRB_ABORT_PENDING;
  2352. mb[0] = MBC_ABORT_COMMAND;
  2353. mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
  2354. mb[2] = handle >> 16;
  2355. mb[3] = handle & 0xffff;
  2356. status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
  2357. if (status) {
  2358. dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
  2359. sp->flags &= ~SRB_ABORT_PENDING;
  2360. }
  2361. LEAVE("qla1280_abort_command");
  2362. return status;
  2363. }
  2364. /*
  2365. * qla1280_reset_adapter
  2366. * Reset adapter.
  2367. *
  2368. * Input:
  2369. * ha = adapter block pointer.
  2370. */
  2371. static void
  2372. qla1280_reset_adapter(struct scsi_qla_host *ha)
  2373. {
  2374. struct device_reg __iomem *reg = ha->iobase;
  2375. ENTER("qla1280_reset_adapter");
  2376. /* Disable ISP chip */
  2377. ha->flags.online = 0;
  2378. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  2379. WRT_REG_WORD(&reg->host_cmd,
  2380. HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
  2381. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2382. LEAVE("qla1280_reset_adapter");
  2383. }
  2384. /*
  2385. * Issue marker command.
  2386. * Function issues marker IOCB.
  2387. *
  2388. * Input:
  2389. * ha = adapter block pointer.
  2390. * bus = SCSI BUS number
  2391. * id = SCSI ID
  2392. * lun = SCSI LUN
  2393. * type = marker modifier
  2394. */
  2395. static void
  2396. qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
  2397. {
  2398. struct mrk_entry *pkt;
  2399. ENTER("qla1280_marker");
  2400. /* Get request packet. */
  2401. if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
  2402. pkt->entry_type = MARKER_TYPE;
  2403. pkt->lun = (uint8_t) lun;
  2404. pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
  2405. pkt->modifier = type;
  2406. pkt->entry_status = 0;
  2407. /* Issue command to ISP */
  2408. qla1280_isp_cmd(ha);
  2409. }
  2410. LEAVE("qla1280_marker");
  2411. }
  2412. /*
  2413. * qla1280_64bit_start_scsi
  2414. * The start SCSI is responsible for building request packets on
  2415. * request ring and modifying ISP input pointer.
  2416. *
  2417. * Input:
  2418. * ha = adapter block pointer.
  2419. * sp = SB structure pointer.
  2420. *
  2421. * Returns:
  2422. * 0 = success, was able to issue command.
  2423. */
  2424. #ifdef QLA_64BIT_PTR
  2425. static int
  2426. qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2427. {
  2428. struct device_reg __iomem *reg = ha->iobase;
  2429. struct scsi_cmnd *cmd = sp->cmd;
  2430. cmd_a64_entry_t *pkt;
  2431. struct scatterlist *sg = NULL;
  2432. __le32 *dword_ptr;
  2433. dma_addr_t dma_handle;
  2434. int status = 0;
  2435. int cnt;
  2436. int req_cnt;
  2437. u16 seg_cnt;
  2438. u8 dir;
  2439. ENTER("qla1280_64bit_start_scsi:");
  2440. /* Calculate number of entries and segments required. */
  2441. req_cnt = 1;
  2442. if (cmd->use_sg) {
  2443. sg = (struct scatterlist *) cmd->request_buffer;
  2444. seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
  2445. cmd->sc_data_direction);
  2446. if (seg_cnt > 2) {
  2447. req_cnt += (seg_cnt - 2) / 5;
  2448. if ((seg_cnt - 2) % 5)
  2449. req_cnt++;
  2450. }
  2451. } else if (cmd->request_bufflen) { /* If data transfer. */
  2452. seg_cnt = 1;
  2453. } else {
  2454. seg_cnt = 0;
  2455. }
  2456. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2457. /* Calculate number of free request entries. */
  2458. cnt = RD_REG_WORD(&reg->mailbox4);
  2459. if (ha->req_ring_index < cnt)
  2460. ha->req_q_cnt = cnt - ha->req_ring_index;
  2461. else
  2462. ha->req_q_cnt =
  2463. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2464. }
  2465. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2466. ha->req_q_cnt, seg_cnt);
  2467. /* If room for request in request ring. */
  2468. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2469. status = 1;
  2470. dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
  2471. "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
  2472. req_cnt);
  2473. goto out;
  2474. }
  2475. /* Check for room in outstanding command list. */
  2476. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2477. ha->outstanding_cmds[cnt] != 0; cnt++);
  2478. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2479. status = 1;
  2480. dprintk(2, "qla1280_start_scsi: NO ROOM IN "
  2481. "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
  2482. goto out;
  2483. }
  2484. ha->outstanding_cmds[cnt] = sp;
  2485. ha->req_q_cnt -= req_cnt;
  2486. CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
  2487. dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
  2488. cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
  2489. dprintk(2, " bus %i, target %i, lun %i\n",
  2490. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2491. qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
  2492. /*
  2493. * Build command packet.
  2494. */
  2495. pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
  2496. pkt->entry_type = COMMAND_A64_TYPE;
  2497. pkt->entry_count = (uint8_t) req_cnt;
  2498. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2499. pkt->entry_status = 0;
  2500. pkt->handle = cpu_to_le32(cnt);
  2501. /* Zero out remaining portion of packet. */
  2502. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2503. /* Set ISP command timeout. */
  2504. pkt->timeout = cpu_to_le16(30);
  2505. /* Set device target ID and LUN */
  2506. pkt->lun = SCSI_LUN_32(cmd);
  2507. pkt->target = SCSI_BUS_32(cmd) ?
  2508. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2509. /* Enable simple tag queuing if device supports it. */
  2510. if (cmd->device->simple_tags)
  2511. pkt->control_flags |= cpu_to_le16(BIT_3);
  2512. /* Load SCSI command packet. */
  2513. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2514. memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
  2515. /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2516. /* Set transfer direction. */
  2517. dir = qla1280_data_direction(cmd);
  2518. pkt->control_flags |= cpu_to_le16(dir);
  2519. /* Set total data segment count. */
  2520. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2521. /*
  2522. * Load data segments.
  2523. */
  2524. if (seg_cnt) { /* If data transfer. */
  2525. /* Setup packet address segment pointer. */
  2526. dword_ptr = (u32 *)&pkt->dseg_0_address;
  2527. if (cmd->use_sg) { /* If scatter gather */
  2528. /* Load command entry data segments. */
  2529. for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
  2530. dma_handle = sg_dma_address(sg);
  2531. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2532. if (ha->flags.use_pci_vchannel)
  2533. sn_pci_set_vchan(ha->pdev,
  2534. (unsigned long *)&dma_handle,
  2535. SCSI_BUS_32(cmd));
  2536. #endif
  2537. *dword_ptr++ =
  2538. cpu_to_le32(pci_dma_lo32(dma_handle));
  2539. *dword_ptr++ =
  2540. cpu_to_le32(pci_dma_hi32(dma_handle));
  2541. *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
  2542. sg++;
  2543. dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
  2544. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2545. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2546. cpu_to_le32(sg_dma_len(sg)));
  2547. }
  2548. dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
  2549. "command packet data - b %i, t %i, l %i \n",
  2550. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
  2551. SCSI_LUN_32(cmd));
  2552. qla1280_dump_buffer(5, (char *)pkt,
  2553. REQUEST_ENTRY_SIZE);
  2554. /*
  2555. * Build continuation packets.
  2556. */
  2557. dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
  2558. "remains\n", seg_cnt);
  2559. while (seg_cnt > 0) {
  2560. /* Adjust ring index. */
  2561. ha->req_ring_index++;
  2562. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2563. ha->req_ring_index = 0;
  2564. ha->request_ring_ptr =
  2565. ha->request_ring;
  2566. } else
  2567. ha->request_ring_ptr++;
  2568. pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
  2569. /* Zero out packet. */
  2570. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2571. /* Load packet defaults. */
  2572. ((struct cont_a64_entry *) pkt)->entry_type =
  2573. CONTINUE_A64_TYPE;
  2574. ((struct cont_a64_entry *) pkt)->entry_count = 1;
  2575. ((struct cont_a64_entry *) pkt)->sys_define =
  2576. (uint8_t)ha->req_ring_index;
  2577. /* Setup packet address segment pointer. */
  2578. dword_ptr =
  2579. (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
  2580. /* Load continuation entry data segments. */
  2581. for (cnt = 0; cnt < 5 && seg_cnt;
  2582. cnt++, seg_cnt--) {
  2583. dma_handle = sg_dma_address(sg);
  2584. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2585. if (ha->flags.use_pci_vchannel)
  2586. sn_pci_set_vchan(ha->pdev,
  2587. (unsigned long *)&dma_handle,
  2588. SCSI_BUS_32(cmd));
  2589. #endif
  2590. *dword_ptr++ =
  2591. cpu_to_le32(pci_dma_lo32(dma_handle));
  2592. *dword_ptr++ =
  2593. cpu_to_le32(pci_dma_hi32(dma_handle));
  2594. *dword_ptr++ =
  2595. cpu_to_le32(sg_dma_len(sg));
  2596. dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
  2597. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2598. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2599. cpu_to_le32(sg_dma_len(sg)));
  2600. sg++;
  2601. }
  2602. dprintk(5, "qla1280_64bit_start_scsi: "
  2603. "continuation packet data - b %i, t "
  2604. "%i, l %i \n", SCSI_BUS_32(cmd),
  2605. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2606. qla1280_dump_buffer(5, (char *)pkt,
  2607. REQUEST_ENTRY_SIZE);
  2608. }
  2609. } else { /* No scatter gather data transfer */
  2610. dma_handle = pci_map_single(ha->pdev,
  2611. cmd->request_buffer,
  2612. cmd->request_bufflen,
  2613. cmd->sc_data_direction);
  2614. sp->saved_dma_handle = dma_handle;
  2615. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2616. if (ha->flags.use_pci_vchannel)
  2617. sn_pci_set_vchan(ha->pdev,
  2618. (unsigned long *)&dma_handle,
  2619. SCSI_BUS_32(cmd));
  2620. #endif
  2621. *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
  2622. *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
  2623. *dword_ptr = cpu_to_le32(cmd->request_bufflen);
  2624. dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
  2625. "gather command packet data - b %i, t %i, "
  2626. "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
  2627. SCSI_LUN_32(cmd));
  2628. qla1280_dump_buffer(5, (char *)pkt,
  2629. REQUEST_ENTRY_SIZE);
  2630. }
  2631. } else { /* No data transfer */
  2632. dprintk(5, "qla1280_64bit_start_scsi: No data, command "
  2633. "packet data - b %i, t %i, l %i \n",
  2634. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2635. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2636. }
  2637. /* Adjust ring index. */
  2638. ha->req_ring_index++;
  2639. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2640. ha->req_ring_index = 0;
  2641. ha->request_ring_ptr = ha->request_ring;
  2642. } else
  2643. ha->request_ring_ptr++;
  2644. /* Set chip new ring index. */
  2645. dprintk(2,
  2646. "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
  2647. sp->flags |= SRB_SENT;
  2648. ha->actthreads++;
  2649. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2650. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2651. mmiowb();
  2652. out:
  2653. if (status)
  2654. dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
  2655. else
  2656. dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
  2657. return status;
  2658. }
  2659. #else /* !QLA_64BIT_PTR */
  2660. /*
  2661. * qla1280_32bit_start_scsi
  2662. * The start SCSI is responsible for building request packets on
  2663. * request ring and modifying ISP input pointer.
  2664. *
  2665. * The Qlogic firmware interface allows every queue slot to have a SCSI
  2666. * command and up to 4 scatter/gather (SG) entries. If we need more
  2667. * than 4 SG entries, then continuation entries are used that can
  2668. * hold another 7 entries each. The start routine determines if there
  2669. * is eought empty slots then build the combination of requests to
  2670. * fulfill the OS request.
  2671. *
  2672. * Input:
  2673. * ha = adapter block pointer.
  2674. * sp = SCSI Request Block structure pointer.
  2675. *
  2676. * Returns:
  2677. * 0 = success, was able to issue command.
  2678. */
  2679. static int
  2680. qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2681. {
  2682. struct device_reg __iomem *reg = ha->iobase;
  2683. struct scsi_cmnd *cmd = sp->cmd;
  2684. struct cmd_entry *pkt;
  2685. struct scatterlist *sg = NULL;
  2686. __le32 *dword_ptr;
  2687. int status = 0;
  2688. int cnt;
  2689. int req_cnt;
  2690. uint16_t seg_cnt;
  2691. dma_addr_t dma_handle;
  2692. u8 dir;
  2693. ENTER("qla1280_32bit_start_scsi");
  2694. dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
  2695. cmd->cmnd[0]);
  2696. /* Calculate number of entries and segments required. */
  2697. req_cnt = 1;
  2698. if (cmd->use_sg) {
  2699. /*
  2700. * We must build an SG list in adapter format, as the kernel's
  2701. * SG list cannot be used directly because of data field size
  2702. * (__alpha__) differences and the kernel SG list uses virtual
  2703. * addresses where we need physical addresses.
  2704. */
  2705. sg = (struct scatterlist *) cmd->request_buffer;
  2706. seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
  2707. cmd->sc_data_direction);
  2708. /*
  2709. * if greater than four sg entries then we need to allocate
  2710. * continuation entries
  2711. */
  2712. if (seg_cnt > 4) {
  2713. req_cnt += (seg_cnt - 4) / 7;
  2714. if ((seg_cnt - 4) % 7)
  2715. req_cnt++;
  2716. }
  2717. dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
  2718. cmd, seg_cnt, req_cnt);
  2719. } else if (cmd->request_bufflen) { /* If data transfer. */
  2720. dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
  2721. SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
  2722. cmd->cmnd[0]);
  2723. seg_cnt = 1;
  2724. } else {
  2725. /* dprintk(1, "No data transfer \n"); */
  2726. seg_cnt = 0;
  2727. }
  2728. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2729. /* Calculate number of free request entries. */
  2730. cnt = RD_REG_WORD(&reg->mailbox4);
  2731. if (ha->req_ring_index < cnt)
  2732. ha->req_q_cnt = cnt - ha->req_ring_index;
  2733. else
  2734. ha->req_q_cnt =
  2735. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2736. }
  2737. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2738. ha->req_q_cnt, seg_cnt);
  2739. /* If room for request in request ring. */
  2740. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2741. status = 1;
  2742. dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
  2743. "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
  2744. ha->req_q_cnt, req_cnt);
  2745. goto out;
  2746. }
  2747. /* Check for empty slot in outstanding command list. */
  2748. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2749. (ha->outstanding_cmds[cnt] != 0); cnt++) ;
  2750. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2751. status = 1;
  2752. dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
  2753. "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
  2754. goto out;
  2755. }
  2756. CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
  2757. ha->outstanding_cmds[cnt] = sp;
  2758. ha->req_q_cnt -= req_cnt;
  2759. /*
  2760. * Build command packet.
  2761. */
  2762. pkt = (struct cmd_entry *) ha->request_ring_ptr;
  2763. pkt->entry_type = COMMAND_TYPE;
  2764. pkt->entry_count = (uint8_t) req_cnt;
  2765. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2766. pkt->entry_status = 0;
  2767. pkt->handle = cpu_to_le32(cnt);
  2768. /* Zero out remaining portion of packet. */
  2769. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2770. /* Set ISP command timeout. */
  2771. pkt->timeout = cpu_to_le16(30);
  2772. /* Set device target ID and LUN */
  2773. pkt->lun = SCSI_LUN_32(cmd);
  2774. pkt->target = SCSI_BUS_32(cmd) ?
  2775. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2776. /* Enable simple tag queuing if device supports it. */
  2777. if (cmd->device->simple_tags)
  2778. pkt->control_flags |= cpu_to_le16(BIT_3);
  2779. /* Load SCSI command packet. */
  2780. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2781. memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
  2782. /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2783. /* Set transfer direction. */
  2784. dir = qla1280_data_direction(cmd);
  2785. pkt->control_flags |= cpu_to_le16(dir);
  2786. /* Set total data segment count. */
  2787. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2788. /*
  2789. * Load data segments.
  2790. */
  2791. if (seg_cnt) {
  2792. /* Setup packet address segment pointer. */
  2793. dword_ptr = &pkt->dseg_0_address;
  2794. if (cmd->use_sg) { /* If scatter gather */
  2795. dprintk(3, "Building S/G data segments..\n");
  2796. qla1280_dump_buffer(1, (char *)sg, 4 * 16);
  2797. /* Load command entry data segments. */
  2798. for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
  2799. *dword_ptr++ =
  2800. cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
  2801. *dword_ptr++ =
  2802. cpu_to_le32(sg_dma_len(sg));
  2803. dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
  2804. (pci_dma_lo32(sg_dma_address(sg))),
  2805. (sg_dma_len(sg)));
  2806. sg++;
  2807. }
  2808. /*
  2809. * Build continuation packets.
  2810. */
  2811. dprintk(3, "S/G Building Continuation"
  2812. "...seg_cnt=0x%x remains\n", seg_cnt);
  2813. while (seg_cnt > 0) {
  2814. /* Adjust ring index. */
  2815. ha->req_ring_index++;
  2816. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2817. ha->req_ring_index = 0;
  2818. ha->request_ring_ptr =
  2819. ha->request_ring;
  2820. } else
  2821. ha->request_ring_ptr++;
  2822. pkt = (struct cmd_entry *)ha->request_ring_ptr;
  2823. /* Zero out packet. */
  2824. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2825. /* Load packet defaults. */
  2826. ((struct cont_entry *) pkt)->
  2827. entry_type = CONTINUE_TYPE;
  2828. ((struct cont_entry *) pkt)->entry_count = 1;
  2829. ((struct cont_entry *) pkt)->sys_define =
  2830. (uint8_t) ha->req_ring_index;
  2831. /* Setup packet address segment pointer. */
  2832. dword_ptr =
  2833. &((struct cont_entry *) pkt)->dseg_0_address;
  2834. /* Load continuation entry data segments. */
  2835. for (cnt = 0; cnt < 7 && seg_cnt;
  2836. cnt++, seg_cnt--) {
  2837. *dword_ptr++ =
  2838. cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
  2839. *dword_ptr++ =
  2840. cpu_to_le32(sg_dma_len(sg));
  2841. dprintk(1,
  2842. "S/G Segment Cont. phys_addr=0x%x, "
  2843. "len=0x%x\n",
  2844. cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
  2845. cpu_to_le32(sg_dma_len(sg)));
  2846. sg++;
  2847. }
  2848. dprintk(5, "qla1280_32bit_start_scsi: "
  2849. "continuation packet data - "
  2850. "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
  2851. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2852. qla1280_dump_buffer(5, (char *)pkt,
  2853. REQUEST_ENTRY_SIZE);
  2854. }
  2855. } else { /* No S/G data transfer */
  2856. dma_handle = pci_map_single(ha->pdev,
  2857. cmd->request_buffer,
  2858. cmd->request_bufflen,
  2859. cmd->sc_data_direction);
  2860. sp->saved_dma_handle = dma_handle;
  2861. *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
  2862. *dword_ptr = cpu_to_le32(cmd->request_bufflen);
  2863. }
  2864. } else { /* No data transfer at all */
  2865. dprintk(5, "qla1280_32bit_start_scsi: No data, command "
  2866. "packet data - \n");
  2867. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2868. }
  2869. dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
  2870. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2871. REQUEST_ENTRY_SIZE);
  2872. /* Adjust ring index. */
  2873. ha->req_ring_index++;
  2874. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2875. ha->req_ring_index = 0;
  2876. ha->request_ring_ptr = ha->request_ring;
  2877. } else
  2878. ha->request_ring_ptr++;
  2879. /* Set chip new ring index. */
  2880. dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
  2881. "for pending command\n");
  2882. sp->flags |= SRB_SENT;
  2883. ha->actthreads++;
  2884. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2885. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2886. mmiowb();
  2887. out:
  2888. if (status)
  2889. dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
  2890. LEAVE("qla1280_32bit_start_scsi");
  2891. return status;
  2892. }
  2893. #endif
  2894. /*
  2895. * qla1280_req_pkt
  2896. * Function is responsible for locking ring and
  2897. * getting a zeroed out request packet.
  2898. *
  2899. * Input:
  2900. * ha = adapter block pointer.
  2901. *
  2902. * Returns:
  2903. * 0 = failed to get slot.
  2904. */
  2905. static request_t *
  2906. qla1280_req_pkt(struct scsi_qla_host *ha)
  2907. {
  2908. struct device_reg __iomem *reg = ha->iobase;
  2909. request_t *pkt = NULL;
  2910. int cnt;
  2911. uint32_t timer;
  2912. ENTER("qla1280_req_pkt");
  2913. /*
  2914. * This can be called from interrupt context, damn it!!!
  2915. */
  2916. /* Wait for 30 seconds for slot. */
  2917. for (timer = 15000000; timer; timer--) {
  2918. if (ha->req_q_cnt > 0) {
  2919. /* Calculate number of free request entries. */
  2920. cnt = RD_REG_WORD(&reg->mailbox4);
  2921. if (ha->req_ring_index < cnt)
  2922. ha->req_q_cnt = cnt - ha->req_ring_index;
  2923. else
  2924. ha->req_q_cnt =
  2925. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2926. }
  2927. /* Found empty request ring slot? */
  2928. if (ha->req_q_cnt > 0) {
  2929. ha->req_q_cnt--;
  2930. pkt = ha->request_ring_ptr;
  2931. /* Zero out packet. */
  2932. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2933. /*
  2934. * How can this be right when we have a ring
  2935. * size of 512???
  2936. */
  2937. /* Set system defined field. */
  2938. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2939. /* Set entry count. */
  2940. pkt->entry_count = 1;
  2941. break;
  2942. }
  2943. udelay(2); /* 10 */
  2944. /* Check for pending interrupts. */
  2945. qla1280_poll(ha);
  2946. }
  2947. if (!pkt)
  2948. dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
  2949. else
  2950. dprintk(3, "qla1280_req_pkt: exiting normally\n");
  2951. return pkt;
  2952. }
  2953. /*
  2954. * qla1280_isp_cmd
  2955. * Function is responsible for modifying ISP input pointer.
  2956. * Releases ring lock.
  2957. *
  2958. * Input:
  2959. * ha = adapter block pointer.
  2960. */
  2961. static void
  2962. qla1280_isp_cmd(struct scsi_qla_host *ha)
  2963. {
  2964. struct device_reg __iomem *reg = ha->iobase;
  2965. ENTER("qla1280_isp_cmd");
  2966. dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
  2967. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2968. REQUEST_ENTRY_SIZE);
  2969. /* Adjust ring index. */
  2970. ha->req_ring_index++;
  2971. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2972. ha->req_ring_index = 0;
  2973. ha->request_ring_ptr = ha->request_ring;
  2974. } else
  2975. ha->request_ring_ptr++;
  2976. /*
  2977. * Update request index to mailbox4 (Request Queue In).
  2978. * The mmiowb() ensures that this write is ordered with writes by other
  2979. * CPUs. Without the mmiowb(), it is possible for the following:
  2980. * CPUA posts write of index 5 to mailbox4
  2981. * CPUA releases host lock
  2982. * CPUB acquires host lock
  2983. * CPUB posts write of index 6 to mailbox4
  2984. * On PCI bus, order reverses and write of 6 posts, then index 5,
  2985. * causing chip to issue full queue of stale commands
  2986. * The mmiowb() prevents future writes from crossing the barrier.
  2987. * See Documentation/DocBook/deviceiobook.tmpl for more information.
  2988. */
  2989. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2990. mmiowb();
  2991. LEAVE("qla1280_isp_cmd");
  2992. }
  2993. /****************************************************************************/
  2994. /* Interrupt Service Routine. */
  2995. /****************************************************************************/
  2996. /****************************************************************************
  2997. * qla1280_isr
  2998. * Calls I/O done on command completion.
  2999. *
  3000. * Input:
  3001. * ha = adapter block pointer.
  3002. * done_q = done queue.
  3003. ****************************************************************************/
  3004. static void
  3005. qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
  3006. {
  3007. struct device_reg __iomem *reg = ha->iobase;
  3008. struct response *pkt;
  3009. struct srb *sp = NULL;
  3010. uint16_t mailbox[MAILBOX_REGISTER_COUNT];
  3011. uint16_t *wptr;
  3012. uint32_t index;
  3013. u16 istatus;
  3014. ENTER("qla1280_isr");
  3015. istatus = RD_REG_WORD(&reg->istatus);
  3016. if (!(istatus & (RISC_INT | PCI_INT)))
  3017. return;
  3018. /* Save mailbox register 5 */
  3019. mailbox[5] = RD_REG_WORD(&reg->mailbox5);
  3020. /* Check for mailbox interrupt. */
  3021. mailbox[0] = RD_REG_WORD_dmasync(&reg->semaphore);
  3022. if (mailbox[0] & BIT_0) {
  3023. /* Get mailbox data. */
  3024. /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
  3025. wptr = &mailbox[0];
  3026. *wptr++ = RD_REG_WORD(&reg->mailbox0);
  3027. *wptr++ = RD_REG_WORD(&reg->mailbox1);
  3028. *wptr = RD_REG_WORD(&reg->mailbox2);
  3029. if (mailbox[0] != MBA_SCSI_COMPLETION) {
  3030. wptr++;
  3031. *wptr++ = RD_REG_WORD(&reg->mailbox3);
  3032. *wptr++ = RD_REG_WORD(&reg->mailbox4);
  3033. wptr++;
  3034. *wptr++ = RD_REG_WORD(&reg->mailbox6);
  3035. *wptr = RD_REG_WORD(&reg->mailbox7);
  3036. }
  3037. /* Release mailbox registers. */
  3038. WRT_REG_WORD(&reg->semaphore, 0);
  3039. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  3040. dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
  3041. mailbox[0]);
  3042. /* Handle asynchronous event */
  3043. switch (mailbox[0]) {
  3044. case MBA_SCSI_COMPLETION: /* Response completion */
  3045. dprintk(5, "qla1280_isr: mailbox SCSI response "
  3046. "completion\n");
  3047. if (ha->flags.online) {
  3048. /* Get outstanding command index. */
  3049. index = mailbox[2] << 16 | mailbox[1];
  3050. /* Validate handle. */
  3051. if (index < MAX_OUTSTANDING_COMMANDS)
  3052. sp = ha->outstanding_cmds[index];
  3053. else
  3054. sp = NULL;
  3055. if (sp) {
  3056. /* Free outstanding command slot. */
  3057. ha->outstanding_cmds[index] = NULL;
  3058. /* Save ISP completion status */
  3059. CMD_RESULT(sp->cmd) = 0;
  3060. /* Place block on done queue */
  3061. list_add_tail(&sp->list, done_q);
  3062. } else {
  3063. /*
  3064. * If we get here we have a real problem!
  3065. */
  3066. printk(KERN_WARNING
  3067. "qla1280: ISP invalid handle");
  3068. }
  3069. }
  3070. break;
  3071. case MBA_BUS_RESET: /* SCSI Bus Reset */
  3072. ha->flags.reset_marker = 1;
  3073. index = mailbox[6] & BIT_0;
  3074. ha->bus_settings[index].reset_marker = 1;
  3075. printk(KERN_DEBUG "qla1280_isr(): index %i "
  3076. "asynchronous BUS_RESET\n", index);
  3077. break;
  3078. case MBA_SYSTEM_ERR: /* System Error */
  3079. printk(KERN_WARNING
  3080. "qla1280: ISP System Error - mbx1=%xh, mbx2="
  3081. "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
  3082. mailbox[3]);
  3083. break;
  3084. case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
  3085. printk(KERN_WARNING
  3086. "qla1280: ISP Request Transfer Error\n");
  3087. break;
  3088. case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
  3089. printk(KERN_WARNING
  3090. "qla1280: ISP Response Transfer Error\n");
  3091. break;
  3092. case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
  3093. dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
  3094. break;
  3095. case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
  3096. dprintk(2,
  3097. "qla1280_isr: asynchronous TIMEOUT_RESET\n");
  3098. break;
  3099. case MBA_DEVICE_RESET: /* Bus Device Reset */
  3100. printk(KERN_INFO "qla1280_isr(): asynchronous "
  3101. "BUS_DEVICE_RESET\n");
  3102. ha->flags.reset_marker = 1;
  3103. index = mailbox[6] & BIT_0;
  3104. ha->bus_settings[index].reset_marker = 1;
  3105. break;
  3106. case MBA_BUS_MODE_CHANGE:
  3107. dprintk(2,
  3108. "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
  3109. break;
  3110. default:
  3111. /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
  3112. if (mailbox[0] < MBA_ASYNC_EVENT) {
  3113. wptr = &mailbox[0];
  3114. memcpy((uint16_t *) ha->mailbox_out, wptr,
  3115. MAILBOX_REGISTER_COUNT *
  3116. sizeof(uint16_t));
  3117. if(ha->mailbox_wait != NULL)
  3118. complete(ha->mailbox_wait);
  3119. }
  3120. break;
  3121. }
  3122. } else {
  3123. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  3124. }
  3125. /*
  3126. * We will receive interrupts during mailbox testing prior to
  3127. * the card being marked online, hence the double check.
  3128. */
  3129. if (!(ha->flags.online && !ha->mailbox_wait)) {
  3130. dprintk(2, "qla1280_isr: Response pointer Error\n");
  3131. goto out;
  3132. }
  3133. if (mailbox[5] >= RESPONSE_ENTRY_CNT)
  3134. goto out;
  3135. while (ha->rsp_ring_index != mailbox[5]) {
  3136. pkt = ha->response_ring_ptr;
  3137. dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
  3138. " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
  3139. dprintk(5,"qla1280_isr: response packet data\n");
  3140. qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
  3141. if (pkt->entry_type == STATUS_TYPE) {
  3142. if ((le16_to_cpu(pkt->scsi_status) & 0xff)
  3143. || pkt->comp_status || pkt->entry_status) {
  3144. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3145. "0x%x mailbox[5] = 0x%x, comp_status "
  3146. "= 0x%x, scsi_status = 0x%x\n",
  3147. ha->rsp_ring_index, mailbox[5],
  3148. le16_to_cpu(pkt->comp_status),
  3149. le16_to_cpu(pkt->scsi_status));
  3150. }
  3151. } else {
  3152. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3153. "0x%x, mailbox[5] = 0x%x\n",
  3154. ha->rsp_ring_index, mailbox[5]);
  3155. dprintk(2, "qla1280_isr: response packet data\n");
  3156. qla1280_dump_buffer(2, (char *)pkt,
  3157. RESPONSE_ENTRY_SIZE);
  3158. }
  3159. if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
  3160. dprintk(2, "status: Cmd %p, handle %i\n",
  3161. ha->outstanding_cmds[pkt->handle]->cmd,
  3162. pkt->handle);
  3163. if (pkt->entry_type == STATUS_TYPE)
  3164. qla1280_status_entry(ha, pkt, done_q);
  3165. else
  3166. qla1280_error_entry(ha, pkt, done_q);
  3167. /* Adjust ring index. */
  3168. ha->rsp_ring_index++;
  3169. if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
  3170. ha->rsp_ring_index = 0;
  3171. ha->response_ring_ptr = ha->response_ring;
  3172. } else
  3173. ha->response_ring_ptr++;
  3174. WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
  3175. }
  3176. }
  3177. out:
  3178. LEAVE("qla1280_isr");
  3179. }
  3180. /*
  3181. * qla1280_rst_aen
  3182. * Processes asynchronous reset.
  3183. *
  3184. * Input:
  3185. * ha = adapter block pointer.
  3186. */
  3187. static void
  3188. qla1280_rst_aen(struct scsi_qla_host *ha)
  3189. {
  3190. uint8_t bus;
  3191. ENTER("qla1280_rst_aen");
  3192. if (ha->flags.online && !ha->flags.reset_active &&
  3193. !ha->flags.abort_isp_active) {
  3194. ha->flags.reset_active = 1;
  3195. while (ha->flags.reset_marker) {
  3196. /* Issue marker command. */
  3197. ha->flags.reset_marker = 0;
  3198. for (bus = 0; bus < ha->ports &&
  3199. !ha->flags.reset_marker; bus++) {
  3200. if (ha->bus_settings[bus].reset_marker) {
  3201. ha->bus_settings[bus].reset_marker = 0;
  3202. qla1280_marker(ha, bus, 0, 0,
  3203. MK_SYNC_ALL);
  3204. }
  3205. }
  3206. }
  3207. }
  3208. LEAVE("qla1280_rst_aen");
  3209. }
  3210. /*
  3211. * qla1280_status_entry
  3212. * Processes received ISP status entry.
  3213. *
  3214. * Input:
  3215. * ha = adapter block pointer.
  3216. * pkt = entry pointer.
  3217. * done_q = done queue.
  3218. */
  3219. static void
  3220. qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
  3221. struct list_head *done_q)
  3222. {
  3223. unsigned int bus, target, lun;
  3224. int sense_sz;
  3225. struct srb *sp;
  3226. struct scsi_cmnd *cmd;
  3227. uint32_t handle = le32_to_cpu(pkt->handle);
  3228. uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
  3229. uint16_t comp_status = le16_to_cpu(pkt->comp_status);
  3230. ENTER("qla1280_status_entry");
  3231. /* Validate handle. */
  3232. if (handle < MAX_OUTSTANDING_COMMANDS)
  3233. sp = ha->outstanding_cmds[handle];
  3234. else
  3235. sp = NULL;
  3236. if (!sp) {
  3237. printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
  3238. goto out;
  3239. }
  3240. /* Free outstanding command slot. */
  3241. ha->outstanding_cmds[handle] = NULL;
  3242. cmd = sp->cmd;
  3243. /* Generate LU queue on cntrl, target, LUN */
  3244. bus = SCSI_BUS_32(cmd);
  3245. target = SCSI_TCN_32(cmd);
  3246. lun = SCSI_LUN_32(cmd);
  3247. if (comp_status || scsi_status) {
  3248. dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
  3249. "0x%x, handle = 0x%x\n", comp_status,
  3250. scsi_status, handle);
  3251. }
  3252. /* Target busy or queue full */
  3253. if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
  3254. (scsi_status & 0xFF) == SAM_STAT_BUSY) {
  3255. CMD_RESULT(cmd) = scsi_status & 0xff;
  3256. } else {
  3257. /* Save ISP completion status */
  3258. CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
  3259. if (scsi_status & SAM_STAT_CHECK_CONDITION) {
  3260. if (comp_status != CS_ARS_FAILED) {
  3261. uint16_t req_sense_length =
  3262. le16_to_cpu(pkt->req_sense_length);
  3263. if (req_sense_length < CMD_SNSLEN(cmd))
  3264. sense_sz = req_sense_length;
  3265. else
  3266. /*
  3267. * scsi_cmnd->sense_buffer is
  3268. * 64 bytes, why only copy 63?
  3269. * This looks wrong! /Jes
  3270. */
  3271. sense_sz = CMD_SNSLEN(cmd) - 1;
  3272. memcpy(cmd->sense_buffer,
  3273. &pkt->req_sense_data, sense_sz);
  3274. } else
  3275. sense_sz = 0;
  3276. memset(cmd->sense_buffer + sense_sz, 0,
  3277. sizeof(cmd->sense_buffer) - sense_sz);
  3278. dprintk(2, "qla1280_status_entry: Check "
  3279. "condition Sense data, b %i, t %i, "
  3280. "l %i\n", bus, target, lun);
  3281. if (sense_sz)
  3282. qla1280_dump_buffer(2,
  3283. (char *)cmd->sense_buffer,
  3284. sense_sz);
  3285. }
  3286. }
  3287. /* Place command on done queue. */
  3288. list_add_tail(&sp->list, done_q);
  3289. out:
  3290. LEAVE("qla1280_status_entry");
  3291. }
  3292. /*
  3293. * qla1280_error_entry
  3294. * Processes error entry.
  3295. *
  3296. * Input:
  3297. * ha = adapter block pointer.
  3298. * pkt = entry pointer.
  3299. * done_q = done queue.
  3300. */
  3301. static void
  3302. qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
  3303. struct list_head *done_q)
  3304. {
  3305. struct srb *sp;
  3306. uint32_t handle = le32_to_cpu(pkt->handle);
  3307. ENTER("qla1280_error_entry");
  3308. if (pkt->entry_status & BIT_3)
  3309. dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
  3310. else if (pkt->entry_status & BIT_2)
  3311. dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
  3312. else if (pkt->entry_status & BIT_1)
  3313. dprintk(2, "qla1280_error_entry: FULL flag error\n");
  3314. else
  3315. dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
  3316. /* Validate handle. */
  3317. if (handle < MAX_OUTSTANDING_COMMANDS)
  3318. sp = ha->outstanding_cmds[handle];
  3319. else
  3320. sp = NULL;
  3321. if (sp) {
  3322. /* Free outstanding command slot. */
  3323. ha->outstanding_cmds[handle] = NULL;
  3324. /* Bad payload or header */
  3325. if (pkt->entry_status & (BIT_3 + BIT_2)) {
  3326. /* Bad payload or header, set error status. */
  3327. /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
  3328. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3329. } else if (pkt->entry_status & BIT_1) { /* FULL flag */
  3330. CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
  3331. } else {
  3332. /* Set error status. */
  3333. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3334. }
  3335. /* Place command on done queue. */
  3336. list_add_tail(&sp->list, done_q);
  3337. }
  3338. #ifdef QLA_64BIT_PTR
  3339. else if (pkt->entry_type == COMMAND_A64_TYPE) {
  3340. printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
  3341. }
  3342. #endif
  3343. LEAVE("qla1280_error_entry");
  3344. }
  3345. /*
  3346. * qla1280_abort_isp
  3347. * Resets ISP and aborts all outstanding commands.
  3348. *
  3349. * Input:
  3350. * ha = adapter block pointer.
  3351. *
  3352. * Returns:
  3353. * 0 = success
  3354. */
  3355. static int
  3356. qla1280_abort_isp(struct scsi_qla_host *ha)
  3357. {
  3358. struct device_reg __iomem *reg = ha->iobase;
  3359. struct srb *sp;
  3360. int status = 0;
  3361. int cnt;
  3362. int bus;
  3363. ENTER("qla1280_abort_isp");
  3364. if (ha->flags.abort_isp_active || !ha->flags.online)
  3365. goto out;
  3366. ha->flags.abort_isp_active = 1;
  3367. /* Disable ISP interrupts. */
  3368. qla1280_disable_intrs(ha);
  3369. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3370. RD_REG_WORD(&reg->id_l);
  3371. printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
  3372. ha->host_no);
  3373. /* Dequeue all commands in outstanding command list. */
  3374. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  3375. struct scsi_cmnd *cmd;
  3376. sp = ha->outstanding_cmds[cnt];
  3377. if (sp) {
  3378. cmd = sp->cmd;
  3379. CMD_RESULT(cmd) = DID_RESET << 16;
  3380. sp->cmd = NULL;
  3381. ha->outstanding_cmds[cnt] = NULL;
  3382. (*cmd->scsi_done)(cmd);
  3383. sp->flags = 0;
  3384. }
  3385. }
  3386. status = qla1280_load_firmware(ha);
  3387. if (status)
  3388. goto out;
  3389. /* Setup adapter based on NVRAM parameters. */
  3390. qla1280_nvram_config (ha);
  3391. status = qla1280_init_rings(ha);
  3392. if (status)
  3393. goto out;
  3394. /* Issue SCSI reset. */
  3395. for (bus = 0; bus < ha->ports; bus++)
  3396. qla1280_bus_reset(ha, bus);
  3397. ha->flags.abort_isp_active = 0;
  3398. out:
  3399. if (status) {
  3400. printk(KERN_WARNING
  3401. "qla1280: ISP error recovery failed, board disabled");
  3402. qla1280_reset_adapter(ha);
  3403. dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
  3404. }
  3405. LEAVE("qla1280_abort_isp");
  3406. return status;
  3407. }
  3408. /*
  3409. * qla1280_debounce_register
  3410. * Debounce register.
  3411. *
  3412. * Input:
  3413. * port = register address.
  3414. *
  3415. * Returns:
  3416. * register value.
  3417. */
  3418. static u16
  3419. qla1280_debounce_register(volatile u16 __iomem * addr)
  3420. {
  3421. volatile u16 ret;
  3422. volatile u16 ret2;
  3423. ret = RD_REG_WORD(addr);
  3424. ret2 = RD_REG_WORD(addr);
  3425. if (ret == ret2)
  3426. return ret;
  3427. do {
  3428. cpu_relax();
  3429. ret = RD_REG_WORD(addr);
  3430. ret2 = RD_REG_WORD(addr);
  3431. } while (ret != ret2);
  3432. return ret;
  3433. }
  3434. /************************************************************************
  3435. * qla1280_check_for_dead_scsi_bus *
  3436. * *
  3437. * This routine checks for a dead SCSI bus *
  3438. ************************************************************************/
  3439. #define SET_SXP_BANK 0x0100
  3440. #define SCSI_PHASE_INVALID 0x87FF
  3441. static int
  3442. qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
  3443. {
  3444. uint16_t config_reg, scsi_control;
  3445. struct device_reg __iomem *reg = ha->iobase;
  3446. if (ha->bus_settings[bus].scsi_bus_dead) {
  3447. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3448. config_reg = RD_REG_WORD(&reg->cfg_1);
  3449. WRT_REG_WORD(&reg->cfg_1, SET_SXP_BANK);
  3450. scsi_control = RD_REG_WORD(&reg->scsiControlPins);
  3451. WRT_REG_WORD(&reg->cfg_1, config_reg);
  3452. WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
  3453. if (scsi_control == SCSI_PHASE_INVALID) {
  3454. ha->bus_settings[bus].scsi_bus_dead = 1;
  3455. #if 0
  3456. CMD_RESULT(cp) = DID_NO_CONNECT << 16;
  3457. CMD_HANDLE(cp) = INVALID_HANDLE;
  3458. /* ha->actthreads--; */
  3459. (*(cp)->scsi_done)(cp);
  3460. #endif
  3461. return 1; /* bus is dead */
  3462. } else {
  3463. ha->bus_settings[bus].scsi_bus_dead = 0;
  3464. ha->bus_settings[bus].failed_reset_count = 0;
  3465. }
  3466. }
  3467. return 0; /* bus is not dead */
  3468. }
  3469. static void
  3470. qla1280_get_target_parameters(struct scsi_qla_host *ha,
  3471. struct scsi_device *device)
  3472. {
  3473. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3474. int bus, target, lun;
  3475. bus = device->channel;
  3476. target = device->id;
  3477. lun = device->lun;
  3478. mb[0] = MBC_GET_TARGET_PARAMETERS;
  3479. mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
  3480. mb[1] <<= 8;
  3481. qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
  3482. &mb[0]);
  3483. printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
  3484. if (mb[3] != 0) {
  3485. printk(" Sync: period %d, offset %d",
  3486. (mb[3] & 0xff), (mb[3] >> 8));
  3487. if (mb[2] & BIT_13)
  3488. printk(", Wide");
  3489. if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
  3490. printk(", DT");
  3491. } else
  3492. printk(" Async");
  3493. if (device->simple_tags)
  3494. printk(", Tagged queuing: depth %d", device->queue_depth);
  3495. printk("\n");
  3496. }
  3497. #if DEBUG_QLA1280
  3498. static void
  3499. __qla1280_dump_buffer(char *b, int size)
  3500. {
  3501. int cnt;
  3502. u8 c;
  3503. printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
  3504. "Bh Ch Dh Eh Fh\n");
  3505. printk(KERN_DEBUG "---------------------------------------------"
  3506. "------------------\n");
  3507. for (cnt = 0; cnt < size;) {
  3508. c = *b++;
  3509. printk("0x%02x", c);
  3510. cnt++;
  3511. if (!(cnt % 16))
  3512. printk("\n");
  3513. else
  3514. printk(" ");
  3515. }
  3516. if (cnt % 16)
  3517. printk("\n");
  3518. }
  3519. /**************************************************************************
  3520. * ql1280_print_scsi_cmd
  3521. *
  3522. **************************************************************************/
  3523. static void
  3524. __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
  3525. {
  3526. struct scsi_qla_host *ha;
  3527. struct Scsi_Host *host = CMD_HOST(cmd);
  3528. struct srb *sp;
  3529. /* struct scatterlist *sg; */
  3530. int i;
  3531. ha = (struct scsi_qla_host *)host->hostdata;
  3532. sp = (struct srb *)CMD_SP(cmd);
  3533. printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
  3534. printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  3535. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
  3536. CMD_CDBLEN(cmd));
  3537. printk(" CDB = ");
  3538. for (i = 0; i < cmd->cmd_len; i++) {
  3539. printk("0x%02x ", cmd->cmnd[i]);
  3540. }
  3541. printk(" seg_cnt =%d\n", cmd->use_sg);
  3542. printk(" request buffer=0x%p, request buffer len=0x%x\n",
  3543. cmd->request_buffer, cmd->request_bufflen);
  3544. /* if (cmd->use_sg)
  3545. {
  3546. sg = (struct scatterlist *) cmd->request_buffer;
  3547. printk(" SG buffer: \n");
  3548. qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
  3549. } */
  3550. printk(" tag=%d, transfersize=0x%x \n",
  3551. cmd->tag, cmd->transfersize);
  3552. printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
  3553. printk(" underflow size = 0x%x, direction=0x%x\n",
  3554. cmd->underflow, cmd->sc_data_direction);
  3555. }
  3556. /**************************************************************************
  3557. * ql1280_dump_device
  3558. *
  3559. **************************************************************************/
  3560. static void
  3561. ql1280_dump_device(struct scsi_qla_host *ha)
  3562. {
  3563. struct scsi_cmnd *cp;
  3564. struct srb *sp;
  3565. int i;
  3566. printk(KERN_DEBUG "Outstanding Commands on controller:\n");
  3567. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  3568. if ((sp = ha->outstanding_cmds[i]) == NULL)
  3569. continue;
  3570. if ((cp = sp->cmd) == NULL)
  3571. continue;
  3572. qla1280_print_scsi_cmd(1, cp);
  3573. }
  3574. }
  3575. #endif
  3576. enum tokens {
  3577. TOKEN_NVRAM,
  3578. TOKEN_SYNC,
  3579. TOKEN_WIDE,
  3580. TOKEN_PPR,
  3581. TOKEN_VERBOSE,
  3582. TOKEN_DEBUG,
  3583. };
  3584. struct setup_tokens {
  3585. char *token;
  3586. int val;
  3587. };
  3588. static struct setup_tokens setup_token[] __initdata =
  3589. {
  3590. { "nvram", TOKEN_NVRAM },
  3591. { "sync", TOKEN_SYNC },
  3592. { "wide", TOKEN_WIDE },
  3593. { "ppr", TOKEN_PPR },
  3594. { "verbose", TOKEN_VERBOSE },
  3595. { "debug", TOKEN_DEBUG },
  3596. };
  3597. /**************************************************************************
  3598. * qla1280_setup
  3599. *
  3600. * Handle boot parameters. This really needs to be changed so one
  3601. * can specify per adapter parameters.
  3602. **************************************************************************/
  3603. static int __init
  3604. qla1280_setup(char *s)
  3605. {
  3606. char *cp, *ptr;
  3607. unsigned long val;
  3608. int toke;
  3609. cp = s;
  3610. while (cp && (ptr = strchr(cp, ':'))) {
  3611. ptr++;
  3612. if (!strcmp(ptr, "yes")) {
  3613. val = 0x10000;
  3614. ptr += 3;
  3615. } else if (!strcmp(ptr, "no")) {
  3616. val = 0;
  3617. ptr += 2;
  3618. } else
  3619. val = simple_strtoul(ptr, &ptr, 0);
  3620. switch ((toke = qla1280_get_token(cp))) {
  3621. case TOKEN_NVRAM:
  3622. if (!val)
  3623. driver_setup.no_nvram = 1;
  3624. break;
  3625. case TOKEN_SYNC:
  3626. if (!val)
  3627. driver_setup.no_sync = 1;
  3628. else if (val != 0x10000)
  3629. driver_setup.sync_mask = val;
  3630. break;
  3631. case TOKEN_WIDE:
  3632. if (!val)
  3633. driver_setup.no_wide = 1;
  3634. else if (val != 0x10000)
  3635. driver_setup.wide_mask = val;
  3636. break;
  3637. case TOKEN_PPR:
  3638. if (!val)
  3639. driver_setup.no_ppr = 1;
  3640. else if (val != 0x10000)
  3641. driver_setup.ppr_mask = val;
  3642. break;
  3643. case TOKEN_VERBOSE:
  3644. qla1280_verbose = val;
  3645. break;
  3646. default:
  3647. printk(KERN_INFO "qla1280: unknown boot option %s\n",
  3648. cp);
  3649. }
  3650. cp = strchr(ptr, ';');
  3651. if (cp)
  3652. cp++;
  3653. else {
  3654. break;
  3655. }
  3656. }
  3657. return 1;
  3658. }
  3659. static int
  3660. qla1280_get_token(char *str)
  3661. {
  3662. char *sep;
  3663. long ret = -1;
  3664. int i, len;
  3665. len = sizeof(setup_token)/sizeof(struct setup_tokens);
  3666. sep = strchr(str, ':');
  3667. if (sep) {
  3668. for (i = 0; i < len; i++){
  3669. if (!strncmp(setup_token[i].token, str, (sep - str))) {
  3670. ret = setup_token[i].val;
  3671. break;
  3672. }
  3673. }
  3674. }
  3675. return ret;
  3676. }
  3677. static struct scsi_host_template qla1280_driver_template = {
  3678. .module = THIS_MODULE,
  3679. .proc_name = "qla1280",
  3680. .name = "Qlogic ISP 1280/12160",
  3681. .info = qla1280_info,
  3682. .slave_configure = qla1280_slave_configure,
  3683. .queuecommand = qla1280_queuecommand,
  3684. .eh_abort_handler = qla1280_eh_abort,
  3685. .eh_device_reset_handler= qla1280_eh_device_reset,
  3686. .eh_bus_reset_handler = qla1280_eh_bus_reset,
  3687. .eh_host_reset_handler = qla1280_eh_adapter_reset,
  3688. .bios_param = qla1280_biosparam,
  3689. .can_queue = 0xfffff,
  3690. .this_id = -1,
  3691. .sg_tablesize = SG_ALL,
  3692. .cmd_per_lun = 1,
  3693. .use_clustering = ENABLE_CLUSTERING,
  3694. };
  3695. static int __devinit
  3696. qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  3697. {
  3698. int devnum = id->driver_data;
  3699. struct qla_boards *bdp = &ql1280_board_tbl[devnum];
  3700. struct Scsi_Host *host;
  3701. struct scsi_qla_host *ha;
  3702. int error = -ENODEV;
  3703. /* Bypass all AMI SUBSYS VENDOR IDs */
  3704. if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
  3705. printk(KERN_INFO
  3706. "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
  3707. goto error;
  3708. }
  3709. printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
  3710. bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
  3711. if (pci_enable_device(pdev)) {
  3712. printk(KERN_WARNING
  3713. "qla1280: Failed to enabled pci device, aborting.\n");
  3714. goto error;
  3715. }
  3716. pci_set_master(pdev);
  3717. error = -ENOMEM;
  3718. host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
  3719. if (!host) {
  3720. printk(KERN_WARNING
  3721. "qla1280: Failed to register host, aborting.\n");
  3722. goto error_disable_device;
  3723. }
  3724. ha = (struct scsi_qla_host *)host->hostdata;
  3725. memset(ha, 0, sizeof(struct scsi_qla_host));
  3726. ha->pdev = pdev;
  3727. ha->devnum = devnum; /* specifies microcode load address */
  3728. #ifdef QLA_64BIT_PTR
  3729. if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
  3730. if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
  3731. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3732. "suitable DMA mask - aborting\n", ha->host_no);
  3733. error = -ENODEV;
  3734. goto error_free_irq;
  3735. }
  3736. } else
  3737. dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
  3738. ha->host_no);
  3739. #else
  3740. if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
  3741. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3742. "suitable DMA mask - aborting\n", ha->host_no);
  3743. error = -ENODEV;
  3744. goto error_free_irq;
  3745. }
  3746. #endif
  3747. ha->request_ring = pci_alloc_consistent(ha->pdev,
  3748. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3749. &ha->request_dma);
  3750. if (!ha->request_ring) {
  3751. printk(KERN_INFO "qla1280: Failed to get request memory\n");
  3752. goto error_put_host;
  3753. }
  3754. ha->response_ring = pci_alloc_consistent(ha->pdev,
  3755. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3756. &ha->response_dma);
  3757. if (!ha->response_ring) {
  3758. printk(KERN_INFO "qla1280: Failed to get response memory\n");
  3759. goto error_free_request_ring;
  3760. }
  3761. ha->ports = bdp->numPorts;
  3762. ha->host = host;
  3763. ha->host_no = host->host_no;
  3764. host->irq = pdev->irq;
  3765. host->max_channel = bdp->numPorts - 1;
  3766. host->max_lun = MAX_LUNS - 1;
  3767. host->max_id = MAX_TARGETS;
  3768. host->max_sectors = 1024;
  3769. host->unique_id = host->host_no;
  3770. error = -ENODEV;
  3771. #if MEMORY_MAPPED_IO
  3772. ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
  3773. pci_resource_len(ha->pdev, 1));
  3774. if (!ha->mmpbase) {
  3775. printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
  3776. goto error_free_response_ring;
  3777. }
  3778. host->base = (unsigned long)ha->mmpbase;
  3779. ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
  3780. #else
  3781. host->io_port = pci_resource_start(ha->pdev, 0);
  3782. if (!request_region(host->io_port, 0xff, "qla1280")) {
  3783. printk(KERN_INFO "qla1280: Failed to reserve i/o region "
  3784. "0x%04lx-0x%04lx - already in use\n",
  3785. host->io_port, host->io_port + 0xff);
  3786. goto error_free_response_ring;
  3787. }
  3788. ha->iobase = (struct device_reg *)host->io_port;
  3789. #endif
  3790. INIT_LIST_HEAD(&ha->done_q);
  3791. /* Disable ISP interrupts. */
  3792. qla1280_disable_intrs(ha);
  3793. if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
  3794. "qla1280", ha)) {
  3795. printk("qla1280 : Failed to reserve interrupt %d already "
  3796. "in use\n", pdev->irq);
  3797. goto error_release_region;
  3798. }
  3799. /* load the F/W, read paramaters, and init the H/W */
  3800. if (qla1280_initialize_adapter(ha)) {
  3801. printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
  3802. goto error_free_irq;
  3803. }
  3804. /* set our host ID (need to do something about our two IDs) */
  3805. host->this_id = ha->bus_settings[0].id;
  3806. pci_set_drvdata(pdev, host);
  3807. error = scsi_add_host(host, &pdev->dev);
  3808. if (error)
  3809. goto error_disable_adapter;
  3810. scsi_scan_host(host);
  3811. return 0;
  3812. error_disable_adapter:
  3813. qla1280_disable_intrs(ha);
  3814. error_free_irq:
  3815. free_irq(pdev->irq, ha);
  3816. error_release_region:
  3817. #if MEMORY_MAPPED_IO
  3818. iounmap(ha->mmpbase);
  3819. #else
  3820. release_region(host->io_port, 0xff);
  3821. #endif
  3822. error_free_response_ring:
  3823. pci_free_consistent(ha->pdev,
  3824. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3825. ha->response_ring, ha->response_dma);
  3826. error_free_request_ring:
  3827. pci_free_consistent(ha->pdev,
  3828. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3829. ha->request_ring, ha->request_dma);
  3830. error_put_host:
  3831. scsi_host_put(host);
  3832. error_disable_device:
  3833. pci_disable_device(pdev);
  3834. error:
  3835. return error;
  3836. }
  3837. static void __devexit
  3838. qla1280_remove_one(struct pci_dev *pdev)
  3839. {
  3840. struct Scsi_Host *host = pci_get_drvdata(pdev);
  3841. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  3842. scsi_remove_host(host);
  3843. qla1280_disable_intrs(ha);
  3844. free_irq(pdev->irq, ha);
  3845. #if MEMORY_MAPPED_IO
  3846. iounmap(ha->mmpbase);
  3847. #else
  3848. release_region(host->io_port, 0xff);
  3849. #endif
  3850. pci_free_consistent(ha->pdev,
  3851. ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
  3852. ha->request_ring, ha->request_dma);
  3853. pci_free_consistent(ha->pdev,
  3854. ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
  3855. ha->response_ring, ha->response_dma);
  3856. pci_disable_device(pdev);
  3857. scsi_host_put(host);
  3858. }
  3859. static struct pci_driver qla1280_pci_driver = {
  3860. .name = "qla1280",
  3861. .id_table = qla1280_pci_tbl,
  3862. .probe = qla1280_probe_one,
  3863. .remove = __devexit_p(qla1280_remove_one),
  3864. };
  3865. static int __init
  3866. qla1280_init(void)
  3867. {
  3868. if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
  3869. printk(KERN_WARNING
  3870. "qla1280: struct srb too big, aborting\n");
  3871. return -EINVAL;
  3872. }
  3873. #ifdef MODULE
  3874. /*
  3875. * If we are called as a module, the qla1280 pointer may not be null
  3876. * and it would point to our bootup string, just like on the lilo
  3877. * command line. IF not NULL, then process this config string with
  3878. * qla1280_setup
  3879. *
  3880. * Boot time Options
  3881. * To add options at boot time add a line to your lilo.conf file like:
  3882. * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
  3883. * which will result in the first four devices on the first two
  3884. * controllers being set to a tagged queue depth of 32.
  3885. */
  3886. if (qla1280)
  3887. qla1280_setup(qla1280);
  3888. #endif
  3889. return pci_module_init(&qla1280_pci_driver);
  3890. }
  3891. static void __exit
  3892. qla1280_exit(void)
  3893. {
  3894. pci_unregister_driver(&qla1280_pci_driver);
  3895. }
  3896. module_init(qla1280_init);
  3897. module_exit(qla1280_exit);
  3898. MODULE_AUTHOR("Qlogic & Jes Sorensen");
  3899. MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
  3900. MODULE_LICENSE("GPL");
  3901. MODULE_VERSION(QLA1280_VERSION);
  3902. /*
  3903. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  3904. * Emacs will notice this stuff at the end of the file and automatically
  3905. * adjust the settings for this buffer only. This must remain at the end
  3906. * of the file.
  3907. * ---------------------------------------------------------------------------
  3908. * Local variables:
  3909. * c-basic-offset: 8
  3910. * tab-width: 8
  3911. * End:
  3912. */