aachba.c 74 KB

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