aachba.c 73 KB

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