aachba.c 75 KB

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