aachba.c 72 KB

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