aachba.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  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 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/sched.h>
  29. #include <linux/pci.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/slab.h>
  32. #include <linux/completion.h>
  33. #include <linux/blkdev.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 int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
  124. #ifdef AAC_DETAILED_STATUS_INFO
  125. static char *aac_get_status_string(u32 status);
  126. #endif
  127. /*
  128. * Non dasd selection is handled entirely in aachba now
  129. */
  130. static int nondasd = -1;
  131. static int dacmode = -1;
  132. static int commit = -1;
  133. module_param(nondasd, int, 0);
  134. MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
  135. module_param(dacmode, int, 0);
  136. MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
  137. module_param(commit, int, 0);
  138. 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");
  139. int numacb = -1;
  140. module_param(numacb, int, S_IRUGO|S_IWUSR);
  141. MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid\nvalues are 512 and down. Default is to use suggestion from Firmware.");
  142. int acbsize = -1;
  143. module_param(acbsize, int, S_IRUGO|S_IWUSR);
  144. MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512,\n2048, 4096 and 8192. Default is to use suggestion from Firmware.");
  145. /**
  146. * aac_get_config_status - check the adapter configuration
  147. * @common: adapter to query
  148. *
  149. * Query config status, and commit the configuration if needed.
  150. */
  151. int aac_get_config_status(struct aac_dev *dev)
  152. {
  153. int status = 0;
  154. struct fib * fibptr;
  155. if (!(fibptr = fib_alloc(dev)))
  156. return -ENOMEM;
  157. fib_init(fibptr);
  158. {
  159. struct aac_get_config_status *dinfo;
  160. dinfo = (struct aac_get_config_status *) fib_data(fibptr);
  161. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  162. dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
  163. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
  164. }
  165. status = fib_send(ContainerCommand,
  166. fibptr,
  167. sizeof (struct aac_get_config_status),
  168. FsaNormal,
  169. 1, 1,
  170. NULL, NULL);
  171. if (status < 0 ) {
  172. printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
  173. } else {
  174. struct aac_get_config_status_resp *reply
  175. = (struct aac_get_config_status_resp *) fib_data(fibptr);
  176. dprintk((KERN_WARNING
  177. "aac_get_config_status: response=%d status=%d action=%d\n",
  178. le32_to_cpu(reply->response),
  179. le32_to_cpu(reply->status),
  180. le32_to_cpu(reply->data.action)));
  181. if ((le32_to_cpu(reply->response) != ST_OK) ||
  182. (le32_to_cpu(reply->status) != CT_OK) ||
  183. (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
  184. printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
  185. status = -EINVAL;
  186. }
  187. }
  188. fib_complete(fibptr);
  189. /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
  190. if (status >= 0) {
  191. if (commit == 1) {
  192. struct aac_commit_config * dinfo;
  193. fib_init(fibptr);
  194. dinfo = (struct aac_commit_config *) fib_data(fibptr);
  195. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  196. dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
  197. status = fib_send(ContainerCommand,
  198. fibptr,
  199. sizeof (struct aac_commit_config),
  200. FsaNormal,
  201. 1, 1,
  202. NULL, NULL);
  203. fib_complete(fibptr);
  204. } else if (commit == 0) {
  205. printk(KERN_WARNING
  206. "aac_get_config_status: Foreign device configurations are being ignored\n");
  207. }
  208. }
  209. fib_free(fibptr);
  210. return status;
  211. }
  212. /**
  213. * aac_get_containers - list containers
  214. * @common: adapter to probe
  215. *
  216. * Make a list of all containers on this controller
  217. */
  218. int aac_get_containers(struct aac_dev *dev)
  219. {
  220. struct fsa_dev_info *fsa_dev_ptr;
  221. u32 index;
  222. int status = 0;
  223. struct fib * fibptr;
  224. unsigned instance;
  225. struct aac_get_container_count *dinfo;
  226. struct aac_get_container_count_resp *dresp;
  227. int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  228. instance = dev->scsi_host_ptr->unique_id;
  229. if (!(fibptr = fib_alloc(dev)))
  230. return -ENOMEM;
  231. fib_init(fibptr);
  232. dinfo = (struct aac_get_container_count *) fib_data(fibptr);
  233. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  234. dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
  235. status = fib_send(ContainerCommand,
  236. fibptr,
  237. sizeof (struct aac_get_container_count),
  238. FsaNormal,
  239. 1, 1,
  240. NULL, NULL);
  241. if (status >= 0) {
  242. dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
  243. maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
  244. fib_complete(fibptr);
  245. }
  246. if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
  247. maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  248. fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
  249. sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
  250. if (!fsa_dev_ptr) {
  251. fib_free(fibptr);
  252. return -ENOMEM;
  253. }
  254. memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
  255. dev->fsa_dev = fsa_dev_ptr;
  256. dev->maximum_num_containers = maximum_num_containers;
  257. for (index = 0; index < dev->maximum_num_containers; index++) {
  258. struct aac_query_mount *dinfo;
  259. struct aac_mount *dresp;
  260. fsa_dev_ptr[index].devname[0] = '\0';
  261. fib_init(fibptr);
  262. dinfo = (struct aac_query_mount *) fib_data(fibptr);
  263. dinfo->command = cpu_to_le32(VM_NameServe);
  264. dinfo->count = cpu_to_le32(index);
  265. dinfo->type = cpu_to_le32(FT_FILESYS);
  266. status = fib_send(ContainerCommand,
  267. fibptr,
  268. sizeof (struct aac_query_mount),
  269. FsaNormal,
  270. 1, 1,
  271. NULL, NULL);
  272. if (status < 0 ) {
  273. printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
  274. break;
  275. }
  276. dresp = (struct aac_mount *)fib_data(fibptr);
  277. dprintk ((KERN_DEBUG
  278. "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
  279. (int)index, (int)le32_to_cpu(dresp->status),
  280. (int)le32_to_cpu(dresp->mnt[0].vol),
  281. (int)le32_to_cpu(dresp->mnt[0].state),
  282. (unsigned)le32_to_cpu(dresp->mnt[0].capacity)));
  283. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  284. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
  285. (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
  286. fsa_dev_ptr[index].valid = 1;
  287. fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
  288. fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity);
  289. if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
  290. fsa_dev_ptr[index].ro = 1;
  291. }
  292. fib_complete(fibptr);
  293. /*
  294. * If there are no more containers, then stop asking.
  295. */
  296. if ((index + 1) >= le32_to_cpu(dresp->count)){
  297. break;
  298. }
  299. }
  300. fib_free(fibptr);
  301. return status;
  302. }
  303. static void aac_io_done(struct scsi_cmnd * scsicmd)
  304. {
  305. unsigned long cpu_flags;
  306. struct Scsi_Host *host = scsicmd->device->host;
  307. spin_lock_irqsave(host->host_lock, cpu_flags);
  308. scsicmd->scsi_done(scsicmd);
  309. spin_unlock_irqrestore(host->host_lock, cpu_flags);
  310. }
  311. static void get_container_name_callback(void *context, struct fib * fibptr)
  312. {
  313. struct aac_get_name_resp * get_name_reply;
  314. struct scsi_cmnd * scsicmd;
  315. scsicmd = (struct scsi_cmnd *) context;
  316. dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
  317. if (fibptr == NULL)
  318. BUG();
  319. get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
  320. /* Failure is irrelevant, using default value instead */
  321. if ((le32_to_cpu(get_name_reply->status) == CT_OK)
  322. && (get_name_reply->data[0] != '\0')) {
  323. int count;
  324. char * dp;
  325. char * sp = get_name_reply->data;
  326. sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
  327. while (*sp == ' ')
  328. ++sp;
  329. count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
  330. dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
  331. if (*sp) do {
  332. *dp++ = (*sp) ? *sp++ : ' ';
  333. } while (--count > 0);
  334. }
  335. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  336. fib_complete(fibptr);
  337. fib_free(fibptr);
  338. aac_io_done(scsicmd);
  339. }
  340. /**
  341. * aac_get_container_name - get container name, none blocking.
  342. */
  343. static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
  344. {
  345. int status;
  346. struct aac_get_name *dinfo;
  347. struct fib * cmd_fibcontext;
  348. struct aac_dev * dev;
  349. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  350. if (!(cmd_fibcontext = fib_alloc(dev)))
  351. return -ENOMEM;
  352. fib_init(cmd_fibcontext);
  353. dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
  354. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  355. dinfo->type = cpu_to_le32(CT_READ_NAME);
  356. dinfo->cid = cpu_to_le32(cid);
  357. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
  358. status = fib_send(ContainerCommand,
  359. cmd_fibcontext,
  360. sizeof (struct aac_get_name),
  361. FsaNormal,
  362. 0, 1,
  363. (fib_callback) get_container_name_callback,
  364. (void *) scsicmd);
  365. /*
  366. * Check that the command queued to the controller
  367. */
  368. if (status == -EINPROGRESS)
  369. return 0;
  370. printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
  371. fib_complete(cmd_fibcontext);
  372. fib_free(cmd_fibcontext);
  373. return -1;
  374. }
  375. /**
  376. * probe_container - query a logical volume
  377. * @dev: device to query
  378. * @cid: container identifier
  379. *
  380. * Queries the controller about the given volume. The volume information
  381. * is updated in the struct fsa_dev_info structure rather than returned.
  382. */
  383. static int probe_container(struct aac_dev *dev, int cid)
  384. {
  385. struct fsa_dev_info *fsa_dev_ptr;
  386. int status;
  387. struct aac_query_mount *dinfo;
  388. struct aac_mount *dresp;
  389. struct fib * fibptr;
  390. unsigned instance;
  391. fsa_dev_ptr = dev->fsa_dev;
  392. instance = dev->scsi_host_ptr->unique_id;
  393. if (!(fibptr = fib_alloc(dev)))
  394. return -ENOMEM;
  395. fib_init(fibptr);
  396. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  397. dinfo->command = cpu_to_le32(VM_NameServe);
  398. dinfo->count = cpu_to_le32(cid);
  399. dinfo->type = cpu_to_le32(FT_FILESYS);
  400. status = fib_send(ContainerCommand,
  401. fibptr,
  402. sizeof(struct aac_query_mount),
  403. FsaNormal,
  404. 1, 1,
  405. NULL, NULL);
  406. if (status < 0) {
  407. printk(KERN_WARNING "aacraid: probe_container query failed.\n");
  408. goto error;
  409. }
  410. dresp = (struct aac_mount *) fib_data(fibptr);
  411. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  412. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
  413. (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
  414. fsa_dev_ptr[cid].valid = 1;
  415. fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
  416. fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity);
  417. if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
  418. fsa_dev_ptr[cid].ro = 1;
  419. }
  420. error:
  421. fib_complete(fibptr);
  422. fib_free(fibptr);
  423. return status;
  424. }
  425. /* Local Structure to set SCSI inquiry data strings */
  426. struct scsi_inq {
  427. char vid[8]; /* Vendor ID */
  428. char pid[16]; /* Product ID */
  429. char prl[4]; /* Product Revision Level */
  430. };
  431. /**
  432. * InqStrCopy - string merge
  433. * @a: string to copy from
  434. * @b: string to copy to
  435. *
  436. * Copy a String from one location to another
  437. * without copying \0
  438. */
  439. static void inqstrcpy(char *a, char *b)
  440. {
  441. while(*a != (char)0)
  442. *b++ = *a++;
  443. }
  444. static char *container_types[] = {
  445. "None",
  446. "Volume",
  447. "Mirror",
  448. "Stripe",
  449. "RAID5",
  450. "SSRW",
  451. "SSRO",
  452. "Morph",
  453. "Legacy",
  454. "RAID4",
  455. "RAID10",
  456. "RAID00",
  457. "V-MIRRORS",
  458. "PSEUDO R4",
  459. "RAID50",
  460. "RAID5D",
  461. "RAID5D0",
  462. "RAID1E",
  463. "RAID6",
  464. "RAID60",
  465. "Unknown"
  466. };
  467. /* Function: setinqstr
  468. *
  469. * Arguments: [1] pointer to void [1] int
  470. *
  471. * Purpose: Sets SCSI inquiry data strings for vendor, product
  472. * and revision level. Allows strings to be set in platform dependant
  473. * files instead of in OS dependant driver source.
  474. */
  475. static void setinqstr(int devtype, void *data, int tindex)
  476. {
  477. struct scsi_inq *str;
  478. struct aac_driver_ident *mp;
  479. mp = aac_get_driver_ident(devtype);
  480. str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
  481. inqstrcpy (mp->vname, str->vid);
  482. inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
  483. if (tindex < (sizeof(container_types)/sizeof(char *))){
  484. char *findit = str->pid;
  485. for ( ; *findit != ' '; findit++); /* walk till we find a space */
  486. /* RAID is superfluous in the context of a RAID device */
  487. if (memcmp(findit-4, "RAID", 4) == 0)
  488. *(findit -= 4) = ' ';
  489. inqstrcpy (container_types[tindex], findit + 1);
  490. }
  491. inqstrcpy ("V1.0", str->prl);
  492. }
  493. static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
  494. u8 a_sense_code, u8 incorrect_length,
  495. u8 bit_pointer, u16 field_pointer,
  496. u32 residue)
  497. {
  498. sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
  499. sense_buf[1] = 0; /* Segment number, always zero */
  500. if (incorrect_length) {
  501. sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
  502. sense_buf[3] = BYTE3(residue);
  503. sense_buf[4] = BYTE2(residue);
  504. sense_buf[5] = BYTE1(residue);
  505. sense_buf[6] = BYTE0(residue);
  506. } else
  507. sense_buf[2] = sense_key; /* Sense key */
  508. if (sense_key == ILLEGAL_REQUEST)
  509. sense_buf[7] = 10; /* Additional sense length */
  510. else
  511. sense_buf[7] = 6; /* Additional sense length */
  512. sense_buf[12] = sense_code; /* Additional sense code */
  513. sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
  514. if (sense_key == ILLEGAL_REQUEST) {
  515. sense_buf[15] = 0;
  516. if (sense_code == SENCODE_INVALID_PARAM_FIELD)
  517. sense_buf[15] = 0x80;/* Std sense key specific field */
  518. /* Illegal parameter is in the parameter block */
  519. if (sense_code == SENCODE_INVALID_CDB_FIELD)
  520. sense_buf[15] = 0xc0;/* Std sense key specific field */
  521. /* Illegal parameter is in the CDB block */
  522. sense_buf[15] |= bit_pointer;
  523. sense_buf[16] = field_pointer >> 8; /* MSB */
  524. sense_buf[17] = field_pointer; /* LSB */
  525. }
  526. }
  527. int aac_get_adapter_info(struct aac_dev* dev)
  528. {
  529. struct fib* fibptr;
  530. int rcode;
  531. u32 tmp;
  532. struct aac_adapter_info *info;
  533. struct aac_bus_info *command;
  534. struct aac_bus_info_response *bus_info;
  535. if (!(fibptr = fib_alloc(dev)))
  536. return -ENOMEM;
  537. fib_init(fibptr);
  538. info = (struct aac_adapter_info *) fib_data(fibptr);
  539. memset(info,0,sizeof(*info));
  540. rcode = fib_send(RequestAdapterInfo,
  541. fibptr,
  542. sizeof(*info),
  543. FsaNormal,
  544. 1, 1,
  545. NULL,
  546. NULL);
  547. if (rcode < 0) {
  548. fib_complete(fibptr);
  549. fib_free(fibptr);
  550. return rcode;
  551. }
  552. memcpy(&dev->adapter_info, info, sizeof(*info));
  553. if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
  554. struct aac_supplement_adapter_info * info;
  555. fib_init(fibptr);
  556. info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
  557. memset(info,0,sizeof(*info));
  558. rcode = fib_send(RequestSupplementAdapterInfo,
  559. fibptr,
  560. sizeof(*info),
  561. FsaNormal,
  562. 1, 1,
  563. NULL,
  564. NULL);
  565. if (rcode >= 0)
  566. memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
  567. }
  568. /*
  569. * GetBusInfo
  570. */
  571. fib_init(fibptr);
  572. bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
  573. memset(bus_info, 0, sizeof(*bus_info));
  574. command = (struct aac_bus_info *)bus_info;
  575. command->Command = cpu_to_le32(VM_Ioctl);
  576. command->ObjType = cpu_to_le32(FT_DRIVE);
  577. command->MethodId = cpu_to_le32(1);
  578. command->CtlCmd = cpu_to_le32(GetBusInfo);
  579. rcode = fib_send(ContainerCommand,
  580. fibptr,
  581. sizeof (*bus_info),
  582. FsaNormal,
  583. 1, 1,
  584. NULL, NULL);
  585. if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
  586. dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
  587. dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
  588. }
  589. tmp = le32_to_cpu(dev->adapter_info.kernelrev);
  590. printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
  591. dev->name,
  592. dev->id,
  593. tmp>>24,
  594. (tmp>>16)&0xff,
  595. tmp&0xff,
  596. le32_to_cpu(dev->adapter_info.kernelbuild),
  597. (int)sizeof(dev->supplement_adapter_info.BuildDate),
  598. dev->supplement_adapter_info.BuildDate);
  599. tmp = le32_to_cpu(dev->adapter_info.monitorrev);
  600. printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
  601. dev->name, dev->id,
  602. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  603. le32_to_cpu(dev->adapter_info.monitorbuild));
  604. tmp = le32_to_cpu(dev->adapter_info.biosrev);
  605. printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
  606. dev->name, dev->id,
  607. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  608. le32_to_cpu(dev->adapter_info.biosbuild));
  609. if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
  610. printk(KERN_INFO "%s%d: serial %x\n",
  611. dev->name, dev->id,
  612. le32_to_cpu(dev->adapter_info.serial[0]));
  613. dev->nondasd_support = 0;
  614. dev->raid_scsi_mode = 0;
  615. if(dev->adapter_info.options & AAC_OPT_NONDASD){
  616. dev->nondasd_support = 1;
  617. }
  618. /*
  619. * If the firmware supports ROMB RAID/SCSI mode and we are currently
  620. * in RAID/SCSI mode, set the flag. For now if in this mode we will
  621. * force nondasd support on. If we decide to allow the non-dasd flag
  622. * additional changes changes will have to be made to support
  623. * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
  624. * changed to support the new dev->raid_scsi_mode flag instead of
  625. * leaching off of the dev->nondasd_support flag. Also in linit.c the
  626. * function aac_detect will have to be modified where it sets up the
  627. * max number of channels based on the aac->nondasd_support flag only.
  628. */
  629. if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
  630. (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
  631. dev->nondasd_support = 1;
  632. dev->raid_scsi_mode = 1;
  633. }
  634. if (dev->raid_scsi_mode != 0)
  635. printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
  636. dev->name, dev->id);
  637. if(nondasd != -1) {
  638. dev->nondasd_support = (nondasd!=0);
  639. }
  640. if(dev->nondasd_support != 0){
  641. printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
  642. }
  643. dev->dac_support = 0;
  644. if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
  645. printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
  646. dev->dac_support = 1;
  647. }
  648. if(dacmode != -1) {
  649. dev->dac_support = (dacmode!=0);
  650. }
  651. if(dev->dac_support != 0) {
  652. if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL) &&
  653. !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL)) {
  654. printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
  655. dev->name, dev->id);
  656. } else if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFULL) &&
  657. !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFULL)) {
  658. printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
  659. dev->name, dev->id);
  660. dev->dac_support = 0;
  661. } else {
  662. printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
  663. dev->name, dev->id);
  664. rcode = -ENOMEM;
  665. }
  666. }
  667. /*
  668. * 57 scatter gather elements
  669. */
  670. dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
  671. sizeof(struct aac_fibhdr) -
  672. sizeof(struct aac_write) + sizeof(struct sgmap)) /
  673. sizeof(struct sgmap);
  674. if (dev->dac_support) {
  675. /*
  676. * 38 scatter gather elements
  677. */
  678. dev->scsi_host_ptr->sg_tablesize =
  679. (dev->max_fib_size -
  680. sizeof(struct aac_fibhdr) -
  681. sizeof(struct aac_write64) +
  682. sizeof(struct sgmap64)) /
  683. sizeof(struct sgmap64);
  684. }
  685. dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  686. if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
  687. /*
  688. * Worst case size that could cause sg overflow when
  689. * we break up SG elements that are larger than 64KB.
  690. * Would be nice if we could tell the SCSI layer what
  691. * the maximum SG element size can be. Worst case is
  692. * (sg_tablesize-1) 4KB elements with one 64KB
  693. * element.
  694. * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
  695. */
  696. dev->scsi_host_ptr->max_sectors =
  697. (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
  698. }
  699. fib_complete(fibptr);
  700. fib_free(fibptr);
  701. return rcode;
  702. }
  703. static void read_callback(void *context, struct fib * fibptr)
  704. {
  705. struct aac_dev *dev;
  706. struct aac_read_reply *readreply;
  707. struct scsi_cmnd *scsicmd;
  708. u32 lba;
  709. u32 cid;
  710. scsicmd = (struct scsi_cmnd *) context;
  711. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  712. cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
  713. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  714. dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
  715. if (fibptr == NULL)
  716. BUG();
  717. if(scsicmd->use_sg)
  718. pci_unmap_sg(dev->pdev,
  719. (struct scatterlist *)scsicmd->buffer,
  720. scsicmd->use_sg,
  721. scsicmd->sc_data_direction);
  722. else if(scsicmd->request_bufflen)
  723. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
  724. scsicmd->request_bufflen,
  725. scsicmd->sc_data_direction);
  726. readreply = (struct aac_read_reply *)fib_data(fibptr);
  727. if (le32_to_cpu(readreply->status) == ST_OK)
  728. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  729. else {
  730. #ifdef AAC_DETAILED_STATUS_INFO
  731. printk(KERN_WARNING "read_callback: io failed, status = %d\n",
  732. le32_to_cpu(readreply->status));
  733. #endif
  734. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  735. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  736. HARDWARE_ERROR,
  737. SENCODE_INTERNAL_TARGET_FAILURE,
  738. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  739. 0, 0);
  740. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  741. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  742. ? sizeof(scsicmd->sense_buffer)
  743. : sizeof(dev->fsa_dev[cid].sense_data));
  744. }
  745. fib_complete(fibptr);
  746. fib_free(fibptr);
  747. aac_io_done(scsicmd);
  748. }
  749. static void write_callback(void *context, struct fib * fibptr)
  750. {
  751. struct aac_dev *dev;
  752. struct aac_write_reply *writereply;
  753. struct scsi_cmnd *scsicmd;
  754. u32 lba;
  755. u32 cid;
  756. scsicmd = (struct scsi_cmnd *) context;
  757. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  758. cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
  759. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  760. dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
  761. if (fibptr == NULL)
  762. BUG();
  763. if(scsicmd->use_sg)
  764. pci_unmap_sg(dev->pdev,
  765. (struct scatterlist *)scsicmd->buffer,
  766. scsicmd->use_sg,
  767. scsicmd->sc_data_direction);
  768. else if(scsicmd->request_bufflen)
  769. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
  770. scsicmd->request_bufflen,
  771. scsicmd->sc_data_direction);
  772. writereply = (struct aac_write_reply *) fib_data(fibptr);
  773. if (le32_to_cpu(writereply->status) == ST_OK)
  774. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  775. else {
  776. printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
  777. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  778. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  779. HARDWARE_ERROR,
  780. SENCODE_INTERNAL_TARGET_FAILURE,
  781. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  782. 0, 0);
  783. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  784. sizeof(struct sense_data));
  785. }
  786. fib_complete(fibptr);
  787. fib_free(fibptr);
  788. aac_io_done(scsicmd);
  789. }
  790. static int aac_read(struct scsi_cmnd * scsicmd, int cid)
  791. {
  792. u32 lba;
  793. u32 count;
  794. int status;
  795. u16 fibsize;
  796. struct aac_dev *dev;
  797. struct fib * cmd_fibcontext;
  798. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  799. /*
  800. * Get block address and transfer length
  801. */
  802. if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
  803. {
  804. dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
  805. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  806. count = scsicmd->cmnd[4];
  807. if (count == 0)
  808. count = 256;
  809. } else {
  810. dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
  811. lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  812. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  813. }
  814. dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n",
  815. smp_processor_id(), (unsigned long long)lba, jiffies));
  816. /*
  817. * Alocate and initialize a Fib
  818. */
  819. if (!(cmd_fibcontext = fib_alloc(dev))) {
  820. return -1;
  821. }
  822. fib_init(cmd_fibcontext);
  823. if (dev->dac_support == 1) {
  824. struct aac_read64 *readcmd;
  825. readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
  826. readcmd->command = cpu_to_le32(VM_CtHostRead64);
  827. readcmd->cid = cpu_to_le16(cid);
  828. readcmd->sector_count = cpu_to_le16(count);
  829. readcmd->block = cpu_to_le32(lba);
  830. readcmd->pad = 0;
  831. readcmd->flags = 0;
  832. aac_build_sg64(scsicmd, &readcmd->sg);
  833. fibsize = sizeof(struct aac_read64) +
  834. ((le32_to_cpu(readcmd->sg.count) - 1) *
  835. sizeof (struct sgentry64));
  836. BUG_ON (fibsize > (sizeof(struct hw_fib) -
  837. sizeof(struct aac_fibhdr)));
  838. /*
  839. * Now send the Fib to the adapter
  840. */
  841. status = fib_send(ContainerCommand64,
  842. cmd_fibcontext,
  843. fibsize,
  844. FsaNormal,
  845. 0, 1,
  846. (fib_callback) read_callback,
  847. (void *) scsicmd);
  848. } else {
  849. struct aac_read *readcmd;
  850. readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
  851. readcmd->command = cpu_to_le32(VM_CtBlockRead);
  852. readcmd->cid = cpu_to_le32(cid);
  853. readcmd->block = cpu_to_le32(lba);
  854. readcmd->count = cpu_to_le32(count * 512);
  855. aac_build_sg(scsicmd, &readcmd->sg);
  856. fibsize = sizeof(struct aac_read) +
  857. ((le32_to_cpu(readcmd->sg.count) - 1) *
  858. sizeof (struct sgentry));
  859. BUG_ON (fibsize > (dev->max_fib_size -
  860. sizeof(struct aac_fibhdr)));
  861. /*
  862. * Now send the Fib to the adapter
  863. */
  864. status = fib_send(ContainerCommand,
  865. cmd_fibcontext,
  866. fibsize,
  867. FsaNormal,
  868. 0, 1,
  869. (fib_callback) read_callback,
  870. (void *) scsicmd);
  871. }
  872. /*
  873. * Check that the command queued to the controller
  874. */
  875. if (status == -EINPROGRESS)
  876. return 0;
  877. printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
  878. /*
  879. * For some reason, the Fib didn't queue, return QUEUE_FULL
  880. */
  881. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  882. aac_io_done(scsicmd);
  883. fib_complete(cmd_fibcontext);
  884. fib_free(cmd_fibcontext);
  885. return 0;
  886. }
  887. static int aac_write(struct scsi_cmnd * scsicmd, int cid)
  888. {
  889. u32 lba;
  890. u32 count;
  891. int status;
  892. u16 fibsize;
  893. struct aac_dev *dev;
  894. struct fib * cmd_fibcontext;
  895. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  896. /*
  897. * Get block address and transfer length
  898. */
  899. if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
  900. {
  901. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  902. count = scsicmd->cmnd[4];
  903. if (count == 0)
  904. count = 256;
  905. } else {
  906. dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
  907. lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  908. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  909. }
  910. dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n",
  911. smp_processor_id(), (unsigned long long)lba, jiffies));
  912. /*
  913. * Allocate and initialize a Fib then setup a BlockWrite command
  914. */
  915. if (!(cmd_fibcontext = fib_alloc(dev))) {
  916. scsicmd->result = DID_ERROR << 16;
  917. aac_io_done(scsicmd);
  918. return 0;
  919. }
  920. fib_init(cmd_fibcontext);
  921. if(dev->dac_support == 1) {
  922. struct aac_write64 *writecmd;
  923. writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
  924. writecmd->command = cpu_to_le32(VM_CtHostWrite64);
  925. writecmd->cid = cpu_to_le16(cid);
  926. writecmd->sector_count = cpu_to_le16(count);
  927. writecmd->block = cpu_to_le32(lba);
  928. writecmd->pad = 0;
  929. writecmd->flags = 0;
  930. aac_build_sg64(scsicmd, &writecmd->sg);
  931. fibsize = sizeof(struct aac_write64) +
  932. ((le32_to_cpu(writecmd->sg.count) - 1) *
  933. sizeof (struct sgentry64));
  934. BUG_ON (fibsize > (dev->max_fib_size -
  935. sizeof(struct aac_fibhdr)));
  936. /*
  937. * Now send the Fib to the adapter
  938. */
  939. status = fib_send(ContainerCommand64,
  940. cmd_fibcontext,
  941. fibsize,
  942. FsaNormal,
  943. 0, 1,
  944. (fib_callback) write_callback,
  945. (void *) scsicmd);
  946. } else {
  947. struct aac_write *writecmd;
  948. writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
  949. writecmd->command = cpu_to_le32(VM_CtBlockWrite);
  950. writecmd->cid = cpu_to_le32(cid);
  951. writecmd->block = cpu_to_le32(lba);
  952. writecmd->count = cpu_to_le32(count * 512);
  953. writecmd->sg.count = cpu_to_le32(1);
  954. /* ->stable is not used - it did mean which type of write */
  955. aac_build_sg(scsicmd, &writecmd->sg);
  956. fibsize = sizeof(struct aac_write) +
  957. ((le32_to_cpu(writecmd->sg.count) - 1) *
  958. sizeof (struct sgentry));
  959. BUG_ON (fibsize > (dev->max_fib_size -
  960. sizeof(struct aac_fibhdr)));
  961. /*
  962. * Now send the Fib to the adapter
  963. */
  964. status = fib_send(ContainerCommand,
  965. cmd_fibcontext,
  966. fibsize,
  967. FsaNormal,
  968. 0, 1,
  969. (fib_callback) write_callback,
  970. (void *) scsicmd);
  971. }
  972. /*
  973. * Check that the command queued to the controller
  974. */
  975. if (status == -EINPROGRESS)
  976. {
  977. return 0;
  978. }
  979. printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
  980. /*
  981. * For some reason, the Fib didn't queue, return QUEUE_FULL
  982. */
  983. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  984. aac_io_done(scsicmd);
  985. fib_complete(cmd_fibcontext);
  986. fib_free(cmd_fibcontext);
  987. return 0;
  988. }
  989. static void synchronize_callback(void *context, struct fib *fibptr)
  990. {
  991. struct aac_synchronize_reply *synchronizereply;
  992. struct scsi_cmnd *cmd;
  993. cmd = context;
  994. dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
  995. smp_processor_id(), jiffies));
  996. BUG_ON(fibptr == NULL);
  997. synchronizereply = fib_data(fibptr);
  998. if (le32_to_cpu(synchronizereply->status) == CT_OK)
  999. cmd->result = DID_OK << 16 |
  1000. COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1001. else {
  1002. struct scsi_device *sdev = cmd->device;
  1003. struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
  1004. u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
  1005. printk(KERN_WARNING
  1006. "synchronize_callback: synchronize failed, status = %d\n",
  1007. le32_to_cpu(synchronizereply->status));
  1008. cmd->result = DID_OK << 16 |
  1009. COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1010. set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
  1011. HARDWARE_ERROR,
  1012. SENCODE_INTERNAL_TARGET_FAILURE,
  1013. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1014. 0, 0);
  1015. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1016. min(sizeof(dev->fsa_dev[cid].sense_data),
  1017. sizeof(cmd->sense_buffer)));
  1018. }
  1019. fib_complete(fibptr);
  1020. fib_free(fibptr);
  1021. aac_io_done(cmd);
  1022. }
  1023. static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
  1024. {
  1025. int status;
  1026. struct fib *cmd_fibcontext;
  1027. struct aac_synchronize *synchronizecmd;
  1028. struct scsi_cmnd *cmd;
  1029. struct scsi_device *sdev = scsicmd->device;
  1030. int active = 0;
  1031. unsigned long flags;
  1032. /*
  1033. * Wait for all commands to complete to this specific
  1034. * target (block).
  1035. */
  1036. spin_lock_irqsave(&sdev->list_lock, flags);
  1037. list_for_each_entry(cmd, &sdev->cmd_list, list)
  1038. if (cmd != scsicmd && cmd->serial_number != 0) {
  1039. ++active;
  1040. break;
  1041. }
  1042. spin_unlock_irqrestore(&sdev->list_lock, flags);
  1043. /*
  1044. * Yield the processor (requeue for later)
  1045. */
  1046. if (active)
  1047. return SCSI_MLQUEUE_DEVICE_BUSY;
  1048. /*
  1049. * Allocate and initialize a Fib
  1050. */
  1051. if (!(cmd_fibcontext =
  1052. fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
  1053. return SCSI_MLQUEUE_HOST_BUSY;
  1054. fib_init(cmd_fibcontext);
  1055. synchronizecmd = fib_data(cmd_fibcontext);
  1056. synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
  1057. synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
  1058. synchronizecmd->cid = cpu_to_le32(cid);
  1059. synchronizecmd->count =
  1060. cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
  1061. /*
  1062. * Now send the Fib to the adapter
  1063. */
  1064. status = fib_send(ContainerCommand,
  1065. cmd_fibcontext,
  1066. sizeof(struct aac_synchronize),
  1067. FsaNormal,
  1068. 0, 1,
  1069. (fib_callback)synchronize_callback,
  1070. (void *)scsicmd);
  1071. /*
  1072. * Check that the command queued to the controller
  1073. */
  1074. if (status == -EINPROGRESS)
  1075. return 0;
  1076. printk(KERN_WARNING
  1077. "aac_synchronize: fib_send failed with status: %d.\n", status);
  1078. fib_complete(cmd_fibcontext);
  1079. fib_free(cmd_fibcontext);
  1080. return SCSI_MLQUEUE_HOST_BUSY;
  1081. }
  1082. /**
  1083. * aac_scsi_cmd() - Process SCSI command
  1084. * @scsicmd: SCSI command block
  1085. *
  1086. * Emulate a SCSI command and queue the required request for the
  1087. * aacraid firmware.
  1088. */
  1089. int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
  1090. {
  1091. u32 cid = 0;
  1092. struct Scsi_Host *host = scsicmd->device->host;
  1093. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  1094. struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
  1095. int cardtype = dev->cardtype;
  1096. int ret;
  1097. /*
  1098. * If the bus, id or lun is out of range, return fail
  1099. * Test does not apply to ID 16, the pseudo id for the controller
  1100. * itself.
  1101. */
  1102. if (scsicmd->device->id != host->this_id) {
  1103. if ((scsicmd->device->channel == 0) ){
  1104. if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
  1105. scsicmd->result = DID_NO_CONNECT << 16;
  1106. scsicmd->scsi_done(scsicmd);
  1107. return 0;
  1108. }
  1109. cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
  1110. /*
  1111. * If the target container doesn't exist, it may have
  1112. * been newly created
  1113. */
  1114. if ((fsa_dev_ptr[cid].valid & 1) == 0) {
  1115. switch (scsicmd->cmnd[0]) {
  1116. case INQUIRY:
  1117. case READ_CAPACITY:
  1118. case TEST_UNIT_READY:
  1119. spin_unlock_irq(host->host_lock);
  1120. probe_container(dev, cid);
  1121. spin_lock_irq(host->host_lock);
  1122. if (fsa_dev_ptr[cid].valid == 0) {
  1123. scsicmd->result = DID_NO_CONNECT << 16;
  1124. scsicmd->scsi_done(scsicmd);
  1125. return 0;
  1126. }
  1127. default:
  1128. break;
  1129. }
  1130. }
  1131. /*
  1132. * If the target container still doesn't exist,
  1133. * return failure
  1134. */
  1135. if (fsa_dev_ptr[cid].valid == 0) {
  1136. scsicmd->result = DID_BAD_TARGET << 16;
  1137. scsicmd->scsi_done(scsicmd);
  1138. return 0;
  1139. }
  1140. } else { /* check for physical non-dasd devices */
  1141. if(dev->nondasd_support == 1){
  1142. return aac_send_srb_fib(scsicmd);
  1143. } else {
  1144. scsicmd->result = DID_NO_CONNECT << 16;
  1145. scsicmd->scsi_done(scsicmd);
  1146. return 0;
  1147. }
  1148. }
  1149. }
  1150. /*
  1151. * else Command for the controller itself
  1152. */
  1153. else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
  1154. (scsicmd->cmnd[0] != TEST_UNIT_READY))
  1155. {
  1156. dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
  1157. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1158. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1159. ILLEGAL_REQUEST,
  1160. SENCODE_INVALID_COMMAND,
  1161. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1162. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1163. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1164. ? sizeof(scsicmd->sense_buffer)
  1165. : sizeof(dev->fsa_dev[cid].sense_data));
  1166. scsicmd->scsi_done(scsicmd);
  1167. return 0;
  1168. }
  1169. /* Handle commands here that don't really require going out to the adapter */
  1170. switch (scsicmd->cmnd[0]) {
  1171. case INQUIRY:
  1172. {
  1173. struct inquiry_data *inq_data_ptr;
  1174. dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
  1175. inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
  1176. memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
  1177. inq_data_ptr->inqd_ver = 2; /* claim compliance to SCSI-2 */
  1178. inq_data_ptr->inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
  1179. inq_data_ptr->inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
  1180. inq_data_ptr->inqd_len = 31;
  1181. /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  1182. inq_data_ptr->inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
  1183. /*
  1184. * Set the Vendor, Product, and Revision Level
  1185. * see: <vendor>.c i.e. aac.c
  1186. */
  1187. if (scsicmd->device->id == host->this_id) {
  1188. setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
  1189. inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
  1190. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1191. scsicmd->scsi_done(scsicmd);
  1192. return 0;
  1193. }
  1194. setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
  1195. inq_data_ptr->inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
  1196. return aac_get_container_name(scsicmd, cid);
  1197. }
  1198. case READ_CAPACITY:
  1199. {
  1200. u32 capacity;
  1201. char *cp;
  1202. dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
  1203. if (fsa_dev_ptr[cid].size <= 0x100000000LL)
  1204. capacity = fsa_dev_ptr[cid].size - 1;
  1205. else
  1206. capacity = (u32)-1;
  1207. cp = scsicmd->request_buffer;
  1208. cp[0] = (capacity >> 24) & 0xff;
  1209. cp[1] = (capacity >> 16) & 0xff;
  1210. cp[2] = (capacity >> 8) & 0xff;
  1211. cp[3] = (capacity >> 0) & 0xff;
  1212. cp[4] = 0;
  1213. cp[5] = 0;
  1214. cp[6] = 2;
  1215. cp[7] = 0;
  1216. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1217. scsicmd->scsi_done(scsicmd);
  1218. return 0;
  1219. }
  1220. case MODE_SENSE:
  1221. {
  1222. char *mode_buf;
  1223. dprintk((KERN_DEBUG "MODE SENSE command.\n"));
  1224. mode_buf = scsicmd->request_buffer;
  1225. mode_buf[0] = 3; /* Mode data length */
  1226. mode_buf[1] = 0; /* Medium type - default */
  1227. mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1228. mode_buf[3] = 0; /* Block descriptor length */
  1229. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1230. scsicmd->scsi_done(scsicmd);
  1231. return 0;
  1232. }
  1233. case MODE_SENSE_10:
  1234. {
  1235. char *mode_buf;
  1236. dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
  1237. mode_buf = scsicmd->request_buffer;
  1238. mode_buf[0] = 0; /* Mode data length (MSB) */
  1239. mode_buf[1] = 6; /* Mode data length (LSB) */
  1240. mode_buf[2] = 0; /* Medium type - default */
  1241. mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1242. mode_buf[4] = 0; /* reserved */
  1243. mode_buf[5] = 0; /* reserved */
  1244. mode_buf[6] = 0; /* Block descriptor length (MSB) */
  1245. mode_buf[7] = 0; /* Block descriptor length (LSB) */
  1246. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1247. scsicmd->scsi_done(scsicmd);
  1248. return 0;
  1249. }
  1250. case REQUEST_SENSE:
  1251. dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
  1252. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
  1253. memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
  1254. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1255. scsicmd->scsi_done(scsicmd);
  1256. return 0;
  1257. case ALLOW_MEDIUM_REMOVAL:
  1258. dprintk((KERN_DEBUG "LOCK command.\n"));
  1259. if (scsicmd->cmnd[4])
  1260. fsa_dev_ptr[cid].locked = 1;
  1261. else
  1262. fsa_dev_ptr[cid].locked = 0;
  1263. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1264. scsicmd->scsi_done(scsicmd);
  1265. return 0;
  1266. /*
  1267. * These commands are all No-Ops
  1268. */
  1269. case TEST_UNIT_READY:
  1270. case RESERVE:
  1271. case RELEASE:
  1272. case REZERO_UNIT:
  1273. case REASSIGN_BLOCKS:
  1274. case SEEK_10:
  1275. case START_STOP:
  1276. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1277. scsicmd->scsi_done(scsicmd);
  1278. return 0;
  1279. }
  1280. switch (scsicmd->cmnd[0])
  1281. {
  1282. case READ_6:
  1283. case READ_10:
  1284. /*
  1285. * Hack to keep track of ordinal number of the device that
  1286. * corresponds to a container. Needed to convert
  1287. * containers to /dev/sd device names
  1288. */
  1289. spin_unlock_irq(host->host_lock);
  1290. if (scsicmd->request->rq_disk)
  1291. memcpy(fsa_dev_ptr[cid].devname,
  1292. scsicmd->request->rq_disk->disk_name,
  1293. 8);
  1294. ret = aac_read(scsicmd, cid);
  1295. spin_lock_irq(host->host_lock);
  1296. return ret;
  1297. case WRITE_6:
  1298. case WRITE_10:
  1299. spin_unlock_irq(host->host_lock);
  1300. ret = aac_write(scsicmd, cid);
  1301. spin_lock_irq(host->host_lock);
  1302. return ret;
  1303. case SYNCHRONIZE_CACHE:
  1304. /* Issue FIB to tell Firmware to flush it's cache */
  1305. return aac_synchronize(scsicmd, cid);
  1306. default:
  1307. /*
  1308. * Unhandled commands
  1309. */
  1310. dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
  1311. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1312. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1313. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  1314. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1315. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1316. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1317. ? sizeof(scsicmd->sense_buffer)
  1318. : sizeof(dev->fsa_dev[cid].sense_data));
  1319. scsicmd->scsi_done(scsicmd);
  1320. return 0;
  1321. }
  1322. }
  1323. static int query_disk(struct aac_dev *dev, void __user *arg)
  1324. {
  1325. struct aac_query_disk qd;
  1326. struct fsa_dev_info *fsa_dev_ptr;
  1327. fsa_dev_ptr = dev->fsa_dev;
  1328. if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
  1329. return -EFAULT;
  1330. if (qd.cnum == -1)
  1331. qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
  1332. else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
  1333. {
  1334. if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
  1335. return -EINVAL;
  1336. qd.instance = dev->scsi_host_ptr->host_no;
  1337. qd.bus = 0;
  1338. qd.id = CONTAINER_TO_ID(qd.cnum);
  1339. qd.lun = CONTAINER_TO_LUN(qd.cnum);
  1340. }
  1341. else return -EINVAL;
  1342. qd.valid = fsa_dev_ptr[qd.cnum].valid;
  1343. qd.locked = fsa_dev_ptr[qd.cnum].locked;
  1344. qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
  1345. if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
  1346. qd.unmapped = 1;
  1347. else
  1348. qd.unmapped = 0;
  1349. strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
  1350. min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
  1351. if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
  1352. return -EFAULT;
  1353. return 0;
  1354. }
  1355. static int force_delete_disk(struct aac_dev *dev, void __user *arg)
  1356. {
  1357. struct aac_delete_disk dd;
  1358. struct fsa_dev_info *fsa_dev_ptr;
  1359. fsa_dev_ptr = dev->fsa_dev;
  1360. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1361. return -EFAULT;
  1362. if (dd.cnum >= dev->maximum_num_containers)
  1363. return -EINVAL;
  1364. /*
  1365. * Mark this container as being deleted.
  1366. */
  1367. fsa_dev_ptr[dd.cnum].deleted = 1;
  1368. /*
  1369. * Mark the container as no longer valid
  1370. */
  1371. fsa_dev_ptr[dd.cnum].valid = 0;
  1372. return 0;
  1373. }
  1374. static int delete_disk(struct aac_dev *dev, void __user *arg)
  1375. {
  1376. struct aac_delete_disk dd;
  1377. struct fsa_dev_info *fsa_dev_ptr;
  1378. fsa_dev_ptr = dev->fsa_dev;
  1379. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1380. return -EFAULT;
  1381. if (dd.cnum >= dev->maximum_num_containers)
  1382. return -EINVAL;
  1383. /*
  1384. * If the container is locked, it can not be deleted by the API.
  1385. */
  1386. if (fsa_dev_ptr[dd.cnum].locked)
  1387. return -EBUSY;
  1388. else {
  1389. /*
  1390. * Mark the container as no longer being valid.
  1391. */
  1392. fsa_dev_ptr[dd.cnum].valid = 0;
  1393. fsa_dev_ptr[dd.cnum].devname[0] = '\0';
  1394. return 0;
  1395. }
  1396. }
  1397. int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
  1398. {
  1399. switch (cmd) {
  1400. case FSACTL_QUERY_DISK:
  1401. return query_disk(dev, arg);
  1402. case FSACTL_DELETE_DISK:
  1403. return delete_disk(dev, arg);
  1404. case FSACTL_FORCE_DELETE_DISK:
  1405. return force_delete_disk(dev, arg);
  1406. case FSACTL_GET_CONTAINERS:
  1407. return aac_get_containers(dev);
  1408. default:
  1409. return -ENOTTY;
  1410. }
  1411. }
  1412. /**
  1413. *
  1414. * aac_srb_callback
  1415. * @context: the context set in the fib - here it is scsi cmd
  1416. * @fibptr: pointer to the fib
  1417. *
  1418. * Handles the completion of a scsi command to a non dasd device
  1419. *
  1420. */
  1421. static void aac_srb_callback(void *context, struct fib * fibptr)
  1422. {
  1423. struct aac_dev *dev;
  1424. struct aac_srb_reply *srbreply;
  1425. struct scsi_cmnd *scsicmd;
  1426. scsicmd = (struct scsi_cmnd *) context;
  1427. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1428. if (fibptr == NULL)
  1429. BUG();
  1430. srbreply = (struct aac_srb_reply *) fib_data(fibptr);
  1431. scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
  1432. /*
  1433. * Calculate resid for sg
  1434. */
  1435. scsicmd->resid = scsicmd->request_bufflen -
  1436. le32_to_cpu(srbreply->data_xfer_length);
  1437. if(scsicmd->use_sg)
  1438. pci_unmap_sg(dev->pdev,
  1439. (struct scatterlist *)scsicmd->buffer,
  1440. scsicmd->use_sg,
  1441. scsicmd->sc_data_direction);
  1442. else if(scsicmd->request_bufflen)
  1443. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
  1444. scsicmd->sc_data_direction);
  1445. /*
  1446. * First check the fib status
  1447. */
  1448. if (le32_to_cpu(srbreply->status) != ST_OK){
  1449. int len;
  1450. printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
  1451. len = (le32_to_cpu(srbreply->sense_data_size) >
  1452. sizeof(scsicmd->sense_buffer)) ?
  1453. sizeof(scsicmd->sense_buffer) :
  1454. le32_to_cpu(srbreply->sense_data_size);
  1455. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1456. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1457. }
  1458. /*
  1459. * Next check the srb status
  1460. */
  1461. switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
  1462. case SRB_STATUS_ERROR_RECOVERY:
  1463. case SRB_STATUS_PENDING:
  1464. case SRB_STATUS_SUCCESS:
  1465. if(scsicmd->cmnd[0] == INQUIRY ){
  1466. u8 b;
  1467. u8 b1;
  1468. /* We can't expose disk devices because we can't tell whether they
  1469. * are the raw container drives or stand alone drives. If they have
  1470. * the removable bit set then we should expose them though.
  1471. */
  1472. b = (*(u8*)scsicmd->buffer)&0x1f;
  1473. b1 = ((u8*)scsicmd->buffer)[1];
  1474. if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
  1475. || (b==TYPE_DISK && (b1&0x80)) ){
  1476. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1477. /*
  1478. * We will allow disk devices if in RAID/SCSI mode and
  1479. * the channel is 2
  1480. */
  1481. } else if ((dev->raid_scsi_mode) &&
  1482. (scsicmd->device->channel == 2)) {
  1483. scsicmd->result = DID_OK << 16 |
  1484. COMMAND_COMPLETE << 8;
  1485. } else {
  1486. scsicmd->result = DID_NO_CONNECT << 16 |
  1487. COMMAND_COMPLETE << 8;
  1488. }
  1489. } else {
  1490. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1491. }
  1492. break;
  1493. case SRB_STATUS_DATA_OVERRUN:
  1494. switch(scsicmd->cmnd[0]){
  1495. case READ_6:
  1496. case WRITE_6:
  1497. case READ_10:
  1498. case WRITE_10:
  1499. case READ_12:
  1500. case WRITE_12:
  1501. if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
  1502. printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
  1503. } else {
  1504. printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
  1505. }
  1506. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1507. break;
  1508. case INQUIRY: {
  1509. u8 b;
  1510. u8 b1;
  1511. /* We can't expose disk devices because we can't tell whether they
  1512. * are the raw container drives or stand alone drives
  1513. */
  1514. b = (*(u8*)scsicmd->buffer)&0x0f;
  1515. b1 = ((u8*)scsicmd->buffer)[1];
  1516. if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
  1517. || (b==TYPE_DISK && (b1&0x80)) ){
  1518. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1519. /*
  1520. * We will allow disk devices if in RAID/SCSI mode and
  1521. * the channel is 2
  1522. */
  1523. } else if ((dev->raid_scsi_mode) &&
  1524. (scsicmd->device->channel == 2)) {
  1525. scsicmd->result = DID_OK << 16 |
  1526. COMMAND_COMPLETE << 8;
  1527. } else {
  1528. scsicmd->result = DID_NO_CONNECT << 16 |
  1529. COMMAND_COMPLETE << 8;
  1530. }
  1531. break;
  1532. }
  1533. default:
  1534. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1535. break;
  1536. }
  1537. break;
  1538. case SRB_STATUS_ABORTED:
  1539. scsicmd->result = DID_ABORT << 16 | ABORT << 8;
  1540. break;
  1541. case SRB_STATUS_ABORT_FAILED:
  1542. // Not sure about this one - but assuming the hba was trying to abort for some reason
  1543. scsicmd->result = DID_ERROR << 16 | ABORT << 8;
  1544. break;
  1545. case SRB_STATUS_PARITY_ERROR:
  1546. scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
  1547. break;
  1548. case SRB_STATUS_NO_DEVICE:
  1549. case SRB_STATUS_INVALID_PATH_ID:
  1550. case SRB_STATUS_INVALID_TARGET_ID:
  1551. case SRB_STATUS_INVALID_LUN:
  1552. case SRB_STATUS_SELECTION_TIMEOUT:
  1553. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1554. break;
  1555. case SRB_STATUS_COMMAND_TIMEOUT:
  1556. case SRB_STATUS_TIMEOUT:
  1557. scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
  1558. break;
  1559. case SRB_STATUS_BUSY:
  1560. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1561. break;
  1562. case SRB_STATUS_BUS_RESET:
  1563. scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
  1564. break;
  1565. case SRB_STATUS_MESSAGE_REJECTED:
  1566. scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
  1567. break;
  1568. case SRB_STATUS_REQUEST_FLUSHED:
  1569. case SRB_STATUS_ERROR:
  1570. case SRB_STATUS_INVALID_REQUEST:
  1571. case SRB_STATUS_REQUEST_SENSE_FAILED:
  1572. case SRB_STATUS_NO_HBA:
  1573. case SRB_STATUS_UNEXPECTED_BUS_FREE:
  1574. case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
  1575. case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
  1576. case SRB_STATUS_DELAYED_RETRY:
  1577. case SRB_STATUS_BAD_FUNCTION:
  1578. case SRB_STATUS_NOT_STARTED:
  1579. case SRB_STATUS_NOT_IN_USE:
  1580. case SRB_STATUS_FORCE_ABORT:
  1581. case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
  1582. default:
  1583. #ifdef AAC_DETAILED_STATUS_INFO
  1584. printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
  1585. le32_to_cpu(srbreply->srb_status) & 0x3F,
  1586. aac_get_status_string(
  1587. le32_to_cpu(srbreply->srb_status) & 0x3F),
  1588. scsicmd->cmnd[0],
  1589. le32_to_cpu(srbreply->scsi_status));
  1590. #endif
  1591. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1592. break;
  1593. }
  1594. if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
  1595. int len;
  1596. scsicmd->result |= SAM_STAT_CHECK_CONDITION;
  1597. len = (le32_to_cpu(srbreply->sense_data_size) >
  1598. sizeof(scsicmd->sense_buffer)) ?
  1599. sizeof(scsicmd->sense_buffer) :
  1600. le32_to_cpu(srbreply->sense_data_size);
  1601. #ifdef AAC_DETAILED_STATUS_INFO
  1602. dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
  1603. le32_to_cpu(srbreply->status), len));
  1604. #endif
  1605. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1606. }
  1607. /*
  1608. * OR in the scsi status (already shifted up a bit)
  1609. */
  1610. scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
  1611. fib_complete(fibptr);
  1612. fib_free(fibptr);
  1613. aac_io_done(scsicmd);
  1614. }
  1615. /**
  1616. *
  1617. * aac_send_scb_fib
  1618. * @scsicmd: the scsi command block
  1619. *
  1620. * This routine will form a FIB and fill in the aac_srb from the
  1621. * scsicmd passed in.
  1622. */
  1623. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
  1624. {
  1625. struct fib* cmd_fibcontext;
  1626. struct aac_dev* dev;
  1627. int status;
  1628. struct aac_srb *srbcmd;
  1629. u16 fibsize;
  1630. u32 flag;
  1631. u32 timeout;
  1632. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1633. if (scsicmd->device->id >= dev->maximum_num_physicals ||
  1634. scsicmd->device->lun > 7) {
  1635. scsicmd->result = DID_NO_CONNECT << 16;
  1636. scsicmd->scsi_done(scsicmd);
  1637. return 0;
  1638. }
  1639. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1640. switch(scsicmd->sc_data_direction){
  1641. case DMA_TO_DEVICE:
  1642. flag = SRB_DataOut;
  1643. break;
  1644. case DMA_BIDIRECTIONAL:
  1645. flag = SRB_DataIn | SRB_DataOut;
  1646. break;
  1647. case DMA_FROM_DEVICE:
  1648. flag = SRB_DataIn;
  1649. break;
  1650. case DMA_NONE:
  1651. default: /* shuts up some versions of gcc */
  1652. flag = SRB_NoDataXfer;
  1653. break;
  1654. }
  1655. /*
  1656. * Allocate and initialize a Fib then setup a BlockWrite command
  1657. */
  1658. if (!(cmd_fibcontext = fib_alloc(dev))) {
  1659. return -1;
  1660. }
  1661. fib_init(cmd_fibcontext);
  1662. srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
  1663. srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
  1664. srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
  1665. srbcmd->id = cpu_to_le32(scsicmd->device->id);
  1666. srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
  1667. srbcmd->flags = cpu_to_le32(flag);
  1668. timeout = (scsicmd->timeout-jiffies)/HZ;
  1669. if(timeout == 0){
  1670. timeout = 1;
  1671. }
  1672. srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
  1673. srbcmd->retry_limit = 0; /* Obsolete parameter */
  1674. srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
  1675. if( dev->dac_support == 1 ) {
  1676. aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
  1677. srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
  1678. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  1679. memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
  1680. /*
  1681. * Build Scatter/Gather list
  1682. */
  1683. fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
  1684. ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
  1685. sizeof (struct sgentry64));
  1686. BUG_ON (fibsize > (dev->max_fib_size -
  1687. sizeof(struct aac_fibhdr)));
  1688. /*
  1689. * Now send the Fib to the adapter
  1690. */
  1691. status = fib_send(ScsiPortCommand64, cmd_fibcontext,
  1692. fibsize, FsaNormal, 0, 1,
  1693. (fib_callback) aac_srb_callback,
  1694. (void *) scsicmd);
  1695. } else {
  1696. aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
  1697. srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
  1698. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  1699. memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
  1700. /*
  1701. * Build Scatter/Gather list
  1702. */
  1703. fibsize = sizeof (struct aac_srb) +
  1704. (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
  1705. sizeof (struct sgentry));
  1706. BUG_ON (fibsize > (dev->max_fib_size -
  1707. sizeof(struct aac_fibhdr)));
  1708. /*
  1709. * Now send the Fib to the adapter
  1710. */
  1711. status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
  1712. (fib_callback) aac_srb_callback, (void *) scsicmd);
  1713. }
  1714. /*
  1715. * Check that the command queued to the controller
  1716. */
  1717. if (status == -EINPROGRESS){
  1718. return 0;
  1719. }
  1720. printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
  1721. fib_complete(cmd_fibcontext);
  1722. fib_free(cmd_fibcontext);
  1723. return -1;
  1724. }
  1725. static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
  1726. {
  1727. struct aac_dev *dev;
  1728. unsigned long byte_count = 0;
  1729. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1730. // Get rid of old data
  1731. psg->count = 0;
  1732. psg->sg[0].addr = 0;
  1733. psg->sg[0].count = 0;
  1734. if (scsicmd->use_sg) {
  1735. struct scatterlist *sg;
  1736. int i;
  1737. int sg_count;
  1738. sg = (struct scatterlist *) scsicmd->request_buffer;
  1739. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  1740. scsicmd->sc_data_direction);
  1741. psg->count = cpu_to_le32(sg_count);
  1742. byte_count = 0;
  1743. for (i = 0; i < sg_count; i++) {
  1744. psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
  1745. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  1746. byte_count += sg_dma_len(sg);
  1747. sg++;
  1748. }
  1749. /* hba wants the size to be exact */
  1750. if(byte_count > scsicmd->request_bufflen){
  1751. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  1752. (byte_count - scsicmd->request_bufflen);
  1753. psg->sg[i-1].count = cpu_to_le32(temp);
  1754. byte_count = scsicmd->request_bufflen;
  1755. }
  1756. /* Check for command underflow */
  1757. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  1758. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  1759. byte_count, scsicmd->underflow);
  1760. }
  1761. }
  1762. else if(scsicmd->request_bufflen) {
  1763. dma_addr_t addr;
  1764. addr = pci_map_single(dev->pdev,
  1765. scsicmd->request_buffer,
  1766. scsicmd->request_bufflen,
  1767. scsicmd->sc_data_direction);
  1768. psg->count = cpu_to_le32(1);
  1769. psg->sg[0].addr = cpu_to_le32(addr);
  1770. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  1771. scsicmd->SCp.dma_handle = addr;
  1772. byte_count = scsicmd->request_bufflen;
  1773. }
  1774. return byte_count;
  1775. }
  1776. static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
  1777. {
  1778. struct aac_dev *dev;
  1779. unsigned long byte_count = 0;
  1780. u64 addr;
  1781. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1782. // Get rid of old data
  1783. psg->count = 0;
  1784. psg->sg[0].addr[0] = 0;
  1785. psg->sg[0].addr[1] = 0;
  1786. psg->sg[0].count = 0;
  1787. if (scsicmd->use_sg) {
  1788. struct scatterlist *sg;
  1789. int i;
  1790. int sg_count;
  1791. sg = (struct scatterlist *) scsicmd->request_buffer;
  1792. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  1793. scsicmd->sc_data_direction);
  1794. psg->count = cpu_to_le32(sg_count);
  1795. byte_count = 0;
  1796. for (i = 0; i < sg_count; i++) {
  1797. addr = sg_dma_address(sg);
  1798. psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
  1799. psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
  1800. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  1801. byte_count += sg_dma_len(sg);
  1802. sg++;
  1803. }
  1804. /* hba wants the size to be exact */
  1805. if(byte_count > scsicmd->request_bufflen){
  1806. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  1807. (byte_count - scsicmd->request_bufflen);
  1808. psg->sg[i-1].count = cpu_to_le32(temp);
  1809. byte_count = scsicmd->request_bufflen;
  1810. }
  1811. /* Check for command underflow */
  1812. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  1813. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  1814. byte_count, scsicmd->underflow);
  1815. }
  1816. }
  1817. else if(scsicmd->request_bufflen) {
  1818. u64 addr;
  1819. addr = pci_map_single(dev->pdev,
  1820. scsicmd->request_buffer,
  1821. scsicmd->request_bufflen,
  1822. scsicmd->sc_data_direction);
  1823. psg->count = cpu_to_le32(1);
  1824. psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
  1825. psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
  1826. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  1827. scsicmd->SCp.dma_handle = addr;
  1828. byte_count = scsicmd->request_bufflen;
  1829. }
  1830. return byte_count;
  1831. }
  1832. #ifdef AAC_DETAILED_STATUS_INFO
  1833. struct aac_srb_status_info {
  1834. u32 status;
  1835. char *str;
  1836. };
  1837. static struct aac_srb_status_info srb_status_info[] = {
  1838. { SRB_STATUS_PENDING, "Pending Status"},
  1839. { SRB_STATUS_SUCCESS, "Success"},
  1840. { SRB_STATUS_ABORTED, "Aborted Command"},
  1841. { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
  1842. { SRB_STATUS_ERROR, "Error Event"},
  1843. { SRB_STATUS_BUSY, "Device Busy"},
  1844. { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
  1845. { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
  1846. { SRB_STATUS_NO_DEVICE, "No Device"},
  1847. { SRB_STATUS_TIMEOUT, "Timeout"},
  1848. { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
  1849. { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
  1850. { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
  1851. { SRB_STATUS_BUS_RESET, "Bus Reset"},
  1852. { SRB_STATUS_PARITY_ERROR, "Parity Error"},
  1853. { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
  1854. { SRB_STATUS_NO_HBA, "No HBA"},
  1855. { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
  1856. { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
  1857. { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
  1858. { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
  1859. { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
  1860. { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
  1861. { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
  1862. { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
  1863. { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
  1864. { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
  1865. { SRB_STATUS_NOT_STARTED, "Not Started"},
  1866. { SRB_STATUS_NOT_IN_USE, "Not In Use"},
  1867. { SRB_STATUS_FORCE_ABORT, "Force Abort"},
  1868. { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
  1869. { 0xff, "Unknown Error"}
  1870. };
  1871. char *aac_get_status_string(u32 status)
  1872. {
  1873. int i;
  1874. for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
  1875. if(srb_status_info[i].status == status){
  1876. return srb_status_info[i].str;
  1877. }
  1878. }
  1879. return "Bad Status Code";
  1880. }
  1881. #endif