aachba.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446
  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, int commit_flag)
  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) || commit_flag) {
  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. BUG_ON(fibptr == NULL);
  352. get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
  353. /* Failure is irrelevant, using default value instead */
  354. if ((le32_to_cpu(get_name_reply->status) == CT_OK)
  355. && (get_name_reply->data[0] != '\0')) {
  356. char *sp = get_name_reply->data;
  357. sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
  358. while (*sp == ' ')
  359. ++sp;
  360. if (*sp) {
  361. char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
  362. int count = sizeof(d);
  363. char *dp = d;
  364. do {
  365. *dp++ = (*sp) ? *sp++ : ' ';
  366. } while (--count > 0);
  367. aac_internal_transfer(scsicmd, d,
  368. offsetof(struct inquiry_data, inqd_pid), sizeof(d));
  369. }
  370. }
  371. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  372. aac_fib_complete(fibptr);
  373. aac_fib_free(fibptr);
  374. scsicmd->scsi_done(scsicmd);
  375. }
  376. /**
  377. * aac_get_container_name - get container name, none blocking.
  378. */
  379. static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
  380. {
  381. int status;
  382. struct aac_get_name *dinfo;
  383. struct fib * cmd_fibcontext;
  384. struct aac_dev * dev;
  385. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  386. if (!(cmd_fibcontext = aac_fib_alloc(dev)))
  387. return -ENOMEM;
  388. aac_fib_init(cmd_fibcontext);
  389. dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
  390. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  391. dinfo->type = cpu_to_le32(CT_READ_NAME);
  392. dinfo->cid = cpu_to_le32(cid);
  393. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
  394. status = aac_fib_send(ContainerCommand,
  395. cmd_fibcontext,
  396. sizeof (struct aac_get_name),
  397. FsaNormal,
  398. 0, 1,
  399. (fib_callback) get_container_name_callback,
  400. (void *) scsicmd);
  401. /*
  402. * Check that the command queued to the controller
  403. */
  404. if (status == -EINPROGRESS) {
  405. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  406. return 0;
  407. }
  408. printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
  409. aac_fib_complete(cmd_fibcontext);
  410. aac_fib_free(cmd_fibcontext);
  411. return -1;
  412. }
  413. /**
  414. * aac_probe_container - query a logical volume
  415. * @dev: device to query
  416. * @cid: container identifier
  417. *
  418. * Queries the controller about the given volume. The volume information
  419. * is updated in the struct fsa_dev_info structure rather than returned.
  420. */
  421. int aac_probe_container(struct aac_dev *dev, int cid)
  422. {
  423. struct fsa_dev_info *fsa_dev_ptr;
  424. int status;
  425. struct aac_query_mount *dinfo;
  426. struct aac_mount *dresp;
  427. struct fib * fibptr;
  428. unsigned instance;
  429. fsa_dev_ptr = dev->fsa_dev;
  430. if (!fsa_dev_ptr)
  431. return -ENOMEM;
  432. instance = dev->scsi_host_ptr->unique_id;
  433. if (!(fibptr = aac_fib_alloc(dev)))
  434. return -ENOMEM;
  435. aac_fib_init(fibptr);
  436. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  437. dinfo->command = cpu_to_le32(VM_NameServe);
  438. dinfo->count = cpu_to_le32(cid);
  439. dinfo->type = cpu_to_le32(FT_FILESYS);
  440. status = aac_fib_send(ContainerCommand,
  441. fibptr,
  442. sizeof(struct aac_query_mount),
  443. FsaNormal,
  444. 1, 1,
  445. NULL, NULL);
  446. if (status < 0) {
  447. printk(KERN_WARNING "aacraid: aac_probe_container query failed.\n");
  448. goto error;
  449. }
  450. dresp = (struct aac_mount *) fib_data(fibptr);
  451. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  452. (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
  453. dinfo->command = cpu_to_le32(VM_NameServe64);
  454. dinfo->count = cpu_to_le32(cid);
  455. dinfo->type = cpu_to_le32(FT_FILESYS);
  456. if (aac_fib_send(ContainerCommand,
  457. fibptr,
  458. sizeof(struct aac_query_mount),
  459. FsaNormal,
  460. 1, 1,
  461. NULL, NULL) < 0)
  462. goto error;
  463. } else
  464. dresp->mnt[0].capacityhigh = 0;
  465. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  466. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
  467. (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
  468. fsa_dev_ptr[cid].valid = 1;
  469. fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
  470. fsa_dev_ptr[cid].size
  471. = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
  472. (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
  473. if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
  474. fsa_dev_ptr[cid].ro = 1;
  475. }
  476. error:
  477. aac_fib_complete(fibptr);
  478. aac_fib_free(fibptr);
  479. return status;
  480. }
  481. /* Local Structure to set SCSI inquiry data strings */
  482. struct scsi_inq {
  483. char vid[8]; /* Vendor ID */
  484. char pid[16]; /* Product ID */
  485. char prl[4]; /* Product Revision Level */
  486. };
  487. /**
  488. * InqStrCopy - string merge
  489. * @a: string to copy from
  490. * @b: string to copy to
  491. *
  492. * Copy a String from one location to another
  493. * without copying \0
  494. */
  495. static void inqstrcpy(char *a, char *b)
  496. {
  497. while(*a != (char)0)
  498. *b++ = *a++;
  499. }
  500. static char *container_types[] = {
  501. "None",
  502. "Volume",
  503. "Mirror",
  504. "Stripe",
  505. "RAID5",
  506. "SSRW",
  507. "SSRO",
  508. "Morph",
  509. "Legacy",
  510. "RAID4",
  511. "RAID10",
  512. "RAID00",
  513. "V-MIRRORS",
  514. "PSEUDO R4",
  515. "RAID50",
  516. "RAID5D",
  517. "RAID5D0",
  518. "RAID1E",
  519. "RAID6",
  520. "RAID60",
  521. "Unknown"
  522. };
  523. /* Function: setinqstr
  524. *
  525. * Arguments: [1] pointer to void [1] int
  526. *
  527. * Purpose: Sets SCSI inquiry data strings for vendor, product
  528. * and revision level. Allows strings to be set in platform dependant
  529. * files instead of in OS dependant driver source.
  530. */
  531. static void setinqstr(struct aac_dev *dev, void *data, int tindex)
  532. {
  533. struct scsi_inq *str;
  534. str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
  535. memset(str, ' ', sizeof(*str));
  536. if (dev->supplement_adapter_info.AdapterTypeText[0]) {
  537. char * cp = dev->supplement_adapter_info.AdapterTypeText;
  538. int c = sizeof(str->vid);
  539. while (*cp && *cp != ' ' && --c)
  540. ++cp;
  541. c = *cp;
  542. *cp = '\0';
  543. inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
  544. str->vid);
  545. *cp = c;
  546. while (*cp && *cp != ' ')
  547. ++cp;
  548. while (*cp == ' ')
  549. ++cp;
  550. /* last six chars reserved for vol type */
  551. c = 0;
  552. if (strlen(cp) > sizeof(str->pid)) {
  553. c = cp[sizeof(str->pid)];
  554. cp[sizeof(str->pid)] = '\0';
  555. }
  556. inqstrcpy (cp, str->pid);
  557. if (c)
  558. cp[sizeof(str->pid)] = c;
  559. } else {
  560. struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
  561. inqstrcpy (mp->vname, str->vid);
  562. /* last six chars reserved for vol type */
  563. inqstrcpy (mp->model, str->pid);
  564. }
  565. if (tindex < ARRAY_SIZE(container_types)){
  566. char *findit = str->pid;
  567. for ( ; *findit != ' '; findit++); /* walk till we find a space */
  568. /* RAID is superfluous in the context of a RAID device */
  569. if (memcmp(findit-4, "RAID", 4) == 0)
  570. *(findit -= 4) = ' ';
  571. if (((findit - str->pid) + strlen(container_types[tindex]))
  572. < (sizeof(str->pid) + sizeof(str->prl)))
  573. inqstrcpy (container_types[tindex], findit + 1);
  574. }
  575. inqstrcpy ("V1.0", str->prl);
  576. }
  577. static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
  578. u8 a_sense_code, u8 incorrect_length,
  579. u8 bit_pointer, u16 field_pointer,
  580. u32 residue)
  581. {
  582. sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
  583. sense_buf[1] = 0; /* Segment number, always zero */
  584. if (incorrect_length) {
  585. sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
  586. sense_buf[3] = BYTE3(residue);
  587. sense_buf[4] = BYTE2(residue);
  588. sense_buf[5] = BYTE1(residue);
  589. sense_buf[6] = BYTE0(residue);
  590. } else
  591. sense_buf[2] = sense_key; /* Sense key */
  592. if (sense_key == ILLEGAL_REQUEST)
  593. sense_buf[7] = 10; /* Additional sense length */
  594. else
  595. sense_buf[7] = 6; /* Additional sense length */
  596. sense_buf[12] = sense_code; /* Additional sense code */
  597. sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
  598. if (sense_key == ILLEGAL_REQUEST) {
  599. sense_buf[15] = 0;
  600. if (sense_code == SENCODE_INVALID_PARAM_FIELD)
  601. sense_buf[15] = 0x80;/* Std sense key specific field */
  602. /* Illegal parameter is in the parameter block */
  603. if (sense_code == SENCODE_INVALID_CDB_FIELD)
  604. sense_buf[15] = 0xc0;/* Std sense key specific field */
  605. /* Illegal parameter is in the CDB block */
  606. sense_buf[15] |= bit_pointer;
  607. sense_buf[16] = field_pointer >> 8; /* MSB */
  608. sense_buf[17] = field_pointer; /* LSB */
  609. }
  610. }
  611. int aac_get_adapter_info(struct aac_dev* dev)
  612. {
  613. struct fib* fibptr;
  614. int rcode;
  615. u32 tmp;
  616. struct aac_adapter_info *info;
  617. struct aac_bus_info *command;
  618. struct aac_bus_info_response *bus_info;
  619. if (!(fibptr = aac_fib_alloc(dev)))
  620. return -ENOMEM;
  621. aac_fib_init(fibptr);
  622. info = (struct aac_adapter_info *) fib_data(fibptr);
  623. memset(info,0,sizeof(*info));
  624. rcode = aac_fib_send(RequestAdapterInfo,
  625. fibptr,
  626. sizeof(*info),
  627. FsaNormal,
  628. -1, 1, /* First `interrupt' command uses special wait */
  629. NULL,
  630. NULL);
  631. if (rcode < 0) {
  632. aac_fib_complete(fibptr);
  633. aac_fib_free(fibptr);
  634. return rcode;
  635. }
  636. memcpy(&dev->adapter_info, info, sizeof(*info));
  637. if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
  638. struct aac_supplement_adapter_info * info;
  639. aac_fib_init(fibptr);
  640. info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
  641. memset(info,0,sizeof(*info));
  642. rcode = aac_fib_send(RequestSupplementAdapterInfo,
  643. fibptr,
  644. sizeof(*info),
  645. FsaNormal,
  646. 1, 1,
  647. NULL,
  648. NULL);
  649. if (rcode >= 0)
  650. memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
  651. }
  652. /*
  653. * GetBusInfo
  654. */
  655. aac_fib_init(fibptr);
  656. bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
  657. memset(bus_info, 0, sizeof(*bus_info));
  658. command = (struct aac_bus_info *)bus_info;
  659. command->Command = cpu_to_le32(VM_Ioctl);
  660. command->ObjType = cpu_to_le32(FT_DRIVE);
  661. command->MethodId = cpu_to_le32(1);
  662. command->CtlCmd = cpu_to_le32(GetBusInfo);
  663. rcode = aac_fib_send(ContainerCommand,
  664. fibptr,
  665. sizeof (*bus_info),
  666. FsaNormal,
  667. 1, 1,
  668. NULL, NULL);
  669. if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
  670. dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
  671. dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
  672. }
  673. if (!dev->in_reset) {
  674. tmp = le32_to_cpu(dev->adapter_info.kernelrev);
  675. printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
  676. dev->name,
  677. dev->id,
  678. tmp>>24,
  679. (tmp>>16)&0xff,
  680. tmp&0xff,
  681. le32_to_cpu(dev->adapter_info.kernelbuild),
  682. (int)sizeof(dev->supplement_adapter_info.BuildDate),
  683. dev->supplement_adapter_info.BuildDate);
  684. tmp = le32_to_cpu(dev->adapter_info.monitorrev);
  685. printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
  686. dev->name, dev->id,
  687. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  688. le32_to_cpu(dev->adapter_info.monitorbuild));
  689. tmp = le32_to_cpu(dev->adapter_info.biosrev);
  690. printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
  691. dev->name, dev->id,
  692. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  693. le32_to_cpu(dev->adapter_info.biosbuild));
  694. if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
  695. printk(KERN_INFO "%s%d: serial %x\n",
  696. dev->name, dev->id,
  697. le32_to_cpu(dev->adapter_info.serial[0]));
  698. }
  699. dev->nondasd_support = 0;
  700. dev->raid_scsi_mode = 0;
  701. if(dev->adapter_info.options & AAC_OPT_NONDASD){
  702. dev->nondasd_support = 1;
  703. }
  704. /*
  705. * If the firmware supports ROMB RAID/SCSI mode and we are currently
  706. * in RAID/SCSI mode, set the flag. For now if in this mode we will
  707. * force nondasd support on. If we decide to allow the non-dasd flag
  708. * additional changes changes will have to be made to support
  709. * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
  710. * changed to support the new dev->raid_scsi_mode flag instead of
  711. * leaching off of the dev->nondasd_support flag. Also in linit.c the
  712. * function aac_detect will have to be modified where it sets up the
  713. * max number of channels based on the aac->nondasd_support flag only.
  714. */
  715. if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
  716. (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
  717. dev->nondasd_support = 1;
  718. dev->raid_scsi_mode = 1;
  719. }
  720. if (dev->raid_scsi_mode != 0)
  721. printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
  722. dev->name, dev->id);
  723. if(nondasd != -1) {
  724. dev->nondasd_support = (nondasd!=0);
  725. }
  726. if(dev->nondasd_support != 0){
  727. printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
  728. }
  729. dev->dac_support = 0;
  730. if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
  731. printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
  732. dev->dac_support = 1;
  733. }
  734. if(dacmode != -1) {
  735. dev->dac_support = (dacmode!=0);
  736. }
  737. if(dev->dac_support != 0) {
  738. if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
  739. !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
  740. printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
  741. dev->name, dev->id);
  742. } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
  743. !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
  744. printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
  745. dev->name, dev->id);
  746. dev->dac_support = 0;
  747. } else {
  748. printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
  749. dev->name, dev->id);
  750. rcode = -ENOMEM;
  751. }
  752. }
  753. /*
  754. * 57 scatter gather elements
  755. */
  756. if (!(dev->raw_io_interface)) {
  757. dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
  758. sizeof(struct aac_fibhdr) -
  759. sizeof(struct aac_write) + sizeof(struct sgentry)) /
  760. sizeof(struct sgentry);
  761. if (dev->dac_support) {
  762. /*
  763. * 38 scatter gather elements
  764. */
  765. dev->scsi_host_ptr->sg_tablesize =
  766. (dev->max_fib_size -
  767. sizeof(struct aac_fibhdr) -
  768. sizeof(struct aac_write64) +
  769. sizeof(struct sgentry64)) /
  770. sizeof(struct sgentry64);
  771. }
  772. dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  773. if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
  774. /*
  775. * Worst case size that could cause sg overflow when
  776. * we break up SG elements that are larger than 64KB.
  777. * Would be nice if we could tell the SCSI layer what
  778. * the maximum SG element size can be. Worst case is
  779. * (sg_tablesize-1) 4KB elements with one 64KB
  780. * element.
  781. * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
  782. */
  783. dev->scsi_host_ptr->max_sectors =
  784. (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
  785. }
  786. }
  787. aac_fib_complete(fibptr);
  788. aac_fib_free(fibptr);
  789. return rcode;
  790. }
  791. static void io_callback(void *context, struct fib * fibptr)
  792. {
  793. struct aac_dev *dev;
  794. struct aac_read_reply *readreply;
  795. struct scsi_cmnd *scsicmd;
  796. u32 cid;
  797. scsicmd = (struct scsi_cmnd *) context;
  798. scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
  799. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  800. cid = scmd_id(scsicmd);
  801. if (nblank(dprintk(x))) {
  802. u64 lba;
  803. switch (scsicmd->cmnd[0]) {
  804. case WRITE_6:
  805. case READ_6:
  806. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  807. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  808. break;
  809. case WRITE_16:
  810. case READ_16:
  811. lba = ((u64)scsicmd->cmnd[2] << 56) |
  812. ((u64)scsicmd->cmnd[3] << 48) |
  813. ((u64)scsicmd->cmnd[4] << 40) |
  814. ((u64)scsicmd->cmnd[5] << 32) |
  815. ((u64)scsicmd->cmnd[6] << 24) |
  816. (scsicmd->cmnd[7] << 16) |
  817. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  818. break;
  819. case WRITE_12:
  820. case READ_12:
  821. lba = ((u64)scsicmd->cmnd[2] << 24) |
  822. (scsicmd->cmnd[3] << 16) |
  823. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  824. break;
  825. default:
  826. lba = ((u64)scsicmd->cmnd[2] << 24) |
  827. (scsicmd->cmnd[3] << 16) |
  828. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  829. break;
  830. }
  831. printk(KERN_DEBUG
  832. "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
  833. smp_processor_id(), (unsigned long long)lba, jiffies);
  834. }
  835. BUG_ON(fibptr == NULL);
  836. if(scsicmd->use_sg)
  837. pci_unmap_sg(dev->pdev,
  838. (struct scatterlist *)scsicmd->request_buffer,
  839. scsicmd->use_sg,
  840. scsicmd->sc_data_direction);
  841. else if(scsicmd->request_bufflen)
  842. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
  843. scsicmd->request_bufflen,
  844. scsicmd->sc_data_direction);
  845. readreply = (struct aac_read_reply *)fib_data(fibptr);
  846. if (le32_to_cpu(readreply->status) == ST_OK)
  847. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  848. else {
  849. #ifdef AAC_DETAILED_STATUS_INFO
  850. printk(KERN_WARNING "io_callback: io failed, status = %d\n",
  851. le32_to_cpu(readreply->status));
  852. #endif
  853. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  854. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  855. HARDWARE_ERROR,
  856. SENCODE_INTERNAL_TARGET_FAILURE,
  857. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  858. 0, 0);
  859. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  860. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  861. ? sizeof(scsicmd->sense_buffer)
  862. : sizeof(dev->fsa_dev[cid].sense_data));
  863. }
  864. aac_fib_complete(fibptr);
  865. aac_fib_free(fibptr);
  866. scsicmd->scsi_done(scsicmd);
  867. }
  868. static int aac_read(struct scsi_cmnd * scsicmd, int cid)
  869. {
  870. u64 lba;
  871. u32 count;
  872. int status;
  873. u16 fibsize;
  874. struct aac_dev *dev;
  875. struct fib * cmd_fibcontext;
  876. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  877. /*
  878. * Get block address and transfer length
  879. */
  880. switch (scsicmd->cmnd[0]) {
  881. case READ_6:
  882. dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
  883. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  884. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  885. count = scsicmd->cmnd[4];
  886. if (count == 0)
  887. count = 256;
  888. break;
  889. case READ_16:
  890. dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
  891. lba = ((u64)scsicmd->cmnd[2] << 56) |
  892. ((u64)scsicmd->cmnd[3] << 48) |
  893. ((u64)scsicmd->cmnd[4] << 40) |
  894. ((u64)scsicmd->cmnd[5] << 32) |
  895. ((u64)scsicmd->cmnd[6] << 24) |
  896. (scsicmd->cmnd[7] << 16) |
  897. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  898. count = (scsicmd->cmnd[10] << 24) |
  899. (scsicmd->cmnd[11] << 16) |
  900. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  901. break;
  902. case READ_12:
  903. dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
  904. lba = ((u64)scsicmd->cmnd[2] << 24) |
  905. (scsicmd->cmnd[3] << 16) |
  906. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  907. count = (scsicmd->cmnd[6] << 24) |
  908. (scsicmd->cmnd[7] << 16) |
  909. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  910. break;
  911. default:
  912. dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
  913. lba = ((u64)scsicmd->cmnd[2] << 24) |
  914. (scsicmd->cmnd[3] << 16) |
  915. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  916. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  917. break;
  918. }
  919. dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
  920. smp_processor_id(), (unsigned long long)lba, jiffies));
  921. if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) &&
  922. (lba & 0xffffffff00000000LL)) {
  923. dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
  924. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
  925. SAM_STAT_CHECK_CONDITION;
  926. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  927. HARDWARE_ERROR,
  928. SENCODE_INTERNAL_TARGET_FAILURE,
  929. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  930. 0, 0);
  931. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  932. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  933. ? sizeof(scsicmd->sense_buffer)
  934. : sizeof(dev->fsa_dev[cid].sense_data));
  935. scsicmd->scsi_done(scsicmd);
  936. return 0;
  937. }
  938. /*
  939. * Alocate and initialize a Fib
  940. */
  941. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  942. return -1;
  943. }
  944. aac_fib_init(cmd_fibcontext);
  945. if (dev->raw_io_interface) {
  946. struct aac_raw_io *readcmd;
  947. readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
  948. readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  949. readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  950. readcmd->count = cpu_to_le32(count<<9);
  951. readcmd->cid = cpu_to_le16(cid);
  952. readcmd->flags = cpu_to_le16(1);
  953. readcmd->bpTotal = 0;
  954. readcmd->bpComplete = 0;
  955. aac_build_sgraw(scsicmd, &readcmd->sg);
  956. fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
  957. BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
  958. /*
  959. * Now send the Fib to the adapter
  960. */
  961. status = aac_fib_send(ContainerRawIo,
  962. cmd_fibcontext,
  963. fibsize,
  964. FsaNormal,
  965. 0, 1,
  966. (fib_callback) io_callback,
  967. (void *) scsicmd);
  968. } else if (dev->dac_support == 1) {
  969. struct aac_read64 *readcmd;
  970. readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
  971. readcmd->command = cpu_to_le32(VM_CtHostRead64);
  972. readcmd->cid = cpu_to_le16(cid);
  973. readcmd->sector_count = cpu_to_le16(count);
  974. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  975. readcmd->pad = 0;
  976. readcmd->flags = 0;
  977. aac_build_sg64(scsicmd, &readcmd->sg);
  978. fibsize = sizeof(struct aac_read64) +
  979. ((le32_to_cpu(readcmd->sg.count) - 1) *
  980. sizeof (struct sgentry64));
  981. BUG_ON (fibsize > (dev->max_fib_size -
  982. sizeof(struct aac_fibhdr)));
  983. /*
  984. * Now send the Fib to the adapter
  985. */
  986. status = aac_fib_send(ContainerCommand64,
  987. cmd_fibcontext,
  988. fibsize,
  989. FsaNormal,
  990. 0, 1,
  991. (fib_callback) io_callback,
  992. (void *) scsicmd);
  993. } else {
  994. struct aac_read *readcmd;
  995. readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
  996. readcmd->command = cpu_to_le32(VM_CtBlockRead);
  997. readcmd->cid = cpu_to_le32(cid);
  998. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  999. readcmd->count = cpu_to_le32(count * 512);
  1000. aac_build_sg(scsicmd, &readcmd->sg);
  1001. fibsize = sizeof(struct aac_read) +
  1002. ((le32_to_cpu(readcmd->sg.count) - 1) *
  1003. sizeof (struct sgentry));
  1004. BUG_ON (fibsize > (dev->max_fib_size -
  1005. sizeof(struct aac_fibhdr)));
  1006. /*
  1007. * Now send the Fib to the adapter
  1008. */
  1009. status = aac_fib_send(ContainerCommand,
  1010. cmd_fibcontext,
  1011. fibsize,
  1012. FsaNormal,
  1013. 0, 1,
  1014. (fib_callback) io_callback,
  1015. (void *) scsicmd);
  1016. }
  1017. /*
  1018. * Check that the command queued to the controller
  1019. */
  1020. if (status == -EINPROGRESS) {
  1021. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1022. return 0;
  1023. }
  1024. printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
  1025. /*
  1026. * For some reason, the Fib didn't queue, return QUEUE_FULL
  1027. */
  1028. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
  1029. scsicmd->scsi_done(scsicmd);
  1030. aac_fib_complete(cmd_fibcontext);
  1031. aac_fib_free(cmd_fibcontext);
  1032. return 0;
  1033. }
  1034. static int aac_write(struct scsi_cmnd * scsicmd, int cid)
  1035. {
  1036. u64 lba;
  1037. u32 count;
  1038. int status;
  1039. u16 fibsize;
  1040. struct aac_dev *dev;
  1041. struct fib * cmd_fibcontext;
  1042. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1043. /*
  1044. * Get block address and transfer length
  1045. */
  1046. if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
  1047. {
  1048. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  1049. count = scsicmd->cmnd[4];
  1050. if (count == 0)
  1051. count = 256;
  1052. } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
  1053. dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
  1054. lba = ((u64)scsicmd->cmnd[2] << 56) |
  1055. ((u64)scsicmd->cmnd[3] << 48) |
  1056. ((u64)scsicmd->cmnd[4] << 40) |
  1057. ((u64)scsicmd->cmnd[5] << 32) |
  1058. ((u64)scsicmd->cmnd[6] << 24) |
  1059. (scsicmd->cmnd[7] << 16) |
  1060. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1061. count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
  1062. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  1063. } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
  1064. dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
  1065. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
  1066. | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1067. count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
  1068. | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  1069. } else {
  1070. dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
  1071. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  1072. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  1073. }
  1074. dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
  1075. smp_processor_id(), (unsigned long long)lba, jiffies));
  1076. if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
  1077. && (lba & 0xffffffff00000000LL)) {
  1078. dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
  1079. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1080. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1081. HARDWARE_ERROR,
  1082. SENCODE_INTERNAL_TARGET_FAILURE,
  1083. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
  1084. 0, 0);
  1085. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1086. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1087. ? sizeof(scsicmd->sense_buffer)
  1088. : sizeof(dev->fsa_dev[cid].sense_data));
  1089. scsicmd->scsi_done(scsicmd);
  1090. return 0;
  1091. }
  1092. /*
  1093. * Allocate and initialize a Fib then setup a BlockWrite command
  1094. */
  1095. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1096. scsicmd->result = DID_ERROR << 16;
  1097. scsicmd->scsi_done(scsicmd);
  1098. return 0;
  1099. }
  1100. aac_fib_init(cmd_fibcontext);
  1101. if (dev->raw_io_interface) {
  1102. struct aac_raw_io *writecmd;
  1103. writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
  1104. writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  1105. writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  1106. writecmd->count = cpu_to_le32(count<<9);
  1107. writecmd->cid = cpu_to_le16(cid);
  1108. writecmd->flags = 0;
  1109. writecmd->bpTotal = 0;
  1110. writecmd->bpComplete = 0;
  1111. aac_build_sgraw(scsicmd, &writecmd->sg);
  1112. fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
  1113. BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
  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. struct aac_dev *aac;
  1236. unsigned long flags;
  1237. /*
  1238. * Wait for all outstanding queued commands to complete to this
  1239. * specific target (block).
  1240. */
  1241. spin_lock_irqsave(&sdev->list_lock, flags);
  1242. list_for_each_entry(cmd, &sdev->cmd_list, list)
  1243. if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
  1244. ++active;
  1245. break;
  1246. }
  1247. spin_unlock_irqrestore(&sdev->list_lock, flags);
  1248. /*
  1249. * Yield the processor (requeue for later)
  1250. */
  1251. if (active)
  1252. return SCSI_MLQUEUE_DEVICE_BUSY;
  1253. aac = (struct aac_dev *)scsicmd->device->host->hostdata;
  1254. if (aac->in_reset)
  1255. return SCSI_MLQUEUE_HOST_BUSY;
  1256. /*
  1257. * Allocate and initialize a Fib
  1258. */
  1259. if (!(cmd_fibcontext = aac_fib_alloc(aac)))
  1260. return SCSI_MLQUEUE_HOST_BUSY;
  1261. aac_fib_init(cmd_fibcontext);
  1262. synchronizecmd = fib_data(cmd_fibcontext);
  1263. synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
  1264. synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
  1265. synchronizecmd->cid = cpu_to_le32(cid);
  1266. synchronizecmd->count =
  1267. cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
  1268. /*
  1269. * Now send the Fib to the adapter
  1270. */
  1271. status = aac_fib_send(ContainerCommand,
  1272. cmd_fibcontext,
  1273. sizeof(struct aac_synchronize),
  1274. FsaNormal,
  1275. 0, 1,
  1276. (fib_callback)synchronize_callback,
  1277. (void *)scsicmd);
  1278. /*
  1279. * Check that the command queued to the controller
  1280. */
  1281. if (status == -EINPROGRESS) {
  1282. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1283. return 0;
  1284. }
  1285. printk(KERN_WARNING
  1286. "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
  1287. aac_fib_complete(cmd_fibcontext);
  1288. aac_fib_free(cmd_fibcontext);
  1289. return SCSI_MLQUEUE_HOST_BUSY;
  1290. }
  1291. /**
  1292. * aac_scsi_cmd() - Process SCSI command
  1293. * @scsicmd: SCSI command block
  1294. *
  1295. * Emulate a SCSI command and queue the required request for the
  1296. * aacraid firmware.
  1297. */
  1298. int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
  1299. {
  1300. u32 cid = 0;
  1301. struct Scsi_Host *host = scsicmd->device->host;
  1302. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  1303. struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
  1304. if (fsa_dev_ptr == NULL)
  1305. return -1;
  1306. /*
  1307. * If the bus, id or lun is out of range, return fail
  1308. * Test does not apply to ID 16, the pseudo id for the controller
  1309. * itself.
  1310. */
  1311. if (scmd_id(scsicmd) != host->this_id) {
  1312. if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
  1313. if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
  1314. (scsicmd->device->lun != 0)) {
  1315. scsicmd->result = DID_NO_CONNECT << 16;
  1316. scsicmd->scsi_done(scsicmd);
  1317. return 0;
  1318. }
  1319. cid = scmd_id(scsicmd);
  1320. /*
  1321. * If the target container doesn't exist, it may have
  1322. * been newly created
  1323. */
  1324. if ((fsa_dev_ptr[cid].valid & 1) == 0) {
  1325. switch (scsicmd->cmnd[0]) {
  1326. case SERVICE_ACTION_IN:
  1327. if (!(dev->raw_io_interface) ||
  1328. !(dev->raw_io_64) ||
  1329. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1330. break;
  1331. case INQUIRY:
  1332. case READ_CAPACITY:
  1333. case TEST_UNIT_READY:
  1334. if (dev->in_reset)
  1335. return -1;
  1336. spin_unlock_irq(host->host_lock);
  1337. aac_probe_container(dev, cid);
  1338. if ((fsa_dev_ptr[cid].valid & 1) == 0)
  1339. fsa_dev_ptr[cid].valid = 0;
  1340. spin_lock_irq(host->host_lock);
  1341. if (fsa_dev_ptr[cid].valid == 0) {
  1342. scsicmd->result = DID_NO_CONNECT << 16;
  1343. scsicmd->scsi_done(scsicmd);
  1344. return 0;
  1345. }
  1346. default:
  1347. break;
  1348. }
  1349. }
  1350. /*
  1351. * If the target container still doesn't exist,
  1352. * return failure
  1353. */
  1354. if (fsa_dev_ptr[cid].valid == 0) {
  1355. scsicmd->result = DID_BAD_TARGET << 16;
  1356. scsicmd->scsi_done(scsicmd);
  1357. return 0;
  1358. }
  1359. } else { /* check for physical non-dasd devices */
  1360. if(dev->nondasd_support == 1){
  1361. if (dev->in_reset)
  1362. return -1;
  1363. return aac_send_srb_fib(scsicmd);
  1364. } else {
  1365. scsicmd->result = DID_NO_CONNECT << 16;
  1366. scsicmd->scsi_done(scsicmd);
  1367. return 0;
  1368. }
  1369. }
  1370. }
  1371. /*
  1372. * else Command for the controller itself
  1373. */
  1374. else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
  1375. (scsicmd->cmnd[0] != TEST_UNIT_READY))
  1376. {
  1377. dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
  1378. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1379. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1380. ILLEGAL_REQUEST,
  1381. SENCODE_INVALID_COMMAND,
  1382. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1383. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1384. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1385. ? sizeof(scsicmd->sense_buffer)
  1386. : sizeof(dev->fsa_dev[cid].sense_data));
  1387. scsicmd->scsi_done(scsicmd);
  1388. return 0;
  1389. }
  1390. /* Handle commands here that don't really require going out to the adapter */
  1391. switch (scsicmd->cmnd[0]) {
  1392. case INQUIRY:
  1393. {
  1394. struct inquiry_data inq_data;
  1395. dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
  1396. memset(&inq_data, 0, sizeof (struct inquiry_data));
  1397. inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
  1398. 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 */
  1399. inq_data.inqd_len = 31;
  1400. /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  1401. inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
  1402. /*
  1403. * Set the Vendor, Product, and Revision Level
  1404. * see: <vendor>.c i.e. aac.c
  1405. */
  1406. if (scmd_id(scsicmd) == host->this_id) {
  1407. setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
  1408. inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
  1409. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1410. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1411. scsicmd->scsi_done(scsicmd);
  1412. return 0;
  1413. }
  1414. if (dev->in_reset)
  1415. return -1;
  1416. setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
  1417. inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
  1418. aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
  1419. return aac_get_container_name(scsicmd, cid);
  1420. }
  1421. case SERVICE_ACTION_IN:
  1422. if (!(dev->raw_io_interface) ||
  1423. !(dev->raw_io_64) ||
  1424. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  1425. break;
  1426. {
  1427. u64 capacity;
  1428. char cp[13];
  1429. dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
  1430. capacity = fsa_dev_ptr[cid].size - 1;
  1431. cp[0] = (capacity >> 56) & 0xff;
  1432. cp[1] = (capacity >> 48) & 0xff;
  1433. cp[2] = (capacity >> 40) & 0xff;
  1434. cp[3] = (capacity >> 32) & 0xff;
  1435. cp[4] = (capacity >> 24) & 0xff;
  1436. cp[5] = (capacity >> 16) & 0xff;
  1437. cp[6] = (capacity >> 8) & 0xff;
  1438. cp[7] = (capacity >> 0) & 0xff;
  1439. cp[8] = 0;
  1440. cp[9] = 0;
  1441. cp[10] = 2;
  1442. cp[11] = 0;
  1443. cp[12] = 0;
  1444. aac_internal_transfer(scsicmd, cp, 0,
  1445. min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
  1446. if (sizeof(cp) < scsicmd->cmnd[13]) {
  1447. unsigned int len, offset = sizeof(cp);
  1448. memset(cp, 0, offset);
  1449. do {
  1450. len = min_t(size_t, scsicmd->cmnd[13] - offset,
  1451. sizeof(cp));
  1452. aac_internal_transfer(scsicmd, cp, offset, len);
  1453. } while ((offset += len) < scsicmd->cmnd[13]);
  1454. }
  1455. /* Do not cache partition table for arrays */
  1456. scsicmd->device->removable = 1;
  1457. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1458. scsicmd->scsi_done(scsicmd);
  1459. return 0;
  1460. }
  1461. case READ_CAPACITY:
  1462. {
  1463. u32 capacity;
  1464. char cp[8];
  1465. dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
  1466. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  1467. capacity = fsa_dev_ptr[cid].size - 1;
  1468. else
  1469. capacity = (u32)-1;
  1470. cp[0] = (capacity >> 24) & 0xff;
  1471. cp[1] = (capacity >> 16) & 0xff;
  1472. cp[2] = (capacity >> 8) & 0xff;
  1473. cp[3] = (capacity >> 0) & 0xff;
  1474. cp[4] = 0;
  1475. cp[5] = 0;
  1476. cp[6] = 2;
  1477. cp[7] = 0;
  1478. aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
  1479. /* Do not cache partition table for arrays */
  1480. scsicmd->device->removable = 1;
  1481. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1482. scsicmd->scsi_done(scsicmd);
  1483. return 0;
  1484. }
  1485. case MODE_SENSE:
  1486. {
  1487. char mode_buf[4];
  1488. dprintk((KERN_DEBUG "MODE SENSE command.\n"));
  1489. mode_buf[0] = 3; /* Mode data length */
  1490. mode_buf[1] = 0; /* Medium type - default */
  1491. mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1492. mode_buf[3] = 0; /* Block descriptor length */
  1493. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1494. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1495. scsicmd->scsi_done(scsicmd);
  1496. return 0;
  1497. }
  1498. case MODE_SENSE_10:
  1499. {
  1500. char mode_buf[8];
  1501. dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
  1502. mode_buf[0] = 0; /* Mode data length (MSB) */
  1503. mode_buf[1] = 6; /* Mode data length (LSB) */
  1504. mode_buf[2] = 0; /* Medium type - default */
  1505. mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
  1506. mode_buf[4] = 0; /* reserved */
  1507. mode_buf[5] = 0; /* reserved */
  1508. mode_buf[6] = 0; /* Block descriptor length (MSB) */
  1509. mode_buf[7] = 0; /* Block descriptor length (LSB) */
  1510. aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
  1511. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1512. scsicmd->scsi_done(scsicmd);
  1513. return 0;
  1514. }
  1515. case REQUEST_SENSE:
  1516. dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
  1517. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
  1518. memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
  1519. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1520. scsicmd->scsi_done(scsicmd);
  1521. return 0;
  1522. case ALLOW_MEDIUM_REMOVAL:
  1523. dprintk((KERN_DEBUG "LOCK command.\n"));
  1524. if (scsicmd->cmnd[4])
  1525. fsa_dev_ptr[cid].locked = 1;
  1526. else
  1527. fsa_dev_ptr[cid].locked = 0;
  1528. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1529. scsicmd->scsi_done(scsicmd);
  1530. return 0;
  1531. /*
  1532. * These commands are all No-Ops
  1533. */
  1534. case TEST_UNIT_READY:
  1535. case RESERVE:
  1536. case RELEASE:
  1537. case REZERO_UNIT:
  1538. case REASSIGN_BLOCKS:
  1539. case SEEK_10:
  1540. case START_STOP:
  1541. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
  1542. scsicmd->scsi_done(scsicmd);
  1543. return 0;
  1544. }
  1545. switch (scsicmd->cmnd[0])
  1546. {
  1547. case READ_6:
  1548. case READ_10:
  1549. case READ_12:
  1550. case READ_16:
  1551. if (dev->in_reset)
  1552. return -1;
  1553. /*
  1554. * Hack to keep track of ordinal number of the device that
  1555. * corresponds to a container. Needed to convert
  1556. * containers to /dev/sd device names
  1557. */
  1558. if (scsicmd->request->rq_disk)
  1559. strlcpy(fsa_dev_ptr[cid].devname,
  1560. scsicmd->request->rq_disk->disk_name,
  1561. min(sizeof(fsa_dev_ptr[cid].devname),
  1562. sizeof(scsicmd->request->rq_disk->disk_name) + 1));
  1563. return aac_read(scsicmd, cid);
  1564. case WRITE_6:
  1565. case WRITE_10:
  1566. case WRITE_12:
  1567. case WRITE_16:
  1568. if (dev->in_reset)
  1569. return -1;
  1570. return aac_write(scsicmd, cid);
  1571. case SYNCHRONIZE_CACHE:
  1572. /* Issue FIB to tell Firmware to flush it's cache */
  1573. return aac_synchronize(scsicmd, cid);
  1574. default:
  1575. /*
  1576. * Unhandled commands
  1577. */
  1578. dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
  1579. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1580. set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
  1581. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  1582. ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
  1583. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1584. (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
  1585. ? sizeof(scsicmd->sense_buffer)
  1586. : sizeof(dev->fsa_dev[cid].sense_data));
  1587. scsicmd->scsi_done(scsicmd);
  1588. return 0;
  1589. }
  1590. }
  1591. static int query_disk(struct aac_dev *dev, void __user *arg)
  1592. {
  1593. struct aac_query_disk qd;
  1594. struct fsa_dev_info *fsa_dev_ptr;
  1595. fsa_dev_ptr = dev->fsa_dev;
  1596. if (!fsa_dev_ptr)
  1597. return -ENODEV;
  1598. if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
  1599. return -EFAULT;
  1600. if (qd.cnum == -1)
  1601. qd.cnum = qd.id;
  1602. else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
  1603. {
  1604. if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
  1605. return -EINVAL;
  1606. qd.instance = dev->scsi_host_ptr->host_no;
  1607. qd.bus = 0;
  1608. qd.id = CONTAINER_TO_ID(qd.cnum);
  1609. qd.lun = CONTAINER_TO_LUN(qd.cnum);
  1610. }
  1611. else return -EINVAL;
  1612. qd.valid = fsa_dev_ptr[qd.cnum].valid;
  1613. qd.locked = fsa_dev_ptr[qd.cnum].locked;
  1614. qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
  1615. if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
  1616. qd.unmapped = 1;
  1617. else
  1618. qd.unmapped = 0;
  1619. strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
  1620. min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
  1621. if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
  1622. return -EFAULT;
  1623. return 0;
  1624. }
  1625. static int force_delete_disk(struct aac_dev *dev, void __user *arg)
  1626. {
  1627. struct aac_delete_disk dd;
  1628. struct fsa_dev_info *fsa_dev_ptr;
  1629. fsa_dev_ptr = dev->fsa_dev;
  1630. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1631. return -EFAULT;
  1632. if (dd.cnum >= dev->maximum_num_containers)
  1633. return -EINVAL;
  1634. /*
  1635. * Mark this container as being deleted.
  1636. */
  1637. fsa_dev_ptr[dd.cnum].deleted = 1;
  1638. /*
  1639. * Mark the container as no longer valid
  1640. */
  1641. fsa_dev_ptr[dd.cnum].valid = 0;
  1642. return 0;
  1643. }
  1644. static int delete_disk(struct aac_dev *dev, void __user *arg)
  1645. {
  1646. struct aac_delete_disk dd;
  1647. struct fsa_dev_info *fsa_dev_ptr;
  1648. fsa_dev_ptr = dev->fsa_dev;
  1649. if (!fsa_dev_ptr)
  1650. return -ENODEV;
  1651. if (!fsa_dev_ptr)
  1652. return -ENODEV;
  1653. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  1654. return -EFAULT;
  1655. if (dd.cnum >= dev->maximum_num_containers)
  1656. return -EINVAL;
  1657. /*
  1658. * If the container is locked, it can not be deleted by the API.
  1659. */
  1660. if (fsa_dev_ptr[dd.cnum].locked)
  1661. return -EBUSY;
  1662. else {
  1663. /*
  1664. * Mark the container as no longer being valid.
  1665. */
  1666. fsa_dev_ptr[dd.cnum].valid = 0;
  1667. fsa_dev_ptr[dd.cnum].devname[0] = '\0';
  1668. return 0;
  1669. }
  1670. }
  1671. int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
  1672. {
  1673. switch (cmd) {
  1674. case FSACTL_QUERY_DISK:
  1675. return query_disk(dev, arg);
  1676. case FSACTL_DELETE_DISK:
  1677. return delete_disk(dev, arg);
  1678. case FSACTL_FORCE_DELETE_DISK:
  1679. return force_delete_disk(dev, arg);
  1680. case FSACTL_GET_CONTAINERS:
  1681. return aac_get_containers(dev);
  1682. default:
  1683. return -ENOTTY;
  1684. }
  1685. }
  1686. /**
  1687. *
  1688. * aac_srb_callback
  1689. * @context: the context set in the fib - here it is scsi cmd
  1690. * @fibptr: pointer to the fib
  1691. *
  1692. * Handles the completion of a scsi command to a non dasd device
  1693. *
  1694. */
  1695. static void aac_srb_callback(void *context, struct fib * fibptr)
  1696. {
  1697. struct aac_dev *dev;
  1698. struct aac_srb_reply *srbreply;
  1699. struct scsi_cmnd *scsicmd;
  1700. scsicmd = (struct scsi_cmnd *) context;
  1701. scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
  1702. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1703. BUG_ON(fibptr == NULL);
  1704. srbreply = (struct aac_srb_reply *) fib_data(fibptr);
  1705. scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
  1706. /*
  1707. * Calculate resid for sg
  1708. */
  1709. scsicmd->resid = scsicmd->request_bufflen -
  1710. le32_to_cpu(srbreply->data_xfer_length);
  1711. if(scsicmd->use_sg)
  1712. pci_unmap_sg(dev->pdev,
  1713. (struct scatterlist *)scsicmd->request_buffer,
  1714. scsicmd->use_sg,
  1715. scsicmd->sc_data_direction);
  1716. else if(scsicmd->request_bufflen)
  1717. pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
  1718. scsicmd->sc_data_direction);
  1719. /*
  1720. * First check the fib status
  1721. */
  1722. if (le32_to_cpu(srbreply->status) != ST_OK){
  1723. int len;
  1724. printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
  1725. len = (le32_to_cpu(srbreply->sense_data_size) >
  1726. sizeof(scsicmd->sense_buffer)) ?
  1727. sizeof(scsicmd->sense_buffer) :
  1728. le32_to_cpu(srbreply->sense_data_size);
  1729. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
  1730. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1731. }
  1732. /*
  1733. * Next check the srb status
  1734. */
  1735. switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
  1736. case SRB_STATUS_ERROR_RECOVERY:
  1737. case SRB_STATUS_PENDING:
  1738. case SRB_STATUS_SUCCESS:
  1739. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1740. break;
  1741. case SRB_STATUS_DATA_OVERRUN:
  1742. switch(scsicmd->cmnd[0]){
  1743. case READ_6:
  1744. case WRITE_6:
  1745. case READ_10:
  1746. case WRITE_10:
  1747. case READ_12:
  1748. case WRITE_12:
  1749. case READ_16:
  1750. case WRITE_16:
  1751. if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
  1752. printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
  1753. } else {
  1754. printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
  1755. }
  1756. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1757. break;
  1758. case INQUIRY: {
  1759. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1760. break;
  1761. }
  1762. default:
  1763. scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  1764. break;
  1765. }
  1766. break;
  1767. case SRB_STATUS_ABORTED:
  1768. scsicmd->result = DID_ABORT << 16 | ABORT << 8;
  1769. break;
  1770. case SRB_STATUS_ABORT_FAILED:
  1771. // Not sure about this one - but assuming the hba was trying to abort for some reason
  1772. scsicmd->result = DID_ERROR << 16 | ABORT << 8;
  1773. break;
  1774. case SRB_STATUS_PARITY_ERROR:
  1775. scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
  1776. break;
  1777. case SRB_STATUS_NO_DEVICE:
  1778. case SRB_STATUS_INVALID_PATH_ID:
  1779. case SRB_STATUS_INVALID_TARGET_ID:
  1780. case SRB_STATUS_INVALID_LUN:
  1781. case SRB_STATUS_SELECTION_TIMEOUT:
  1782. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1783. break;
  1784. case SRB_STATUS_COMMAND_TIMEOUT:
  1785. case SRB_STATUS_TIMEOUT:
  1786. scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
  1787. break;
  1788. case SRB_STATUS_BUSY:
  1789. scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  1790. break;
  1791. case SRB_STATUS_BUS_RESET:
  1792. scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
  1793. break;
  1794. case SRB_STATUS_MESSAGE_REJECTED:
  1795. scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
  1796. break;
  1797. case SRB_STATUS_REQUEST_FLUSHED:
  1798. case SRB_STATUS_ERROR:
  1799. case SRB_STATUS_INVALID_REQUEST:
  1800. case SRB_STATUS_REQUEST_SENSE_FAILED:
  1801. case SRB_STATUS_NO_HBA:
  1802. case SRB_STATUS_UNEXPECTED_BUS_FREE:
  1803. case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
  1804. case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
  1805. case SRB_STATUS_DELAYED_RETRY:
  1806. case SRB_STATUS_BAD_FUNCTION:
  1807. case SRB_STATUS_NOT_STARTED:
  1808. case SRB_STATUS_NOT_IN_USE:
  1809. case SRB_STATUS_FORCE_ABORT:
  1810. case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
  1811. default:
  1812. #ifdef AAC_DETAILED_STATUS_INFO
  1813. printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
  1814. le32_to_cpu(srbreply->srb_status) & 0x3F,
  1815. aac_get_status_string(
  1816. le32_to_cpu(srbreply->srb_status) & 0x3F),
  1817. scsicmd->cmnd[0],
  1818. le32_to_cpu(srbreply->scsi_status));
  1819. #endif
  1820. scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  1821. break;
  1822. }
  1823. if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
  1824. int len;
  1825. scsicmd->result |= SAM_STAT_CHECK_CONDITION;
  1826. len = (le32_to_cpu(srbreply->sense_data_size) >
  1827. sizeof(scsicmd->sense_buffer)) ?
  1828. sizeof(scsicmd->sense_buffer) :
  1829. le32_to_cpu(srbreply->sense_data_size);
  1830. #ifdef AAC_DETAILED_STATUS_INFO
  1831. printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
  1832. le32_to_cpu(srbreply->status), len);
  1833. #endif
  1834. memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
  1835. }
  1836. /*
  1837. * OR in the scsi status (already shifted up a bit)
  1838. */
  1839. scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
  1840. aac_fib_complete(fibptr);
  1841. aac_fib_free(fibptr);
  1842. scsicmd->scsi_done(scsicmd);
  1843. }
  1844. /**
  1845. *
  1846. * aac_send_scb_fib
  1847. * @scsicmd: the scsi command block
  1848. *
  1849. * This routine will form a FIB and fill in the aac_srb from the
  1850. * scsicmd passed in.
  1851. */
  1852. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
  1853. {
  1854. struct fib* cmd_fibcontext;
  1855. struct aac_dev* dev;
  1856. int status;
  1857. struct aac_srb *srbcmd;
  1858. u16 fibsize;
  1859. u32 flag;
  1860. u32 timeout;
  1861. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1862. if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
  1863. scsicmd->device->lun > 7) {
  1864. scsicmd->result = DID_NO_CONNECT << 16;
  1865. scsicmd->scsi_done(scsicmd);
  1866. return 0;
  1867. }
  1868. switch(scsicmd->sc_data_direction){
  1869. case DMA_TO_DEVICE:
  1870. flag = SRB_DataOut;
  1871. break;
  1872. case DMA_BIDIRECTIONAL:
  1873. flag = SRB_DataIn | SRB_DataOut;
  1874. break;
  1875. case DMA_FROM_DEVICE:
  1876. flag = SRB_DataIn;
  1877. break;
  1878. case DMA_NONE:
  1879. default: /* shuts up some versions of gcc */
  1880. flag = SRB_NoDataXfer;
  1881. break;
  1882. }
  1883. /*
  1884. * Allocate and initialize a Fib then setup a BlockWrite command
  1885. */
  1886. if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
  1887. return -1;
  1888. }
  1889. aac_fib_init(cmd_fibcontext);
  1890. srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
  1891. srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
  1892. srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(scsicmd)));
  1893. srbcmd->id = cpu_to_le32(scmd_id(scsicmd));
  1894. srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
  1895. srbcmd->flags = cpu_to_le32(flag);
  1896. timeout = scsicmd->timeout_per_command/HZ;
  1897. if(timeout == 0){
  1898. timeout = 1;
  1899. }
  1900. srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
  1901. srbcmd->retry_limit = 0; /* Obsolete parameter */
  1902. srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
  1903. if( dev->dac_support == 1 ) {
  1904. aac_build_sg64(scsicmd, (struct sgmap64*) &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) - sizeof (struct sgentry) +
  1912. ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
  1913. sizeof (struct sgentry64));
  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(ScsiPortCommand64, cmd_fibcontext,
  1920. fibsize, FsaNormal, 0, 1,
  1921. (fib_callback) aac_srb_callback,
  1922. (void *) scsicmd);
  1923. } else {
  1924. aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
  1925. srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
  1926. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  1927. memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
  1928. /*
  1929. * Build Scatter/Gather list
  1930. */
  1931. fibsize = sizeof (struct aac_srb) +
  1932. (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
  1933. sizeof (struct sgentry));
  1934. BUG_ON (fibsize > (dev->max_fib_size -
  1935. sizeof(struct aac_fibhdr)));
  1936. /*
  1937. * Now send the Fib to the adapter
  1938. */
  1939. status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
  1940. (fib_callback) aac_srb_callback, (void *) scsicmd);
  1941. }
  1942. /*
  1943. * Check that the command queued to the controller
  1944. */
  1945. if (status == -EINPROGRESS) {
  1946. scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
  1947. return 0;
  1948. }
  1949. printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
  1950. aac_fib_complete(cmd_fibcontext);
  1951. aac_fib_free(cmd_fibcontext);
  1952. return -1;
  1953. }
  1954. static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
  1955. {
  1956. struct aac_dev *dev;
  1957. unsigned long byte_count = 0;
  1958. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  1959. // Get rid of old data
  1960. psg->count = 0;
  1961. psg->sg[0].addr = 0;
  1962. psg->sg[0].count = 0;
  1963. if (scsicmd->use_sg) {
  1964. struct scatterlist *sg;
  1965. int i;
  1966. int sg_count;
  1967. sg = (struct scatterlist *) scsicmd->request_buffer;
  1968. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  1969. scsicmd->sc_data_direction);
  1970. psg->count = cpu_to_le32(sg_count);
  1971. for (i = 0; i < sg_count; i++) {
  1972. psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
  1973. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  1974. byte_count += sg_dma_len(sg);
  1975. sg++;
  1976. }
  1977. /* hba wants the size to be exact */
  1978. if(byte_count > scsicmd->request_bufflen){
  1979. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  1980. (byte_count - scsicmd->request_bufflen);
  1981. psg->sg[i-1].count = cpu_to_le32(temp);
  1982. byte_count = scsicmd->request_bufflen;
  1983. }
  1984. /* Check for command underflow */
  1985. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  1986. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  1987. byte_count, scsicmd->underflow);
  1988. }
  1989. }
  1990. else if(scsicmd->request_bufflen) {
  1991. u32 addr;
  1992. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  1993. scsicmd->request_buffer,
  1994. scsicmd->request_bufflen,
  1995. scsicmd->sc_data_direction);
  1996. addr = scsicmd->SCp.dma_handle;
  1997. psg->count = cpu_to_le32(1);
  1998. psg->sg[0].addr = cpu_to_le32(addr);
  1999. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2000. byte_count = scsicmd->request_bufflen;
  2001. }
  2002. return byte_count;
  2003. }
  2004. static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
  2005. {
  2006. struct aac_dev *dev;
  2007. unsigned long byte_count = 0;
  2008. u64 addr;
  2009. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2010. // Get rid of old data
  2011. psg->count = 0;
  2012. psg->sg[0].addr[0] = 0;
  2013. psg->sg[0].addr[1] = 0;
  2014. psg->sg[0].count = 0;
  2015. if (scsicmd->use_sg) {
  2016. struct scatterlist *sg;
  2017. int i;
  2018. int sg_count;
  2019. sg = (struct scatterlist *) scsicmd->request_buffer;
  2020. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2021. scsicmd->sc_data_direction);
  2022. for (i = 0; i < sg_count; i++) {
  2023. int count = sg_dma_len(sg);
  2024. addr = sg_dma_address(sg);
  2025. psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2026. psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
  2027. psg->sg[i].count = cpu_to_le32(count);
  2028. byte_count += count;
  2029. sg++;
  2030. }
  2031. psg->count = cpu_to_le32(sg_count);
  2032. /* hba wants the size to be exact */
  2033. if(byte_count > scsicmd->request_bufflen){
  2034. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2035. (byte_count - scsicmd->request_bufflen);
  2036. psg->sg[i-1].count = cpu_to_le32(temp);
  2037. byte_count = scsicmd->request_bufflen;
  2038. }
  2039. /* Check for command underflow */
  2040. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2041. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2042. byte_count, scsicmd->underflow);
  2043. }
  2044. }
  2045. else if(scsicmd->request_bufflen) {
  2046. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2047. scsicmd->request_buffer,
  2048. scsicmd->request_bufflen,
  2049. scsicmd->sc_data_direction);
  2050. addr = scsicmd->SCp.dma_handle;
  2051. psg->count = cpu_to_le32(1);
  2052. psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
  2053. psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
  2054. psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
  2055. byte_count = scsicmd->request_bufflen;
  2056. }
  2057. return byte_count;
  2058. }
  2059. static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
  2060. {
  2061. struct Scsi_Host *host = scsicmd->device->host;
  2062. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  2063. unsigned long byte_count = 0;
  2064. // Get rid of old data
  2065. psg->count = 0;
  2066. psg->sg[0].next = 0;
  2067. psg->sg[0].prev = 0;
  2068. psg->sg[0].addr[0] = 0;
  2069. psg->sg[0].addr[1] = 0;
  2070. psg->sg[0].count = 0;
  2071. psg->sg[0].flags = 0;
  2072. if (scsicmd->use_sg) {
  2073. struct scatterlist *sg;
  2074. int i;
  2075. int sg_count;
  2076. sg = (struct scatterlist *) scsicmd->request_buffer;
  2077. sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
  2078. scsicmd->sc_data_direction);
  2079. for (i = 0; i < sg_count; i++) {
  2080. int count = sg_dma_len(sg);
  2081. u64 addr = sg_dma_address(sg);
  2082. psg->sg[i].next = 0;
  2083. psg->sg[i].prev = 0;
  2084. psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
  2085. psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2086. psg->sg[i].count = cpu_to_le32(count);
  2087. psg->sg[i].flags = 0;
  2088. byte_count += count;
  2089. sg++;
  2090. }
  2091. psg->count = cpu_to_le32(sg_count);
  2092. /* hba wants the size to be exact */
  2093. if(byte_count > scsicmd->request_bufflen){
  2094. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  2095. (byte_count - scsicmd->request_bufflen);
  2096. psg->sg[i-1].count = cpu_to_le32(temp);
  2097. byte_count = scsicmd->request_bufflen;
  2098. }
  2099. /* Check for command underflow */
  2100. if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
  2101. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  2102. byte_count, scsicmd->underflow);
  2103. }
  2104. }
  2105. else if(scsicmd->request_bufflen) {
  2106. int count;
  2107. u64 addr;
  2108. scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
  2109. scsicmd->request_buffer,
  2110. scsicmd->request_bufflen,
  2111. scsicmd->sc_data_direction);
  2112. addr = scsicmd->SCp.dma_handle;
  2113. count = scsicmd->request_bufflen;
  2114. psg->count = cpu_to_le32(1);
  2115. psg->sg[0].next = 0;
  2116. psg->sg[0].prev = 0;
  2117. psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
  2118. psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  2119. psg->sg[0].count = cpu_to_le32(count);
  2120. psg->sg[0].flags = 0;
  2121. byte_count = scsicmd->request_bufflen;
  2122. }
  2123. return byte_count;
  2124. }
  2125. #ifdef AAC_DETAILED_STATUS_INFO
  2126. struct aac_srb_status_info {
  2127. u32 status;
  2128. char *str;
  2129. };
  2130. static struct aac_srb_status_info srb_status_info[] = {
  2131. { SRB_STATUS_PENDING, "Pending Status"},
  2132. { SRB_STATUS_SUCCESS, "Success"},
  2133. { SRB_STATUS_ABORTED, "Aborted Command"},
  2134. { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
  2135. { SRB_STATUS_ERROR, "Error Event"},
  2136. { SRB_STATUS_BUSY, "Device Busy"},
  2137. { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
  2138. { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
  2139. { SRB_STATUS_NO_DEVICE, "No Device"},
  2140. { SRB_STATUS_TIMEOUT, "Timeout"},
  2141. { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
  2142. { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
  2143. { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
  2144. { SRB_STATUS_BUS_RESET, "Bus Reset"},
  2145. { SRB_STATUS_PARITY_ERROR, "Parity Error"},
  2146. { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
  2147. { SRB_STATUS_NO_HBA, "No HBA"},
  2148. { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
  2149. { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
  2150. { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
  2151. { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
  2152. { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
  2153. { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
  2154. { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
  2155. { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
  2156. { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
  2157. { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
  2158. { SRB_STATUS_NOT_STARTED, "Not Started"},
  2159. { SRB_STATUS_NOT_IN_USE, "Not In Use"},
  2160. { SRB_STATUS_FORCE_ABORT, "Force Abort"},
  2161. { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
  2162. { 0xff, "Unknown Error"}
  2163. };
  2164. char *aac_get_status_string(u32 status)
  2165. {
  2166. int i;
  2167. for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
  2168. if (srb_status_info[i].status == status)
  2169. return srb_status_info[i].str;
  2170. return "Bad Status Code";
  2171. }
  2172. #endif