aachba.c 71 KB

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