aachba.c 79 KB

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