aachba.c 71 KB

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