aachba.c 77 KB

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