qla1280.c 124 KB

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