aachba.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  1. /*
  2. * Adaptec AAC series RAID controller driver
  3. * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
  4. *
  5. * based on the old aacraid driver that is..
  6. * Adaptec aacraid device driver for Linux.
  7. *
  8. * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; see the file COPYING. If not, write to
  22. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/types.h>
  28. #include <linux/pci.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/slab.h>
  31. #include <linux/completion.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/dma-mapping.h>
  34. #include <asm/semaphore.h>
  35. #include <asm/uaccess.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_cmnd.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_host.h>
  40. #include "aacraid.h"
  41. /* values for inqd_pdt: Peripheral device type in plain English */
  42. #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
  43. #define INQD_PDT_PROC 0x03 /* Processor device */
  44. #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
  45. #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
  46. #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
  47. #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
  48. #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
  49. #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
  50. /*
  51. * Sense codes
  52. */
  53. #define SENCODE_NO_SENSE 0x00
  54. #define SENCODE_END_OF_DATA 0x00
  55. #define SENCODE_BECOMING_READY 0x04
  56. #define SENCODE_INIT_CMD_REQUIRED 0x04
  57. #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
  58. #define SENCODE_INVALID_COMMAND 0x20
  59. #define SENCODE_LBA_OUT_OF_RANGE 0x21
  60. #define SENCODE_INVALID_CDB_FIELD 0x24
  61. #define SENCODE_LUN_NOT_SUPPORTED 0x25
  62. #define SENCODE_INVALID_PARAM_FIELD 0x26
  63. #define SENCODE_PARAM_NOT_SUPPORTED 0x26
  64. #define SENCODE_PARAM_VALUE_INVALID 0x26
  65. #define SENCODE_RESET_OCCURRED 0x29
  66. #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
  67. #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
  68. #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
  69. #define SENCODE_DIAGNOSTIC_FAILURE 0x40
  70. #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
  71. #define SENCODE_INVALID_MESSAGE_ERROR 0x49
  72. #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
  73. #define SENCODE_OVERLAPPED_COMMAND 0x4E
  74. /*
  75. * Additional sense codes
  76. */
  77. #define ASENCODE_NO_SENSE 0x00
  78. #define ASENCODE_END_OF_DATA 0x05
  79. #define ASENCODE_BECOMING_READY 0x01
  80. #define ASENCODE_INIT_CMD_REQUIRED 0x02
  81. #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
  82. #define ASENCODE_INVALID_COMMAND 0x00
  83. #define ASENCODE_LBA_OUT_OF_RANGE 0x00
  84. #define ASENCODE_INVALID_CDB_FIELD 0x00
  85. #define ASENCODE_LUN_NOT_SUPPORTED 0x00
  86. #define ASENCODE_INVALID_PARAM_FIELD 0x00
  87. #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
  88. #define ASENCODE_PARAM_VALUE_INVALID 0x02
  89. #define ASENCODE_RESET_OCCURRED 0x00
  90. #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
  91. #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
  92. #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
  93. #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
  94. #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
  95. #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
  96. #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
  97. #define ASENCODE_OVERLAPPED_COMMAND 0x00
  98. #define BYTE0(x) (unsigned char)(x)
  99. #define BYTE1(x) (unsigned char)((x) >> 8)
  100. #define BYTE2(x) (unsigned char)((x) >> 16)
  101. #define BYTE3(x) (unsigned char)((x) >> 24)
  102. /*------------------------------------------------------------------------------
  103. * S T R U C T S / T Y P E D E F S
  104. *----------------------------------------------------------------------------*/
  105. /* SCSI inquiry data */
  106. struct inquiry_data {
  107. u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
  108. u8 inqd_dtq; /* RMB | Device Type Qualifier */
  109. u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
  110. u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
  111. u8 inqd_len; /* Additional length (n-4) */
  112. u8 inqd_pad1[2];/* Reserved - must be zero */
  113. u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  114. u8 inqd_vid[8]; /* Vendor ID */
  115. u8 inqd_pid[16];/* Product ID */
  116. u8 inqd_prl[4]; /* Product Revision Level */
  117. };
  118. /*
  119. * M O D U L E G L O B A L S
  120. */
  121. static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
  122. static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
  123. static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
  124. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
  125. #ifdef AAC_DETAILED_STATUS_INFO
  126. static char *aac_get_status_string(u32 status);
  127. #endif
  128. /*
  129. * Non dasd selection is handled entirely in aachba now
  130. */
  131. static int nondasd = -1;
  132. static int dacmode = -1;
  133. int aac_commit = -1;
  134. int startup_timeout = 180;
  135. int aif_timeout = 120;
  136. module_param(nondasd, int, S_IRUGO|S_IWUSR);
  137. MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
  138. module_param(dacmode, int, S_IRUGO|S_IWUSR);
  139. MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
  140. module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
  141. MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
  142. module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
  143. MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS.");
  144. module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
  145. MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems.");
  146. int numacb = -1;
  147. module_param(numacb, int, S_IRUGO|S_IWUSR);
  148. MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
  149. int acbsize = -1;
  150. module_param(acbsize, int, S_IRUGO|S_IWUSR);
  151. MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
  152. int expose_physicals = -1;
  153. module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
  154. MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
  155. int aac_reset_devices = 0;
  156. module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
  157. MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
  158. static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
  159. struct fib *fibptr) {
  160. struct scsi_device *device;
  161. if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
  162. dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"))
  163. ;
  164. aac_fib_complete(fibptr);
  165. aac_fib_free(fibptr);
  166. return 0;
  167. }
  168. scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
  169. device = scsicmd->device;
  170. if (unlikely(!device || !scsi_device_online(device))) {
  171. dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
  172. aac_fib_complete(fibptr);
  173. aac_fib_free(fibptr);
  174. return 0;
  175. }
  176. return 1;
  177. }
  178. /**
  179. * aac_get_config_status - check the adapter configuration
  180. * @common: adapter to query
  181. *
  182. * Query config status, and commit the configuration if needed.
  183. */
  184. int aac_get_config_status(struct aac_dev *dev, int commit_flag)
  185. {
  186. int status = 0;
  187. struct fib * fibptr;
  188. if (!(fibptr = aac_fib_alloc(dev)))
  189. return -ENOMEM;
  190. aac_fib_init(fibptr);
  191. {
  192. struct aac_get_config_status *dinfo;
  193. dinfo = (struct aac_get_config_status *) fib_data(fibptr);
  194. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  195. dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
  196. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
  197. }
  198. status = aac_fib_send(ContainerCommand,
  199. fibptr,
  200. sizeof (struct aac_get_config_status),
  201. FsaNormal,
  202. 1, 1,
  203. NULL, NULL);
  204. if (status < 0 ) {
  205. printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
  206. } else {
  207. struct aac_get_config_status_resp *reply
  208. = (struct aac_get_config_status_resp *) fib_data(fibptr);
  209. dprintk((KERN_WARNING
  210. "aac_get_config_status: response=%d status=%d action=%d\n",
  211. le32_to_cpu(reply->response),
  212. le32_to_cpu(reply->status),
  213. le32_to_cpu(reply->data.action)));
  214. if ((le32_to_cpu(reply->response) != ST_OK) ||
  215. (le32_to_cpu(reply->status) != CT_OK) ||
  216. (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
  217. printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
  218. status = -EINVAL;
  219. }
  220. }
  221. aac_fib_complete(fibptr);
  222. /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
  223. if (status >= 0) {
  224. if ((aac_commit == 1) || commit_flag) {
  225. struct aac_commit_config * dinfo;
  226. aac_fib_init(fibptr);
  227. dinfo = (struct aac_commit_config *) fib_data(fibptr);
  228. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  229. dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
  230. status = aac_fib_send(ContainerCommand,
  231. fibptr,
  232. sizeof (struct aac_commit_config),
  233. FsaNormal,
  234. 1, 1,
  235. NULL, NULL);
  236. aac_fib_complete(fibptr);
  237. } else if (aac_commit == 0) {
  238. printk(KERN_WARNING
  239. "aac_get_config_status: Foreign device configurations are being ignored\n");
  240. }
  241. }
  242. aac_fib_free(fibptr);
  243. return status;
  244. }
  245. /**
  246. * aac_get_containers - list containers
  247. * @common: adapter to probe
  248. *
  249. * Make a list of all containers on this controller
  250. */
  251. int aac_get_containers(struct aac_dev *dev)
  252. {
  253. struct fsa_dev_info *fsa_dev_ptr;
  254. u32 index;
  255. int status = 0;
  256. struct fib * fibptr;
  257. struct aac_get_container_count *dinfo;
  258. struct aac_get_container_count_resp *dresp;
  259. int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  260. if (!(fibptr = aac_fib_alloc(dev)))
  261. return -ENOMEM;
  262. aac_fib_init(fibptr);
  263. dinfo = (struct aac_get_container_count *) fib_data(fibptr);
  264. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  265. dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
  266. status = aac_fib_send(ContainerCommand,
  267. fibptr,
  268. sizeof (struct aac_get_container_count),
  269. FsaNormal,
  270. 1, 1,
  271. NULL, NULL);
  272. if (status >= 0) {
  273. dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
  274. maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
  275. aac_fib_complete(fibptr);
  276. }
  277. aac_fib_free(fibptr);
  278. if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
  279. maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  280. fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
  281. GFP_KERNEL);
  282. if (!fsa_dev_ptr)
  283. return -ENOMEM;
  284. memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
  285. dev->fsa_dev = fsa_dev_ptr;
  286. dev->maximum_num_containers = maximum_num_containers;
  287. for (index = 0; index < dev->maximum_num_containers; ) {
  288. fsa_dev_ptr[index].devname[0] = '\0';
  289. status = aac_probe_container(dev, index);
  290. if (status < 0) {
  291. printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
  292. break;
  293. }
  294. /*
  295. * If there are no more containers, then stop asking.
  296. */
  297. if (++index >= status)
  298. break;
  299. }
  300. return status;
  301. }
  302. static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
  303. {
  304. void *buf;
  305. int transfer_len;
  306. struct scatterlist *sg = scsicmd->request_buffer;
  307. if (scsicmd->use_sg) {
  308. buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
  309. transfer_len = min(sg->length, len + offset);
  310. } else {
  311. buf = scsicmd->request_buffer;
  312. transfer_len = min(scsicmd->request_bufflen, len + offset);
  313. }
  314. transfer_len -= offset;
  315. if (buf && transfer_len > 0)
  316. memcpy(buf + offset, data, transfer_len);
  317. if (scsicmd->use_sg)
  318. kunmap_atomic(buf - sg->offset, KM_IRQ0);
  319. }
  320. static void get_container_name_callback(void *context, struct fib * fibptr)
  321. {
  322. struct aac_get_name_resp * get_name_reply;
  323. struct scsi_cmnd * scsicmd;
  324. scsicmd = (struct scsi_cmnd *) context;
  325. if (!aac_valid_context(scsicmd, fibptr))
  326. return;
  327. dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
  328. BUG_ON(fibptr == NULL);
  329. get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
  330. /* Failure is irrelevant, using default value instead */
  331. if ((le32_to_cpu(get_name_reply->status) == CT_OK)
  332. && (get_name_reply->data[0] != '\0')) {
  333. char *sp = get_name_reply->data;
  334. sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
  335. while (*sp == ' ')
  336. ++sp;
  337. if (*sp) {
  338. char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
  339. int count = sizeof(d);
  340. char *dp = d;
  341. do {
  342. *dp++ = (*sp) ? *sp++ : ' ';
  343. } while (--count > 0);
  344. aac_internal_transfer(scsicmd, d,
  345. offsetof(struct inquiry_data, inqd_pid), sizeof(d));
  346. }
  347. }
  348. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  349. aac_fib_complete(fibptr);
  350. aac_fib_free(fibptr);
  351. scsicmd->scsi_done(scsicmd);
  352. }
  353. /**
  354. * aac_get_container_name - get container name, none blocking.
  355. */
  356. static int aac_get_container_name(struct scsi_cmnd * scsicmd)
  357. {
  358. int status;
  359. struct aac_get_name *dinfo;
  360. struct fib * cmd_fibcontext;
  361. struct aac_dev * dev;
  362. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  363. if (!(cmd_fibcontext = aac_fib_alloc(dev)))
  364. return -ENOMEM;
  365. aac_fib_init(cmd_fibcontext);
  366. dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
  367. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  368. dinfo->type = cpu_to_le32(CT_READ_NAME);
  369. dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
  370. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
  371. status = aac_fib_send(ContainerCommand,
  372. cmd_fibcontext,
  373. sizeof (struct aac_get_name),
  374. FsaNormal,
  375. 0, 1,
  376. (fib_callback) get_container_name_callback,
  377. (void *) scsicmd);
  378. /*
  379. * Check that the command queued to the controller
  380. */
  381. if (status == -EINPROGRESS) {
  382. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  383. return 0;
  384. }
  385. printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
  386. aac_fib_complete(cmd_fibcontext);
  387. aac_fib_free(cmd_fibcontext);
  388. return -1;
  389. }
  390. static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
  391. {
  392. struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
  393. if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
  394. return aac_scsi_cmd(scsicmd);
  395. scsicmd->result = DID_NO_CONNECT << 16;
  396. scsicmd->scsi_done(scsicmd);
  397. return 0;
  398. }
  399. static int _aac_probe_container2(void * context, struct fib * fibptr)
  400. {
  401. struct fsa_dev_info *fsa_dev_ptr;
  402. int (*callback)(struct scsi_cmnd *);
  403. struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
  404. if (!aac_valid_context(scsicmd, fibptr))
  405. return 0;
  406. fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
  407. scsicmd->SCp.Status = 0;
  408. if (fsa_dev_ptr) {
  409. struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
  410. fsa_dev_ptr += scmd_id(scsicmd);
  411. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  412. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
  413. (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
  414. fsa_dev_ptr->valid = 1;
  415. fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
  416. fsa_dev_ptr->size
  417. = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
  418. (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
  419. fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
  420. }
  421. if ((fsa_dev_ptr->valid & 1) == 0)
  422. fsa_dev_ptr->valid = 0;
  423. scsicmd->SCp.Status = le32_to_cpu(dresp->count);
  424. }
  425. aac_fib_complete(fibptr);
  426. aac_fib_free(fibptr);
  427. callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
  428. scsicmd->SCp.ptr = NULL;
  429. return (*callback)(scsicmd);
  430. }
  431. static int _aac_probe_container1(void * context, struct fib * fibptr)
  432. {
  433. struct scsi_cmnd * scsicmd;
  434. struct aac_mount * dresp;
  435. struct aac_query_mount *dinfo;
  436. int status;
  437. dresp = (struct aac_mount *) fib_data(fibptr);
  438. dresp->mnt[0].capacityhigh = 0;
  439. if ((le32_to_cpu(dresp->status) != ST_OK) ||
  440. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE))
  441. return _aac_probe_container2(context, fibptr);
  442. scsicmd = (struct scsi_cmnd *) context;
  443. scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
  444. if (!aac_valid_context(scsicmd, fibptr))
  445. return 0;
  446. aac_fib_init(fibptr);
  447. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  448. dinfo->command = cpu_to_le32(VM_NameServe64);
  449. dinfo->count = cpu_to_le32(scmd_id(scsicmd));
  450. dinfo->type = cpu_to_le32(FT_FILESYS);
  451. status = aac_fib_send(ContainerCommand,
  452. fibptr,
  453. sizeof(struct aac_query_mount),
  454. FsaNormal,
  455. 0, 1,
  456. (fib_callback) _aac_probe_container2,
  457. (void *) scsicmd);
  458. /*
  459. * Check that the command queued to the controller
  460. */
  461. if (status == -EINPROGRESS) {
  462. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  463. return 0;
  464. }
  465. if (status < 0) {
  466. /* Inherit results from VM_NameServe, if any */
  467. dresp->status = cpu_to_le32(ST_OK);
  468. return _aac_probe_container2(context, fibptr);
  469. }
  470. return 0;
  471. }
  472. static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
  473. {
  474. struct fib * fibptr;
  475. int status = -ENOMEM;
  476. if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
  477. struct aac_query_mount *dinfo;
  478. aac_fib_init(fibptr);
  479. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  480. dinfo->command = cpu_to_le32(VM_NameServe);
  481. dinfo->count = cpu_to_le32(scmd_id(scsicmd));
  482. dinfo->type = cpu_to_le32(FT_FILESYS);
  483. scsicmd->SCp.ptr = (char *)callback;
  484. status = aac_fib_send(ContainerCommand,
  485. fibptr,
  486. sizeof(struct aac_query_mount),
  487. FsaNormal,
  488. 0, 1,
  489. (fib_callback) _aac_probe_container1,
  490. (void *) scsicmd);
  491. /*
  492. * Check that the command queued to the controller
  493. */
  494. if (status == -EINPROGRESS) {
  495. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  496. return 0;
  497. }
  498. if (status < 0) {
  499. scsicmd->SCp.ptr = NULL;
  500. aac_fib_complete(fibptr);
  501. aac_fib_free(fibptr);
  502. }
  503. }
  504. if (status < 0) {
  505. struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
  506. if (fsa_dev_ptr) {
  507. fsa_dev_ptr += scmd_id(scsicmd);
  508. if ((fsa_dev_ptr->valid & 1) == 0) {
  509. fsa_dev_ptr->valid = 0;
  510. return (*callback)(scsicmd);
  511. }
  512. }
  513. }
  514. return status;
  515. }
  516. /**
  517. * aac_probe_container - query a logical volume
  518. * @dev: device to query
  519. * @cid: container identifier
  520. *
  521. * Queries the controller about the given volume. The volume information
  522. * is updated in the struct fsa_dev_info structure rather than returned.
  523. */
  524. static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
  525. {
  526. scsicmd->device = NULL;
  527. return 0;
  528. }
  529. int aac_probe_container(struct aac_dev *dev, int cid)
  530. {
  531. struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
  532. struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
  533. int status;
  534. if (!scsicmd || !scsidev) {
  535. kfree(scsicmd);
  536. kfree(scsidev);
  537. return -ENOMEM;
  538. }
  539. scsicmd->list.next = NULL;
  540. scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
  541. scsicmd->device = scsidev;
  542. scsidev->sdev_state = 0;
  543. scsidev->id = cid;
  544. scsidev->host = dev->scsi_host_ptr;
  545. if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
  546. while (scsicmd->device == scsidev)
  547. schedule();
  548. kfree(scsidev);
  549. status = scsicmd->SCp.Status;
  550. kfree(scsicmd);
  551. return status;
  552. }
  553. /* Local Structure to set SCSI inquiry data strings */
  554. struct scsi_inq {
  555. char vid[8]; /* Vendor ID */
  556. char pid[16]; /* Product ID */
  557. char prl[4]; /* Product Revision Level */
  558. };
  559. /**
  560. * InqStrCopy - string merge
  561. * @a: string to copy from
  562. * @b: string to copy to
  563. *
  564. * Copy a String from one location to another
  565. * without copying \0
  566. */
  567. static void inqstrcpy(char *a, char *b)
  568. {
  569. while(*a != (char)0)
  570. *b++ = *a++;
  571. }
  572. static char *container_types[] = {
  573. "None",
  574. "Volume",
  575. "Mirror",
  576. "Stripe",
  577. "RAID5",
  578. "SSRW",
  579. "SSRO",
  580. "Morph",
  581. "Legacy",
  582. "RAID4",
  583. "RAID10",
  584. "RAID00",
  585. "V-MIRRORS",
  586. "PSEUDO R4",
  587. "RAID50",
  588. "RAID5D",
  589. "RAID5D0",
  590. "RAID1E",
  591. "RAID6",
  592. "RAID60",
  593. "Unknown"
  594. };
  595. /* Function: setinqstr
  596. *
  597. * Arguments: [1] pointer to void [1] int
  598. *
  599. * Purpose: Sets SCSI inquiry data strings for vendor, product
  600. * and revision level. Allows strings to be set in platform dependant
  601. * files instead of in OS dependant driver source.
  602. */
  603. static void setinqstr(struct aac_dev *dev, void *data, int tindex)
  604. {
  605. struct scsi_inq *str;
  606. str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
  607. memset(str, ' ', sizeof(*str));
  608. if (dev->supplement_adapter_info.AdapterTypeText[0]) {
  609. char * cp = dev->supplement_adapter_info.AdapterTypeText;
  610. int c = sizeof(str->vid);
  611. while (*cp && *cp != ' ' && --c)
  612. ++cp;
  613. c = *cp;
  614. *cp = '\0';
  615. inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
  616. str->vid);
  617. *cp = c;
  618. while (*cp && *cp != ' ')
  619. ++cp;
  620. while (*cp == ' ')
  621. ++cp;
  622. /* last six chars reserved for vol type */
  623. c = 0;
  624. if (strlen(cp) > sizeof(str->pid)) {
  625. c = cp[sizeof(str->pid)];
  626. cp[sizeof(str->pid)] = '\0';
  627. }
  628. inqstrcpy (cp, str->pid);
  629. if (c)
  630. cp[sizeof(str->pid)] = c;
  631. } else {
  632. struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
  633. inqstrcpy (mp->vname, str->vid);
  634. /* last six chars reserved for vol type */
  635. inqstrcpy (mp->model, str->pid);
  636. }
  637. if (tindex < ARRAY_SIZE(container_types)){
  638. char *findit = str->pid;
  639. for ( ; *findit != ' '; findit++); /* walk till we find a space */
  640. /* RAID is superfluous in the context of a RAID device */
  641. if (memcmp(findit-4, "RAID", 4) == 0)
  642. *(findit -= 4) = ' ';
  643. if (((findit - str->pid) + strlen(container_types[tindex]))
  644. < (sizeof(str->pid) + sizeof(str->prl)))
  645. inqstrcpy (container_types[tindex], findit + 1);
  646. }
  647. inqstrcpy ("V1.0", str->prl);
  648. }
  649. static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
  650. u8 a_sense_code, u8 incorrect_length,
  651. u8 bit_pointer, u16 field_pointer,
  652. u32 residue)
  653. {
  654. sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
  655. sense_buf[1] = 0; /* Segment number, always zero */
  656. if (incorrect_length) {
  657. sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
  658. sense_buf[3] = BYTE3(residue);
  659. sense_buf[4] = BYTE2(residue);
  660. sense_buf[5] = BYTE1(residue);
  661. sense_buf[6] = BYTE0(residue);
  662. } else
  663. sense_buf[2] = sense_key; /* Sense key */
  664. if (sense_key == ILLEGAL_REQUEST)
  665. sense_buf[7] = 10; /* Additional sense length */
  666. else
  667. sense_buf[7] = 6; /* Additional sense length */
  668. sense_buf[12] = sense_code; /* Additional sense code */
  669. sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
  670. if (sense_key == ILLEGAL_REQUEST) {
  671. sense_buf[15] = 0;
  672. if (sense_code == SENCODE_INVALID_PARAM_FIELD)
  673. sense_buf[15] = 0x80;/* Std sense key specific field */
  674. /* Illegal parameter is in the parameter block */
  675. if (sense_code == SENCODE_INVALID_CDB_FIELD)
  676. sense_buf[15] = 0xc0;/* Std sense key specific field */
  677. /* Illegal parameter is in the CDB block */
  678. sense_buf[15] |= bit_pointer;
  679. sense_buf[16] = field_pointer >> 8; /* MSB */
  680. sense_buf[17] = field_pointer; /* LSB */
  681. }
  682. }
  683. static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
  684. {
  685. if (lba & 0xffffffff00000000LL) {
  686. int cid = scmd_id(cmd);
  687. dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
  688. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
  689. SAM_STAT_CHECK_CONDITION;
  690. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  691. HARDWARE_ERROR,
  692. SENCODE_INTERNAL_TARGET_FAILURE,
  693. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  694. 0, 0);
  695. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  696. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
  697. ? sizeof(cmd->sense_buffer)
  698. : sizeof(dev->fsa_dev[cid].sense_data));
  699. cmd->scsi_done(cmd);
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
  705. {
  706. return 0;
  707. }
  708. static void io_callback(void *context, struct fib * fibptr);
  709. static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  710. {
  711. u16 fibsize;
  712. struct aac_raw_io *readcmd;
  713. aac_fib_init(fib);
  714. readcmd = (struct aac_raw_io *) fib_data(fib);
  715. readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  716. readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  717. readcmd->count = cpu_to_le32(count<<9);
  718. readcmd->cid = cpu_to_le16(scmd_id(cmd));
  719. readcmd->flags = cpu_to_le16(1);
  720. readcmd->bpTotal = 0;
  721. readcmd->bpComplete = 0;
  722. aac_build_sgraw(cmd, &readcmd->sg);
  723. fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
  724. BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
  725. /*
  726. * Now send the Fib to the adapter
  727. */
  728. return aac_fib_send(ContainerRawIo,
  729. fib,
  730. fibsize,
  731. FsaNormal,
  732. 0, 1,
  733. (fib_callback) io_callback,
  734. (void *) cmd);
  735. }
  736. static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  737. {
  738. u16 fibsize;
  739. struct aac_read64 *readcmd;
  740. aac_fib_init(fib);
  741. readcmd = (struct aac_read64 *) fib_data(fib);
  742. readcmd->command = cpu_to_le32(VM_CtHostRead64);
  743. readcmd->cid = cpu_to_le16(scmd_id(cmd));
  744. readcmd->sector_count = cpu_to_le16(count);
  745. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  746. readcmd->pad = 0;
  747. readcmd->flags = 0;
  748. aac_build_sg64(cmd, &readcmd->sg);
  749. fibsize = sizeof(struct aac_read64) +
  750. ((le32_to_cpu(readcmd->sg.count) - 1) *
  751. sizeof (struct sgentry64));
  752. BUG_ON (fibsize > (fib->dev->max_fib_size -
  753. sizeof(struct aac_fibhdr)));
  754. /*
  755. * Now send the Fib to the adapter
  756. */
  757. return aac_fib_send(ContainerCommand64,
  758. fib,
  759. fibsize,
  760. FsaNormal,
  761. 0, 1,
  762. (fib_callback) io_callback,
  763. (void *) cmd);
  764. }
  765. static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  766. {
  767. u16 fibsize;
  768. struct aac_read *readcmd;
  769. aac_fib_init(fib);
  770. readcmd = (struct aac_read *) fib_data(fib);
  771. readcmd->command = cpu_to_le32(VM_CtBlockRead);
  772. readcmd->cid = cpu_to_le16(scmd_id(cmd));
  773. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  774. readcmd->count = cpu_to_le32(count * 512);
  775. aac_build_sg(cmd, &readcmd->sg);
  776. fibsize = sizeof(struct aac_read) +
  777. ((le32_to_cpu(readcmd->sg.count) - 1) *
  778. sizeof (struct sgentry));
  779. BUG_ON (fibsize > (fib->dev->max_fib_size -
  780. sizeof(struct aac_fibhdr)));
  781. /*
  782. * Now send the Fib to the adapter
  783. */
  784. return aac_fib_send(ContainerCommand,
  785. fib,
  786. fibsize,
  787. FsaNormal,
  788. 0, 1,
  789. (fib_callback) io_callback,
  790. (void *) cmd);
  791. }
  792. static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  793. {
  794. u16 fibsize;
  795. struct aac_raw_io *writecmd;
  796. aac_fib_init(fib);
  797. writecmd = (struct aac_raw_io *) fib_data(fib);
  798. writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  799. writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  800. writecmd->count = cpu_to_le32(count<<9);
  801. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  802. writecmd->flags = 0;
  803. writecmd->bpTotal = 0;
  804. writecmd->bpComplete = 0;
  805. aac_build_sgraw(cmd, &writecmd->sg);
  806. fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
  807. BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
  808. /*
  809. * Now send the Fib to the adapter
  810. */
  811. return aac_fib_send(ContainerRawIo,
  812. fib,
  813. fibsize,
  814. FsaNormal,
  815. 0, 1,
  816. (fib_callback) io_callback,
  817. (void *) cmd);
  818. }
  819. static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  820. {
  821. u16 fibsize;
  822. struct aac_write64 *writecmd;
  823. aac_fib_init(fib);
  824. writecmd = (struct aac_write64 *) fib_data(fib);
  825. writecmd->command = cpu_to_le32(VM_CtHostWrite64);
  826. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  827. writecmd->sector_count = cpu_to_le16(count);
  828. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  829. writecmd->pad = 0;
  830. writecmd->flags = 0;
  831. aac_build_sg64(cmd, &writecmd->sg);
  832. fibsize = sizeof(struct aac_write64) +
  833. ((le32_to_cpu(writecmd->sg.count) - 1) *
  834. sizeof (struct sgentry64));
  835. BUG_ON (fibsize > (fib->dev->max_fib_size -
  836. sizeof(struct aac_fibhdr)));
  837. /*
  838. * Now send the Fib to the adapter
  839. */
  840. return aac_fib_send(ContainerCommand64,
  841. fib,
  842. fibsize,
  843. FsaNormal,
  844. 0, 1,
  845. (fib_callback) io_callback,
  846. (void *) cmd);
  847. }
  848. static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  849. {
  850. u16 fibsize;
  851. struct aac_write *writecmd;
  852. aac_fib_init(fib);
  853. writecmd = (struct aac_write *) fib_data(fib);
  854. writecmd->command = cpu_to_le32(VM_CtBlockWrite);
  855. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  856. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  857. writecmd->count = cpu_to_le32(count * 512);
  858. writecmd->sg.count = cpu_to_le32(1);
  859. /* ->stable is not used - it did mean which type of write */
  860. aac_build_sg(cmd, &writecmd->sg);
  861. fibsize = sizeof(struct aac_write) +
  862. ((le32_to_cpu(writecmd->sg.count) - 1) *
  863. sizeof (struct sgentry));
  864. BUG_ON (fibsize > (fib->dev->max_fib_size -
  865. sizeof(struct aac_fibhdr)));
  866. /*
  867. * Now send the Fib to the adapter
  868. */
  869. return aac_fib_send(ContainerCommand,
  870. fib,
  871. fibsize,
  872. FsaNormal,
  873. 0, 1,
  874. (fib_callback) io_callback,
  875. (void *) cmd);
  876. }
  877. static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
  878. {
  879. struct aac_srb * srbcmd;
  880. u32 flag;
  881. u32 timeout;
  882. aac_fib_init(fib);
  883. switch(cmd->sc_data_direction){
  884. case DMA_TO_DEVICE:
  885. flag = SRB_DataOut;
  886. break;
  887. case DMA_BIDIRECTIONAL:
  888. flag = SRB_DataIn | SRB_DataOut;
  889. break;
  890. case DMA_FROM_DEVICE:
  891. flag = SRB_DataIn;
  892. break;
  893. case DMA_NONE:
  894. default: /* shuts up some versions of gcc */
  895. flag = SRB_NoDataXfer;
  896. break;
  897. }
  898. srbcmd = (struct aac_srb*) fib_data(fib);
  899. srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
  900. srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
  901. srbcmd->id = cpu_to_le32(scmd_id(cmd));
  902. srbcmd->lun = cpu_to_le32(cmd->device->lun);
  903. srbcmd->flags = cpu_to_le32(flag);
  904. timeout = cmd->timeout_per_command/HZ;
  905. if (timeout == 0)
  906. timeout = 1;
  907. srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
  908. srbcmd->retry_limit = 0; /* Obsolete parameter */
  909. srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
  910. return srbcmd;
  911. }
  912. static void aac_srb_callback(void *context, struct fib * fibptr);
  913. static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
  914. {
  915. u16 fibsize;
  916. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  917. aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
  918. srbcmd->count = cpu_to_le32(cmd->request_bufflen);
  919. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  920. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  921. /*
  922. * Build Scatter/Gather list
  923. */
  924. fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
  925. ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
  926. sizeof (struct sgentry64));
  927. BUG_ON (fibsize > (fib->dev->max_fib_size -
  928. sizeof(struct aac_fibhdr)));
  929. /*
  930. * Now send the Fib to the adapter
  931. */
  932. return aac_fib_send(ScsiPortCommand64, fib,
  933. fibsize, FsaNormal, 0, 1,
  934. (fib_callback) aac_srb_callback,
  935. (void *) cmd);
  936. }
  937. static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
  938. {
  939. u16 fibsize;
  940. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  941. aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
  942. srbcmd->count = cpu_to_le32(cmd->request_bufflen);
  943. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  944. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  945. /*
  946. * Build Scatter/Gather list
  947. */
  948. fibsize = sizeof (struct aac_srb) +
  949. (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
  950. sizeof (struct sgentry));
  951. BUG_ON (fibsize > (fib->dev->max_fib_size -
  952. sizeof(struct aac_fibhdr)));
  953. /*
  954. * Now send the Fib to the adapter
  955. */
  956. return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
  957. (fib_callback) aac_srb_callback, (void *) cmd);
  958. }
  959. int aac_get_adapter_info(struct aac_dev* dev)
  960. {
  961. struct fib* fibptr;
  962. int rcode;
  963. u32 tmp;
  964. struct aac_adapter_info *info;
  965. struct aac_bus_info *command;
  966. struct aac_bus_info_response *bus_info;
  967. if (!(fibptr = aac_fib_alloc(dev)))
  968. return -ENOMEM;
  969. aac_fib_init(fibptr);
  970. info = (struct aac_adapter_info *) fib_data(fibptr);
  971. memset(info,0,sizeof(*info));
  972. rcode = aac_fib_send(RequestAdapterInfo,
  973. fibptr,
  974. sizeof(*info),
  975. FsaNormal,
  976. -1, 1, /* First `interrupt' command uses special wait */
  977. NULL,
  978. NULL);
  979. if (rcode < 0) {
  980. aac_fib_complete(fibptr);
  981. aac_fib_free(fibptr);
  982. return rcode;
  983. }
  984. memcpy(&dev->adapter_info, info, sizeof(*info));
  985. if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
  986. struct aac_supplement_adapter_info * info;
  987. aac_fib_init(fibptr);
  988. info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
  989. memset(info,0,sizeof(*info));
  990. rcode = aac_fib_send(RequestSupplementAdapterInfo,
  991. fibptr,
  992. sizeof(*info),
  993. FsaNormal,
  994. 1, 1,
  995. NULL,
  996. NULL);
  997. if (rcode >= 0)
  998. memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
  999. }
  1000. /*
  1001. * GetBusInfo
  1002. */
  1003. aac_fib_init(fibptr);
  1004. bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
  1005. memset(bus_info, 0, sizeof(*bus_info));
  1006. command = (struct aac_bus_info *)bus_info;
  1007. command->Command = cpu_to_le32(VM_Ioctl);
  1008. command->ObjType = cpu_to_le32(FT_DRIVE);
  1009. command->MethodId = cpu_to_le32(1);
  1010. command->CtlCmd = cpu_to_le32(GetBusInfo);
  1011. rcode = aac_fib_send(ContainerCommand,
  1012. fibptr,
  1013. sizeof (*bus_info),
  1014. FsaNormal,
  1015. 1, 1,
  1016. NULL, NULL);
  1017. if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
  1018. dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
  1019. dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
  1020. }
  1021. if (!dev->in_reset) {
  1022. tmp = le32_to_cpu(dev->adapter_info.kernelrev);
  1023. printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
  1024. dev->name,
  1025. dev->id,
  1026. tmp>>24,
  1027. (tmp>>16)&0xff,
  1028. tmp&0xff,
  1029. le32_to_cpu(dev->adapter_info.kernelbuild),
  1030. (int)sizeof(dev->supplement_adapter_info.BuildDate),
  1031. dev->supplement_adapter_info.BuildDate);
  1032. tmp = le32_to_cpu(dev->adapter_info.monitorrev);
  1033. printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
  1034. dev->name, dev->id,
  1035. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1036. le32_to_cpu(dev->adapter_info.monitorbuild));
  1037. tmp = le32_to_cpu(dev->adapter_info.biosrev);
  1038. printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
  1039. dev->name, dev->id,
  1040. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1041. le32_to_cpu(dev->adapter_info.biosbuild));
  1042. if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
  1043. printk(KERN_INFO "%s%d: serial %x\n",
  1044. dev->name, dev->id,
  1045. le32_to_cpu(dev->adapter_info.serial[0]));
  1046. if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
  1047. printk(KERN_INFO "%s%d: TSID %.*s\n",
  1048. dev->name, dev->id,
  1049. (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
  1050. dev->supplement_adapter_info.VpdInfo.Tsid);
  1051. }
  1052. }
  1053. dev->nondasd_support = 0;
  1054. dev->raid_scsi_mode = 0;
  1055. if(dev->adapter_info.options & AAC_OPT_NONDASD){
  1056. dev->nondasd_support = 1;
  1057. }
  1058. /*
  1059. * If the firmware supports ROMB RAID/SCSI mode and we are currently
  1060. * in RAID/SCSI mode, set the flag. For now if in this mode we will
  1061. * force nondasd support on. If we decide to allow the non-dasd flag
  1062. * additional changes changes will have to be made to support
  1063. * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
  1064. * changed to support the new dev->raid_scsi_mode flag instead of
  1065. * leaching off of the dev->nondasd_support flag. Also in linit.c the
  1066. * function aac_detect will have to be modified where it sets up the
  1067. * max number of channels based on the aac->nondasd_support flag only.
  1068. */
  1069. if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
  1070. (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
  1071. dev->nondasd_support = 1;
  1072. dev->raid_scsi_mode = 1;
  1073. }
  1074. if (dev->raid_scsi_mode != 0)
  1075. printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
  1076. dev->name, dev->id);
  1077. if(nondasd != -1) {
  1078. dev->nondasd_support = (nondasd!=0);
  1079. }
  1080. if(dev->nondasd_support != 0){
  1081. printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
  1082. }
  1083. dev->dac_support = 0;
  1084. if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
  1085. printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
  1086. dev->dac_support = 1;
  1087. }
  1088. if(dacmode != -1) {
  1089. dev->dac_support = (dacmode!=0);
  1090. }
  1091. if(dev->dac_support != 0) {
  1092. if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
  1093. !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
  1094. printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
  1095. dev->name, dev->id);
  1096. } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
  1097. !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
  1098. printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
  1099. dev->name, dev->id);
  1100. dev->dac_support = 0;
  1101. } else {
  1102. printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
  1103. dev->name, dev->id);
  1104. rcode = -ENOMEM;
  1105. }
  1106. }
  1107. /*
  1108. * Deal with configuring for the individualized limits of each packet
  1109. * interface.
  1110. */
  1111. dev->a_ops.adapter_scsi = (dev->dac_support)
  1112. ? aac_scsi_64
  1113. : aac_scsi_32;
  1114. if (dev->raw_io_interface) {
  1115. dev->a_ops.adapter_bounds = (dev->raw_io_64)
  1116. ? aac_bounds_64
  1117. : aac_bounds_32;
  1118. dev->a_ops.adapter_read = aac_read_raw_io;
  1119. dev->a_ops.adapter_write = aac_write_raw_io;
  1120. } else {
  1121. dev->a_ops.adapter_bounds = aac_bounds_32;
  1122. dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
  1123. sizeof(struct aac_fibhdr) -
  1124. sizeof(struct aac_write) + sizeof(struct sgentry)) /
  1125. sizeof(struct sgentry);
  1126. if (dev->dac_support) {
  1127. dev->a_ops.adapter_read = aac_read_block64;
  1128. dev->a_ops.adapter_write = aac_write_block64;
  1129. /*
  1130. * 38 scatter gather elements
  1131. */
  1132. dev->scsi_host_ptr->sg_tablesize =
  1133. (dev->max_fib_size -
  1134. sizeof(struct aac_fibhdr) -
  1135. sizeof(struct aac_write64) +
  1136. sizeof(struct sgentry64)) /
  1137. sizeof(struct sgentry64);
  1138. } else {
  1139. dev->a_ops.adapter_read = aac_read_block;
  1140. dev->a_ops.adapter_write = aac_write_block;
  1141. }
  1142. dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  1143. if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
  1144. /*
  1145. * Worst case size that could cause sg overflow when
  1146. * we break up SG elements that are larger than 64KB.
  1147. * Would be nice if we could tell the SCSI layer what
  1148. * the maximum SG element size can be. Worst case is
  1149. * (sg_tablesize-1) 4KB elements with one 64KB
  1150. * element.
  1151. * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
  1152. */
  1153. dev->scsi_host_ptr->max_sectors =
  1154. (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
  1155. }
  1156. }
  1157. aac_fib_complete(fibptr);
  1158. aac_fib_free(fibptr);
  1159. return rcode;
  1160. }
  1161. static void io_callback(void *context, struct fib * fibptr)
  1162. {
  1163. struct aac_dev *dev;
  1164. struct aac_read_reply *readreply;
  1165. struct scsi_cmnd *scsicmd;
  1166. u32 cid;
  1167. scsicmd = (struct scsi_cmnd *) context;
  1168. if (!aac_valid_context(scsicmd, fibptr))
  1169. return;
  1170. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1171. cid = scmd_id(scsicmd);
  1172. if (nblank(dprintk(x))) {
  1173. u64 lba;
  1174. switch (scsicmd->cmnd[0]) {
  1175. case WRITE_6:
  1176. case READ_6:
  1177. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  1178. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1179. break;
  1180. case WRITE_16:
  1181. case READ_16:
  1182. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1183. ((u64)scsicmd->cmnd[3] << 48) |
  1184. ((u64)scsicmd->cmnd[4] << 40) |
  1185. ((u64)scsicmd->cmnd[5] << 32) |
  1186. ((u64)scsicmd->cmnd[6] << 24) |
  1187. (scsicmd->cmnd[7] << 16) |
  1188. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1189. break;
  1190. case WRITE_12:
  1191. case READ_12:
  1192. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1193. (scsicmd->cmnd[3] << 16) |
  1194. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1195. break;
  1196. default:
  1197. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1198. (scsicmd->cmnd[3] << 16) |
  1199. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1200. break;
  1201. }
  1202. printk(KERN_DEBUG
  1203. "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
  1204. smp_processor_id(), (unsigned long long)lba, jiffies);
  1205. }
  1206. BUG_ON(fibptr == NULL);
  1207. if(scsicmd->use_sg)
  1208. pci_unmap_sg(dev->pdev,
  1209. (struct scatterlist *)scsicmd->request_buffer,
  1210. scsicmd->use_sg,
  1211. scsicmd->sc_data_direction);
  1212. else if(scsicmd->request_bufflen)
  1213. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
  1214. scsicmd->request_bufflen,
  1215. scsicmd->sc_data_direction);
  1216. readreply = (struct aac_read_reply *)fib_data(fibptr);
  1217. if (le32_to_cpu(readreply->status) == ST_OK)
  1218. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1219. else {
  1220. #ifdef AAC_DETAILED_STATUS_INFO
  1221. printk(KERN_WARNING "io_callback: io failed, status = %d\n",
  1222. le32_to_cpu(readreply->status));
  1223. #endif
  1224. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1225. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1226. HARDWARE_ERROR,
  1227. SENCODE_INTERNAL_TARGET_FAILURE,
  1228. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1229. 0, 0);
  1230. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1231. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1232. ? sizeof(scsicmd->sense_buffer)
  1233. : sizeof(dev->fsa_dev[cid].sense_data));
  1234. }
  1235. aac_fib_complete(fibptr);
  1236. aac_fib_free(fibptr);
  1237. scsicmd->scsi_done(scsicmd);
  1238. }
  1239. static int aac_read(struct scsi_cmnd * scsicmd)
  1240. {
  1241. u64 lba;
  1242. u32 count;
  1243. int status;
  1244. struct aac_dev *dev;
  1245. struct fib * cmd_fibcontext;
  1246. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1247. /*
  1248. * Get block address and transfer length
  1249. */
  1250. switch (scsicmd->cmnd[0]) {
  1251. case READ_6:
  1252. dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
  1253. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  1254. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1255. count = scsicmd->cmnd[4];
  1256. if (count == 0)
  1257. count = 256;
  1258. break;
  1259. case READ_16:
  1260. dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
  1261. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1262. ((u64)scsicmd->cmnd[3] << 48) |
  1263. ((u64)scsicmd->cmnd[4] << 40) |
  1264. ((u64)scsicmd->cmnd[5] << 32) |
  1265. ((u64)scsicmd->cmnd[6] << 24) |
  1266. (scsicmd->cmnd[7] << 16) |
  1267. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1268. count = (scsicmd->cmnd[10] << 24) |
  1269. (scsicmd->cmnd[11] << 16) |
  1270. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  1271. break;
  1272. case READ_12:
  1273. dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
  1274. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1275. (scsicmd->cmnd[3] << 16) |
  1276. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1277. count = (scsicmd->cmnd[6] << 24) |
  1278. (scsicmd->cmnd[7] << 16) |
  1279. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1280. break;
  1281. default:
  1282. dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
  1283. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1284. (scsicmd->cmnd[3] << 16) |
  1285. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1286. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  1287. break;
  1288. }
  1289. dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
  1290. smp_processor_id(), (unsigned long long)lba, jiffies));
  1291. if (aac_adapter_bounds(dev,scsicmd,lba))
  1292. return 0;
  1293. /*
  1294. * Alocate and initialize a Fib
  1295. */
  1296. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1297. return -1;
  1298. }
  1299. status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
  1300. /*
  1301. * Check that the command queued to the controller
  1302. */
  1303. if (status == -EINPROGRESS) {
  1304. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1305. return 0;
  1306. }
  1307. printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
  1308. /*
  1309. * For some reason, the Fib didn't queue, return QUEUE_FULL
  1310. */
  1311. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  1312. scsicmd->scsi_done(scsicmd);
  1313. aac_fib_complete(cmd_fibcontext);
  1314. aac_fib_free(cmd_fibcontext);
  1315. return 0;
  1316. }
  1317. static int aac_write(struct scsi_cmnd * scsicmd)
  1318. {
  1319. u64 lba;
  1320. u32 count;
  1321. int status;
  1322. struct aac_dev *dev;
  1323. struct fib * cmd_fibcontext;
  1324. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1325. /*
  1326. * Get block address and transfer length
  1327. */
  1328. if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
  1329. {
  1330. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1331. count = scsicmd->cmnd[4];
  1332. if (count == 0)
  1333. count = 256;
  1334. } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
  1335. dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
  1336. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1337. ((u64)scsicmd->cmnd[3] << 48) |
  1338. ((u64)scsicmd->cmnd[4] << 40) |
  1339. ((u64)scsicmd->cmnd[5] << 32) |
  1340. ((u64)scsicmd->cmnd[6] << 24) |
  1341. (scsicmd->cmnd[7] << 16) |
  1342. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1343. count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
  1344. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  1345. } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
  1346. dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
  1347. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
  1348. | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1349. count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
  1350. | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1351. } else {
  1352. dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
  1353. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1354. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  1355. }
  1356. dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
  1357. smp_processor_id(), (unsigned long long)lba, jiffies));
  1358. if (aac_adapter_bounds(dev,scsicmd,lba))
  1359. return 0;
  1360. /*
  1361. * Allocate and initialize a Fib then setup a BlockWrite command
  1362. */
  1363. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1364. scsicmd->result = DID_ERROR << 16;
  1365. scsicmd->scsi_done(scsicmd);
  1366. return 0;
  1367. }
  1368. status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
  1369. /*
  1370. * Check that the command queued to the controller
  1371. */
  1372. if (status == -EINPROGRESS) {
  1373. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1374. return 0;
  1375. }
  1376. printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
  1377. /*
  1378. * For some reason, the Fib didn't queue, return QUEUE_FULL
  1379. */
  1380. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  1381. scsicmd->scsi_done(scsicmd);
  1382. aac_fib_complete(cmd_fibcontext);
  1383. aac_fib_free(cmd_fibcontext);
  1384. return 0;
  1385. }
  1386. static void synchronize_callback(void *context, struct fib *fibptr)
  1387. {
  1388. struct aac_synchronize_reply *synchronizereply;
  1389. struct scsi_cmnd *cmd;
  1390. cmd = context;
  1391. if (!aac_valid_context(cmd, fibptr))
  1392. return;
  1393. dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
  1394. smp_processor_id(), jiffies));
  1395. BUG_ON(fibptr == NULL);
  1396. synchronizereply = fib_data(fibptr);
  1397. if (le32_to_cpu(synchronizereply->status) == CT_OK)
  1398. cmd->result = DID_OK << 16 |
  1399. COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1400. else {
  1401. struct scsi_device *sdev = cmd->device;
  1402. struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
  1403. u32 cid = sdev_id(sdev);
  1404. printk(KERN_WARNING
  1405. "synchronize_callback: synchronize failed, status = %d\n",
  1406. le32_to_cpu(synchronizereply->status));
  1407. cmd->result = DID_OK << 16 |
  1408. COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1409. set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
  1410. HARDWARE_ERROR,
  1411. SENCODE_INTERNAL_TARGET_FAILURE,
  1412. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1413. 0, 0);
  1414. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1415. min(sizeof(dev->fsa_dev[cid].sense_data),
  1416. sizeof(cmd->sense_buffer)));
  1417. }
  1418. aac_fib_complete(fibptr);
  1419. aac_fib_free(fibptr);
  1420. cmd->scsi_done(cmd);
  1421. }
  1422. static int aac_synchronize(struct scsi_cmnd *scsicmd)
  1423. {
  1424. int status;
  1425. struct fib *cmd_fibcontext;
  1426. struct aac_synchronize *synchronizecmd;
  1427. struct scsi_cmnd *cmd;
  1428. struct scsi_device *sdev = scsicmd->device;
  1429. int active = 0;
  1430. struct aac_dev *aac;
  1431. unsigned long flags;
  1432. /*
  1433. * Wait for all outstanding queued commands to complete to this
  1434. * specific target (block).
  1435. */
  1436. spin_lock_irqsave(&sdev->list_lock, flags);
  1437. list_for_each_entry(cmd, &sdev->cmd_list, list)
  1438. if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
  1439. ++active;
  1440. break;
  1441. }
  1442. spin_unlock_irqrestore(&sdev->list_lock, flags);
  1443. /*
  1444. * Yield the processor (requeue for later)
  1445. */
  1446. if (active)
  1447. return SCSI_MLQUEUE_DEVICE_BUSY;
  1448. aac = (struct aac_dev *)scsicmd->device->host->hostdata;
  1449. if (aac->in_reset)
  1450. return SCSI_MLQUEUE_HOST_BUSY;
  1451. /*
  1452. * Allocate and initialize a Fib
  1453. */
  1454. if (!(cmd_fibcontext = aac_fib_alloc(aac)))
  1455. return SCSI_MLQUEUE_HOST_BUSY;
  1456. aac_fib_init(cmd_fibcontext);
  1457. synchronizecmd = fib_data(cmd_fibcontext);
  1458. synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
  1459. synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
  1460. synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
  1461. synchronizecmd->count =
  1462. cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
  1463. /*
  1464. * Now send the Fib to the adapter
  1465. */
  1466. status = aac_fib_send(ContainerCommand,
  1467. cmd_fibcontext,
  1468. sizeof(struct aac_synchronize),
  1469. FsaNormal,
  1470. 0, 1,
  1471. (fib_callback)synchronize_callback,
  1472. (void *)scsicmd);
  1473. /*
  1474. * Check that the command queued to the controller
  1475. */
  1476. if (status == -EINPROGRESS) {
  1477. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1478. return 0;
  1479. }
  1480. printk(KERN_WARNING
  1481. "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
  1482. aac_fib_complete(cmd_fibcontext);
  1483. aac_fib_free(cmd_fibcontext);
  1484. return SCSI_MLQUEUE_HOST_BUSY;
  1485. }
  1486. /**
  1487. * aac_scsi_cmd() - Process SCSI command
  1488. * @scsicmd: SCSI command block
  1489. *
  1490. * Emulate a SCSI command and queue the required request for the
  1491. * aacraid firmware.
  1492. */
  1493. int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
  1494. {
  1495. u32 cid = 0;
  1496. struct Scsi_Host *host = scsicmd->device->host;
  1497. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  1498. struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
  1499. if (fsa_dev_ptr == NULL)
  1500. return -1;
  1501. /*
  1502. * If the bus, id or lun is out of range, return fail
  1503. * Test does not apply to ID 16, the pseudo id for the controller
  1504. * itself.
  1505. */
  1506. if (scmd_id(scsicmd) != host->this_id) {
  1507. if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
  1508. if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
  1509. (scsicmd->device->lun != 0)) {
  1510. scsicmd->result = DID_NO_CONNECT << 16;
  1511. scsicmd->scsi_done(scsicmd);
  1512. return 0;
  1513. }
  1514. cid = scmd_id(scsicmd);
  1515. /*
  1516. * If the target container doesn't exist, it may have
  1517. * been newly created
  1518. */
  1519. if ((fsa_dev_ptr[cid].valid & 1) == 0) {
  1520. switch (scsicmd->cmnd[0]) {
  1521. case SERVICE_ACTION_IN:
  1522. if (!(dev->raw_io_interface) ||
  1523. !(dev->raw_io_64) ||
  1524. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1525. break;
  1526. case INQUIRY:
  1527. case READ_CAPACITY:
  1528. case TEST_UNIT_READY:
  1529. if (dev->in_reset)
  1530. return -1;
  1531. return _aac_probe_container(scsicmd,
  1532. aac_probe_container_callback2);
  1533. default:
  1534. break;
  1535. }
  1536. }
  1537. } else { /* check for physical non-dasd devices */
  1538. if ((dev->nondasd_support == 1) || expose_physicals) {
  1539. if (dev->in_reset)
  1540. return -1;
  1541. return aac_send_srb_fib(scsicmd);
  1542. } else {
  1543. scsicmd->result = DID_NO_CONNECT << 16;
  1544. scsicmd->scsi_done(scsicmd);
  1545. return 0;
  1546. }
  1547. }
  1548. }
  1549. /*
  1550. * else Command for the controller itself
  1551. */
  1552. else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
  1553. (scsicmd->cmnd[0] != TEST_UNIT_READY))
  1554. {
  1555. dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
  1556. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1557. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1558. ILLEGAL_REQUEST,
  1559. SENCODE_INVALID_COMMAND,
  1560. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1561. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1562. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1563. ? sizeof(scsicmd->sense_buffer)
  1564. : sizeof(dev->fsa_dev[cid].sense_data));
  1565. scsicmd->scsi_done(scsicmd);
  1566. return 0;
  1567. }
  1568. /* Handle commands here that don't really require going out to the adapter */
  1569. switch (scsicmd->cmnd[0]) {
  1570. case INQUIRY:
  1571. {
  1572. struct inquiry_data inq_data;
  1573. dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
  1574. memset(&inq_data, 0, sizeof (struct inquiry_data));
  1575. inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
  1576. inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
  1577. inq_data.inqd_len = 31;
  1578. /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  1579. inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
  1580. /*
  1581. * Set the Vendor, Product, and Revision Level
  1582. * see: <vendor>.c i.e. aac.c
  1583. */
  1584. if (scmd_id(scsicmd) == host->this_id) {
  1585. setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
  1586. inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
  1587. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1588. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1589. scsicmd->scsi_done(scsicmd);
  1590. return 0;
  1591. }
  1592. if (dev->in_reset)
  1593. return -1;
  1594. setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
  1595. inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
  1596. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1597. return aac_get_container_name(scsicmd);
  1598. }
  1599. case SERVICE_ACTION_IN:
  1600. if (!(dev->raw_io_interface) ||
  1601. !(dev->raw_io_64) ||
  1602. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1603. break;
  1604. {
  1605. u64 capacity;
  1606. char cp[13];
  1607. dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
  1608. capacity = fsa_dev_ptr[cid].size - 1;
  1609. cp[0] = (capacity >> 56) & 0xff;
  1610. cp[1] = (capacity >> 48) & 0xff;
  1611. cp[2] = (capacity >> 40) & 0xff;
  1612. cp[3] = (capacity >> 32) & 0xff;
  1613. cp[4] = (capacity >> 24) & 0xff;
  1614. cp[5] = (capacity >> 16) & 0xff;
  1615. cp[6] = (capacity >> 8) & 0xff;
  1616. cp[7] = (capacity >> 0) & 0xff;
  1617. cp[8] = 0;
  1618. cp[9] = 0;
  1619. cp[10] = 2;
  1620. cp[11] = 0;
  1621. cp[12] = 0;
  1622. aac_internal_transfer(scsicmd, cp, 0,
  1623. min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
  1624. if (sizeof(cp) < scsicmd->cmnd[13]) {
  1625. unsigned int len, offset = sizeof(cp);
  1626. memset(cp, 0, offset);
  1627. do {
  1628. len = min_t(size_t, scsicmd->cmnd[13] - offset,
  1629. sizeof(cp));
  1630. aac_internal_transfer(scsicmd, cp, offset, len);
  1631. } while ((offset += len) < scsicmd->cmnd[13]);
  1632. }
  1633. /* Do not cache partition table for arrays */
  1634. scsicmd->device->removable = 1;
  1635. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1636. scsicmd->scsi_done(scsicmd);
  1637. return 0;
  1638. }
  1639. case READ_CAPACITY:
  1640. {
  1641. u32 capacity;
  1642. char cp[8];
  1643. dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
  1644. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  1645. capacity = fsa_dev_ptr[cid].size - 1;
  1646. else
  1647. capacity = (u32)-1;
  1648. cp[0] = (capacity >> 24) & 0xff;
  1649. cp[1] = (capacity >> 16) & 0xff;
  1650. cp[2] = (capacity >> 8) & 0xff;
  1651. cp[3] = (capacity >> 0) & 0xff;
  1652. cp[4] = 0;
  1653. cp[5] = 0;
  1654. cp[6] = 2;
  1655. cp[7] = 0;
  1656. aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
  1657. /* Do not cache partition table for arrays */
  1658. scsicmd->device->removable = 1;
  1659. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1660. scsicmd->scsi_done(scsicmd);
  1661. return 0;
  1662. }
  1663. case MODE_SENSE:
  1664. {
  1665. char mode_buf[4];
  1666. dprintk((KERN_DEBUG "MODE SENSE command.\n"));
  1667. mode_buf[0] = 3; /* Mode data length */
  1668. mode_buf[1] = 0; /* Medium type - default */
  1669. mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1670. mode_buf[3] = 0; /* Block descriptor length */
  1671. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1672. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1673. scsicmd->scsi_done(scsicmd);
  1674. return 0;
  1675. }
  1676. case MODE_SENSE_10:
  1677. {
  1678. char mode_buf[8];
  1679. dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
  1680. mode_buf[0] = 0; /* Mode data length (MSB) */
  1681. mode_buf[1] = 6; /* Mode data length (LSB) */
  1682. mode_buf[2] = 0; /* Medium type - default */
  1683. mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1684. mode_buf[4] = 0; /* reserved */
  1685. mode_buf[5] = 0; /* reserved */
  1686. mode_buf[6] = 0; /* Block descriptor length (MSB) */
  1687. mode_buf[7] = 0; /* Block descriptor length (LSB) */
  1688. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1689. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1690. scsicmd->scsi_done(scsicmd);
  1691. return 0;
  1692. }
  1693. case REQUEST_SENSE:
  1694. dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
  1695. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
  1696. memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
  1697. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1698. scsicmd->scsi_done(scsicmd);
  1699. return 0;
  1700. case ALLOW_MEDIUM_REMOVAL:
  1701. dprintk((KERN_DEBUG "LOCK command.\n"));
  1702. if (scsicmd->cmnd[4])
  1703. fsa_dev_ptr[cid].locked = 1;
  1704. else
  1705. fsa_dev_ptr[cid].locked = 0;
  1706. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1707. scsicmd->scsi_done(scsicmd);
  1708. return 0;
  1709. /*
  1710. * These commands are all No-Ops
  1711. */
  1712. case TEST_UNIT_READY:
  1713. case RESERVE:
  1714. case RELEASE:
  1715. case REZERO_UNIT:
  1716. case REASSIGN_BLOCKS:
  1717. case SEEK_10:
  1718. case START_STOP:
  1719. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1720. scsicmd->scsi_done(scsicmd);
  1721. return 0;
  1722. }
  1723. switch (scsicmd->cmnd[0])
  1724. {
  1725. case READ_6:
  1726. case READ_10:
  1727. case READ_12:
  1728. case READ_16:
  1729. if (dev->in_reset)
  1730. return -1;
  1731. /*
  1732. * Hack to keep track of ordinal number of the device that
  1733. * corresponds to a container. Needed to convert
  1734. * containers to /dev/sd device names
  1735. */
  1736. if (scsicmd->request->rq_disk)
  1737. strlcpy(fsa_dev_ptr[cid].devname,
  1738. scsicmd->request->rq_disk->disk_name,
  1739. min(sizeof(fsa_dev_ptr[cid].devname),
  1740. sizeof(scsicmd->request->rq_disk->disk_name) + 1));
  1741. return aac_read(scsicmd);
  1742. case WRITE_6:
  1743. case WRITE_10:
  1744. case WRITE_12:
  1745. case WRITE_16:
  1746. if (dev->in_reset)
  1747. return -1;
  1748. return aac_write(scsicmd);
  1749. case SYNCHRONIZE_CACHE:
  1750. /* Issue FIB to tell Firmware to flush it's cache */
  1751. return aac_synchronize(scsicmd);
  1752. default:
  1753. /*
  1754. * Unhandled commands
  1755. */
  1756. dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
  1757. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1758. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1759. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  1760. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1761. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1762. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1763. ? sizeof(scsicmd->sense_buffer)
  1764. : sizeof(dev->fsa_dev[cid].sense_data));
  1765. scsicmd->scsi_done(scsicmd);
  1766. return 0;
  1767. }
  1768. }
  1769. static int query_disk(struct aac_dev *dev, void __user *arg)
  1770. {
  1771. struct aac_query_disk qd;
  1772. struct fsa_dev_info *fsa_dev_ptr;
  1773. fsa_dev_ptr = dev->fsa_dev;
  1774. if (!fsa_dev_ptr)
  1775. return -EBUSY;
  1776. if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
  1777. return -EFAULT;
  1778. if (qd.cnum == -1)
  1779. qd.cnum = qd.id;
  1780. else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
  1781. {
  1782. if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
  1783. return -EINVAL;
  1784. qd.instance = dev->scsi_host_ptr->host_no;
  1785. qd.bus = 0;
  1786. qd.id = CONTAINER_TO_ID(qd.cnum);
  1787. qd.lun = CONTAINER_TO_LUN(qd.cnum);
  1788. }
  1789. else return -EINVAL;
  1790. qd.valid = fsa_dev_ptr[qd.cnum].valid;
  1791. qd.locked = fsa_dev_ptr[qd.cnum].locked;
  1792. qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
  1793. if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
  1794. qd.unmapped = 1;
  1795. else
  1796. qd.unmapped = 0;
  1797. strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
  1798. min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
  1799. if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
  1800. return -EFAULT;
  1801. return 0;
  1802. }
  1803. static int force_delete_disk(struct aac_dev *dev, void __user *arg)
  1804. {
  1805. struct aac_delete_disk dd;
  1806. struct fsa_dev_info *fsa_dev_ptr;
  1807. fsa_dev_ptr = dev->fsa_dev;
  1808. if (!fsa_dev_ptr)
  1809. return -EBUSY;
  1810. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1811. return -EFAULT;
  1812. if (dd.cnum >= dev->maximum_num_containers)
  1813. return -EINVAL;
  1814. /*
  1815. * Mark this container as being deleted.
  1816. */
  1817. fsa_dev_ptr[dd.cnum].deleted = 1;
  1818. /*
  1819. * Mark the container as no longer valid
  1820. */
  1821. fsa_dev_ptr[dd.cnum].valid = 0;
  1822. return 0;
  1823. }
  1824. static int delete_disk(struct aac_dev *dev, void __user *arg)
  1825. {
  1826. struct aac_delete_disk dd;
  1827. struct fsa_dev_info *fsa_dev_ptr;
  1828. fsa_dev_ptr = dev->fsa_dev;
  1829. if (!fsa_dev_ptr)
  1830. return -EBUSY;
  1831. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1832. return -EFAULT;
  1833. if (dd.cnum >= dev->maximum_num_containers)
  1834. return -EINVAL;
  1835. /*
  1836. * If the container is locked, it can not be deleted by the API.
  1837. */
  1838. if (fsa_dev_ptr[dd.cnum].locked)
  1839. return -EBUSY;
  1840. else {
  1841. /*
  1842. * Mark the container as no longer being valid.
  1843. */
  1844. fsa_dev_ptr[dd.cnum].valid = 0;
  1845. fsa_dev_ptr[dd.cnum].devname[0] = '\0';
  1846. return 0;
  1847. }
  1848. }
  1849. int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
  1850. {
  1851. switch (cmd) {
  1852. case FSACTL_QUERY_DISK:
  1853. return query_disk(dev, arg);
  1854. case FSACTL_DELETE_DISK:
  1855. return delete_disk(dev, arg);
  1856. case FSACTL_FORCE_DELETE_DISK:
  1857. return force_delete_disk(dev, arg);
  1858. case FSACTL_GET_CONTAINERS:
  1859. return aac_get_containers(dev);
  1860. default:
  1861. return -ENOTTY;
  1862. }
  1863. }
  1864. /**
  1865. *
  1866. * aac_srb_callback
  1867. * @context: the context set in the fib - here it is scsi cmd
  1868. * @fibptr: pointer to the fib
  1869. *
  1870. * Handles the completion of a scsi command to a non dasd device
  1871. *
  1872. */
  1873. static void aac_srb_callback(void *context, struct fib * fibptr)
  1874. {
  1875. struct aac_dev *dev;
  1876. struct aac_srb_reply *srbreply;
  1877. struct scsi_cmnd *scsicmd;
  1878. scsicmd = (struct scsi_cmnd *) context;
  1879. if (!aac_valid_context(scsicmd, fibptr))
  1880. return;
  1881. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1882. BUG_ON(fibptr == NULL);
  1883. srbreply = (struct aac_srb_reply *) fib_data(fibptr);
  1884. scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
  1885. /*
  1886. * Calculate resid for sg
  1887. */
  1888. scsicmd->resid = scsicmd->request_bufflen -
  1889. le32_to_cpu(srbreply->data_xfer_length);
  1890. if(scsicmd->use_sg)
  1891. pci_unmap_sg(dev->pdev,
  1892. (struct scatterlist *)scsicmd->request_buffer,
  1893. scsicmd->use_sg,
  1894. scsicmd->sc_data_direction);
  1895. else if(scsicmd->request_bufflen)
  1896. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
  1897. scsicmd->sc_data_direction);
  1898. /*
  1899. * First check the fib status
  1900. */
  1901. if (le32_to_cpu(srbreply->status) != ST_OK){
  1902. int len;
  1903. printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
  1904. len = (le32_to_cpu(srbreply->sense_data_size) >
  1905. sizeof(scsicmd->sense_buffer)) ?
  1906. sizeof(scsicmd->sense_buffer) :
  1907. le32_to_cpu(srbreply->sense_data_size);
  1908. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1909. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1910. }
  1911. /*
  1912. * Next check the srb status
  1913. */
  1914. switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
  1915. case SRB_STATUS_ERROR_RECOVERY:
  1916. case SRB_STATUS_PENDING:
  1917. case SRB_STATUS_SUCCESS:
  1918. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1919. break;
  1920. case SRB_STATUS_DATA_OVERRUN:
  1921. switch(scsicmd->cmnd[0]){
  1922. case READ_6:
  1923. case WRITE_6:
  1924. case READ_10:
  1925. case WRITE_10:
  1926. case READ_12:
  1927. case WRITE_12:
  1928. case READ_16:
  1929. case WRITE_16:
  1930. if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
  1931. printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
  1932. } else {
  1933. printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
  1934. }
  1935. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1936. break;
  1937. case INQUIRY: {
  1938. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1939. break;
  1940. }
  1941. default:
  1942. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1943. break;
  1944. }
  1945. break;
  1946. case SRB_STATUS_ABORTED:
  1947. scsicmd->result = DID_ABORT << 16 | ABORT << 8;
  1948. break;
  1949. case SRB_STATUS_ABORT_FAILED:
  1950. // Not sure about this one - but assuming the hba was trying to abort for some reason
  1951. scsicmd->result = DID_ERROR << 16 | ABORT << 8;
  1952. break;
  1953. case SRB_STATUS_PARITY_ERROR:
  1954. scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
  1955. break;
  1956. case SRB_STATUS_NO_DEVICE:
  1957. case SRB_STATUS_INVALID_PATH_ID:
  1958. case SRB_STATUS_INVALID_TARGET_ID:
  1959. case SRB_STATUS_INVALID_LUN:
  1960. case SRB_STATUS_SELECTION_TIMEOUT:
  1961. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1962. break;
  1963. case SRB_STATUS_COMMAND_TIMEOUT:
  1964. case SRB_STATUS_TIMEOUT:
  1965. scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
  1966. break;
  1967. case SRB_STATUS_BUSY:
  1968. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1969. break;
  1970. case SRB_STATUS_BUS_RESET:
  1971. scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
  1972. break;
  1973. case SRB_STATUS_MESSAGE_REJECTED:
  1974. scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
  1975. break;
  1976. case SRB_STATUS_REQUEST_FLUSHED:
  1977. case SRB_STATUS_ERROR:
  1978. case SRB_STATUS_INVALID_REQUEST:
  1979. case SRB_STATUS_REQUEST_SENSE_FAILED:
  1980. case SRB_STATUS_NO_HBA:
  1981. case SRB_STATUS_UNEXPECTED_BUS_FREE:
  1982. case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
  1983. case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
  1984. case SRB_STATUS_DELAYED_RETRY:
  1985. case SRB_STATUS_BAD_FUNCTION:
  1986. case SRB_STATUS_NOT_STARTED:
  1987. case SRB_STATUS_NOT_IN_USE:
  1988. case SRB_STATUS_FORCE_ABORT:
  1989. case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
  1990. default:
  1991. #ifdef AAC_DETAILED_STATUS_INFO
  1992. printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
  1993. le32_to_cpu(srbreply->srb_status) & 0x3F,
  1994. aac_get_status_string(
  1995. le32_to_cpu(srbreply->srb_status) & 0x3F),
  1996. scsicmd->cmnd[0],
  1997. le32_to_cpu(srbreply->scsi_status));
  1998. #endif
  1999. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  2000. break;
  2001. }
  2002. if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
  2003. int len;
  2004. scsicmd->result |= SAM_STAT_CHECK_CONDITION;
  2005. len = (le32_to_cpu(srbreply->sense_data_size) >
  2006. sizeof(scsicmd->sense_buffer)) ?
  2007. sizeof(scsicmd->sense_buffer) :
  2008. le32_to_cpu(srbreply->sense_data_size);
  2009. #ifdef AAC_DETAILED_STATUS_INFO
  2010. printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
  2011. le32_to_cpu(srbreply->status), len);
  2012. #endif
  2013. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  2014. }
  2015. /*
  2016. * OR in the scsi status (already shifted up a bit)
  2017. */
  2018. scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
  2019. aac_fib_complete(fibptr);
  2020. aac_fib_free(fibptr);
  2021. scsicmd->scsi_done(scsicmd);
  2022. }
  2023. /**
  2024. *
  2025. * aac_send_scb_fib
  2026. * @scsicmd: the scsi command block
  2027. *
  2028. * This routine will form a FIB and fill in the aac_srb from the
  2029. * scsicmd passed in.
  2030. */
  2031. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
  2032. {
  2033. struct fib* cmd_fibcontext;
  2034. struct aac_dev* dev;
  2035. int status;
  2036. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2037. if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
  2038. scsicmd->device->lun > 7) {
  2039. scsicmd->result = DID_NO_CONNECT << 16;
  2040. scsicmd->scsi_done(scsicmd);
  2041. return 0;
  2042. }
  2043. /*
  2044. * Allocate and initialize a Fib then setup a BlockWrite command
  2045. */
  2046. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  2047. return -1;
  2048. }
  2049. status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
  2050. /*
  2051. * Check that the command queued to the controller
  2052. */
  2053. if (status == -EINPROGRESS) {
  2054. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  2055. return 0;
  2056. }
  2057. printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
  2058. aac_fib_complete(cmd_fibcontext);
  2059. aac_fib_free(cmd_fibcontext);
  2060. return -1;
  2061. }
  2062. static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
  2063. {
  2064. struct aac_dev *dev;
  2065. unsigned long byte_count = 0;
  2066. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2067. // Get rid of old data
  2068. psg->count = 0;
  2069. psg->sg[0].addr = 0;
  2070. psg->sg[0].count = 0;
  2071. if (scsicmd->use_sg) {
  2072. struct scatterlist *sg;
  2073. int i;
  2074. int sg_count;
  2075. sg = (struct scatterlist *) scsicmd->request_buffer;
  2076. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2077. scsicmd->sc_data_direction);
  2078. psg->count = cpu_to_le32(sg_count);
  2079. for (i = 0; i < sg_count; i++) {
  2080. psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
  2081. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  2082. byte_count += sg_dma_len(sg);
  2083. sg++;
  2084. }
  2085. /* hba wants the size to be exact */
  2086. if(byte_count > scsicmd->request_bufflen){
  2087. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2088. (byte_count - scsicmd->request_bufflen);
  2089. psg->sg[i-1].count = cpu_to_le32(temp);
  2090. byte_count = scsicmd->request_bufflen;
  2091. }
  2092. /* Check for command underflow */
  2093. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2094. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2095. byte_count, scsicmd->underflow);
  2096. }
  2097. }
  2098. else if(scsicmd->request_bufflen) {
  2099. u32 addr;
  2100. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2101. scsicmd->request_buffer,
  2102. scsicmd->request_bufflen,
  2103. scsicmd->sc_data_direction);
  2104. addr = scsicmd->SCp.dma_handle;
  2105. psg->count = cpu_to_le32(1);
  2106. psg->sg[0].addr = cpu_to_le32(addr);
  2107. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2108. byte_count = scsicmd->request_bufflen;
  2109. }
  2110. return byte_count;
  2111. }
  2112. static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
  2113. {
  2114. struct aac_dev *dev;
  2115. unsigned long byte_count = 0;
  2116. u64 addr;
  2117. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2118. // Get rid of old data
  2119. psg->count = 0;
  2120. psg->sg[0].addr[0] = 0;
  2121. psg->sg[0].addr[1] = 0;
  2122. psg->sg[0].count = 0;
  2123. if (scsicmd->use_sg) {
  2124. struct scatterlist *sg;
  2125. int i;
  2126. int sg_count;
  2127. sg = (struct scatterlist *) scsicmd->request_buffer;
  2128. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2129. scsicmd->sc_data_direction);
  2130. for (i = 0; i < sg_count; i++) {
  2131. int count = sg_dma_len(sg);
  2132. addr = sg_dma_address(sg);
  2133. psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2134. psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
  2135. psg->sg[i].count = cpu_to_le32(count);
  2136. byte_count += count;
  2137. sg++;
  2138. }
  2139. psg->count = cpu_to_le32(sg_count);
  2140. /* hba wants the size to be exact */
  2141. if(byte_count > scsicmd->request_bufflen){
  2142. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2143. (byte_count - scsicmd->request_bufflen);
  2144. psg->sg[i-1].count = cpu_to_le32(temp);
  2145. byte_count = scsicmd->request_bufflen;
  2146. }
  2147. /* Check for command underflow */
  2148. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2149. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2150. byte_count, scsicmd->underflow);
  2151. }
  2152. }
  2153. else if(scsicmd->request_bufflen) {
  2154. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2155. scsicmd->request_buffer,
  2156. scsicmd->request_bufflen,
  2157. scsicmd->sc_data_direction);
  2158. addr = scsicmd->SCp.dma_handle;
  2159. psg->count = cpu_to_le32(1);
  2160. psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2161. psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
  2162. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2163. byte_count = scsicmd->request_bufflen;
  2164. }
  2165. return byte_count;
  2166. }
  2167. static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
  2168. {
  2169. struct Scsi_Host *host = scsicmd->device->host;
  2170. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  2171. unsigned long byte_count = 0;
  2172. // Get rid of old data
  2173. psg->count = 0;
  2174. psg->sg[0].next = 0;
  2175. psg->sg[0].prev = 0;
  2176. psg->sg[0].addr[0] = 0;
  2177. psg->sg[0].addr[1] = 0;
  2178. psg->sg[0].count = 0;
  2179. psg->sg[0].flags = 0;
  2180. if (scsicmd->use_sg) {
  2181. struct scatterlist *sg;
  2182. int i;
  2183. int sg_count;
  2184. sg = (struct scatterlist *) scsicmd->request_buffer;
  2185. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2186. scsicmd->sc_data_direction);
  2187. for (i = 0; i < sg_count; i++) {
  2188. int count = sg_dma_len(sg);
  2189. u64 addr = sg_dma_address(sg);
  2190. psg->sg[i].next = 0;
  2191. psg->sg[i].prev = 0;
  2192. psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
  2193. psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2194. psg->sg[i].count = cpu_to_le32(count);
  2195. psg->sg[i].flags = 0;
  2196. byte_count += count;
  2197. sg++;
  2198. }
  2199. psg->count = cpu_to_le32(sg_count);
  2200. /* hba wants the size to be exact */
  2201. if(byte_count > scsicmd->request_bufflen){
  2202. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2203. (byte_count - scsicmd->request_bufflen);
  2204. psg->sg[i-1].count = cpu_to_le32(temp);
  2205. byte_count = scsicmd->request_bufflen;
  2206. }
  2207. /* Check for command underflow */
  2208. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2209. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2210. byte_count, scsicmd->underflow);
  2211. }
  2212. }
  2213. else if(scsicmd->request_bufflen) {
  2214. int count;
  2215. u64 addr;
  2216. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2217. scsicmd->request_buffer,
  2218. scsicmd->request_bufflen,
  2219. scsicmd->sc_data_direction);
  2220. addr = scsicmd->SCp.dma_handle;
  2221. count = scsicmd->request_bufflen;
  2222. psg->count = cpu_to_le32(1);
  2223. psg->sg[0].next = 0;
  2224. psg->sg[0].prev = 0;
  2225. psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
  2226. psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2227. psg->sg[0].count = cpu_to_le32(count);
  2228. psg->sg[0].flags = 0;
  2229. byte_count = scsicmd->request_bufflen;
  2230. }
  2231. return byte_count;
  2232. }
  2233. #ifdef AAC_DETAILED_STATUS_INFO
  2234. struct aac_srb_status_info {
  2235. u32 status;
  2236. char *str;
  2237. };
  2238. static struct aac_srb_status_info srb_status_info[] = {
  2239. { SRB_STATUS_PENDING, "Pending Status"},
  2240. { SRB_STATUS_SUCCESS, "Success"},
  2241. { SRB_STATUS_ABORTED, "Aborted Command"},
  2242. { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
  2243. { SRB_STATUS_ERROR, "Error Event"},
  2244. { SRB_STATUS_BUSY, "Device Busy"},
  2245. { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
  2246. { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
  2247. { SRB_STATUS_NO_DEVICE, "No Device"},
  2248. { SRB_STATUS_TIMEOUT, "Timeout"},
  2249. { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
  2250. { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
  2251. { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
  2252. { SRB_STATUS_BUS_RESET, "Bus Reset"},
  2253. { SRB_STATUS_PARITY_ERROR, "Parity Error"},
  2254. { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
  2255. { SRB_STATUS_NO_HBA, "No HBA"},
  2256. { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
  2257. { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
  2258. { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
  2259. { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
  2260. { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
  2261. { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
  2262. { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
  2263. { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
  2264. { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
  2265. { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
  2266. { SRB_STATUS_NOT_STARTED, "Not Started"},
  2267. { SRB_STATUS_NOT_IN_USE, "Not In Use"},
  2268. { SRB_STATUS_FORCE_ABORT, "Force Abort"},
  2269. { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
  2270. { 0xff, "Unknown Error"}
  2271. };
  2272. char *aac_get_status_string(u32 status)
  2273. {
  2274. int i;
  2275. for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
  2276. if (srb_status_info[i].status == status)
  2277. return srb_status_info[i].str;
  2278. return "Bad Status Code";
  2279. }
  2280. #endif