aachba.c 86 KB

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