aachba.c 85 KB

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