aachba.c 79 KB

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