aachba.c 74 KB

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