aachba.c 83 KB

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