aachba.c 71 KB

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