aachba.c 79 KB

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