aachba.c 73 KB

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