aachba.c 82 KB

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