aachba.c 80 KB

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