aachba.c 91 KB

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