aachba.c 65 KB

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