aachba.c 61 KB

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