aachba.c 74 KB

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