aachba.c 99 KB

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