aachba.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
  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(1);
  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)
  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 = 0;
  800. writecmd->bpTotal = 0;
  801. writecmd->bpComplete = 0;
  802. aac_build_sgraw(cmd, &writecmd->sg);
  803. fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
  804. BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
  805. /*
  806. * Now send the Fib to the adapter
  807. */
  808. return aac_fib_send(ContainerRawIo,
  809. fib,
  810. fibsize,
  811. FsaNormal,
  812. 0, 1,
  813. (fib_callback) io_callback,
  814. (void *) cmd);
  815. }
  816. static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  817. {
  818. u16 fibsize;
  819. struct aac_write64 *writecmd;
  820. aac_fib_init(fib);
  821. writecmd = (struct aac_write64 *) fib_data(fib);
  822. writecmd->command = cpu_to_le32(VM_CtHostWrite64);
  823. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  824. writecmd->sector_count = cpu_to_le16(count);
  825. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  826. writecmd->pad = 0;
  827. writecmd->flags = 0;
  828. aac_build_sg64(cmd, &writecmd->sg);
  829. fibsize = sizeof(struct aac_write64) +
  830. ((le32_to_cpu(writecmd->sg.count) - 1) *
  831. sizeof (struct sgentry64));
  832. BUG_ON (fibsize > (fib->dev->max_fib_size -
  833. sizeof(struct aac_fibhdr)));
  834. /*
  835. * Now send the Fib to the adapter
  836. */
  837. return aac_fib_send(ContainerCommand64,
  838. fib,
  839. fibsize,
  840. FsaNormal,
  841. 0, 1,
  842. (fib_callback) io_callback,
  843. (void *) cmd);
  844. }
  845. static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  846. {
  847. u16 fibsize;
  848. struct aac_write *writecmd;
  849. aac_fib_init(fib);
  850. writecmd = (struct aac_write *) fib_data(fib);
  851. writecmd->command = cpu_to_le32(VM_CtBlockWrite);
  852. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  853. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  854. writecmd->count = cpu_to_le32(count * 512);
  855. writecmd->sg.count = cpu_to_le32(1);
  856. /* ->stable is not used - it did mean which type of write */
  857. aac_build_sg(cmd, &writecmd->sg);
  858. fibsize = sizeof(struct aac_write) +
  859. ((le32_to_cpu(writecmd->sg.count) - 1) *
  860. sizeof (struct sgentry));
  861. BUG_ON (fibsize > (fib->dev->max_fib_size -
  862. sizeof(struct aac_fibhdr)));
  863. /*
  864. * Now send the Fib to the adapter
  865. */
  866. return aac_fib_send(ContainerCommand,
  867. fib,
  868. fibsize,
  869. FsaNormal,
  870. 0, 1,
  871. (fib_callback) io_callback,
  872. (void *) cmd);
  873. }
  874. static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
  875. {
  876. struct aac_srb * srbcmd;
  877. u32 flag;
  878. u32 timeout;
  879. aac_fib_init(fib);
  880. switch(cmd->sc_data_direction){
  881. case DMA_TO_DEVICE:
  882. flag = SRB_DataOut;
  883. break;
  884. case DMA_BIDIRECTIONAL:
  885. flag = SRB_DataIn | SRB_DataOut;
  886. break;
  887. case DMA_FROM_DEVICE:
  888. flag = SRB_DataIn;
  889. break;
  890. case DMA_NONE:
  891. default: /* shuts up some versions of gcc */
  892. flag = SRB_NoDataXfer;
  893. break;
  894. }
  895. srbcmd = (struct aac_srb*) fib_data(fib);
  896. srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
  897. srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
  898. srbcmd->id = cpu_to_le32(scmd_id(cmd));
  899. srbcmd->lun = cpu_to_le32(cmd->device->lun);
  900. srbcmd->flags = cpu_to_le32(flag);
  901. timeout = cmd->timeout_per_command/HZ;
  902. if (timeout == 0)
  903. timeout = 1;
  904. srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
  905. srbcmd->retry_limit = 0; /* Obsolete parameter */
  906. srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
  907. return srbcmd;
  908. }
  909. static void aac_srb_callback(void *context, struct fib * fibptr);
  910. static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
  911. {
  912. u16 fibsize;
  913. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  914. aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
  915. srbcmd->count = cpu_to_le32(cmd->request_bufflen);
  916. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  917. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  918. /*
  919. * Build Scatter/Gather list
  920. */
  921. fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
  922. ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
  923. sizeof (struct sgentry64));
  924. BUG_ON (fibsize > (fib->dev->max_fib_size -
  925. sizeof(struct aac_fibhdr)));
  926. /*
  927. * Now send the Fib to the adapter
  928. */
  929. return aac_fib_send(ScsiPortCommand64, fib,
  930. fibsize, FsaNormal, 0, 1,
  931. (fib_callback) aac_srb_callback,
  932. (void *) cmd);
  933. }
  934. static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
  935. {
  936. u16 fibsize;
  937. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  938. aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
  939. srbcmd->count = cpu_to_le32(cmd->request_bufflen);
  940. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  941. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  942. /*
  943. * Build Scatter/Gather list
  944. */
  945. fibsize = sizeof (struct aac_srb) +
  946. (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
  947. sizeof (struct sgentry));
  948. BUG_ON (fibsize > (fib->dev->max_fib_size -
  949. sizeof(struct aac_fibhdr)));
  950. /*
  951. * Now send the Fib to the adapter
  952. */
  953. return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
  954. (fib_callback) aac_srb_callback, (void *) cmd);
  955. }
  956. int aac_get_adapter_info(struct aac_dev* dev)
  957. {
  958. struct fib* fibptr;
  959. int rcode;
  960. u32 tmp;
  961. struct aac_adapter_info *info;
  962. struct aac_bus_info *command;
  963. struct aac_bus_info_response *bus_info;
  964. if (!(fibptr = aac_fib_alloc(dev)))
  965. return -ENOMEM;
  966. aac_fib_init(fibptr);
  967. info = (struct aac_adapter_info *) fib_data(fibptr);
  968. memset(info,0,sizeof(*info));
  969. rcode = aac_fib_send(RequestAdapterInfo,
  970. fibptr,
  971. sizeof(*info),
  972. FsaNormal,
  973. -1, 1, /* First `interrupt' command uses special wait */
  974. NULL,
  975. NULL);
  976. if (rcode < 0) {
  977. aac_fib_complete(fibptr);
  978. aac_fib_free(fibptr);
  979. return rcode;
  980. }
  981. memcpy(&dev->adapter_info, info, sizeof(*info));
  982. if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
  983. struct aac_supplement_adapter_info * info;
  984. aac_fib_init(fibptr);
  985. info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
  986. memset(info,0,sizeof(*info));
  987. rcode = aac_fib_send(RequestSupplementAdapterInfo,
  988. fibptr,
  989. sizeof(*info),
  990. FsaNormal,
  991. 1, 1,
  992. NULL,
  993. NULL);
  994. if (rcode >= 0)
  995. memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
  996. }
  997. /*
  998. * GetBusInfo
  999. */
  1000. aac_fib_init(fibptr);
  1001. bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
  1002. memset(bus_info, 0, sizeof(*bus_info));
  1003. command = (struct aac_bus_info *)bus_info;
  1004. command->Command = cpu_to_le32(VM_Ioctl);
  1005. command->ObjType = cpu_to_le32(FT_DRIVE);
  1006. command->MethodId = cpu_to_le32(1);
  1007. command->CtlCmd = cpu_to_le32(GetBusInfo);
  1008. rcode = aac_fib_send(ContainerCommand,
  1009. fibptr,
  1010. sizeof (*bus_info),
  1011. FsaNormal,
  1012. 1, 1,
  1013. NULL, NULL);
  1014. if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
  1015. dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
  1016. dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
  1017. }
  1018. if (!dev->in_reset) {
  1019. tmp = le32_to_cpu(dev->adapter_info.kernelrev);
  1020. printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
  1021. dev->name,
  1022. dev->id,
  1023. tmp>>24,
  1024. (tmp>>16)&0xff,
  1025. tmp&0xff,
  1026. le32_to_cpu(dev->adapter_info.kernelbuild),
  1027. (int)sizeof(dev->supplement_adapter_info.BuildDate),
  1028. dev->supplement_adapter_info.BuildDate);
  1029. tmp = le32_to_cpu(dev->adapter_info.monitorrev);
  1030. printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
  1031. dev->name, dev->id,
  1032. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1033. le32_to_cpu(dev->adapter_info.monitorbuild));
  1034. tmp = le32_to_cpu(dev->adapter_info.biosrev);
  1035. printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
  1036. dev->name, dev->id,
  1037. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1038. le32_to_cpu(dev->adapter_info.biosbuild));
  1039. if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
  1040. printk(KERN_INFO "%s%d: serial %x\n",
  1041. dev->name, dev->id,
  1042. le32_to_cpu(dev->adapter_info.serial[0]));
  1043. if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
  1044. printk(KERN_INFO "%s%d: TSID %.*s\n",
  1045. dev->name, dev->id,
  1046. (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
  1047. dev->supplement_adapter_info.VpdInfo.Tsid);
  1048. }
  1049. }
  1050. dev->nondasd_support = 0;
  1051. dev->raid_scsi_mode = 0;
  1052. if(dev->adapter_info.options & AAC_OPT_NONDASD){
  1053. dev->nondasd_support = 1;
  1054. }
  1055. /*
  1056. * If the firmware supports ROMB RAID/SCSI mode and we are currently
  1057. * in RAID/SCSI mode, set the flag. For now if in this mode we will
  1058. * force nondasd support on. If we decide to allow the non-dasd flag
  1059. * additional changes changes will have to be made to support
  1060. * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
  1061. * changed to support the new dev->raid_scsi_mode flag instead of
  1062. * leaching off of the dev->nondasd_support flag. Also in linit.c the
  1063. * function aac_detect will have to be modified where it sets up the
  1064. * max number of channels based on the aac->nondasd_support flag only.
  1065. */
  1066. if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
  1067. (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
  1068. dev->nondasd_support = 1;
  1069. dev->raid_scsi_mode = 1;
  1070. }
  1071. if (dev->raid_scsi_mode != 0)
  1072. printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
  1073. dev->name, dev->id);
  1074. if(nondasd != -1) {
  1075. dev->nondasd_support = (nondasd!=0);
  1076. }
  1077. if(dev->nondasd_support != 0){
  1078. printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
  1079. }
  1080. dev->dac_support = 0;
  1081. if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
  1082. printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
  1083. dev->dac_support = 1;
  1084. }
  1085. if(dacmode != -1) {
  1086. dev->dac_support = (dacmode!=0);
  1087. }
  1088. if(dev->dac_support != 0) {
  1089. if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
  1090. !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
  1091. printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
  1092. dev->name, dev->id);
  1093. } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
  1094. !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
  1095. printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
  1096. dev->name, dev->id);
  1097. dev->dac_support = 0;
  1098. } else {
  1099. printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
  1100. dev->name, dev->id);
  1101. rcode = -ENOMEM;
  1102. }
  1103. }
  1104. /*
  1105. * Deal with configuring for the individualized limits of each packet
  1106. * interface.
  1107. */
  1108. dev->a_ops.adapter_scsi = (dev->dac_support)
  1109. ? aac_scsi_64
  1110. : aac_scsi_32;
  1111. if (dev->raw_io_interface) {
  1112. dev->a_ops.adapter_bounds = (dev->raw_io_64)
  1113. ? aac_bounds_64
  1114. : aac_bounds_32;
  1115. dev->a_ops.adapter_read = aac_read_raw_io;
  1116. dev->a_ops.adapter_write = aac_write_raw_io;
  1117. } else {
  1118. dev->a_ops.adapter_bounds = aac_bounds_32;
  1119. dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
  1120. sizeof(struct aac_fibhdr) -
  1121. sizeof(struct aac_write) + sizeof(struct sgentry)) /
  1122. sizeof(struct sgentry);
  1123. if (dev->dac_support) {
  1124. dev->a_ops.adapter_read = aac_read_block64;
  1125. dev->a_ops.adapter_write = aac_write_block64;
  1126. /*
  1127. * 38 scatter gather elements
  1128. */
  1129. dev->scsi_host_ptr->sg_tablesize =
  1130. (dev->max_fib_size -
  1131. sizeof(struct aac_fibhdr) -
  1132. sizeof(struct aac_write64) +
  1133. sizeof(struct sgentry64)) /
  1134. sizeof(struct sgentry64);
  1135. } else {
  1136. dev->a_ops.adapter_read = aac_read_block;
  1137. dev->a_ops.adapter_write = aac_write_block;
  1138. }
  1139. dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  1140. if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
  1141. /*
  1142. * Worst case size that could cause sg overflow when
  1143. * we break up SG elements that are larger than 64KB.
  1144. * Would be nice if we could tell the SCSI layer what
  1145. * the maximum SG element size can be. Worst case is
  1146. * (sg_tablesize-1) 4KB elements with one 64KB
  1147. * element.
  1148. * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
  1149. */
  1150. dev->scsi_host_ptr->max_sectors =
  1151. (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
  1152. }
  1153. }
  1154. aac_fib_complete(fibptr);
  1155. aac_fib_free(fibptr);
  1156. return rcode;
  1157. }
  1158. static void io_callback(void *context, struct fib * fibptr)
  1159. {
  1160. struct aac_dev *dev;
  1161. struct aac_read_reply *readreply;
  1162. struct scsi_cmnd *scsicmd;
  1163. u32 cid;
  1164. scsicmd = (struct scsi_cmnd *) context;
  1165. if (!aac_valid_context(scsicmd, fibptr))
  1166. return;
  1167. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1168. cid = scmd_id(scsicmd);
  1169. if (nblank(dprintk(x))) {
  1170. u64 lba;
  1171. switch (scsicmd->cmnd[0]) {
  1172. case WRITE_6:
  1173. case READ_6:
  1174. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  1175. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1176. break;
  1177. case WRITE_16:
  1178. case READ_16:
  1179. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1180. ((u64)scsicmd->cmnd[3] << 48) |
  1181. ((u64)scsicmd->cmnd[4] << 40) |
  1182. ((u64)scsicmd->cmnd[5] << 32) |
  1183. ((u64)scsicmd->cmnd[6] << 24) |
  1184. (scsicmd->cmnd[7] << 16) |
  1185. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1186. break;
  1187. case WRITE_12:
  1188. case READ_12:
  1189. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1190. (scsicmd->cmnd[3] << 16) |
  1191. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1192. break;
  1193. default:
  1194. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1195. (scsicmd->cmnd[3] << 16) |
  1196. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1197. break;
  1198. }
  1199. printk(KERN_DEBUG
  1200. "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
  1201. smp_processor_id(), (unsigned long long)lba, jiffies);
  1202. }
  1203. BUG_ON(fibptr == NULL);
  1204. if(scsicmd->use_sg)
  1205. pci_unmap_sg(dev->pdev,
  1206. (struct scatterlist *)scsicmd->request_buffer,
  1207. scsicmd->use_sg,
  1208. scsicmd->sc_data_direction);
  1209. else if(scsicmd->request_bufflen)
  1210. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
  1211. scsicmd->request_bufflen,
  1212. scsicmd->sc_data_direction);
  1213. readreply = (struct aac_read_reply *)fib_data(fibptr);
  1214. if (le32_to_cpu(readreply->status) == ST_OK)
  1215. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1216. else {
  1217. #ifdef AAC_DETAILED_STATUS_INFO
  1218. printk(KERN_WARNING "io_callback: io failed, status = %d\n",
  1219. le32_to_cpu(readreply->status));
  1220. #endif
  1221. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1222. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1223. HARDWARE_ERROR,
  1224. SENCODE_INTERNAL_TARGET_FAILURE,
  1225. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1226. 0, 0);
  1227. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1228. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1229. ? sizeof(scsicmd->sense_buffer)
  1230. : sizeof(dev->fsa_dev[cid].sense_data));
  1231. }
  1232. aac_fib_complete(fibptr);
  1233. aac_fib_free(fibptr);
  1234. scsicmd->scsi_done(scsicmd);
  1235. }
  1236. static int aac_read(struct scsi_cmnd * scsicmd)
  1237. {
  1238. u64 lba;
  1239. u32 count;
  1240. int status;
  1241. struct aac_dev *dev;
  1242. struct fib * cmd_fibcontext;
  1243. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1244. /*
  1245. * Get block address and transfer length
  1246. */
  1247. switch (scsicmd->cmnd[0]) {
  1248. case READ_6:
  1249. dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
  1250. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  1251. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1252. count = scsicmd->cmnd[4];
  1253. if (count == 0)
  1254. count = 256;
  1255. break;
  1256. case READ_16:
  1257. dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
  1258. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1259. ((u64)scsicmd->cmnd[3] << 48) |
  1260. ((u64)scsicmd->cmnd[4] << 40) |
  1261. ((u64)scsicmd->cmnd[5] << 32) |
  1262. ((u64)scsicmd->cmnd[6] << 24) |
  1263. (scsicmd->cmnd[7] << 16) |
  1264. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1265. count = (scsicmd->cmnd[10] << 24) |
  1266. (scsicmd->cmnd[11] << 16) |
  1267. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  1268. break;
  1269. case READ_12:
  1270. dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
  1271. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1272. (scsicmd->cmnd[3] << 16) |
  1273. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1274. count = (scsicmd->cmnd[6] << 24) |
  1275. (scsicmd->cmnd[7] << 16) |
  1276. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1277. break;
  1278. default:
  1279. dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
  1280. lba = ((u64)scsicmd->cmnd[2] << 24) |
  1281. (scsicmd->cmnd[3] << 16) |
  1282. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1283. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  1284. break;
  1285. }
  1286. dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
  1287. smp_processor_id(), (unsigned long long)lba, jiffies));
  1288. if (aac_adapter_bounds(dev,scsicmd,lba))
  1289. return 0;
  1290. /*
  1291. * Alocate and initialize a Fib
  1292. */
  1293. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1294. return -1;
  1295. }
  1296. status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
  1297. /*
  1298. * Check that the command queued to the controller
  1299. */
  1300. if (status == -EINPROGRESS) {
  1301. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1302. return 0;
  1303. }
  1304. printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
  1305. /*
  1306. * For some reason, the Fib didn't queue, return QUEUE_FULL
  1307. */
  1308. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  1309. scsicmd->scsi_done(scsicmd);
  1310. aac_fib_complete(cmd_fibcontext);
  1311. aac_fib_free(cmd_fibcontext);
  1312. return 0;
  1313. }
  1314. static int aac_write(struct scsi_cmnd * scsicmd)
  1315. {
  1316. u64 lba;
  1317. u32 count;
  1318. int status;
  1319. struct aac_dev *dev;
  1320. struct fib * cmd_fibcontext;
  1321. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1322. /*
  1323. * Get block address and transfer length
  1324. */
  1325. if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
  1326. {
  1327. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1328. count = scsicmd->cmnd[4];
  1329. if (count == 0)
  1330. count = 256;
  1331. } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
  1332. dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
  1333. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1334. ((u64)scsicmd->cmnd[3] << 48) |
  1335. ((u64)scsicmd->cmnd[4] << 40) |
  1336. ((u64)scsicmd->cmnd[5] << 32) |
  1337. ((u64)scsicmd->cmnd[6] << 24) |
  1338. (scsicmd->cmnd[7] << 16) |
  1339. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1340. count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
  1341. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  1342. } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
  1343. dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
  1344. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
  1345. | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1346. count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
  1347. | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1348. } else {
  1349. dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
  1350. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1351. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  1352. }
  1353. dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
  1354. smp_processor_id(), (unsigned long long)lba, jiffies));
  1355. if (aac_adapter_bounds(dev,scsicmd,lba))
  1356. return 0;
  1357. /*
  1358. * Allocate and initialize a Fib then setup a BlockWrite command
  1359. */
  1360. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1361. scsicmd->result = DID_ERROR << 16;
  1362. scsicmd->scsi_done(scsicmd);
  1363. return 0;
  1364. }
  1365. status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
  1366. /*
  1367. * Check that the command queued to the controller
  1368. */
  1369. if (status == -EINPROGRESS) {
  1370. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1371. return 0;
  1372. }
  1373. printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
  1374. /*
  1375. * For some reason, the Fib didn't queue, return QUEUE_FULL
  1376. */
  1377. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  1378. scsicmd->scsi_done(scsicmd);
  1379. aac_fib_complete(cmd_fibcontext);
  1380. aac_fib_free(cmd_fibcontext);
  1381. return 0;
  1382. }
  1383. static void synchronize_callback(void *context, struct fib *fibptr)
  1384. {
  1385. struct aac_synchronize_reply *synchronizereply;
  1386. struct scsi_cmnd *cmd;
  1387. cmd = context;
  1388. if (!aac_valid_context(cmd, fibptr))
  1389. return;
  1390. dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
  1391. smp_processor_id(), jiffies));
  1392. BUG_ON(fibptr == NULL);
  1393. synchronizereply = fib_data(fibptr);
  1394. if (le32_to_cpu(synchronizereply->status) == CT_OK)
  1395. cmd->result = DID_OK << 16 |
  1396. COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1397. else {
  1398. struct scsi_device *sdev = cmd->device;
  1399. struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
  1400. u32 cid = sdev_id(sdev);
  1401. printk(KERN_WARNING
  1402. "synchronize_callback: synchronize failed, status = %d\n",
  1403. le32_to_cpu(synchronizereply->status));
  1404. cmd->result = DID_OK << 16 |
  1405. COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1406. set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
  1407. HARDWARE_ERROR,
  1408. SENCODE_INTERNAL_TARGET_FAILURE,
  1409. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1410. 0, 0);
  1411. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1412. min(sizeof(dev->fsa_dev[cid].sense_data),
  1413. sizeof(cmd->sense_buffer)));
  1414. }
  1415. aac_fib_complete(fibptr);
  1416. aac_fib_free(fibptr);
  1417. cmd->scsi_done(cmd);
  1418. }
  1419. static int aac_synchronize(struct scsi_cmnd *scsicmd)
  1420. {
  1421. int status;
  1422. struct fib *cmd_fibcontext;
  1423. struct aac_synchronize *synchronizecmd;
  1424. struct scsi_cmnd *cmd;
  1425. struct scsi_device *sdev = scsicmd->device;
  1426. int active = 0;
  1427. struct aac_dev *aac;
  1428. unsigned long flags;
  1429. /*
  1430. * Wait for all outstanding queued commands to complete to this
  1431. * specific target (block).
  1432. */
  1433. spin_lock_irqsave(&sdev->list_lock, flags);
  1434. list_for_each_entry(cmd, &sdev->cmd_list, list)
  1435. if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
  1436. ++active;
  1437. break;
  1438. }
  1439. spin_unlock_irqrestore(&sdev->list_lock, flags);
  1440. /*
  1441. * Yield the processor (requeue for later)
  1442. */
  1443. if (active)
  1444. return SCSI_MLQUEUE_DEVICE_BUSY;
  1445. aac = (struct aac_dev *)scsicmd->device->host->hostdata;
  1446. if (aac->in_reset)
  1447. return SCSI_MLQUEUE_HOST_BUSY;
  1448. /*
  1449. * Allocate and initialize a Fib
  1450. */
  1451. if (!(cmd_fibcontext = aac_fib_alloc(aac)))
  1452. return SCSI_MLQUEUE_HOST_BUSY;
  1453. aac_fib_init(cmd_fibcontext);
  1454. synchronizecmd = fib_data(cmd_fibcontext);
  1455. synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
  1456. synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
  1457. synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
  1458. synchronizecmd->count =
  1459. cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
  1460. /*
  1461. * Now send the Fib to the adapter
  1462. */
  1463. status = aac_fib_send(ContainerCommand,
  1464. cmd_fibcontext,
  1465. sizeof(struct aac_synchronize),
  1466. FsaNormal,
  1467. 0, 1,
  1468. (fib_callback)synchronize_callback,
  1469. (void *)scsicmd);
  1470. /*
  1471. * Check that the command queued to the controller
  1472. */
  1473. if (status == -EINPROGRESS) {
  1474. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1475. return 0;
  1476. }
  1477. printk(KERN_WARNING
  1478. "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
  1479. aac_fib_complete(cmd_fibcontext);
  1480. aac_fib_free(cmd_fibcontext);
  1481. return SCSI_MLQUEUE_HOST_BUSY;
  1482. }
  1483. /**
  1484. * aac_scsi_cmd() - Process SCSI command
  1485. * @scsicmd: SCSI command block
  1486. *
  1487. * Emulate a SCSI command and queue the required request for the
  1488. * aacraid firmware.
  1489. */
  1490. int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
  1491. {
  1492. u32 cid = 0;
  1493. struct Scsi_Host *host = scsicmd->device->host;
  1494. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  1495. struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
  1496. if (fsa_dev_ptr == NULL)
  1497. return -1;
  1498. /*
  1499. * If the bus, id or lun is out of range, return fail
  1500. * Test does not apply to ID 16, the pseudo id for the controller
  1501. * itself.
  1502. */
  1503. if (scmd_id(scsicmd) != host->this_id) {
  1504. if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
  1505. if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
  1506. (scsicmd->device->lun != 0)) {
  1507. scsicmd->result = DID_NO_CONNECT << 16;
  1508. scsicmd->scsi_done(scsicmd);
  1509. return 0;
  1510. }
  1511. cid = scmd_id(scsicmd);
  1512. /*
  1513. * If the target container doesn't exist, it may have
  1514. * been newly created
  1515. */
  1516. if ((fsa_dev_ptr[cid].valid & 1) == 0) {
  1517. switch (scsicmd->cmnd[0]) {
  1518. case SERVICE_ACTION_IN:
  1519. if (!(dev->raw_io_interface) ||
  1520. !(dev->raw_io_64) ||
  1521. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1522. break;
  1523. case INQUIRY:
  1524. case READ_CAPACITY:
  1525. case TEST_UNIT_READY:
  1526. if (dev->in_reset)
  1527. return -1;
  1528. return _aac_probe_container(scsicmd,
  1529. aac_probe_container_callback2);
  1530. default:
  1531. break;
  1532. }
  1533. }
  1534. } else { /* check for physical non-dasd devices */
  1535. if ((dev->nondasd_support == 1) || expose_physicals) {
  1536. if (dev->in_reset)
  1537. return -1;
  1538. return aac_send_srb_fib(scsicmd);
  1539. } else {
  1540. scsicmd->result = DID_NO_CONNECT << 16;
  1541. scsicmd->scsi_done(scsicmd);
  1542. return 0;
  1543. }
  1544. }
  1545. }
  1546. /*
  1547. * else Command for the controller itself
  1548. */
  1549. else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
  1550. (scsicmd->cmnd[0] != TEST_UNIT_READY))
  1551. {
  1552. dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
  1553. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1554. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1555. ILLEGAL_REQUEST,
  1556. SENCODE_INVALID_COMMAND,
  1557. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1558. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1559. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1560. ? sizeof(scsicmd->sense_buffer)
  1561. : sizeof(dev->fsa_dev[cid].sense_data));
  1562. scsicmd->scsi_done(scsicmd);
  1563. return 0;
  1564. }
  1565. /* Handle commands here that don't really require going out to the adapter */
  1566. switch (scsicmd->cmnd[0]) {
  1567. case INQUIRY:
  1568. {
  1569. struct inquiry_data inq_data;
  1570. dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
  1571. memset(&inq_data, 0, sizeof (struct inquiry_data));
  1572. inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
  1573. 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 */
  1574. inq_data.inqd_len = 31;
  1575. /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  1576. inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
  1577. /*
  1578. * Set the Vendor, Product, and Revision Level
  1579. * see: <vendor>.c i.e. aac.c
  1580. */
  1581. if (scmd_id(scsicmd) == host->this_id) {
  1582. setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
  1583. inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
  1584. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1585. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1586. scsicmd->scsi_done(scsicmd);
  1587. return 0;
  1588. }
  1589. if (dev->in_reset)
  1590. return -1;
  1591. setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
  1592. inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
  1593. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1594. return aac_get_container_name(scsicmd);
  1595. }
  1596. case SERVICE_ACTION_IN:
  1597. if (!(dev->raw_io_interface) ||
  1598. !(dev->raw_io_64) ||
  1599. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1600. break;
  1601. {
  1602. u64 capacity;
  1603. char cp[13];
  1604. dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
  1605. capacity = fsa_dev_ptr[cid].size - 1;
  1606. cp[0] = (capacity >> 56) & 0xff;
  1607. cp[1] = (capacity >> 48) & 0xff;
  1608. cp[2] = (capacity >> 40) & 0xff;
  1609. cp[3] = (capacity >> 32) & 0xff;
  1610. cp[4] = (capacity >> 24) & 0xff;
  1611. cp[5] = (capacity >> 16) & 0xff;
  1612. cp[6] = (capacity >> 8) & 0xff;
  1613. cp[7] = (capacity >> 0) & 0xff;
  1614. cp[8] = 0;
  1615. cp[9] = 0;
  1616. cp[10] = 2;
  1617. cp[11] = 0;
  1618. cp[12] = 0;
  1619. aac_internal_transfer(scsicmd, cp, 0,
  1620. min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
  1621. if (sizeof(cp) < scsicmd->cmnd[13]) {
  1622. unsigned int len, offset = sizeof(cp);
  1623. memset(cp, 0, offset);
  1624. do {
  1625. len = min_t(size_t, scsicmd->cmnd[13] - offset,
  1626. sizeof(cp));
  1627. aac_internal_transfer(scsicmd, cp, offset, len);
  1628. } while ((offset += len) < scsicmd->cmnd[13]);
  1629. }
  1630. /* Do not cache partition table for arrays */
  1631. scsicmd->device->removable = 1;
  1632. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1633. scsicmd->scsi_done(scsicmd);
  1634. return 0;
  1635. }
  1636. case READ_CAPACITY:
  1637. {
  1638. u32 capacity;
  1639. char cp[8];
  1640. dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
  1641. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  1642. capacity = fsa_dev_ptr[cid].size - 1;
  1643. else
  1644. capacity = (u32)-1;
  1645. cp[0] = (capacity >> 24) & 0xff;
  1646. cp[1] = (capacity >> 16) & 0xff;
  1647. cp[2] = (capacity >> 8) & 0xff;
  1648. cp[3] = (capacity >> 0) & 0xff;
  1649. cp[4] = 0;
  1650. cp[5] = 0;
  1651. cp[6] = 2;
  1652. cp[7] = 0;
  1653. aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
  1654. /* Do not cache partition table for arrays */
  1655. scsicmd->device->removable = 1;
  1656. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1657. scsicmd->scsi_done(scsicmd);
  1658. return 0;
  1659. }
  1660. case MODE_SENSE:
  1661. {
  1662. char mode_buf[4];
  1663. dprintk((KERN_DEBUG "MODE SENSE command.\n"));
  1664. mode_buf[0] = 3; /* Mode data length */
  1665. mode_buf[1] = 0; /* Medium type - default */
  1666. mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1667. mode_buf[3] = 0; /* Block descriptor length */
  1668. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1669. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1670. scsicmd->scsi_done(scsicmd);
  1671. return 0;
  1672. }
  1673. case MODE_SENSE_10:
  1674. {
  1675. char mode_buf[8];
  1676. dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
  1677. mode_buf[0] = 0; /* Mode data length (MSB) */
  1678. mode_buf[1] = 6; /* Mode data length (LSB) */
  1679. mode_buf[2] = 0; /* Medium type - default */
  1680. mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1681. mode_buf[4] = 0; /* reserved */
  1682. mode_buf[5] = 0; /* reserved */
  1683. mode_buf[6] = 0; /* Block descriptor length (MSB) */
  1684. mode_buf[7] = 0; /* Block descriptor length (LSB) */
  1685. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1686. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1687. scsicmd->scsi_done(scsicmd);
  1688. return 0;
  1689. }
  1690. case REQUEST_SENSE:
  1691. dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
  1692. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
  1693. memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
  1694. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1695. scsicmd->scsi_done(scsicmd);
  1696. return 0;
  1697. case ALLOW_MEDIUM_REMOVAL:
  1698. dprintk((KERN_DEBUG "LOCK command.\n"));
  1699. if (scsicmd->cmnd[4])
  1700. fsa_dev_ptr[cid].locked = 1;
  1701. else
  1702. fsa_dev_ptr[cid].locked = 0;
  1703. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1704. scsicmd->scsi_done(scsicmd);
  1705. return 0;
  1706. /*
  1707. * These commands are all No-Ops
  1708. */
  1709. case TEST_UNIT_READY:
  1710. case RESERVE:
  1711. case RELEASE:
  1712. case REZERO_UNIT:
  1713. case REASSIGN_BLOCKS:
  1714. case SEEK_10:
  1715. case START_STOP:
  1716. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1717. scsicmd->scsi_done(scsicmd);
  1718. return 0;
  1719. }
  1720. switch (scsicmd->cmnd[0])
  1721. {
  1722. case READ_6:
  1723. case READ_10:
  1724. case READ_12:
  1725. case READ_16:
  1726. if (dev->in_reset)
  1727. return -1;
  1728. /*
  1729. * Hack to keep track of ordinal number of the device that
  1730. * corresponds to a container. Needed to convert
  1731. * containers to /dev/sd device names
  1732. */
  1733. if (scsicmd->request->rq_disk)
  1734. strlcpy(fsa_dev_ptr[cid].devname,
  1735. scsicmd->request->rq_disk->disk_name,
  1736. min(sizeof(fsa_dev_ptr[cid].devname),
  1737. sizeof(scsicmd->request->rq_disk->disk_name) + 1));
  1738. return aac_read(scsicmd);
  1739. case WRITE_6:
  1740. case WRITE_10:
  1741. case WRITE_12:
  1742. case WRITE_16:
  1743. if (dev->in_reset)
  1744. return -1;
  1745. return aac_write(scsicmd);
  1746. case SYNCHRONIZE_CACHE:
  1747. /* Issue FIB to tell Firmware to flush it's cache */
  1748. return aac_synchronize(scsicmd);
  1749. default:
  1750. /*
  1751. * Unhandled commands
  1752. */
  1753. dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
  1754. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1755. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1756. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  1757. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1758. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1759. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1760. ? sizeof(scsicmd->sense_buffer)
  1761. : sizeof(dev->fsa_dev[cid].sense_data));
  1762. scsicmd->scsi_done(scsicmd);
  1763. return 0;
  1764. }
  1765. }
  1766. static int query_disk(struct aac_dev *dev, void __user *arg)
  1767. {
  1768. struct aac_query_disk qd;
  1769. struct fsa_dev_info *fsa_dev_ptr;
  1770. fsa_dev_ptr = dev->fsa_dev;
  1771. if (!fsa_dev_ptr)
  1772. return -EBUSY;
  1773. if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
  1774. return -EFAULT;
  1775. if (qd.cnum == -1)
  1776. qd.cnum = qd.id;
  1777. else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
  1778. {
  1779. if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
  1780. return -EINVAL;
  1781. qd.instance = dev->scsi_host_ptr->host_no;
  1782. qd.bus = 0;
  1783. qd.id = CONTAINER_TO_ID(qd.cnum);
  1784. qd.lun = CONTAINER_TO_LUN(qd.cnum);
  1785. }
  1786. else return -EINVAL;
  1787. qd.valid = fsa_dev_ptr[qd.cnum].valid;
  1788. qd.locked = fsa_dev_ptr[qd.cnum].locked;
  1789. qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
  1790. if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
  1791. qd.unmapped = 1;
  1792. else
  1793. qd.unmapped = 0;
  1794. strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
  1795. min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
  1796. if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
  1797. return -EFAULT;
  1798. return 0;
  1799. }
  1800. static int force_delete_disk(struct aac_dev *dev, void __user *arg)
  1801. {
  1802. struct aac_delete_disk dd;
  1803. struct fsa_dev_info *fsa_dev_ptr;
  1804. fsa_dev_ptr = dev->fsa_dev;
  1805. if (!fsa_dev_ptr)
  1806. return -EBUSY;
  1807. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1808. return -EFAULT;
  1809. if (dd.cnum >= dev->maximum_num_containers)
  1810. return -EINVAL;
  1811. /*
  1812. * Mark this container as being deleted.
  1813. */
  1814. fsa_dev_ptr[dd.cnum].deleted = 1;
  1815. /*
  1816. * Mark the container as no longer valid
  1817. */
  1818. fsa_dev_ptr[dd.cnum].valid = 0;
  1819. return 0;
  1820. }
  1821. static int delete_disk(struct aac_dev *dev, void __user *arg)
  1822. {
  1823. struct aac_delete_disk dd;
  1824. struct fsa_dev_info *fsa_dev_ptr;
  1825. fsa_dev_ptr = dev->fsa_dev;
  1826. if (!fsa_dev_ptr)
  1827. return -EBUSY;
  1828. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1829. return -EFAULT;
  1830. if (dd.cnum >= dev->maximum_num_containers)
  1831. return -EINVAL;
  1832. /*
  1833. * If the container is locked, it can not be deleted by the API.
  1834. */
  1835. if (fsa_dev_ptr[dd.cnum].locked)
  1836. return -EBUSY;
  1837. else {
  1838. /*
  1839. * Mark the container as no longer being valid.
  1840. */
  1841. fsa_dev_ptr[dd.cnum].valid = 0;
  1842. fsa_dev_ptr[dd.cnum].devname[0] = '\0';
  1843. return 0;
  1844. }
  1845. }
  1846. int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
  1847. {
  1848. switch (cmd) {
  1849. case FSACTL_QUERY_DISK:
  1850. return query_disk(dev, arg);
  1851. case FSACTL_DELETE_DISK:
  1852. return delete_disk(dev, arg);
  1853. case FSACTL_FORCE_DELETE_DISK:
  1854. return force_delete_disk(dev, arg);
  1855. case FSACTL_GET_CONTAINERS:
  1856. return aac_get_containers(dev);
  1857. default:
  1858. return -ENOTTY;
  1859. }
  1860. }
  1861. /**
  1862. *
  1863. * aac_srb_callback
  1864. * @context: the context set in the fib - here it is scsi cmd
  1865. * @fibptr: pointer to the fib
  1866. *
  1867. * Handles the completion of a scsi command to a non dasd device
  1868. *
  1869. */
  1870. static void aac_srb_callback(void *context, struct fib * fibptr)
  1871. {
  1872. struct aac_dev *dev;
  1873. struct aac_srb_reply *srbreply;
  1874. struct scsi_cmnd *scsicmd;
  1875. scsicmd = (struct scsi_cmnd *) context;
  1876. if (!aac_valid_context(scsicmd, fibptr))
  1877. return;
  1878. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1879. BUG_ON(fibptr == NULL);
  1880. srbreply = (struct aac_srb_reply *) fib_data(fibptr);
  1881. scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
  1882. /*
  1883. * Calculate resid for sg
  1884. */
  1885. scsicmd->resid = scsicmd->request_bufflen -
  1886. le32_to_cpu(srbreply->data_xfer_length);
  1887. if(scsicmd->use_sg)
  1888. pci_unmap_sg(dev->pdev,
  1889. (struct scatterlist *)scsicmd->request_buffer,
  1890. scsicmd->use_sg,
  1891. scsicmd->sc_data_direction);
  1892. else if(scsicmd->request_bufflen)
  1893. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
  1894. scsicmd->sc_data_direction);
  1895. /*
  1896. * First check the fib status
  1897. */
  1898. if (le32_to_cpu(srbreply->status) != ST_OK){
  1899. int len;
  1900. printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
  1901. len = (le32_to_cpu(srbreply->sense_data_size) >
  1902. sizeof(scsicmd->sense_buffer)) ?
  1903. sizeof(scsicmd->sense_buffer) :
  1904. le32_to_cpu(srbreply->sense_data_size);
  1905. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1906. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1907. }
  1908. /*
  1909. * Next check the srb status
  1910. */
  1911. switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
  1912. case SRB_STATUS_ERROR_RECOVERY:
  1913. case SRB_STATUS_PENDING:
  1914. case SRB_STATUS_SUCCESS:
  1915. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1916. break;
  1917. case SRB_STATUS_DATA_OVERRUN:
  1918. switch(scsicmd->cmnd[0]){
  1919. case READ_6:
  1920. case WRITE_6:
  1921. case READ_10:
  1922. case WRITE_10:
  1923. case READ_12:
  1924. case WRITE_12:
  1925. case READ_16:
  1926. case WRITE_16:
  1927. if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
  1928. printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
  1929. } else {
  1930. printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
  1931. }
  1932. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1933. break;
  1934. case INQUIRY: {
  1935. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1936. break;
  1937. }
  1938. default:
  1939. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1940. break;
  1941. }
  1942. break;
  1943. case SRB_STATUS_ABORTED:
  1944. scsicmd->result = DID_ABORT << 16 | ABORT << 8;
  1945. break;
  1946. case SRB_STATUS_ABORT_FAILED:
  1947. // Not sure about this one - but assuming the hba was trying to abort for some reason
  1948. scsicmd->result = DID_ERROR << 16 | ABORT << 8;
  1949. break;
  1950. case SRB_STATUS_PARITY_ERROR:
  1951. scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
  1952. break;
  1953. case SRB_STATUS_NO_DEVICE:
  1954. case SRB_STATUS_INVALID_PATH_ID:
  1955. case SRB_STATUS_INVALID_TARGET_ID:
  1956. case SRB_STATUS_INVALID_LUN:
  1957. case SRB_STATUS_SELECTION_TIMEOUT:
  1958. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1959. break;
  1960. case SRB_STATUS_COMMAND_TIMEOUT:
  1961. case SRB_STATUS_TIMEOUT:
  1962. scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
  1963. break;
  1964. case SRB_STATUS_BUSY:
  1965. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1966. break;
  1967. case SRB_STATUS_BUS_RESET:
  1968. scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
  1969. break;
  1970. case SRB_STATUS_MESSAGE_REJECTED:
  1971. scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
  1972. break;
  1973. case SRB_STATUS_REQUEST_FLUSHED:
  1974. case SRB_STATUS_ERROR:
  1975. case SRB_STATUS_INVALID_REQUEST:
  1976. case SRB_STATUS_REQUEST_SENSE_FAILED:
  1977. case SRB_STATUS_NO_HBA:
  1978. case SRB_STATUS_UNEXPECTED_BUS_FREE:
  1979. case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
  1980. case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
  1981. case SRB_STATUS_DELAYED_RETRY:
  1982. case SRB_STATUS_BAD_FUNCTION:
  1983. case SRB_STATUS_NOT_STARTED:
  1984. case SRB_STATUS_NOT_IN_USE:
  1985. case SRB_STATUS_FORCE_ABORT:
  1986. case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
  1987. default:
  1988. #ifdef AAC_DETAILED_STATUS_INFO
  1989. printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
  1990. le32_to_cpu(srbreply->srb_status) & 0x3F,
  1991. aac_get_status_string(
  1992. le32_to_cpu(srbreply->srb_status) & 0x3F),
  1993. scsicmd->cmnd[0],
  1994. le32_to_cpu(srbreply->scsi_status));
  1995. #endif
  1996. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1997. break;
  1998. }
  1999. if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
  2000. int len;
  2001. scsicmd->result |= SAM_STAT_CHECK_CONDITION;
  2002. len = (le32_to_cpu(srbreply->sense_data_size) >
  2003. sizeof(scsicmd->sense_buffer)) ?
  2004. sizeof(scsicmd->sense_buffer) :
  2005. le32_to_cpu(srbreply->sense_data_size);
  2006. #ifdef AAC_DETAILED_STATUS_INFO
  2007. printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
  2008. le32_to_cpu(srbreply->status), len);
  2009. #endif
  2010. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  2011. }
  2012. /*
  2013. * OR in the scsi status (already shifted up a bit)
  2014. */
  2015. scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
  2016. aac_fib_complete(fibptr);
  2017. aac_fib_free(fibptr);
  2018. scsicmd->scsi_done(scsicmd);
  2019. }
  2020. /**
  2021. *
  2022. * aac_send_scb_fib
  2023. * @scsicmd: the scsi command block
  2024. *
  2025. * This routine will form a FIB and fill in the aac_srb from the
  2026. * scsicmd passed in.
  2027. */
  2028. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
  2029. {
  2030. struct fib* cmd_fibcontext;
  2031. struct aac_dev* dev;
  2032. int status;
  2033. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2034. if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
  2035. scsicmd->device->lun > 7) {
  2036. scsicmd->result = DID_NO_CONNECT << 16;
  2037. scsicmd->scsi_done(scsicmd);
  2038. return 0;
  2039. }
  2040. /*
  2041. * Allocate and initialize a Fib then setup a BlockWrite command
  2042. */
  2043. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  2044. return -1;
  2045. }
  2046. status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
  2047. /*
  2048. * Check that the command queued to the controller
  2049. */
  2050. if (status == -EINPROGRESS) {
  2051. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  2052. return 0;
  2053. }
  2054. printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
  2055. aac_fib_complete(cmd_fibcontext);
  2056. aac_fib_free(cmd_fibcontext);
  2057. return -1;
  2058. }
  2059. static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
  2060. {
  2061. struct aac_dev *dev;
  2062. unsigned long byte_count = 0;
  2063. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2064. // Get rid of old data
  2065. psg->count = 0;
  2066. psg->sg[0].addr = 0;
  2067. psg->sg[0].count = 0;
  2068. if (scsicmd->use_sg) {
  2069. struct scatterlist *sg;
  2070. int i;
  2071. int sg_count;
  2072. sg = (struct scatterlist *) scsicmd->request_buffer;
  2073. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2074. scsicmd->sc_data_direction);
  2075. psg->count = cpu_to_le32(sg_count);
  2076. for (i = 0; i < sg_count; i++) {
  2077. psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
  2078. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  2079. byte_count += sg_dma_len(sg);
  2080. sg++;
  2081. }
  2082. /* hba wants the size to be exact */
  2083. if(byte_count > scsicmd->request_bufflen){
  2084. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2085. (byte_count - scsicmd->request_bufflen);
  2086. psg->sg[i-1].count = cpu_to_le32(temp);
  2087. byte_count = scsicmd->request_bufflen;
  2088. }
  2089. /* Check for command underflow */
  2090. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2091. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2092. byte_count, scsicmd->underflow);
  2093. }
  2094. }
  2095. else if(scsicmd->request_bufflen) {
  2096. u32 addr;
  2097. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2098. scsicmd->request_buffer,
  2099. scsicmd->request_bufflen,
  2100. scsicmd->sc_data_direction);
  2101. addr = scsicmd->SCp.dma_handle;
  2102. psg->count = cpu_to_le32(1);
  2103. psg->sg[0].addr = cpu_to_le32(addr);
  2104. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2105. byte_count = scsicmd->request_bufflen;
  2106. }
  2107. return byte_count;
  2108. }
  2109. static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
  2110. {
  2111. struct aac_dev *dev;
  2112. unsigned long byte_count = 0;
  2113. u64 addr;
  2114. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2115. // Get rid of old data
  2116. psg->count = 0;
  2117. psg->sg[0].addr[0] = 0;
  2118. psg->sg[0].addr[1] = 0;
  2119. psg->sg[0].count = 0;
  2120. if (scsicmd->use_sg) {
  2121. struct scatterlist *sg;
  2122. int i;
  2123. int sg_count;
  2124. sg = (struct scatterlist *) scsicmd->request_buffer;
  2125. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2126. scsicmd->sc_data_direction);
  2127. for (i = 0; i < sg_count; i++) {
  2128. int count = sg_dma_len(sg);
  2129. addr = sg_dma_address(sg);
  2130. psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2131. psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
  2132. psg->sg[i].count = cpu_to_le32(count);
  2133. byte_count += count;
  2134. sg++;
  2135. }
  2136. psg->count = cpu_to_le32(sg_count);
  2137. /* hba wants the size to be exact */
  2138. if(byte_count > scsicmd->request_bufflen){
  2139. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2140. (byte_count - scsicmd->request_bufflen);
  2141. psg->sg[i-1].count = cpu_to_le32(temp);
  2142. byte_count = scsicmd->request_bufflen;
  2143. }
  2144. /* Check for command underflow */
  2145. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2146. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2147. byte_count, scsicmd->underflow);
  2148. }
  2149. }
  2150. else if(scsicmd->request_bufflen) {
  2151. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2152. scsicmd->request_buffer,
  2153. scsicmd->request_bufflen,
  2154. scsicmd->sc_data_direction);
  2155. addr = scsicmd->SCp.dma_handle;
  2156. psg->count = cpu_to_le32(1);
  2157. psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2158. psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
  2159. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2160. byte_count = scsicmd->request_bufflen;
  2161. }
  2162. return byte_count;
  2163. }
  2164. static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
  2165. {
  2166. struct Scsi_Host *host = scsicmd->device->host;
  2167. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  2168. unsigned long byte_count = 0;
  2169. // Get rid of old data
  2170. psg->count = 0;
  2171. psg->sg[0].next = 0;
  2172. psg->sg[0].prev = 0;
  2173. psg->sg[0].addr[0] = 0;
  2174. psg->sg[0].addr[1] = 0;
  2175. psg->sg[0].count = 0;
  2176. psg->sg[0].flags = 0;
  2177. if (scsicmd->use_sg) {
  2178. struct scatterlist *sg;
  2179. int i;
  2180. int sg_count;
  2181. sg = (struct scatterlist *) scsicmd->request_buffer;
  2182. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2183. scsicmd->sc_data_direction);
  2184. for (i = 0; i < sg_count; i++) {
  2185. int count = sg_dma_len(sg);
  2186. u64 addr = sg_dma_address(sg);
  2187. psg->sg[i].next = 0;
  2188. psg->sg[i].prev = 0;
  2189. psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
  2190. psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2191. psg->sg[i].count = cpu_to_le32(count);
  2192. psg->sg[i].flags = 0;
  2193. byte_count += count;
  2194. sg++;
  2195. }
  2196. psg->count = cpu_to_le32(sg_count);
  2197. /* hba wants the size to be exact */
  2198. if(byte_count > scsicmd->request_bufflen){
  2199. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2200. (byte_count - scsicmd->request_bufflen);
  2201. psg->sg[i-1].count = cpu_to_le32(temp);
  2202. byte_count = scsicmd->request_bufflen;
  2203. }
  2204. /* Check for command underflow */
  2205. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2206. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2207. byte_count, scsicmd->underflow);
  2208. }
  2209. }
  2210. else if(scsicmd->request_bufflen) {
  2211. int count;
  2212. u64 addr;
  2213. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2214. scsicmd->request_buffer,
  2215. scsicmd->request_bufflen,
  2216. scsicmd->sc_data_direction);
  2217. addr = scsicmd->SCp.dma_handle;
  2218. count = scsicmd->request_bufflen;
  2219. psg->count = cpu_to_le32(1);
  2220. psg->sg[0].next = 0;
  2221. psg->sg[0].prev = 0;
  2222. psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
  2223. psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2224. psg->sg[0].count = cpu_to_le32(count);
  2225. psg->sg[0].flags = 0;
  2226. byte_count = scsicmd->request_bufflen;
  2227. }
  2228. return byte_count;
  2229. }
  2230. #ifdef AAC_DETAILED_STATUS_INFO
  2231. struct aac_srb_status_info {
  2232. u32 status;
  2233. char *str;
  2234. };
  2235. static struct aac_srb_status_info srb_status_info[] = {
  2236. { SRB_STATUS_PENDING, "Pending Status"},
  2237. { SRB_STATUS_SUCCESS, "Success"},
  2238. { SRB_STATUS_ABORTED, "Aborted Command"},
  2239. { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
  2240. { SRB_STATUS_ERROR, "Error Event"},
  2241. { SRB_STATUS_BUSY, "Device Busy"},
  2242. { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
  2243. { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
  2244. { SRB_STATUS_NO_DEVICE, "No Device"},
  2245. { SRB_STATUS_TIMEOUT, "Timeout"},
  2246. { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
  2247. { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
  2248. { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
  2249. { SRB_STATUS_BUS_RESET, "Bus Reset"},
  2250. { SRB_STATUS_PARITY_ERROR, "Parity Error"},
  2251. { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
  2252. { SRB_STATUS_NO_HBA, "No HBA"},
  2253. { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
  2254. { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
  2255. { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
  2256. { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
  2257. { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
  2258. { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
  2259. { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
  2260. { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
  2261. { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
  2262. { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
  2263. { SRB_STATUS_NOT_STARTED, "Not Started"},
  2264. { SRB_STATUS_NOT_IN_USE, "Not In Use"},
  2265. { SRB_STATUS_FORCE_ABORT, "Force Abort"},
  2266. { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
  2267. { 0xff, "Unknown Error"}
  2268. };
  2269. char *aac_get_status_string(u32 status)
  2270. {
  2271. int i;
  2272. for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
  2273. if (srb_status_info[i].status == status)
  2274. return srb_status_info[i].str;
  2275. return "Bad Status Code";
  2276. }
  2277. #endif