aachba.c 79 KB

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