aachba.c 79 KB

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