aic79xx_osm.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776
  1. /*
  2. * Adaptec AIC79xx device driver for Linux.
  3. *
  4. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $
  5. *
  6. * --------------------------------------------------------------------------
  7. * Copyright (c) 1994-2000 Justin T. Gibbs.
  8. * Copyright (c) 1997-1999 Doug Ledford
  9. * Copyright (c) 2000-2003 Adaptec Inc.
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions, and the following disclaimer,
  17. * without modification.
  18. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  19. * substantially similar to the "NO WARRANTY" disclaimer below
  20. * ("Disclaimer") and any redistribution must be conditioned upon
  21. * including a substantially similar Disclaimer requirement for further
  22. * binary redistribution.
  23. * 3. Neither the names of the above-listed copyright holders nor the names
  24. * of any contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * Alternatively, this software may be distributed under the terms of the
  28. * GNU General Public License ("GPL") version 2 as published by the Free
  29. * Software Foundation.
  30. *
  31. * NO WARRANTY
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  35. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  41. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. * POSSIBILITY OF SUCH DAMAGES.
  43. */
  44. #include "aic79xx_osm.h"
  45. #include "aic79xx_inline.h"
  46. #include <scsi/scsicam.h>
  47. static struct scsi_transport_template *ahd_linux_transport_template = NULL;
  48. #include <linux/init.h> /* __setup */
  49. #include <linux/mm.h> /* For fetching system memory size */
  50. #include <linux/blkdev.h> /* For block_size() */
  51. #include <linux/delay.h> /* For ssleep/msleep */
  52. #include <linux/device.h>
  53. /*
  54. * Bucket size for counting good commands in between bad ones.
  55. */
  56. #define AHD_LINUX_ERR_THRESH 1000
  57. /*
  58. * Set this to the delay in seconds after SCSI bus reset.
  59. * Note, we honor this only for the initial bus reset.
  60. * The scsi error recovery code performs its own bus settle
  61. * delay handling for error recovery actions.
  62. */
  63. #ifdef CONFIG_AIC79XX_RESET_DELAY_MS
  64. #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
  65. #else
  66. #define AIC79XX_RESET_DELAY 5000
  67. #endif
  68. /*
  69. * To change the default number of tagged transactions allowed per-device,
  70. * add a line to the lilo.conf file like:
  71. * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
  72. * which will result in the first four devices on the first two
  73. * controllers being set to a tagged queue depth of 32.
  74. *
  75. * The tag_commands is an array of 16 to allow for wide and twin adapters.
  76. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
  77. * for channel 1.
  78. */
  79. typedef struct {
  80. uint16_t tag_commands[16]; /* Allow for wide/twin adapters. */
  81. } adapter_tag_info_t;
  82. /*
  83. * Modify this as you see fit for your system.
  84. *
  85. * 0 tagged queuing disabled
  86. * 1 <= n <= 253 n == max tags ever dispatched.
  87. *
  88. * The driver will throttle the number of commands dispatched to a
  89. * device if it returns queue full. For devices with a fixed maximum
  90. * queue depth, the driver will eventually determine this depth and
  91. * lock it in (a console message is printed to indicate that a lock
  92. * has occurred). On some devices, queue full is returned for a temporary
  93. * resource shortage. These devices will return queue full at varying
  94. * depths. The driver will throttle back when the queue fulls occur and
  95. * attempt to slowly increase the depth over time as the device recovers
  96. * from the resource shortage.
  97. *
  98. * In this example, the first line will disable tagged queueing for all
  99. * the devices on the first probed aic79xx adapter.
  100. *
  101. * The second line enables tagged queueing with 4 commands/LUN for IDs
  102. * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  103. * driver to attempt to use up to 64 tags for ID 1.
  104. *
  105. * The third line is the same as the first line.
  106. *
  107. * The fourth line disables tagged queueing for devices 0 and 3. It
  108. * enables tagged queueing for the other IDs, with 16 commands/LUN
  109. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  110. * IDs 2, 5-7, and 9-15.
  111. */
  112. /*
  113. * NOTE: The below structure is for reference only, the actual structure
  114. * to modify in order to change things is just below this comment block.
  115. adapter_tag_info_t aic79xx_tag_info[] =
  116. {
  117. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  118. {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
  119. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  120. {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  121. };
  122. */
  123. #ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
  124. #define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
  125. #else
  126. #define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
  127. #endif
  128. #define AIC79XX_CONFIGED_TAG_COMMANDS { \
  129. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  130. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  131. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  132. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  133. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  134. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  135. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  136. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE \
  137. }
  138. /*
  139. * By default, use the number of commands specified by
  140. * the users kernel configuration.
  141. */
  142. static adapter_tag_info_t aic79xx_tag_info[] =
  143. {
  144. {AIC79XX_CONFIGED_TAG_COMMANDS},
  145. {AIC79XX_CONFIGED_TAG_COMMANDS},
  146. {AIC79XX_CONFIGED_TAG_COMMANDS},
  147. {AIC79XX_CONFIGED_TAG_COMMANDS},
  148. {AIC79XX_CONFIGED_TAG_COMMANDS},
  149. {AIC79XX_CONFIGED_TAG_COMMANDS},
  150. {AIC79XX_CONFIGED_TAG_COMMANDS},
  151. {AIC79XX_CONFIGED_TAG_COMMANDS},
  152. {AIC79XX_CONFIGED_TAG_COMMANDS},
  153. {AIC79XX_CONFIGED_TAG_COMMANDS},
  154. {AIC79XX_CONFIGED_TAG_COMMANDS},
  155. {AIC79XX_CONFIGED_TAG_COMMANDS},
  156. {AIC79XX_CONFIGED_TAG_COMMANDS},
  157. {AIC79XX_CONFIGED_TAG_COMMANDS},
  158. {AIC79XX_CONFIGED_TAG_COMMANDS},
  159. {AIC79XX_CONFIGED_TAG_COMMANDS}
  160. };
  161. /*
  162. * The I/O cell on the chip is very configurable in respect to its analog
  163. * characteristics. Set the defaults here; they can be overriden with
  164. * the proper insmod parameters.
  165. */
  166. struct ahd_linux_iocell_opts
  167. {
  168. uint8_t precomp;
  169. uint8_t slewrate;
  170. uint8_t amplitude;
  171. };
  172. #define AIC79XX_DEFAULT_PRECOMP 0xFF
  173. #define AIC79XX_DEFAULT_SLEWRATE 0xFF
  174. #define AIC79XX_DEFAULT_AMPLITUDE 0xFF
  175. #define AIC79XX_DEFAULT_IOOPTS \
  176. { \
  177. AIC79XX_DEFAULT_PRECOMP, \
  178. AIC79XX_DEFAULT_SLEWRATE, \
  179. AIC79XX_DEFAULT_AMPLITUDE \
  180. }
  181. #define AIC79XX_PRECOMP_INDEX 0
  182. #define AIC79XX_SLEWRATE_INDEX 1
  183. #define AIC79XX_AMPLITUDE_INDEX 2
  184. static struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
  185. {
  186. AIC79XX_DEFAULT_IOOPTS,
  187. AIC79XX_DEFAULT_IOOPTS,
  188. AIC79XX_DEFAULT_IOOPTS,
  189. AIC79XX_DEFAULT_IOOPTS,
  190. AIC79XX_DEFAULT_IOOPTS,
  191. AIC79XX_DEFAULT_IOOPTS,
  192. AIC79XX_DEFAULT_IOOPTS,
  193. AIC79XX_DEFAULT_IOOPTS,
  194. AIC79XX_DEFAULT_IOOPTS,
  195. AIC79XX_DEFAULT_IOOPTS,
  196. AIC79XX_DEFAULT_IOOPTS,
  197. AIC79XX_DEFAULT_IOOPTS,
  198. AIC79XX_DEFAULT_IOOPTS,
  199. AIC79XX_DEFAULT_IOOPTS,
  200. AIC79XX_DEFAULT_IOOPTS,
  201. AIC79XX_DEFAULT_IOOPTS
  202. };
  203. /*
  204. * There should be a specific return value for this in scsi.h, but
  205. * it seems that most drivers ignore it.
  206. */
  207. #define DID_UNDERFLOW DID_ERROR
  208. void
  209. ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
  210. {
  211. printk("(scsi%d:%c:%d:%d): ",
  212. ahd->platform_data->host->host_no,
  213. scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
  214. scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
  215. scb != NULL ? SCB_GET_LUN(scb) : -1);
  216. }
  217. /*
  218. * XXX - these options apply unilaterally to _all_ adapters
  219. * cards in the system. This should be fixed. Exceptions to this
  220. * rule are noted in the comments.
  221. */
  222. /*
  223. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  224. * has no effect on any later resets that might occur due to things like
  225. * SCSI bus timeouts.
  226. */
  227. static uint32_t aic79xx_no_reset;
  228. /*
  229. * Certain PCI motherboards will scan PCI devices from highest to lowest,
  230. * others scan from lowest to highest, and they tend to do all kinds of
  231. * strange things when they come into contact with PCI bridge chips. The
  232. * net result of all this is that the PCI card that is actually used to boot
  233. * the machine is very hard to detect. Most motherboards go from lowest
  234. * PCI slot number to highest, and the first SCSI controller found is the
  235. * one you boot from. The only exceptions to this are when a controller
  236. * has its BIOS disabled. So, we by default sort all of our SCSI controllers
  237. * from lowest PCI slot number to highest PCI slot number. We also force
  238. * all controllers with their BIOS disabled to the end of the list. This
  239. * works on *almost* all computers. Where it doesn't work, we have this
  240. * option. Setting this option to non-0 will reverse the order of the sort
  241. * to highest first, then lowest, but will still leave cards with their BIOS
  242. * disabled at the very end. That should fix everyone up unless there are
  243. * really strange cirumstances.
  244. */
  245. static uint32_t aic79xx_reverse_scan;
  246. /*
  247. * Should we force EXTENDED translation on a controller.
  248. * 0 == Use whatever is in the SEEPROM or default to off
  249. * 1 == Use whatever is in the SEEPROM or default to on
  250. */
  251. static uint32_t aic79xx_extended;
  252. /*
  253. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  254. * dubious at best. To my knowledge, this option has never actually
  255. * solved a PCI parity problem, but on certain machines with broken PCI
  256. * chipset configurations, it can generate tons of false error messages.
  257. * It's included in the driver for completeness.
  258. * 0 = Shut off PCI parity check
  259. * non-0 = Enable PCI parity check
  260. *
  261. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  262. * variable to -1 you would actually want to simply pass the variable
  263. * name without a number. That will invert the 0 which will result in
  264. * -1.
  265. */
  266. static uint32_t aic79xx_pci_parity = ~0;
  267. /*
  268. * There are lots of broken chipsets in the world. Some of them will
  269. * violate the PCI spec when we issue byte sized memory writes to our
  270. * controller. I/O mapped register access, if allowed by the given
  271. * platform, will work in almost all cases.
  272. */
  273. uint32_t aic79xx_allow_memio = ~0;
  274. /*
  275. * So that we can set how long each device is given as a selection timeout.
  276. * The table of values goes like this:
  277. * 0 - 256ms
  278. * 1 - 128ms
  279. * 2 - 64ms
  280. * 3 - 32ms
  281. * We default to 256ms because some older devices need a longer time
  282. * to respond to initial selection.
  283. */
  284. static uint32_t aic79xx_seltime;
  285. /*
  286. * Certain devices do not perform any aging on commands. Should the
  287. * device be saturated by commands in one portion of the disk, it is
  288. * possible for transactions on far away sectors to never be serviced.
  289. * To handle these devices, we can periodically send an ordered tag to
  290. * force all outstanding transactions to be serviced prior to a new
  291. * transaction.
  292. */
  293. uint32_t aic79xx_periodic_otag;
  294. /*
  295. * Module information and settable options.
  296. */
  297. static char *aic79xx = NULL;
  298. MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
  299. MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver");
  300. MODULE_LICENSE("Dual BSD/GPL");
  301. MODULE_VERSION(AIC79XX_DRIVER_VERSION);
  302. module_param(aic79xx, charp, 0444);
  303. MODULE_PARM_DESC(aic79xx,
  304. "period delimited, options string.\n"
  305. " verbose Enable verbose/diagnostic logging\n"
  306. " allow_memio Allow device registers to be memory mapped\n"
  307. " debug Bitmask of debug values to enable\n"
  308. " no_reset Supress initial bus resets\n"
  309. " extended Enable extended geometry on all controllers\n"
  310. " periodic_otag Send an ordered tagged transaction\n"
  311. " periodically to prevent tag starvation.\n"
  312. " This may be required by some older disk\n"
  313. " or drives/RAID arrays.\n"
  314. " reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
  315. " tag_info:<tag_str> Set per-target tag depth\n"
  316. " global_tag_depth:<int> Global tag depth for all targets on all buses\n"
  317. " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
  318. " precomp:<pcomp_list> Set the signal precompensation (0-7).\n"
  319. " amplitude:<int> Set the signal amplitude (0-7).\n"
  320. " seltime:<int> Selection Timeout:\n"
  321. " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
  322. "\n"
  323. " Sample /etc/modprobe.conf line:\n"
  324. " Enable verbose logging\n"
  325. " Set tag depth on Controller 2/Target 2 to 10 tags\n"
  326. " Shorten the selection timeout to 128ms\n"
  327. "\n"
  328. " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
  329. "\n");
  330. static void ahd_linux_handle_scsi_status(struct ahd_softc *,
  331. struct scsi_device *,
  332. struct scb *);
  333. static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
  334. struct scsi_cmnd *cmd);
  335. static void ahd_linux_sem_timeout(u_long arg);
  336. static int ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
  337. static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
  338. static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
  339. struct ahd_devinfo *devinfo);
  340. static void ahd_linux_device_queue_depth(struct scsi_device *);
  341. static int ahd_linux_run_command(struct ahd_softc*,
  342. struct ahd_linux_device *,
  343. struct scsi_cmnd *);
  344. static void ahd_linux_setup_tag_info_global(char *p);
  345. static int aic79xx_setup(char *c);
  346. static int ahd_linux_unit;
  347. /****************************** Inlines ***************************************/
  348. static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
  349. static __inline void
  350. ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
  351. {
  352. struct scsi_cmnd *cmd;
  353. int direction;
  354. cmd = scb->io_ctx;
  355. direction = cmd->sc_data_direction;
  356. ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
  357. if (cmd->use_sg != 0) {
  358. struct scatterlist *sg;
  359. sg = (struct scatterlist *)cmd->request_buffer;
  360. pci_unmap_sg(ahd->dev_softc, sg, cmd->use_sg, direction);
  361. } else if (cmd->request_bufflen != 0) {
  362. pci_unmap_single(ahd->dev_softc,
  363. scb->platform_data->buf_busaddr,
  364. cmd->request_bufflen, direction);
  365. }
  366. }
  367. /******************************** Macros **************************************/
  368. #define BUILD_SCSIID(ahd, cmd) \
  369. (((scmd_id(cmd) << TID_SHIFT) & TID) | (ahd)->our_id)
  370. /*
  371. * Return a string describing the driver.
  372. */
  373. static const char *
  374. ahd_linux_info(struct Scsi_Host *host)
  375. {
  376. static char buffer[512];
  377. char ahd_info[256];
  378. char *bp;
  379. struct ahd_softc *ahd;
  380. bp = &buffer[0];
  381. ahd = *(struct ahd_softc **)host->hostdata;
  382. memset(bp, 0, sizeof(buffer));
  383. strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev ");
  384. strcat(bp, AIC79XX_DRIVER_VERSION);
  385. strcat(bp, "\n");
  386. strcat(bp, " <");
  387. strcat(bp, ahd->description);
  388. strcat(bp, ">\n");
  389. strcat(bp, " ");
  390. ahd_controller_info(ahd, ahd_info);
  391. strcat(bp, ahd_info);
  392. strcat(bp, "\n");
  393. return (bp);
  394. }
  395. /*
  396. * Queue an SCB to the controller.
  397. */
  398. static int
  399. ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
  400. {
  401. struct ahd_softc *ahd;
  402. struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
  403. int rtn = SCSI_MLQUEUE_HOST_BUSY;
  404. unsigned long flags;
  405. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  406. ahd_lock(ahd, &flags);
  407. if (ahd->platform_data->qfrozen == 0) {
  408. cmd->scsi_done = scsi_done;
  409. cmd->result = CAM_REQ_INPROG << 16;
  410. rtn = ahd_linux_run_command(ahd, dev, cmd);
  411. }
  412. ahd_unlock(ahd, &flags);
  413. return rtn;
  414. }
  415. static inline struct scsi_target **
  416. ahd_linux_target_in_softc(struct scsi_target *starget)
  417. {
  418. struct ahd_softc *ahd =
  419. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  420. unsigned int target_offset;
  421. target_offset = starget->id;
  422. if (starget->channel != 0)
  423. target_offset += 8;
  424. return &ahd->platform_data->starget[target_offset];
  425. }
  426. static int
  427. ahd_linux_target_alloc(struct scsi_target *starget)
  428. {
  429. struct ahd_softc *ahd =
  430. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  431. unsigned long flags;
  432. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  433. struct ahd_linux_target *targ = scsi_transport_target_data(starget);
  434. struct ahd_devinfo devinfo;
  435. struct ahd_initiator_tinfo *tinfo;
  436. struct ahd_tmode_tstate *tstate;
  437. char channel = starget->channel + 'A';
  438. ahd_lock(ahd, &flags);
  439. BUG_ON(*ahd_targp != NULL);
  440. *ahd_targp = starget;
  441. memset(targ, 0, sizeof(*targ));
  442. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  443. starget->id, &tstate);
  444. ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
  445. CAM_LUN_WILDCARD, channel,
  446. ROLE_INITIATOR);
  447. spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */
  448. if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
  449. spi_max_offset(starget) = MAX_OFFSET_PACED_BUG;
  450. else
  451. spi_max_offset(starget) = MAX_OFFSET_PACED;
  452. spi_max_width(starget) = ahd->features & AHD_WIDE;
  453. ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
  454. AHD_TRANS_GOAL, /*paused*/FALSE);
  455. ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  456. AHD_TRANS_GOAL, /*paused*/FALSE);
  457. ahd_unlock(ahd, &flags);
  458. return 0;
  459. }
  460. static void
  461. ahd_linux_target_destroy(struct scsi_target *starget)
  462. {
  463. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  464. *ahd_targp = NULL;
  465. }
  466. static int
  467. ahd_linux_slave_alloc(struct scsi_device *sdev)
  468. {
  469. struct ahd_softc *ahd =
  470. *((struct ahd_softc **)sdev->host->hostdata);
  471. struct scsi_target *starget = sdev->sdev_target;
  472. struct ahd_linux_target *targ = scsi_transport_target_data(starget);
  473. struct ahd_linux_device *dev;
  474. if (bootverbose)
  475. printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
  476. BUG_ON(targ->sdev[sdev->lun] != NULL);
  477. dev = scsi_transport_device_data(sdev);
  478. memset(dev, 0, sizeof(*dev));
  479. /*
  480. * We start out life using untagged
  481. * transactions of which we allow one.
  482. */
  483. dev->openings = 1;
  484. /*
  485. * Set maxtags to 0. This will be changed if we
  486. * later determine that we are dealing with
  487. * a tagged queuing capable device.
  488. */
  489. dev->maxtags = 0;
  490. targ->sdev[sdev->lun] = sdev;
  491. return (0);
  492. }
  493. static int
  494. ahd_linux_slave_configure(struct scsi_device *sdev)
  495. {
  496. struct ahd_softc *ahd;
  497. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  498. if (bootverbose)
  499. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  500. ahd_linux_device_queue_depth(sdev);
  501. /* Initial Domain Validation */
  502. if (!spi_initial_dv(sdev->sdev_target))
  503. spi_dv_device(sdev);
  504. return 0;
  505. }
  506. static void
  507. ahd_linux_slave_destroy(struct scsi_device *sdev)
  508. {
  509. struct ahd_softc *ahd;
  510. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  511. struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
  512. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  513. if (bootverbose)
  514. printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id);
  515. BUG_ON(dev->active);
  516. targ->sdev[sdev->lun] = NULL;
  517. }
  518. #if defined(__i386__)
  519. /*
  520. * Return the disk geometry for the given SCSI device.
  521. */
  522. static int
  523. ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  524. sector_t capacity, int geom[])
  525. {
  526. uint8_t *bh;
  527. int heads;
  528. int sectors;
  529. int cylinders;
  530. int ret;
  531. int extended;
  532. struct ahd_softc *ahd;
  533. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  534. bh = scsi_bios_ptable(bdev);
  535. if (bh) {
  536. ret = scsi_partsize(bh, capacity,
  537. &geom[2], &geom[0], &geom[1]);
  538. kfree(bh);
  539. if (ret != -1)
  540. return (ret);
  541. }
  542. heads = 64;
  543. sectors = 32;
  544. cylinders = aic_sector_div(capacity, heads, sectors);
  545. if (aic79xx_extended != 0)
  546. extended = 1;
  547. else
  548. extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
  549. if (extended && cylinders >= 1024) {
  550. heads = 255;
  551. sectors = 63;
  552. cylinders = aic_sector_div(capacity, heads, sectors);
  553. }
  554. geom[0] = heads;
  555. geom[1] = sectors;
  556. geom[2] = cylinders;
  557. return (0);
  558. }
  559. #endif
  560. /*
  561. * Abort the current SCSI command(s).
  562. */
  563. static int
  564. ahd_linux_abort(struct scsi_cmnd *cmd)
  565. {
  566. int error;
  567. error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT);
  568. if (error != 0)
  569. printf("aic79xx_abort returns 0x%x\n", error);
  570. return error;
  571. }
  572. /*
  573. * Attempt to send a target reset message to the device that timed out.
  574. */
  575. static int
  576. ahd_linux_dev_reset(struct scsi_cmnd *cmd)
  577. {
  578. int error;
  579. error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
  580. if (error != 0)
  581. printf("aic79xx_dev_reset returns 0x%x\n", error);
  582. return error;
  583. }
  584. /*
  585. * Reset the SCSI bus.
  586. */
  587. static int
  588. ahd_linux_bus_reset(struct scsi_cmnd *cmd)
  589. {
  590. struct ahd_softc *ahd;
  591. u_long s;
  592. int found;
  593. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  594. #ifdef AHD_DEBUG
  595. if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
  596. printf("%s: Bus reset called for cmd %p\n",
  597. ahd_name(ahd), cmd);
  598. #endif
  599. ahd_lock(ahd, &s);
  600. found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
  601. /*initiate reset*/TRUE);
  602. ahd_unlock(ahd, &s);
  603. if (bootverbose)
  604. printf("%s: SCSI bus reset delivered. "
  605. "%d SCBs aborted.\n", ahd_name(ahd), found);
  606. return (SUCCESS);
  607. }
  608. struct scsi_host_template aic79xx_driver_template = {
  609. .module = THIS_MODULE,
  610. .name = "aic79xx",
  611. .proc_name = "aic79xx",
  612. .proc_info = ahd_linux_proc_info,
  613. .info = ahd_linux_info,
  614. .queuecommand = ahd_linux_queue,
  615. .eh_abort_handler = ahd_linux_abort,
  616. .eh_device_reset_handler = ahd_linux_dev_reset,
  617. .eh_bus_reset_handler = ahd_linux_bus_reset,
  618. #if defined(__i386__)
  619. .bios_param = ahd_linux_biosparam,
  620. #endif
  621. .can_queue = AHD_MAX_QUEUE,
  622. .this_id = -1,
  623. .cmd_per_lun = 2,
  624. .use_clustering = ENABLE_CLUSTERING,
  625. .slave_alloc = ahd_linux_slave_alloc,
  626. .slave_configure = ahd_linux_slave_configure,
  627. .slave_destroy = ahd_linux_slave_destroy,
  628. .target_alloc = ahd_linux_target_alloc,
  629. .target_destroy = ahd_linux_target_destroy,
  630. };
  631. /******************************** Bus DMA *************************************/
  632. int
  633. ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
  634. bus_size_t alignment, bus_size_t boundary,
  635. dma_addr_t lowaddr, dma_addr_t highaddr,
  636. bus_dma_filter_t *filter, void *filterarg,
  637. bus_size_t maxsize, int nsegments,
  638. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  639. {
  640. bus_dma_tag_t dmat;
  641. dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
  642. if (dmat == NULL)
  643. return (ENOMEM);
  644. /*
  645. * Linux is very simplistic about DMA memory. For now don't
  646. * maintain all specification information. Once Linux supplies
  647. * better facilities for doing these operations, or the
  648. * needs of this particular driver change, we might need to do
  649. * more here.
  650. */
  651. dmat->alignment = alignment;
  652. dmat->boundary = boundary;
  653. dmat->maxsize = maxsize;
  654. *ret_tag = dmat;
  655. return (0);
  656. }
  657. void
  658. ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
  659. {
  660. free(dmat, M_DEVBUF);
  661. }
  662. int
  663. ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
  664. int flags, bus_dmamap_t *mapp)
  665. {
  666. *vaddr = pci_alloc_consistent(ahd->dev_softc,
  667. dmat->maxsize, mapp);
  668. if (*vaddr == NULL)
  669. return (ENOMEM);
  670. return(0);
  671. }
  672. void
  673. ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
  674. void* vaddr, bus_dmamap_t map)
  675. {
  676. pci_free_consistent(ahd->dev_softc, dmat->maxsize,
  677. vaddr, map);
  678. }
  679. int
  680. ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
  681. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  682. void *cb_arg, int flags)
  683. {
  684. /*
  685. * Assume for now that this will only be used during
  686. * initialization and not for per-transaction buffer mapping.
  687. */
  688. bus_dma_segment_t stack_sg;
  689. stack_sg.ds_addr = map;
  690. stack_sg.ds_len = dmat->maxsize;
  691. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  692. return (0);
  693. }
  694. void
  695. ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  696. {
  697. }
  698. int
  699. ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  700. {
  701. /* Nothing to do */
  702. return (0);
  703. }
  704. /********************* Platform Dependent Functions ***************************/
  705. /*
  706. * Compare "left hand" softc with "right hand" softc, returning:
  707. * < 0 - lahd has a lower priority than rahd
  708. * 0 - Softcs are equal
  709. * > 0 - lahd has a higher priority than rahd
  710. */
  711. int
  712. ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
  713. {
  714. int value;
  715. /*
  716. * Under Linux, cards are ordered as follows:
  717. * 1) PCI devices that are marked as the boot controller.
  718. * 2) PCI devices with BIOS enabled sorted by bus/slot/func.
  719. * 3) All remaining PCI devices sorted by bus/slot/func.
  720. */
  721. #if 0
  722. value = (lahd->flags & AHD_BOOT_CHANNEL)
  723. - (rahd->flags & AHD_BOOT_CHANNEL);
  724. if (value != 0)
  725. /* Controllers set for boot have a *higher* priority */
  726. return (value);
  727. #endif
  728. value = (lahd->flags & AHD_BIOS_ENABLED)
  729. - (rahd->flags & AHD_BIOS_ENABLED);
  730. if (value != 0)
  731. /* Controllers with BIOS enabled have a *higher* priority */
  732. return (value);
  733. /* Still equal. Sort by bus/slot/func. */
  734. if (aic79xx_reverse_scan != 0)
  735. value = ahd_get_pci_bus(lahd->dev_softc)
  736. - ahd_get_pci_bus(rahd->dev_softc);
  737. else
  738. value = ahd_get_pci_bus(rahd->dev_softc)
  739. - ahd_get_pci_bus(lahd->dev_softc);
  740. if (value != 0)
  741. return (value);
  742. if (aic79xx_reverse_scan != 0)
  743. value = ahd_get_pci_slot(lahd->dev_softc)
  744. - ahd_get_pci_slot(rahd->dev_softc);
  745. else
  746. value = ahd_get_pci_slot(rahd->dev_softc)
  747. - ahd_get_pci_slot(lahd->dev_softc);
  748. if (value != 0)
  749. return (value);
  750. value = rahd->channel - lahd->channel;
  751. return (value);
  752. }
  753. static void
  754. ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
  755. {
  756. if ((instance >= 0)
  757. && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
  758. uint8_t *iocell_info;
  759. iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
  760. iocell_info[index] = value & 0xFFFF;
  761. if (bootverbose)
  762. printf("iocell[%d:%ld] = %d\n", instance, index, value);
  763. }
  764. }
  765. static void
  766. ahd_linux_setup_tag_info_global(char *p)
  767. {
  768. int tags, i, j;
  769. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  770. printf("Setting Global Tags= %d\n", tags);
  771. for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
  772. for (j = 0; j < AHD_NUM_TARGETS; j++) {
  773. aic79xx_tag_info[i].tag_commands[j] = tags;
  774. }
  775. }
  776. }
  777. static void
  778. ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  779. {
  780. if ((instance >= 0) && (targ >= 0)
  781. && (instance < NUM_ELEMENTS(aic79xx_tag_info))
  782. && (targ < AHD_NUM_TARGETS)) {
  783. aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
  784. if (bootverbose)
  785. printf("tag_info[%d:%d] = %d\n", instance, targ, value);
  786. }
  787. }
  788. static char *
  789. ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  790. void (*callback)(u_long, int, int, int32_t),
  791. u_long callback_arg)
  792. {
  793. char *tok_end;
  794. char *tok_end2;
  795. int i;
  796. int instance;
  797. int targ;
  798. int done;
  799. char tok_list[] = {'.', ',', '{', '}', '\0'};
  800. /* All options use a ':' name/arg separator */
  801. if (*opt_arg != ':')
  802. return (opt_arg);
  803. opt_arg++;
  804. instance = -1;
  805. targ = -1;
  806. done = FALSE;
  807. /*
  808. * Restore separator that may be in
  809. * the middle of our option argument.
  810. */
  811. tok_end = strchr(opt_arg, '\0');
  812. if (tok_end < end)
  813. *tok_end = ',';
  814. while (!done) {
  815. switch (*opt_arg) {
  816. case '{':
  817. if (instance == -1) {
  818. instance = 0;
  819. } else {
  820. if (depth > 1) {
  821. if (targ == -1)
  822. targ = 0;
  823. } else {
  824. printf("Malformed Option %s\n",
  825. opt_name);
  826. done = TRUE;
  827. }
  828. }
  829. opt_arg++;
  830. break;
  831. case '}':
  832. if (targ != -1)
  833. targ = -1;
  834. else if (instance != -1)
  835. instance = -1;
  836. opt_arg++;
  837. break;
  838. case ',':
  839. case '.':
  840. if (instance == -1)
  841. done = TRUE;
  842. else if (targ >= 0)
  843. targ++;
  844. else if (instance >= 0)
  845. instance++;
  846. opt_arg++;
  847. break;
  848. case '\0':
  849. done = TRUE;
  850. break;
  851. default:
  852. tok_end = end;
  853. for (i = 0; tok_list[i]; i++) {
  854. tok_end2 = strchr(opt_arg, tok_list[i]);
  855. if ((tok_end2) && (tok_end2 < tok_end))
  856. tok_end = tok_end2;
  857. }
  858. callback(callback_arg, instance, targ,
  859. simple_strtol(opt_arg, NULL, 0));
  860. opt_arg = tok_end;
  861. break;
  862. }
  863. }
  864. return (opt_arg);
  865. }
  866. /*
  867. * Handle Linux boot parameters. This routine allows for assigning a value
  868. * to a parameter with a ':' between the parameter and the value.
  869. * ie. aic79xx=stpwlev:1,extended
  870. */
  871. static int
  872. aic79xx_setup(char *s)
  873. {
  874. int i, n;
  875. char *p;
  876. char *end;
  877. static struct {
  878. const char *name;
  879. uint32_t *flag;
  880. } options[] = {
  881. { "extended", &aic79xx_extended },
  882. { "no_reset", &aic79xx_no_reset },
  883. { "verbose", &aic79xx_verbose },
  884. { "allow_memio", &aic79xx_allow_memio},
  885. #ifdef AHD_DEBUG
  886. { "debug", &ahd_debug },
  887. #endif
  888. { "reverse_scan", &aic79xx_reverse_scan },
  889. { "periodic_otag", &aic79xx_periodic_otag },
  890. { "pci_parity", &aic79xx_pci_parity },
  891. { "seltime", &aic79xx_seltime },
  892. { "tag_info", NULL },
  893. { "global_tag_depth", NULL},
  894. { "slewrate", NULL },
  895. { "precomp", NULL },
  896. { "amplitude", NULL },
  897. };
  898. end = strchr(s, '\0');
  899. /*
  900. * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
  901. * will never be 0 in this case.
  902. */
  903. n = 0;
  904. while ((p = strsep(&s, ",.")) != NULL) {
  905. if (*p == '\0')
  906. continue;
  907. for (i = 0; i < NUM_ELEMENTS(options); i++) {
  908. n = strlen(options[i].name);
  909. if (strncmp(options[i].name, p, n) == 0)
  910. break;
  911. }
  912. if (i == NUM_ELEMENTS(options))
  913. continue;
  914. if (strncmp(p, "global_tag_depth", n) == 0) {
  915. ahd_linux_setup_tag_info_global(p + n);
  916. } else if (strncmp(p, "tag_info", n) == 0) {
  917. s = ahd_parse_brace_option("tag_info", p + n, end,
  918. 2, ahd_linux_setup_tag_info, 0);
  919. } else if (strncmp(p, "slewrate", n) == 0) {
  920. s = ahd_parse_brace_option("slewrate",
  921. p + n, end, 1, ahd_linux_setup_iocell_info,
  922. AIC79XX_SLEWRATE_INDEX);
  923. } else if (strncmp(p, "precomp", n) == 0) {
  924. s = ahd_parse_brace_option("precomp",
  925. p + n, end, 1, ahd_linux_setup_iocell_info,
  926. AIC79XX_PRECOMP_INDEX);
  927. } else if (strncmp(p, "amplitude", n) == 0) {
  928. s = ahd_parse_brace_option("amplitude",
  929. p + n, end, 1, ahd_linux_setup_iocell_info,
  930. AIC79XX_AMPLITUDE_INDEX);
  931. } else if (p[n] == ':') {
  932. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  933. } else if (!strncmp(p, "verbose", n)) {
  934. *(options[i].flag) = 1;
  935. } else {
  936. *(options[i].flag) ^= 0xFFFFFFFF;
  937. }
  938. }
  939. return 1;
  940. }
  941. __setup("aic79xx=", aic79xx_setup);
  942. uint32_t aic79xx_verbose;
  943. int
  944. ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
  945. {
  946. char buf[80];
  947. struct Scsi_Host *host;
  948. char *new_name;
  949. u_long s;
  950. int retval;
  951. template->name = ahd->description;
  952. host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
  953. if (host == NULL)
  954. return (ENOMEM);
  955. *((struct ahd_softc **)host->hostdata) = ahd;
  956. ahd_lock(ahd, &s);
  957. ahd->platform_data->host = host;
  958. host->can_queue = AHD_MAX_QUEUE;
  959. host->cmd_per_lun = 2;
  960. host->sg_tablesize = AHD_NSEG;
  961. host->this_id = ahd->our_id;
  962. host->irq = ahd->platform_data->irq;
  963. host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
  964. host->max_lun = AHD_NUM_LUNS;
  965. host->max_channel = 0;
  966. host->sg_tablesize = AHD_NSEG;
  967. ahd_set_unit(ahd, ahd_linux_unit++);
  968. sprintf(buf, "scsi%d", host->host_no);
  969. new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
  970. if (new_name != NULL) {
  971. strcpy(new_name, buf);
  972. ahd_set_name(ahd, new_name);
  973. }
  974. host->unique_id = ahd->unit;
  975. ahd_linux_initialize_scsi_bus(ahd);
  976. ahd_intr_enable(ahd, TRUE);
  977. ahd_unlock(ahd, &s);
  978. host->transportt = ahd_linux_transport_template;
  979. retval = scsi_add_host(host, &ahd->dev_softc->dev);
  980. if (retval) {
  981. printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
  982. scsi_host_put(host);
  983. return retval;
  984. }
  985. scsi_scan_host(host);
  986. return 0;
  987. }
  988. uint64_t
  989. ahd_linux_get_memsize(void)
  990. {
  991. struct sysinfo si;
  992. si_meminfo(&si);
  993. return ((uint64_t)si.totalram << PAGE_SHIFT);
  994. }
  995. /*
  996. * Place the SCSI bus into a known state by either resetting it,
  997. * or forcing transfer negotiations on the next command to any
  998. * target.
  999. */
  1000. static void
  1001. ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
  1002. {
  1003. u_int target_id;
  1004. u_int numtarg;
  1005. target_id = 0;
  1006. numtarg = 0;
  1007. if (aic79xx_no_reset != 0)
  1008. ahd->flags &= ~AHD_RESET_BUS_A;
  1009. if ((ahd->flags & AHD_RESET_BUS_A) != 0)
  1010. ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
  1011. else
  1012. numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
  1013. /*
  1014. * Force negotiation to async for all targets that
  1015. * will not see an initial bus reset.
  1016. */
  1017. for (; target_id < numtarg; target_id++) {
  1018. struct ahd_devinfo devinfo;
  1019. struct ahd_initiator_tinfo *tinfo;
  1020. struct ahd_tmode_tstate *tstate;
  1021. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1022. target_id, &tstate);
  1023. ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
  1024. CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
  1025. ahd_update_neg_request(ahd, &devinfo, tstate,
  1026. tinfo, AHD_NEG_ALWAYS);
  1027. }
  1028. /* Give the bus some time to recover */
  1029. if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
  1030. ahd_freeze_simq(ahd);
  1031. init_timer(&ahd->platform_data->reset_timer);
  1032. ahd->platform_data->reset_timer.data = (u_long)ahd;
  1033. ahd->platform_data->reset_timer.expires =
  1034. jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
  1035. ahd->platform_data->reset_timer.function =
  1036. (ahd_linux_callback_t *)ahd_release_simq;
  1037. add_timer(&ahd->platform_data->reset_timer);
  1038. }
  1039. }
  1040. int
  1041. ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
  1042. {
  1043. ahd->platform_data =
  1044. malloc(sizeof(struct ahd_platform_data), M_DEVBUF, M_NOWAIT);
  1045. if (ahd->platform_data == NULL)
  1046. return (ENOMEM);
  1047. memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
  1048. ahd->platform_data->irq = AHD_LINUX_NOIRQ;
  1049. ahd_lockinit(ahd);
  1050. init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
  1051. ahd->seltime = (aic79xx_seltime & 0x3) << 4;
  1052. return (0);
  1053. }
  1054. void
  1055. ahd_platform_free(struct ahd_softc *ahd)
  1056. {
  1057. struct scsi_target *starget;
  1058. int i, j;
  1059. if (ahd->platform_data != NULL) {
  1060. /* destroy all of the device and target objects */
  1061. for (i = 0; i < AHD_NUM_TARGETS; i++) {
  1062. starget = ahd->platform_data->starget[i];
  1063. if (starget != NULL) {
  1064. for (j = 0; j < AHD_NUM_LUNS; j++) {
  1065. struct ahd_linux_target *targ =
  1066. scsi_transport_target_data(starget);
  1067. if (targ->sdev[j] == NULL)
  1068. continue;
  1069. targ->sdev[j] = NULL;
  1070. }
  1071. ahd->platform_data->starget[i] = NULL;
  1072. }
  1073. }
  1074. if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
  1075. free_irq(ahd->platform_data->irq, ahd);
  1076. if (ahd->tags[0] == BUS_SPACE_PIO
  1077. && ahd->bshs[0].ioport != 0)
  1078. release_region(ahd->bshs[0].ioport, 256);
  1079. if (ahd->tags[1] == BUS_SPACE_PIO
  1080. && ahd->bshs[1].ioport != 0)
  1081. release_region(ahd->bshs[1].ioport, 256);
  1082. if (ahd->tags[0] == BUS_SPACE_MEMIO
  1083. && ahd->bshs[0].maddr != NULL) {
  1084. iounmap(ahd->bshs[0].maddr);
  1085. release_mem_region(ahd->platform_data->mem_busaddr,
  1086. 0x1000);
  1087. }
  1088. if (ahd->platform_data->host)
  1089. scsi_host_put(ahd->platform_data->host);
  1090. free(ahd->platform_data, M_DEVBUF);
  1091. }
  1092. }
  1093. void
  1094. ahd_platform_init(struct ahd_softc *ahd)
  1095. {
  1096. /*
  1097. * Lookup and commit any modified IO Cell options.
  1098. */
  1099. if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
  1100. struct ahd_linux_iocell_opts *iocell_opts;
  1101. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  1102. if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
  1103. AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
  1104. if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
  1105. AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
  1106. if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
  1107. AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
  1108. }
  1109. }
  1110. void
  1111. ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
  1112. {
  1113. ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
  1114. SCB_GET_CHANNEL(ahd, scb),
  1115. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1116. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1117. }
  1118. void
  1119. ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
  1120. ahd_queue_alg alg)
  1121. {
  1122. struct scsi_target *starget;
  1123. struct ahd_linux_target *targ;
  1124. struct ahd_linux_device *dev;
  1125. struct scsi_device *sdev;
  1126. int was_queuing;
  1127. int now_queuing;
  1128. starget = ahd->platform_data->starget[devinfo->target];
  1129. targ = scsi_transport_target_data(starget);
  1130. BUG_ON(targ == NULL);
  1131. sdev = targ->sdev[devinfo->lun];
  1132. if (sdev == NULL)
  1133. return;
  1134. dev = scsi_transport_device_data(sdev);
  1135. if (dev == NULL)
  1136. return;
  1137. was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
  1138. switch (alg) {
  1139. default:
  1140. case AHD_QUEUE_NONE:
  1141. now_queuing = 0;
  1142. break;
  1143. case AHD_QUEUE_BASIC:
  1144. now_queuing = AHD_DEV_Q_BASIC;
  1145. break;
  1146. case AHD_QUEUE_TAGGED:
  1147. now_queuing = AHD_DEV_Q_TAGGED;
  1148. break;
  1149. }
  1150. if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
  1151. && (was_queuing != now_queuing)
  1152. && (dev->active != 0)) {
  1153. dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
  1154. dev->qfrozen++;
  1155. }
  1156. dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
  1157. if (now_queuing) {
  1158. u_int usertags;
  1159. usertags = ahd_linux_user_tagdepth(ahd, devinfo);
  1160. if (!was_queuing) {
  1161. /*
  1162. * Start out agressively and allow our
  1163. * dynamic queue depth algorithm to take
  1164. * care of the rest.
  1165. */
  1166. dev->maxtags = usertags;
  1167. dev->openings = dev->maxtags - dev->active;
  1168. }
  1169. if (dev->maxtags == 0) {
  1170. /*
  1171. * Queueing is disabled by the user.
  1172. */
  1173. dev->openings = 1;
  1174. } else if (alg == AHD_QUEUE_TAGGED) {
  1175. dev->flags |= AHD_DEV_Q_TAGGED;
  1176. if (aic79xx_periodic_otag != 0)
  1177. dev->flags |= AHD_DEV_PERIODIC_OTAG;
  1178. } else
  1179. dev->flags |= AHD_DEV_Q_BASIC;
  1180. } else {
  1181. /* We can only have one opening. */
  1182. dev->maxtags = 0;
  1183. dev->openings = 1 - dev->active;
  1184. }
  1185. switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
  1186. case AHD_DEV_Q_BASIC:
  1187. scsi_adjust_queue_depth(sdev,
  1188. MSG_SIMPLE_TASK,
  1189. dev->openings + dev->active);
  1190. break;
  1191. case AHD_DEV_Q_TAGGED:
  1192. scsi_adjust_queue_depth(sdev,
  1193. MSG_ORDERED_TASK,
  1194. dev->openings + dev->active);
  1195. break;
  1196. default:
  1197. /*
  1198. * We allow the OS to queue 2 untagged transactions to
  1199. * us at any time even though we can only execute them
  1200. * serially on the controller/device. This should
  1201. * remove some latency.
  1202. */
  1203. scsi_adjust_queue_depth(sdev,
  1204. /*NON-TAGGED*/0,
  1205. /*queue depth*/2);
  1206. break;
  1207. }
  1208. }
  1209. int
  1210. ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
  1211. int lun, u_int tag, role_t role, uint32_t status)
  1212. {
  1213. return 0;
  1214. }
  1215. static u_int
  1216. ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
  1217. {
  1218. static int warned_user;
  1219. u_int tags;
  1220. tags = 0;
  1221. if ((ahd->user_discenable & devinfo->target_mask) != 0) {
  1222. if (ahd->unit >= NUM_ELEMENTS(aic79xx_tag_info)) {
  1223. if (warned_user == 0) {
  1224. printf(KERN_WARNING
  1225. "aic79xx: WARNING: Insufficient tag_info instances\n"
  1226. "aic79xx: for installed controllers. Using defaults\n"
  1227. "aic79xx: Please update the aic79xx_tag_info array in\n"
  1228. "aic79xx: the aic79xx_osm.c source file.\n");
  1229. warned_user++;
  1230. }
  1231. tags = AHD_MAX_QUEUE;
  1232. } else {
  1233. adapter_tag_info_t *tag_info;
  1234. tag_info = &aic79xx_tag_info[ahd->unit];
  1235. tags = tag_info->tag_commands[devinfo->target_offset];
  1236. if (tags > AHD_MAX_QUEUE)
  1237. tags = AHD_MAX_QUEUE;
  1238. }
  1239. }
  1240. return (tags);
  1241. }
  1242. /*
  1243. * Determines the queue depth for a given device.
  1244. */
  1245. static void
  1246. ahd_linux_device_queue_depth(struct scsi_device *sdev)
  1247. {
  1248. struct ahd_devinfo devinfo;
  1249. u_int tags;
  1250. struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
  1251. ahd_compile_devinfo(&devinfo,
  1252. ahd->our_id,
  1253. sdev->sdev_target->id, sdev->lun,
  1254. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1255. ROLE_INITIATOR);
  1256. tags = ahd_linux_user_tagdepth(ahd, &devinfo);
  1257. if (tags != 0 && sdev->tagged_supported != 0) {
  1258. ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED);
  1259. ahd_print_devinfo(ahd, &devinfo);
  1260. printf("Tagged Queuing enabled. Depth %d\n", tags);
  1261. } else {
  1262. ahd_set_tags(ahd, &devinfo, AHD_QUEUE_NONE);
  1263. }
  1264. }
  1265. static int
  1266. ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
  1267. struct scsi_cmnd *cmd)
  1268. {
  1269. struct scb *scb;
  1270. struct hardware_scb *hscb;
  1271. struct ahd_initiator_tinfo *tinfo;
  1272. struct ahd_tmode_tstate *tstate;
  1273. u_int col_idx;
  1274. uint16_t mask;
  1275. /*
  1276. * Get an scb to use.
  1277. */
  1278. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1279. cmd->device->id, &tstate);
  1280. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
  1281. || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  1282. col_idx = AHD_NEVER_COL_IDX;
  1283. } else {
  1284. col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
  1285. cmd->device->lun);
  1286. }
  1287. if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
  1288. ahd->flags |= AHD_RESOURCE_SHORTAGE;
  1289. return SCSI_MLQUEUE_HOST_BUSY;
  1290. }
  1291. scb->io_ctx = cmd;
  1292. scb->platform_data->dev = dev;
  1293. hscb = scb->hscb;
  1294. cmd->host_scribble = (char *)scb;
  1295. /*
  1296. * Fill out basics of the HSCB.
  1297. */
  1298. hscb->control = 0;
  1299. hscb->scsiid = BUILD_SCSIID(ahd, cmd);
  1300. hscb->lun = cmd->device->lun;
  1301. scb->hscb->task_management = 0;
  1302. mask = SCB_GET_TARGET_MASK(ahd, scb);
  1303. if ((ahd->user_discenable & mask) != 0)
  1304. hscb->control |= DISCENB;
  1305. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
  1306. scb->flags |= SCB_PACKETIZED;
  1307. if ((tstate->auto_negotiate & mask) != 0) {
  1308. scb->flags |= SCB_AUTO_NEGOTIATE;
  1309. scb->hscb->control |= MK_MESSAGE;
  1310. }
  1311. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
  1312. int msg_bytes;
  1313. uint8_t tag_msgs[2];
  1314. msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
  1315. if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
  1316. hscb->control |= tag_msgs[0];
  1317. if (tag_msgs[0] == MSG_ORDERED_TASK)
  1318. dev->commands_since_idle_or_otag = 0;
  1319. } else
  1320. if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
  1321. && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
  1322. hscb->control |= MSG_ORDERED_TASK;
  1323. dev->commands_since_idle_or_otag = 0;
  1324. } else {
  1325. hscb->control |= MSG_SIMPLE_TASK;
  1326. }
  1327. }
  1328. hscb->cdb_len = cmd->cmd_len;
  1329. memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
  1330. scb->platform_data->xfer_len = 0;
  1331. ahd_set_residual(scb, 0);
  1332. ahd_set_sense_residual(scb, 0);
  1333. scb->sg_count = 0;
  1334. if (cmd->use_sg != 0) {
  1335. void *sg;
  1336. struct scatterlist *cur_seg;
  1337. u_int nseg;
  1338. int dir;
  1339. cur_seg = (struct scatterlist *)cmd->request_buffer;
  1340. dir = cmd->sc_data_direction;
  1341. nseg = pci_map_sg(ahd->dev_softc, cur_seg,
  1342. cmd->use_sg, dir);
  1343. scb->platform_data->xfer_len = 0;
  1344. for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
  1345. dma_addr_t addr;
  1346. bus_size_t len;
  1347. addr = sg_dma_address(cur_seg);
  1348. len = sg_dma_len(cur_seg);
  1349. scb->platform_data->xfer_len += len;
  1350. sg = ahd_sg_setup(ahd, scb, sg, addr, len,
  1351. /*last*/nseg == 1);
  1352. }
  1353. } else if (cmd->request_bufflen != 0) {
  1354. void *sg;
  1355. dma_addr_t addr;
  1356. int dir;
  1357. sg = scb->sg_list;
  1358. dir = cmd->sc_data_direction;
  1359. addr = pci_map_single(ahd->dev_softc,
  1360. cmd->request_buffer,
  1361. cmd->request_bufflen, dir);
  1362. scb->platform_data->xfer_len = cmd->request_bufflen;
  1363. scb->platform_data->buf_busaddr = addr;
  1364. sg = ahd_sg_setup(ahd, scb, sg, addr,
  1365. cmd->request_bufflen, /*last*/TRUE);
  1366. }
  1367. LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
  1368. dev->openings--;
  1369. dev->active++;
  1370. dev->commands_issued++;
  1371. if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
  1372. dev->commands_since_idle_or_otag++;
  1373. scb->flags |= SCB_ACTIVE;
  1374. ahd_queue_scb(ahd, scb);
  1375. return 0;
  1376. }
  1377. /*
  1378. * SCSI controller interrupt handler.
  1379. */
  1380. irqreturn_t
  1381. ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
  1382. {
  1383. struct ahd_softc *ahd;
  1384. u_long flags;
  1385. int ours;
  1386. ahd = (struct ahd_softc *) dev_id;
  1387. ahd_lock(ahd, &flags);
  1388. ours = ahd_intr(ahd);
  1389. ahd_unlock(ahd, &flags);
  1390. return IRQ_RETVAL(ours);
  1391. }
  1392. void
  1393. ahd_platform_flushwork(struct ahd_softc *ahd)
  1394. {
  1395. }
  1396. void
  1397. ahd_send_async(struct ahd_softc *ahd, char channel,
  1398. u_int target, u_int lun, ac_code code, void *arg)
  1399. {
  1400. switch (code) {
  1401. case AC_TRANSFER_NEG:
  1402. {
  1403. char buf[80];
  1404. struct scsi_target *starget;
  1405. struct ahd_linux_target *targ;
  1406. struct info_str info;
  1407. struct ahd_initiator_tinfo *tinfo;
  1408. struct ahd_tmode_tstate *tstate;
  1409. unsigned int target_ppr_options;
  1410. BUG_ON(target == CAM_TARGET_WILDCARD);
  1411. info.buffer = buf;
  1412. info.length = sizeof(buf);
  1413. info.offset = 0;
  1414. info.pos = 0;
  1415. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  1416. target, &tstate);
  1417. /*
  1418. * Don't bother reporting results while
  1419. * negotiations are still pending.
  1420. */
  1421. if (tinfo->curr.period != tinfo->goal.period
  1422. || tinfo->curr.width != tinfo->goal.width
  1423. || tinfo->curr.offset != tinfo->goal.offset
  1424. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1425. if (bootverbose == 0)
  1426. break;
  1427. /*
  1428. * Don't bother reporting results that
  1429. * are identical to those last reported.
  1430. */
  1431. starget = ahd->platform_data->starget[target];
  1432. if (starget == NULL)
  1433. break;
  1434. targ = scsi_transport_target_data(starget);
  1435. target_ppr_options =
  1436. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1437. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1438. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
  1439. + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
  1440. + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
  1441. + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
  1442. + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
  1443. + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
  1444. if (tinfo->curr.period == spi_period(starget)
  1445. && tinfo->curr.width == spi_width(starget)
  1446. && tinfo->curr.offset == spi_offset(starget)
  1447. && tinfo->curr.ppr_options == target_ppr_options)
  1448. if (bootverbose == 0)
  1449. break;
  1450. spi_period(starget) = tinfo->curr.period;
  1451. spi_width(starget) = tinfo->curr.width;
  1452. spi_offset(starget) = tinfo->curr.offset;
  1453. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1454. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1455. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1456. spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
  1457. spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
  1458. spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
  1459. spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
  1460. spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
  1461. spi_display_xfer_agreement(starget);
  1462. break;
  1463. }
  1464. case AC_SENT_BDR:
  1465. {
  1466. WARN_ON(lun != CAM_LUN_WILDCARD);
  1467. scsi_report_device_reset(ahd->platform_data->host,
  1468. channel - 'A', target);
  1469. break;
  1470. }
  1471. case AC_BUS_RESET:
  1472. if (ahd->platform_data->host != NULL) {
  1473. scsi_report_bus_reset(ahd->platform_data->host,
  1474. channel - 'A');
  1475. }
  1476. break;
  1477. default:
  1478. panic("ahd_send_async: Unexpected async event");
  1479. }
  1480. }
  1481. /*
  1482. * Calls the higher level scsi done function and frees the scb.
  1483. */
  1484. void
  1485. ahd_done(struct ahd_softc *ahd, struct scb *scb)
  1486. {
  1487. struct scsi_cmnd *cmd;
  1488. struct ahd_linux_device *dev;
  1489. if ((scb->flags & SCB_ACTIVE) == 0) {
  1490. printf("SCB %d done'd twice\n", SCB_GET_TAG(scb));
  1491. ahd_dump_card_state(ahd);
  1492. panic("Stopping for safety");
  1493. }
  1494. LIST_REMOVE(scb, pending_links);
  1495. cmd = scb->io_ctx;
  1496. dev = scb->platform_data->dev;
  1497. dev->active--;
  1498. dev->openings++;
  1499. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1500. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1501. dev->qfrozen--;
  1502. }
  1503. ahd_linux_unmap_scb(ahd, scb);
  1504. /*
  1505. * Guard against stale sense data.
  1506. * The Linux mid-layer assumes that sense
  1507. * was retrieved anytime the first byte of
  1508. * the sense buffer looks "sane".
  1509. */
  1510. cmd->sense_buffer[0] = 0;
  1511. if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1512. uint32_t amount_xferred;
  1513. amount_xferred =
  1514. ahd_get_transfer_length(scb) - ahd_get_residual(scb);
  1515. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1516. #ifdef AHD_DEBUG
  1517. if ((ahd_debug & AHD_SHOW_MISC) != 0) {
  1518. ahd_print_path(ahd, scb);
  1519. printf("Set CAM_UNCOR_PARITY\n");
  1520. }
  1521. #endif
  1522. ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1523. #ifdef AHD_REPORT_UNDERFLOWS
  1524. /*
  1525. * This code is disabled by default as some
  1526. * clients of the SCSI system do not properly
  1527. * initialize the underflow parameter. This
  1528. * results in spurious termination of commands
  1529. * that complete as expected (e.g. underflow is
  1530. * allowed as command can return variable amounts
  1531. * of data.
  1532. */
  1533. } else if (amount_xferred < scb->io_ctx->underflow) {
  1534. u_int i;
  1535. ahd_print_path(ahd, scb);
  1536. printf("CDB:");
  1537. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1538. printf(" 0x%x", scb->io_ctx->cmnd[i]);
  1539. printf("\n");
  1540. ahd_print_path(ahd, scb);
  1541. printf("Saw underflow (%ld of %ld bytes). "
  1542. "Treated as error\n",
  1543. ahd_get_residual(scb),
  1544. ahd_get_transfer_length(scb));
  1545. ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1546. #endif
  1547. } else {
  1548. ahd_set_transaction_status(scb, CAM_REQ_CMP);
  1549. }
  1550. } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1551. ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
  1552. }
  1553. if (dev->openings == 1
  1554. && ahd_get_transaction_status(scb) == CAM_REQ_CMP
  1555. && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1556. dev->tag_success_count++;
  1557. /*
  1558. * Some devices deal with temporary internal resource
  1559. * shortages by returning queue full. When the queue
  1560. * full occurrs, we throttle back. Slowly try to get
  1561. * back to our previous queue depth.
  1562. */
  1563. if ((dev->openings + dev->active) < dev->maxtags
  1564. && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
  1565. dev->tag_success_count = 0;
  1566. dev->openings++;
  1567. }
  1568. if (dev->active == 0)
  1569. dev->commands_since_idle_or_otag = 0;
  1570. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1571. printf("Recovery SCB completes\n");
  1572. if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
  1573. || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1574. ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1575. if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
  1576. ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
  1577. up(&ahd->platform_data->eh_sem);
  1578. }
  1579. }
  1580. ahd_free_scb(ahd, scb);
  1581. ahd_linux_queue_cmd_complete(ahd, cmd);
  1582. }
  1583. static void
  1584. ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
  1585. struct scsi_device *sdev, struct scb *scb)
  1586. {
  1587. struct ahd_devinfo devinfo;
  1588. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  1589. ahd_compile_devinfo(&devinfo,
  1590. ahd->our_id,
  1591. sdev->sdev_target->id, sdev->lun,
  1592. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1593. ROLE_INITIATOR);
  1594. /*
  1595. * We don't currently trust the mid-layer to
  1596. * properly deal with queue full or busy. So,
  1597. * when one occurs, we tell the mid-layer to
  1598. * unconditionally requeue the command to us
  1599. * so that we can retry it ourselves. We also
  1600. * implement our own throttling mechanism so
  1601. * we don't clobber the device with too many
  1602. * commands.
  1603. */
  1604. switch (ahd_get_scsi_status(scb)) {
  1605. default:
  1606. break;
  1607. case SCSI_STATUS_CHECK_COND:
  1608. case SCSI_STATUS_CMD_TERMINATED:
  1609. {
  1610. struct scsi_cmnd *cmd;
  1611. /*
  1612. * Copy sense information to the OS's cmd
  1613. * structure if it is available.
  1614. */
  1615. cmd = scb->io_ctx;
  1616. if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
  1617. struct scsi_status_iu_header *siu;
  1618. u_int sense_size;
  1619. u_int sense_offset;
  1620. if (scb->flags & SCB_SENSE) {
  1621. sense_size = MIN(sizeof(struct scsi_sense_data)
  1622. - ahd_get_sense_residual(scb),
  1623. sizeof(cmd->sense_buffer));
  1624. sense_offset = 0;
  1625. } else {
  1626. /*
  1627. * Copy only the sense data into the provided
  1628. * buffer.
  1629. */
  1630. siu = (struct scsi_status_iu_header *)
  1631. scb->sense_data;
  1632. sense_size = MIN(scsi_4btoul(siu->sense_length),
  1633. sizeof(cmd->sense_buffer));
  1634. sense_offset = SIU_SENSE_OFFSET(siu);
  1635. }
  1636. memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
  1637. memcpy(cmd->sense_buffer,
  1638. ahd_get_sense_buf(ahd, scb)
  1639. + sense_offset, sense_size);
  1640. cmd->result |= (DRIVER_SENSE << 24);
  1641. #ifdef AHD_DEBUG
  1642. if (ahd_debug & AHD_SHOW_SENSE) {
  1643. int i;
  1644. printf("Copied %d bytes of sense data at %d:",
  1645. sense_size, sense_offset);
  1646. for (i = 0; i < sense_size; i++) {
  1647. if ((i & 0xF) == 0)
  1648. printf("\n");
  1649. printf("0x%x ", cmd->sense_buffer[i]);
  1650. }
  1651. printf("\n");
  1652. }
  1653. #endif
  1654. }
  1655. break;
  1656. }
  1657. case SCSI_STATUS_QUEUE_FULL:
  1658. /*
  1659. * By the time the core driver has returned this
  1660. * command, all other commands that were queued
  1661. * to us but not the device have been returned.
  1662. * This ensures that dev->active is equal to
  1663. * the number of commands actually queued to
  1664. * the device.
  1665. */
  1666. dev->tag_success_count = 0;
  1667. if (dev->active != 0) {
  1668. /*
  1669. * Drop our opening count to the number
  1670. * of commands currently outstanding.
  1671. */
  1672. dev->openings = 0;
  1673. #ifdef AHD_DEBUG
  1674. if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
  1675. ahd_print_path(ahd, scb);
  1676. printf("Dropping tag count to %d\n",
  1677. dev->active);
  1678. }
  1679. #endif
  1680. if (dev->active == dev->tags_on_last_queuefull) {
  1681. dev->last_queuefull_same_count++;
  1682. /*
  1683. * If we repeatedly see a queue full
  1684. * at the same queue depth, this
  1685. * device has a fixed number of tag
  1686. * slots. Lock in this tag depth
  1687. * so we stop seeing queue fulls from
  1688. * this device.
  1689. */
  1690. if (dev->last_queuefull_same_count
  1691. == AHD_LOCK_TAGS_COUNT) {
  1692. dev->maxtags = dev->active;
  1693. ahd_print_path(ahd, scb);
  1694. printf("Locking max tag count at %d\n",
  1695. dev->active);
  1696. }
  1697. } else {
  1698. dev->tags_on_last_queuefull = dev->active;
  1699. dev->last_queuefull_same_count = 0;
  1700. }
  1701. ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1702. ahd_set_scsi_status(scb, SCSI_STATUS_OK);
  1703. ahd_platform_set_tags(ahd, &devinfo,
  1704. (dev->flags & AHD_DEV_Q_BASIC)
  1705. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1706. break;
  1707. }
  1708. /*
  1709. * Drop down to a single opening, and treat this
  1710. * as if the target returned BUSY SCSI status.
  1711. */
  1712. dev->openings = 1;
  1713. ahd_platform_set_tags(ahd, &devinfo,
  1714. (dev->flags & AHD_DEV_Q_BASIC)
  1715. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1716. ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
  1717. }
  1718. }
  1719. static void
  1720. ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
  1721. {
  1722. /*
  1723. * Map CAM error codes into Linux Error codes. We
  1724. * avoid the conversion so that the DV code has the
  1725. * full error information available when making
  1726. * state change decisions.
  1727. */
  1728. {
  1729. uint32_t status;
  1730. u_int new_status;
  1731. status = ahd_cmd_get_transaction_status(cmd);
  1732. switch (status) {
  1733. case CAM_REQ_INPROG:
  1734. case CAM_REQ_CMP:
  1735. case CAM_SCSI_STATUS_ERROR:
  1736. new_status = DID_OK;
  1737. break;
  1738. case CAM_REQ_ABORTED:
  1739. new_status = DID_ABORT;
  1740. break;
  1741. case CAM_BUSY:
  1742. new_status = DID_BUS_BUSY;
  1743. break;
  1744. case CAM_REQ_INVALID:
  1745. case CAM_PATH_INVALID:
  1746. new_status = DID_BAD_TARGET;
  1747. break;
  1748. case CAM_SEL_TIMEOUT:
  1749. new_status = DID_NO_CONNECT;
  1750. break;
  1751. case CAM_SCSI_BUS_RESET:
  1752. case CAM_BDR_SENT:
  1753. new_status = DID_RESET;
  1754. break;
  1755. case CAM_UNCOR_PARITY:
  1756. new_status = DID_PARITY;
  1757. break;
  1758. case CAM_CMD_TIMEOUT:
  1759. new_status = DID_TIME_OUT;
  1760. break;
  1761. case CAM_UA_ABORT:
  1762. case CAM_REQ_CMP_ERR:
  1763. case CAM_AUTOSENSE_FAIL:
  1764. case CAM_NO_HBA:
  1765. case CAM_DATA_RUN_ERR:
  1766. case CAM_UNEXP_BUSFREE:
  1767. case CAM_SEQUENCE_FAIL:
  1768. case CAM_CCB_LEN_ERR:
  1769. case CAM_PROVIDE_FAIL:
  1770. case CAM_REQ_TERMIO:
  1771. case CAM_UNREC_HBA_ERROR:
  1772. case CAM_REQ_TOO_BIG:
  1773. new_status = DID_ERROR;
  1774. break;
  1775. case CAM_REQUEUE_REQ:
  1776. new_status = DID_REQUEUE;
  1777. break;
  1778. default:
  1779. /* We should never get here */
  1780. new_status = DID_ERROR;
  1781. break;
  1782. }
  1783. ahd_cmd_set_transaction_status(cmd, new_status);
  1784. }
  1785. cmd->scsi_done(cmd);
  1786. }
  1787. static void
  1788. ahd_linux_sem_timeout(u_long arg)
  1789. {
  1790. struct ahd_softc *ahd;
  1791. u_long s;
  1792. ahd = (struct ahd_softc *)arg;
  1793. ahd_lock(ahd, &s);
  1794. if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
  1795. ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
  1796. up(&ahd->platform_data->eh_sem);
  1797. }
  1798. ahd_unlock(ahd, &s);
  1799. }
  1800. void
  1801. ahd_freeze_simq(struct ahd_softc *ahd)
  1802. {
  1803. ahd->platform_data->qfrozen++;
  1804. if (ahd->platform_data->qfrozen == 1) {
  1805. scsi_block_requests(ahd->platform_data->host);
  1806. ahd_platform_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
  1807. CAM_LUN_WILDCARD, SCB_LIST_NULL,
  1808. ROLE_INITIATOR, CAM_REQUEUE_REQ);
  1809. }
  1810. }
  1811. void
  1812. ahd_release_simq(struct ahd_softc *ahd)
  1813. {
  1814. u_long s;
  1815. int unblock_reqs;
  1816. unblock_reqs = 0;
  1817. ahd_lock(ahd, &s);
  1818. if (ahd->platform_data->qfrozen > 0)
  1819. ahd->platform_data->qfrozen--;
  1820. if (ahd->platform_data->qfrozen == 0) {
  1821. unblock_reqs = 1;
  1822. }
  1823. ahd_unlock(ahd, &s);
  1824. /*
  1825. * There is still a race here. The mid-layer
  1826. * should keep its own freeze count and use
  1827. * a bottom half handler to run the queues
  1828. * so we can unblock with our own lock held.
  1829. */
  1830. if (unblock_reqs)
  1831. scsi_unblock_requests(ahd->platform_data->host);
  1832. }
  1833. static int
  1834. ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
  1835. {
  1836. struct ahd_softc *ahd;
  1837. struct ahd_linux_device *dev;
  1838. struct scb *pending_scb;
  1839. u_int saved_scbptr;
  1840. u_int active_scbptr;
  1841. u_int last_phase;
  1842. u_int saved_scsiid;
  1843. u_int cdb_byte;
  1844. int retval;
  1845. int was_paused;
  1846. int paused;
  1847. int wait;
  1848. int disconnected;
  1849. ahd_mode_state saved_modes;
  1850. unsigned long flags;
  1851. pending_scb = NULL;
  1852. paused = FALSE;
  1853. wait = FALSE;
  1854. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  1855. scmd_printk(KERN_INFO, cmd,
  1856. "Attempting to queue a%s message:",
  1857. flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
  1858. printf("CDB:");
  1859. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1860. printf(" 0x%x", cmd->cmnd[cdb_byte]);
  1861. printf("\n");
  1862. ahd_lock(ahd, &flags);
  1863. /*
  1864. * First determine if we currently own this command.
  1865. * Start by searching the device queue. If not found
  1866. * there, check the pending_scb list. If not found
  1867. * at all, and the system wanted us to just abort the
  1868. * command, return success.
  1869. */
  1870. dev = scsi_transport_device_data(cmd->device);
  1871. if (dev == NULL) {
  1872. /*
  1873. * No target device for this command exists,
  1874. * so we must not still own the command.
  1875. */
  1876. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  1877. retval = SUCCESS;
  1878. goto no_cmd;
  1879. }
  1880. /*
  1881. * See if we can find a matching cmd in the pending list.
  1882. */
  1883. LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
  1884. if (pending_scb->io_ctx == cmd)
  1885. break;
  1886. }
  1887. if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
  1888. /* Any SCB for this device will do for a target reset */
  1889. LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
  1890. if (ahd_match_scb(ahd, pending_scb,
  1891. scmd_id(cmd),
  1892. scmd_channel(cmd) + 'A',
  1893. CAM_LUN_WILDCARD,
  1894. SCB_LIST_NULL, ROLE_INITIATOR))
  1895. break;
  1896. }
  1897. }
  1898. if (pending_scb == NULL) {
  1899. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1900. goto no_cmd;
  1901. }
  1902. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1903. /*
  1904. * We can't queue two recovery actions using the same SCB
  1905. */
  1906. retval = FAILED;
  1907. goto done;
  1908. }
  1909. /*
  1910. * Ensure that the card doesn't do anything
  1911. * behind our back. Also make sure that we
  1912. * didn't "just" miss an interrupt that would
  1913. * affect this cmd.
  1914. */
  1915. was_paused = ahd_is_paused(ahd);
  1916. ahd_pause_and_flushwork(ahd);
  1917. paused = TRUE;
  1918. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  1919. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  1920. goto no_cmd;
  1921. }
  1922. printf("%s: At time of recovery, card was %spaused\n",
  1923. ahd_name(ahd), was_paused ? "" : "not ");
  1924. ahd_dump_card_state(ahd);
  1925. disconnected = TRUE;
  1926. if (flag == SCB_ABORT) {
  1927. if (ahd_search_qinfifo(ahd, cmd->device->id,
  1928. cmd->device->channel + 'A',
  1929. cmd->device->lun,
  1930. pending_scb->hscb->tag,
  1931. ROLE_INITIATOR, CAM_REQ_ABORTED,
  1932. SEARCH_COMPLETE) > 0) {
  1933. printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  1934. ahd_name(ahd), cmd->device->channel,
  1935. cmd->device->id, cmd->device->lun);
  1936. retval = SUCCESS;
  1937. goto done;
  1938. }
  1939. } else if (ahd_search_qinfifo(ahd, cmd->device->id,
  1940. cmd->device->channel + 'A',
  1941. cmd->device->lun, pending_scb->hscb->tag,
  1942. ROLE_INITIATOR, /*status*/0,
  1943. SEARCH_COUNT) > 0) {
  1944. disconnected = FALSE;
  1945. }
  1946. saved_modes = ahd_save_modes(ahd);
  1947. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  1948. last_phase = ahd_inb(ahd, LASTPHASE);
  1949. saved_scbptr = ahd_get_scbptr(ahd);
  1950. active_scbptr = saved_scbptr;
  1951. if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  1952. struct scb *bus_scb;
  1953. bus_scb = ahd_lookup_scb(ahd, active_scbptr);
  1954. if (bus_scb == pending_scb)
  1955. disconnected = FALSE;
  1956. else if (flag != SCB_ABORT
  1957. && ahd_inb(ahd, SAVED_SCSIID) == pending_scb->hscb->scsiid
  1958. && ahd_inb(ahd, SAVED_LUN) == SCB_GET_LUN(pending_scb))
  1959. disconnected = FALSE;
  1960. }
  1961. /*
  1962. * At this point, pending_scb is the scb associated with the
  1963. * passed in command. That command is currently active on the
  1964. * bus or is in the disconnected state.
  1965. */
  1966. saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
  1967. if (last_phase != P_BUSFREE
  1968. && (SCB_GET_TAG(pending_scb) == active_scbptr
  1969. || (flag == SCB_DEVICE_RESET
  1970. && SCSIID_TARGET(ahd, saved_scsiid) == scmd_id(cmd)))) {
  1971. /*
  1972. * We're active on the bus, so assert ATN
  1973. * and hope that the target responds.
  1974. */
  1975. pending_scb = ahd_lookup_scb(ahd, active_scbptr);
  1976. pending_scb->flags |= SCB_RECOVERY_SCB|flag;
  1977. ahd_outb(ahd, MSG_OUT, HOST_MSG);
  1978. ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
  1979. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  1980. wait = TRUE;
  1981. } else if (disconnected) {
  1982. /*
  1983. * Actually re-queue this SCB in an attempt
  1984. * to select the device before it reconnects.
  1985. */
  1986. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  1987. ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
  1988. pending_scb->hscb->cdb_len = 0;
  1989. pending_scb->hscb->task_attribute = 0;
  1990. pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
  1991. if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
  1992. /*
  1993. * Mark the SCB has having an outstanding
  1994. * task management function. Should the command
  1995. * complete normally before the task management
  1996. * function can be sent, the host will be notified
  1997. * to abort our requeued SCB.
  1998. */
  1999. ahd_outb(ahd, SCB_TASK_MANAGEMENT,
  2000. pending_scb->hscb->task_management);
  2001. } else {
  2002. /*
  2003. * If non-packetized, set the MK_MESSAGE control
  2004. * bit indicating that we desire to send a message.
  2005. * We also set the disconnected flag since there is
  2006. * no guarantee that our SCB control byte matches
  2007. * the version on the card. We don't want the
  2008. * sequencer to abort the command thinking an
  2009. * unsolicited reselection occurred.
  2010. */
  2011. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2012. /*
  2013. * The sequencer will never re-reference the
  2014. * in-core SCB. To make sure we are notified
  2015. * during reslection, set the MK_MESSAGE flag in
  2016. * the card's copy of the SCB.
  2017. */
  2018. ahd_outb(ahd, SCB_CONTROL,
  2019. ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
  2020. }
  2021. /*
  2022. * Clear out any entries in the QINFIFO first
  2023. * so we are the next SCB for this target
  2024. * to run.
  2025. */
  2026. ahd_search_qinfifo(ahd, cmd->device->id,
  2027. cmd->device->channel + 'A', cmd->device->lun,
  2028. SCB_LIST_NULL, ROLE_INITIATOR,
  2029. CAM_REQUEUE_REQ, SEARCH_COMPLETE);
  2030. ahd_qinfifo_requeue_tail(ahd, pending_scb);
  2031. ahd_set_scbptr(ahd, saved_scbptr);
  2032. ahd_print_path(ahd, pending_scb);
  2033. printf("Device is disconnected, re-queuing SCB\n");
  2034. wait = TRUE;
  2035. } else {
  2036. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2037. retval = FAILED;
  2038. goto done;
  2039. }
  2040. no_cmd:
  2041. /*
  2042. * Our assumption is that if we don't have the command, no
  2043. * recovery action was required, so we return success. Again,
  2044. * the semantics of the mid-layer recovery engine are not
  2045. * well defined, so this may change in time.
  2046. */
  2047. retval = SUCCESS;
  2048. done:
  2049. if (paused)
  2050. ahd_unpause(ahd);
  2051. if (wait) {
  2052. struct timer_list timer;
  2053. int ret;
  2054. ahd->platform_data->flags |= AHD_SCB_UP_EH_SEM;
  2055. ahd_unlock(ahd, &flags);
  2056. init_timer(&timer);
  2057. timer.data = (u_long)ahd;
  2058. timer.expires = jiffies + (5 * HZ);
  2059. timer.function = ahd_linux_sem_timeout;
  2060. add_timer(&timer);
  2061. printf("Recovery code sleeping\n");
  2062. down(&ahd->platform_data->eh_sem);
  2063. printf("Recovery code awake\n");
  2064. ret = del_timer_sync(&timer);
  2065. if (ret == 0) {
  2066. printf("Timer Expired\n");
  2067. retval = FAILED;
  2068. }
  2069. }
  2070. ahd_unlock(ahd, &flags);
  2071. return (retval);
  2072. }
  2073. static void ahd_linux_set_width(struct scsi_target *starget, int width)
  2074. {
  2075. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2076. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2077. struct ahd_devinfo devinfo;
  2078. unsigned long flags;
  2079. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2080. starget->channel + 'A', ROLE_INITIATOR);
  2081. ahd_lock(ahd, &flags);
  2082. ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
  2083. ahd_unlock(ahd, &flags);
  2084. }
  2085. static void ahd_linux_set_period(struct scsi_target *starget, int period)
  2086. {
  2087. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2088. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2089. struct ahd_tmode_tstate *tstate;
  2090. struct ahd_initiator_tinfo *tinfo
  2091. = ahd_fetch_transinfo(ahd,
  2092. starget->channel + 'A',
  2093. shost->this_id, starget->id, &tstate);
  2094. struct ahd_devinfo devinfo;
  2095. unsigned int ppr_options = tinfo->goal.ppr_options;
  2096. unsigned int dt;
  2097. unsigned long flags;
  2098. unsigned long offset = tinfo->goal.offset;
  2099. #ifdef AHD_DEBUG
  2100. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2101. printf("%s: set period to %d\n", ahd_name(ahd), period);
  2102. #endif
  2103. if (offset == 0)
  2104. offset = MAX_OFFSET;
  2105. if (period < 8)
  2106. period = 8;
  2107. if (period < 10) {
  2108. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2109. if (period == 8)
  2110. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2111. }
  2112. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2113. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2114. starget->channel + 'A', ROLE_INITIATOR);
  2115. /* all PPR requests apart from QAS require wide transfers */
  2116. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2117. if (spi_width(starget) == 0)
  2118. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2119. }
  2120. ahd_find_syncrate(ahd, &period, &ppr_options,
  2121. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2122. ahd_lock(ahd, &flags);
  2123. ahd_set_syncrate(ahd, &devinfo, period, offset,
  2124. ppr_options, AHD_TRANS_GOAL, FALSE);
  2125. ahd_unlock(ahd, &flags);
  2126. }
  2127. static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
  2128. {
  2129. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2130. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2131. struct ahd_tmode_tstate *tstate;
  2132. struct ahd_initiator_tinfo *tinfo
  2133. = ahd_fetch_transinfo(ahd,
  2134. starget->channel + 'A',
  2135. shost->this_id, starget->id, &tstate);
  2136. struct ahd_devinfo devinfo;
  2137. unsigned int ppr_options = 0;
  2138. unsigned int period = 0;
  2139. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2140. unsigned long flags;
  2141. #ifdef AHD_DEBUG
  2142. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2143. printf("%s: set offset to %d\n", ahd_name(ahd), offset);
  2144. #endif
  2145. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2146. starget->channel + 'A', ROLE_INITIATOR);
  2147. if (offset != 0) {
  2148. period = tinfo->goal.period;
  2149. ppr_options = tinfo->goal.ppr_options;
  2150. ahd_find_syncrate(ahd, &period, &ppr_options,
  2151. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2152. }
  2153. ahd_lock(ahd, &flags);
  2154. ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
  2155. AHD_TRANS_GOAL, FALSE);
  2156. ahd_unlock(ahd, &flags);
  2157. }
  2158. static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
  2159. {
  2160. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2161. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2162. struct ahd_tmode_tstate *tstate;
  2163. struct ahd_initiator_tinfo *tinfo
  2164. = ahd_fetch_transinfo(ahd,
  2165. starget->channel + 'A',
  2166. shost->this_id, starget->id, &tstate);
  2167. struct ahd_devinfo devinfo;
  2168. unsigned int ppr_options = tinfo->goal.ppr_options
  2169. & ~MSG_EXT_PPR_DT_REQ;
  2170. unsigned int period = tinfo->goal.period;
  2171. unsigned int width = tinfo->goal.width;
  2172. unsigned long flags;
  2173. #ifdef AHD_DEBUG
  2174. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2175. printf("%s: %s DT\n", ahd_name(ahd),
  2176. dt ? "enabling" : "disabling");
  2177. #endif
  2178. if (dt) {
  2179. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2180. if (!width)
  2181. ahd_linux_set_width(starget, 1);
  2182. } else {
  2183. if (period <= 9)
  2184. period = 10; /* If resetting DT, period must be >= 25ns */
  2185. /* IU is invalid without DT set */
  2186. ppr_options &= ~MSG_EXT_PPR_IU_REQ;
  2187. }
  2188. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2189. starget->channel + 'A', ROLE_INITIATOR);
  2190. ahd_find_syncrate(ahd, &period, &ppr_options,
  2191. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2192. ahd_lock(ahd, &flags);
  2193. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2194. ppr_options, AHD_TRANS_GOAL, FALSE);
  2195. ahd_unlock(ahd, &flags);
  2196. }
  2197. static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
  2198. {
  2199. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2200. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2201. struct ahd_tmode_tstate *tstate;
  2202. struct ahd_initiator_tinfo *tinfo
  2203. = ahd_fetch_transinfo(ahd,
  2204. starget->channel + 'A',
  2205. shost->this_id, starget->id, &tstate);
  2206. struct ahd_devinfo devinfo;
  2207. unsigned int ppr_options = tinfo->goal.ppr_options
  2208. & ~MSG_EXT_PPR_QAS_REQ;
  2209. unsigned int period = tinfo->goal.period;
  2210. unsigned int dt;
  2211. unsigned long flags;
  2212. #ifdef AHD_DEBUG
  2213. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2214. printf("%s: %s QAS\n", ahd_name(ahd),
  2215. qas ? "enabling" : "disabling");
  2216. #endif
  2217. if (qas) {
  2218. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2219. }
  2220. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2221. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2222. starget->channel + 'A', ROLE_INITIATOR);
  2223. ahd_find_syncrate(ahd, &period, &ppr_options,
  2224. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2225. ahd_lock(ahd, &flags);
  2226. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2227. ppr_options, AHD_TRANS_GOAL, FALSE);
  2228. ahd_unlock(ahd, &flags);
  2229. }
  2230. static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
  2231. {
  2232. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2233. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2234. struct ahd_tmode_tstate *tstate;
  2235. struct ahd_initiator_tinfo *tinfo
  2236. = ahd_fetch_transinfo(ahd,
  2237. starget->channel + 'A',
  2238. shost->this_id, starget->id, &tstate);
  2239. struct ahd_devinfo devinfo;
  2240. unsigned int ppr_options = tinfo->goal.ppr_options
  2241. & ~MSG_EXT_PPR_IU_REQ;
  2242. unsigned int period = tinfo->goal.period;
  2243. unsigned int dt;
  2244. unsigned long flags;
  2245. #ifdef AHD_DEBUG
  2246. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2247. printf("%s: %s IU\n", ahd_name(ahd),
  2248. iu ? "enabling" : "disabling");
  2249. #endif
  2250. if (iu) {
  2251. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2252. ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
  2253. }
  2254. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2255. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2256. starget->channel + 'A', ROLE_INITIATOR);
  2257. ahd_find_syncrate(ahd, &period, &ppr_options,
  2258. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2259. ahd_lock(ahd, &flags);
  2260. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2261. ppr_options, AHD_TRANS_GOAL, FALSE);
  2262. ahd_unlock(ahd, &flags);
  2263. }
  2264. static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm)
  2265. {
  2266. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2267. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2268. struct ahd_tmode_tstate *tstate;
  2269. struct ahd_initiator_tinfo *tinfo
  2270. = ahd_fetch_transinfo(ahd,
  2271. starget->channel + 'A',
  2272. shost->this_id, starget->id, &tstate);
  2273. struct ahd_devinfo devinfo;
  2274. unsigned int ppr_options = tinfo->goal.ppr_options
  2275. & ~MSG_EXT_PPR_RD_STRM;
  2276. unsigned int period = tinfo->goal.period;
  2277. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2278. unsigned long flags;
  2279. #ifdef AHD_DEBUG
  2280. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2281. printf("%s: %s Read Streaming\n", ahd_name(ahd),
  2282. rdstrm ? "enabling" : "disabling");
  2283. #endif
  2284. if (rdstrm)
  2285. ppr_options |= MSG_EXT_PPR_RD_STRM;
  2286. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2287. starget->channel + 'A', ROLE_INITIATOR);
  2288. ahd_find_syncrate(ahd, &period, &ppr_options,
  2289. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2290. ahd_lock(ahd, &flags);
  2291. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2292. ppr_options, AHD_TRANS_GOAL, FALSE);
  2293. ahd_unlock(ahd, &flags);
  2294. }
  2295. static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
  2296. {
  2297. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2298. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2299. struct ahd_tmode_tstate *tstate;
  2300. struct ahd_initiator_tinfo *tinfo
  2301. = ahd_fetch_transinfo(ahd,
  2302. starget->channel + 'A',
  2303. shost->this_id, starget->id, &tstate);
  2304. struct ahd_devinfo devinfo;
  2305. unsigned int ppr_options = tinfo->goal.ppr_options
  2306. & ~MSG_EXT_PPR_WR_FLOW;
  2307. unsigned int period = tinfo->goal.period;
  2308. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2309. unsigned long flags;
  2310. #ifdef AHD_DEBUG
  2311. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2312. printf("%s: %s Write Flow Control\n", ahd_name(ahd),
  2313. wrflow ? "enabling" : "disabling");
  2314. #endif
  2315. if (wrflow)
  2316. ppr_options |= MSG_EXT_PPR_WR_FLOW;
  2317. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2318. starget->channel + 'A', ROLE_INITIATOR);
  2319. ahd_find_syncrate(ahd, &period, &ppr_options,
  2320. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2321. ahd_lock(ahd, &flags);
  2322. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2323. ppr_options, AHD_TRANS_GOAL, FALSE);
  2324. ahd_unlock(ahd, &flags);
  2325. }
  2326. static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
  2327. {
  2328. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2329. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2330. struct ahd_tmode_tstate *tstate;
  2331. struct ahd_initiator_tinfo *tinfo
  2332. = ahd_fetch_transinfo(ahd,
  2333. starget->channel + 'A',
  2334. shost->this_id, starget->id, &tstate);
  2335. struct ahd_devinfo devinfo;
  2336. unsigned int ppr_options = tinfo->goal.ppr_options
  2337. & ~MSG_EXT_PPR_RTI;
  2338. unsigned int period = tinfo->goal.period;
  2339. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2340. unsigned long flags;
  2341. if ((ahd->features & AHD_RTI) == 0) {
  2342. #ifdef AHD_DEBUG
  2343. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2344. printf("%s: RTI not available\n", ahd_name(ahd));
  2345. #endif
  2346. return;
  2347. }
  2348. #ifdef AHD_DEBUG
  2349. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2350. printf("%s: %s RTI\n", ahd_name(ahd),
  2351. rti ? "enabling" : "disabling");
  2352. #endif
  2353. if (rti)
  2354. ppr_options |= MSG_EXT_PPR_RTI;
  2355. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2356. starget->channel + 'A', ROLE_INITIATOR);
  2357. ahd_find_syncrate(ahd, &period, &ppr_options,
  2358. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2359. ahd_lock(ahd, &flags);
  2360. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2361. ppr_options, AHD_TRANS_GOAL, FALSE);
  2362. ahd_unlock(ahd, &flags);
  2363. }
  2364. static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
  2365. {
  2366. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2367. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2368. struct ahd_tmode_tstate *tstate;
  2369. struct ahd_initiator_tinfo *tinfo
  2370. = ahd_fetch_transinfo(ahd,
  2371. starget->channel + 'A',
  2372. shost->this_id, starget->id, &tstate);
  2373. struct ahd_devinfo devinfo;
  2374. unsigned int ppr_options = tinfo->goal.ppr_options
  2375. & ~MSG_EXT_PPR_PCOMP_EN;
  2376. unsigned int period = tinfo->goal.period;
  2377. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2378. unsigned long flags;
  2379. #ifdef AHD_DEBUG
  2380. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2381. printf("%s: %s Precompensation\n", ahd_name(ahd),
  2382. pcomp ? "Enable" : "Disable");
  2383. #endif
  2384. if (pcomp)
  2385. ppr_options |= MSG_EXT_PPR_PCOMP_EN;
  2386. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2387. starget->channel + 'A', ROLE_INITIATOR);
  2388. ahd_find_syncrate(ahd, &period, &ppr_options,
  2389. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2390. ahd_lock(ahd, &flags);
  2391. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2392. ppr_options, AHD_TRANS_GOAL, FALSE);
  2393. ahd_unlock(ahd, &flags);
  2394. }
  2395. static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
  2396. {
  2397. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2398. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2399. struct ahd_tmode_tstate *tstate;
  2400. struct ahd_initiator_tinfo *tinfo
  2401. = ahd_fetch_transinfo(ahd,
  2402. starget->channel + 'A',
  2403. shost->this_id, starget->id, &tstate);
  2404. struct ahd_devinfo devinfo;
  2405. unsigned int ppr_options = tinfo->goal.ppr_options
  2406. & ~MSG_EXT_PPR_HOLD_MCS;
  2407. unsigned int period = tinfo->goal.period;
  2408. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2409. unsigned long flags;
  2410. if (hold)
  2411. ppr_options |= MSG_EXT_PPR_HOLD_MCS;
  2412. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2413. starget->channel + 'A', ROLE_INITIATOR);
  2414. ahd_find_syncrate(ahd, &period, &ppr_options,
  2415. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2416. ahd_lock(ahd, &flags);
  2417. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2418. ppr_options, AHD_TRANS_GOAL, FALSE);
  2419. ahd_unlock(ahd, &flags);
  2420. }
  2421. static struct spi_function_template ahd_linux_transport_functions = {
  2422. .set_offset = ahd_linux_set_offset,
  2423. .show_offset = 1,
  2424. .set_period = ahd_linux_set_period,
  2425. .show_period = 1,
  2426. .set_width = ahd_linux_set_width,
  2427. .show_width = 1,
  2428. .set_dt = ahd_linux_set_dt,
  2429. .show_dt = 1,
  2430. .set_iu = ahd_linux_set_iu,
  2431. .show_iu = 1,
  2432. .set_qas = ahd_linux_set_qas,
  2433. .show_qas = 1,
  2434. .set_rd_strm = ahd_linux_set_rd_strm,
  2435. .show_rd_strm = 1,
  2436. .set_wr_flow = ahd_linux_set_wr_flow,
  2437. .show_wr_flow = 1,
  2438. .set_rti = ahd_linux_set_rti,
  2439. .show_rti = 1,
  2440. .set_pcomp_en = ahd_linux_set_pcomp_en,
  2441. .show_pcomp_en = 1,
  2442. .set_hold_mcs = ahd_linux_set_hold_mcs,
  2443. .show_hold_mcs = 1,
  2444. };
  2445. static int __init
  2446. ahd_linux_init(void)
  2447. {
  2448. int error = 0;
  2449. /*
  2450. * If we've been passed any parameters, process them now.
  2451. */
  2452. if (aic79xx)
  2453. aic79xx_setup(aic79xx);
  2454. ahd_linux_transport_template =
  2455. spi_attach_transport(&ahd_linux_transport_functions);
  2456. if (!ahd_linux_transport_template)
  2457. return -ENODEV;
  2458. scsi_transport_reserve_target(ahd_linux_transport_template,
  2459. sizeof(struct ahd_linux_target));
  2460. scsi_transport_reserve_device(ahd_linux_transport_template,
  2461. sizeof(struct ahd_linux_device));
  2462. error = ahd_linux_pci_init();
  2463. if (error)
  2464. spi_release_transport(ahd_linux_transport_template);
  2465. return error;
  2466. }
  2467. static void __exit
  2468. ahd_linux_exit(void)
  2469. {
  2470. ahd_linux_pci_exit();
  2471. spi_release_transport(ahd_linux_transport_template);
  2472. }
  2473. module_init(ahd_linux_init);
  2474. module_exit(ahd_linux_exit);