aachba.c 71 KB

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