aachba.c 82 KB

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