cciss.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322
  1. /*
  2. * Disk Array driver for HP SA 5xxx and 6xxx Controllers
  3. * Copyright 2000, 2005 Hewlett-Packard Development Company, L.P.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * Questions/Comments/Bugfixes to iss_storagedev@hp.com
  20. *
  21. */
  22. #include <linux/config.h> /* CONFIG_PROC_FS */
  23. #include <linux/module.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/types.h>
  26. #include <linux/pci.h>
  27. #include <linux/kernel.h>
  28. #include <linux/slab.h>
  29. #include <linux/delay.h>
  30. #include <linux/major.h>
  31. #include <linux/fs.h>
  32. #include <linux/bio.h>
  33. #include <linux/blkpg.h>
  34. #include <linux/timer.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/init.h>
  37. #include <linux/hdreg.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/compat.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/io.h>
  42. #include <linux/dma-mapping.h>
  43. #include <linux/blkdev.h>
  44. #include <linux/genhd.h>
  45. #include <linux/completion.h>
  46. #define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
  47. #define DRIVER_NAME "HP CISS Driver (v 2.6.8)"
  48. #define DRIVER_VERSION CCISS_DRIVER_VERSION(2,6,8)
  49. /* Embedded module documentation macros - see modules.h */
  50. MODULE_AUTHOR("Hewlett-Packard Company");
  51. MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.8");
  52. MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
  53. " SA6i P600 P800 P400 P400i E200 E200i");
  54. MODULE_LICENSE("GPL");
  55. #include "cciss_cmd.h"
  56. #include "cciss.h"
  57. #include <linux/cciss_ioctl.h>
  58. /* define the PCI info for the cards we can control */
  59. static const struct pci_device_id cciss_pci_device_id[] = {
  60. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS,
  61. 0x0E11, 0x4070, 0, 0, 0},
  62. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
  63. 0x0E11, 0x4080, 0, 0, 0},
  64. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
  65. 0x0E11, 0x4082, 0, 0, 0},
  66. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB,
  67. 0x0E11, 0x4083, 0, 0, 0},
  68. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
  69. 0x0E11, 0x409A, 0, 0, 0},
  70. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
  71. 0x0E11, 0x409B, 0, 0, 0},
  72. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
  73. 0x0E11, 0x409C, 0, 0, 0},
  74. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
  75. 0x0E11, 0x409D, 0, 0, 0},
  76. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSC,
  77. 0x0E11, 0x4091, 0, 0, 0},
  78. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSA,
  79. 0x103C, 0x3225, 0, 0, 0},
  80. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
  81. 0x103c, 0x3223, 0, 0, 0},
  82. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
  83. 0x103c, 0x3234, 0, 0, 0},
  84. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
  85. 0x103c, 0x3235, 0, 0, 0},
  86. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
  87. 0x103c, 0x3211, 0, 0, 0},
  88. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
  89. 0x103c, 0x3212, 0, 0, 0},
  90. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
  91. 0x103c, 0x3213, 0, 0, 0},
  92. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
  93. 0x103c, 0x3214, 0, 0, 0},
  94. { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD,
  95. 0x103c, 0x3215, 0, 0, 0},
  96. {0,}
  97. };
  98. MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
  99. #define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))
  100. /* board_id = Subsystem Device ID & Vendor ID
  101. * product = Marketing Name for the board
  102. * access = Address of the struct of function pointers
  103. */
  104. static struct board_type products[] = {
  105. { 0x40700E11, "Smart Array 5300", &SA5_access },
  106. { 0x40800E11, "Smart Array 5i", &SA5B_access},
  107. { 0x40820E11, "Smart Array 532", &SA5B_access},
  108. { 0x40830E11, "Smart Array 5312", &SA5B_access},
  109. { 0x409A0E11, "Smart Array 641", &SA5_access},
  110. { 0x409B0E11, "Smart Array 642", &SA5_access},
  111. { 0x409C0E11, "Smart Array 6400", &SA5_access},
  112. { 0x409D0E11, "Smart Array 6400 EM", &SA5_access},
  113. { 0x40910E11, "Smart Array 6i", &SA5_access},
  114. { 0x3225103C, "Smart Array P600", &SA5_access},
  115. { 0x3223103C, "Smart Array P800", &SA5_access},
  116. { 0x3234103C, "Smart Array P400", &SA5_access},
  117. { 0x3235103C, "Smart Array P400i", &SA5_access},
  118. { 0x3211103C, "Smart Array E200i", &SA5_access},
  119. { 0x3212103C, "Smart Array E200", &SA5_access},
  120. { 0x3213103C, "Smart Array E200i", &SA5_access},
  121. { 0x3214103C, "Smart Array E200i", &SA5_access},
  122. { 0x3215103C, "Smart Array E200i", &SA5_access},
  123. };
  124. /* How long to wait (in millesconds) for board to go into simple mode */
  125. #define MAX_CONFIG_WAIT 30000
  126. #define MAX_IOCTL_CONFIG_WAIT 1000
  127. /*define how many times we will try a command because of bus resets */
  128. #define MAX_CMD_RETRIES 3
  129. #define READ_AHEAD 1024
  130. #define NR_CMDS 384 /* #commands that can be outstanding */
  131. #define MAX_CTLR 32
  132. /* Originally cciss driver only supports 8 major numbers */
  133. #define MAX_CTLR_ORIG 8
  134. static ctlr_info_t *hba[MAX_CTLR];
  135. static void do_cciss_request(request_queue_t *q);
  136. static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs);
  137. static int cciss_open(struct inode *inode, struct file *filep);
  138. static int cciss_release(struct inode *inode, struct file *filep);
  139. static int cciss_ioctl(struct inode *inode, struct file *filep,
  140. unsigned int cmd, unsigned long arg);
  141. static int revalidate_allvol(ctlr_info_t *host);
  142. static int cciss_revalidate(struct gendisk *disk);
  143. static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk);
  144. static int deregister_disk(struct gendisk *disk, drive_info_struct *drv, int clear_all);
  145. static void cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
  146. int withirq, unsigned int *total_size, unsigned int *block_size);
  147. static void cciss_geometry_inquiry(int ctlr, int logvol,
  148. int withirq, unsigned int total_size,
  149. unsigned int block_size, InquiryData_struct *inq_buff,
  150. drive_info_struct *drv);
  151. static void cciss_getgeometry(int cntl_num);
  152. static void start_io( ctlr_info_t *h);
  153. static int sendcmd( __u8 cmd, int ctlr, void *buff, size_t size,
  154. unsigned int use_unit_num, unsigned int log_unit, __u8 page_code,
  155. unsigned char *scsi3addr, int cmd_type);
  156. static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
  157. unsigned int use_unit_num, unsigned int log_unit, __u8 page_code,
  158. int cmd_type);
  159. static void fail_all_cmds(unsigned long ctlr);
  160. #ifdef CONFIG_PROC_FS
  161. static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
  162. int length, int *eof, void *data);
  163. static void cciss_procinit(int i);
  164. #else
  165. static void cciss_procinit(int i) {}
  166. #endif /* CONFIG_PROC_FS */
  167. #ifdef CONFIG_COMPAT
  168. static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg);
  169. #endif
  170. static struct block_device_operations cciss_fops = {
  171. .owner = THIS_MODULE,
  172. .open = cciss_open,
  173. .release = cciss_release,
  174. .ioctl = cciss_ioctl,
  175. #ifdef CONFIG_COMPAT
  176. .compat_ioctl = cciss_compat_ioctl,
  177. #endif
  178. .revalidate_disk= cciss_revalidate,
  179. };
  180. /*
  181. * Enqueuing and dequeuing functions for cmdlists.
  182. */
  183. static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c)
  184. {
  185. if (*Qptr == NULL) {
  186. *Qptr = c;
  187. c->next = c->prev = c;
  188. } else {
  189. c->prev = (*Qptr)->prev;
  190. c->next = (*Qptr);
  191. (*Qptr)->prev->next = c;
  192. (*Qptr)->prev = c;
  193. }
  194. }
  195. static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
  196. CommandList_struct *c)
  197. {
  198. if (c && c->next != c) {
  199. if (*Qptr == c) *Qptr = c->next;
  200. c->prev->next = c->next;
  201. c->next->prev = c->prev;
  202. } else {
  203. *Qptr = NULL;
  204. }
  205. return c;
  206. }
  207. #include "cciss_scsi.c" /* For SCSI tape support */
  208. #ifdef CONFIG_PROC_FS
  209. /*
  210. * Report information about this controller.
  211. */
  212. #define ENG_GIG 1000000000
  213. #define ENG_GIG_FACTOR (ENG_GIG/512)
  214. #define RAID_UNKNOWN 6
  215. static const char *raid_label[] = {"0","4","1(1+0)","5","5+1","ADG",
  216. "UNKNOWN"};
  217. static struct proc_dir_entry *proc_cciss;
  218. static int cciss_proc_get_info(char *buffer, char **start, off_t offset,
  219. int length, int *eof, void *data)
  220. {
  221. off_t pos = 0;
  222. off_t len = 0;
  223. int size, i, ctlr;
  224. ctlr_info_t *h = (ctlr_info_t*)data;
  225. drive_info_struct *drv;
  226. unsigned long flags;
  227. sector_t vol_sz, vol_sz_frac;
  228. ctlr = h->ctlr;
  229. /* prevent displaying bogus info during configuration
  230. * or deconfiguration of a logical volume
  231. */
  232. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  233. if (h->busy_configuring) {
  234. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  235. return -EBUSY;
  236. }
  237. h->busy_configuring = 1;
  238. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  239. size = sprintf(buffer, "%s: HP %s Controller\n"
  240. "Board ID: 0x%08lx\n"
  241. "Firmware Version: %c%c%c%c\n"
  242. "IRQ: %d\n"
  243. "Logical drives: %d\n"
  244. "Current Q depth: %d\n"
  245. "Current # commands on controller: %d\n"
  246. "Max Q depth since init: %d\n"
  247. "Max # commands on controller since init: %d\n"
  248. "Max SG entries since init: %d\n\n",
  249. h->devname,
  250. h->product_name,
  251. (unsigned long)h->board_id,
  252. h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], h->firm_ver[3],
  253. (unsigned int)h->intr,
  254. h->num_luns,
  255. h->Qdepth, h->commands_outstanding,
  256. h->maxQsinceinit, h->max_outstanding, h->maxSG);
  257. pos += size; len += size;
  258. cciss_proc_tape_report(ctlr, buffer, &pos, &len);
  259. for(i=0; i<=h->highest_lun; i++) {
  260. drv = &h->drv[i];
  261. if (drv->heads == 0)
  262. continue;
  263. vol_sz = drv->nr_blocks;
  264. vol_sz_frac = sector_div(vol_sz, ENG_GIG_FACTOR);
  265. vol_sz_frac *= 100;
  266. sector_div(vol_sz_frac, ENG_GIG_FACTOR);
  267. if (drv->raid_level > 5)
  268. drv->raid_level = RAID_UNKNOWN;
  269. size = sprintf(buffer+len, "cciss/c%dd%d:"
  270. "\t%4u.%02uGB\tRAID %s\n",
  271. ctlr, i, (int)vol_sz, (int)vol_sz_frac,
  272. raid_label[drv->raid_level]);
  273. pos += size; len += size;
  274. }
  275. *eof = 1;
  276. *start = buffer+offset;
  277. len -= offset;
  278. if (len>length)
  279. len = length;
  280. h->busy_configuring = 0;
  281. return len;
  282. }
  283. static int
  284. cciss_proc_write(struct file *file, const char __user *buffer,
  285. unsigned long count, void *data)
  286. {
  287. unsigned char cmd[80];
  288. int len;
  289. #ifdef CONFIG_CISS_SCSI_TAPE
  290. ctlr_info_t *h = (ctlr_info_t *) data;
  291. int rc;
  292. #endif
  293. if (count > sizeof(cmd)-1) return -EINVAL;
  294. if (copy_from_user(cmd, buffer, count)) return -EFAULT;
  295. cmd[count] = '\0';
  296. len = strlen(cmd); // above 3 lines ensure safety
  297. if (len && cmd[len-1] == '\n')
  298. cmd[--len] = '\0';
  299. # ifdef CONFIG_CISS_SCSI_TAPE
  300. if (strcmp("engage scsi", cmd)==0) {
  301. rc = cciss_engage_scsi(h->ctlr);
  302. if (rc != 0) return -rc;
  303. return count;
  304. }
  305. /* might be nice to have "disengage" too, but it's not
  306. safely possible. (only 1 module use count, lock issues.) */
  307. # endif
  308. return -EINVAL;
  309. }
  310. /*
  311. * Get us a file in /proc/cciss that says something about each controller.
  312. * Create /proc/cciss if it doesn't exist yet.
  313. */
  314. static void __devinit cciss_procinit(int i)
  315. {
  316. struct proc_dir_entry *pde;
  317. if (proc_cciss == NULL) {
  318. proc_cciss = proc_mkdir("cciss", proc_root_driver);
  319. if (!proc_cciss)
  320. return;
  321. }
  322. pde = create_proc_read_entry(hba[i]->devname,
  323. S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
  324. proc_cciss, cciss_proc_get_info, hba[i]);
  325. pde->write_proc = cciss_proc_write;
  326. }
  327. #endif /* CONFIG_PROC_FS */
  328. /*
  329. * For operations that cannot sleep, a command block is allocated at init,
  330. * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
  331. * which ones are free or in use. For operations that can wait for kmalloc
  332. * to possible sleep, this routine can be called with get_from_pool set to 0.
  333. * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
  334. */
  335. static CommandList_struct * cmd_alloc(ctlr_info_t *h, int get_from_pool)
  336. {
  337. CommandList_struct *c;
  338. int i;
  339. u64bit temp64;
  340. dma_addr_t cmd_dma_handle, err_dma_handle;
  341. if (!get_from_pool)
  342. {
  343. c = (CommandList_struct *) pci_alloc_consistent(
  344. h->pdev, sizeof(CommandList_struct), &cmd_dma_handle);
  345. if(c==NULL)
  346. return NULL;
  347. memset(c, 0, sizeof(CommandList_struct));
  348. c->cmdindex = -1;
  349. c->err_info = (ErrorInfo_struct *)pci_alloc_consistent(
  350. h->pdev, sizeof(ErrorInfo_struct),
  351. &err_dma_handle);
  352. if (c->err_info == NULL)
  353. {
  354. pci_free_consistent(h->pdev,
  355. sizeof(CommandList_struct), c, cmd_dma_handle);
  356. return NULL;
  357. }
  358. memset(c->err_info, 0, sizeof(ErrorInfo_struct));
  359. } else /* get it out of the controllers pool */
  360. {
  361. do {
  362. i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS);
  363. if (i == NR_CMDS)
  364. return NULL;
  365. } while(test_and_set_bit(i & (BITS_PER_LONG - 1), h->cmd_pool_bits+(i/BITS_PER_LONG)) != 0);
  366. #ifdef CCISS_DEBUG
  367. printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
  368. #endif
  369. c = h->cmd_pool + i;
  370. memset(c, 0, sizeof(CommandList_struct));
  371. cmd_dma_handle = h->cmd_pool_dhandle
  372. + i*sizeof(CommandList_struct);
  373. c->err_info = h->errinfo_pool + i;
  374. memset(c->err_info, 0, sizeof(ErrorInfo_struct));
  375. err_dma_handle = h->errinfo_pool_dhandle
  376. + i*sizeof(ErrorInfo_struct);
  377. h->nr_allocs++;
  378. c->cmdindex = i;
  379. }
  380. c->busaddr = (__u32) cmd_dma_handle;
  381. temp64.val = (__u64) err_dma_handle;
  382. c->ErrDesc.Addr.lower = temp64.val32.lower;
  383. c->ErrDesc.Addr.upper = temp64.val32.upper;
  384. c->ErrDesc.Len = sizeof(ErrorInfo_struct);
  385. c->ctlr = h->ctlr;
  386. return c;
  387. }
  388. /*
  389. * Frees a command block that was previously allocated with cmd_alloc().
  390. */
  391. static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool)
  392. {
  393. int i;
  394. u64bit temp64;
  395. if( !got_from_pool)
  396. {
  397. temp64.val32.lower = c->ErrDesc.Addr.lower;
  398. temp64.val32.upper = c->ErrDesc.Addr.upper;
  399. pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
  400. c->err_info, (dma_addr_t) temp64.val);
  401. pci_free_consistent(h->pdev, sizeof(CommandList_struct),
  402. c, (dma_addr_t) c->busaddr);
  403. } else
  404. {
  405. i = c - h->cmd_pool;
  406. clear_bit(i&(BITS_PER_LONG-1), h->cmd_pool_bits+(i/BITS_PER_LONG));
  407. h->nr_frees++;
  408. }
  409. }
  410. static inline ctlr_info_t *get_host(struct gendisk *disk)
  411. {
  412. return disk->queue->queuedata;
  413. }
  414. static inline drive_info_struct *get_drv(struct gendisk *disk)
  415. {
  416. return disk->private_data;
  417. }
  418. /*
  419. * Open. Make sure the device is really there.
  420. */
  421. static int cciss_open(struct inode *inode, struct file *filep)
  422. {
  423. ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
  424. drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk);
  425. #ifdef CCISS_DEBUG
  426. printk(KERN_DEBUG "cciss_open %s\n", inode->i_bdev->bd_disk->disk_name);
  427. #endif /* CCISS_DEBUG */
  428. if (host->busy_initializing || drv->busy_configuring)
  429. return -EBUSY;
  430. /*
  431. * Root is allowed to open raw volume zero even if it's not configured
  432. * so array config can still work. Root is also allowed to open any
  433. * volume that has a LUN ID, so it can issue IOCTL to reread the
  434. * disk information. I don't think I really like this
  435. * but I'm already using way to many device nodes to claim another one
  436. * for "raw controller".
  437. */
  438. if (drv->nr_blocks == 0) {
  439. if (iminor(inode) != 0) { /* not node 0? */
  440. /* if not node 0 make sure it is a partition = 0 */
  441. if (iminor(inode) & 0x0f) {
  442. return -ENXIO;
  443. /* if it is, make sure we have a LUN ID */
  444. } else if (drv->LunID == 0) {
  445. return -ENXIO;
  446. }
  447. }
  448. if (!capable(CAP_SYS_ADMIN))
  449. return -EPERM;
  450. }
  451. drv->usage_count++;
  452. host->usage_count++;
  453. return 0;
  454. }
  455. /*
  456. * Close. Sync first.
  457. */
  458. static int cciss_release(struct inode *inode, struct file *filep)
  459. {
  460. ctlr_info_t *host = get_host(inode->i_bdev->bd_disk);
  461. drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk);
  462. #ifdef CCISS_DEBUG
  463. printk(KERN_DEBUG "cciss_release %s\n", inode->i_bdev->bd_disk->disk_name);
  464. #endif /* CCISS_DEBUG */
  465. drv->usage_count--;
  466. host->usage_count--;
  467. return 0;
  468. }
  469. #ifdef CONFIG_COMPAT
  470. static int do_ioctl(struct file *f, unsigned cmd, unsigned long arg)
  471. {
  472. int ret;
  473. lock_kernel();
  474. ret = cciss_ioctl(f->f_dentry->d_inode, f, cmd, arg);
  475. unlock_kernel();
  476. return ret;
  477. }
  478. static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, unsigned long arg);
  479. static int cciss_ioctl32_big_passthru(struct file *f, unsigned cmd, unsigned long arg);
  480. static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg)
  481. {
  482. switch (cmd) {
  483. case CCISS_GETPCIINFO:
  484. case CCISS_GETINTINFO:
  485. case CCISS_SETINTINFO:
  486. case CCISS_GETNODENAME:
  487. case CCISS_SETNODENAME:
  488. case CCISS_GETHEARTBEAT:
  489. case CCISS_GETBUSTYPES:
  490. case CCISS_GETFIRMVER:
  491. case CCISS_GETDRIVVER:
  492. case CCISS_REVALIDVOLS:
  493. case CCISS_DEREGDISK:
  494. case CCISS_REGNEWDISK:
  495. case CCISS_REGNEWD:
  496. case CCISS_RESCANDISK:
  497. case CCISS_GETLUNINFO:
  498. return do_ioctl(f, cmd, arg);
  499. case CCISS_PASSTHRU32:
  500. return cciss_ioctl32_passthru(f, cmd, arg);
  501. case CCISS_BIG_PASSTHRU32:
  502. return cciss_ioctl32_big_passthru(f, cmd, arg);
  503. default:
  504. return -ENOIOCTLCMD;
  505. }
  506. }
  507. static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, unsigned long arg)
  508. {
  509. IOCTL32_Command_struct __user *arg32 =
  510. (IOCTL32_Command_struct __user *) arg;
  511. IOCTL_Command_struct arg64;
  512. IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64));
  513. int err;
  514. u32 cp;
  515. err = 0;
  516. err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, sizeof(arg64.LUN_info));
  517. err |= copy_from_user(&arg64.Request, &arg32->Request, sizeof(arg64.Request));
  518. err |= copy_from_user(&arg64.error_info, &arg32->error_info, sizeof(arg64.error_info));
  519. err |= get_user(arg64.buf_size, &arg32->buf_size);
  520. err |= get_user(cp, &arg32->buf);
  521. arg64.buf = compat_ptr(cp);
  522. err |= copy_to_user(p, &arg64, sizeof(arg64));
  523. if (err)
  524. return -EFAULT;
  525. err = do_ioctl(f, CCISS_PASSTHRU, (unsigned long) p);
  526. if (err)
  527. return err;
  528. err |= copy_in_user(&arg32->error_info, &p->error_info, sizeof(arg32->error_info));
  529. if (err)
  530. return -EFAULT;
  531. return err;
  532. }
  533. static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd, unsigned long arg)
  534. {
  535. BIG_IOCTL32_Command_struct __user *arg32 =
  536. (BIG_IOCTL32_Command_struct __user *) arg;
  537. BIG_IOCTL_Command_struct arg64;
  538. BIG_IOCTL_Command_struct __user *p = compat_alloc_user_space(sizeof(arg64));
  539. int err;
  540. u32 cp;
  541. err = 0;
  542. err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info, sizeof(arg64.LUN_info));
  543. err |= copy_from_user(&arg64.Request, &arg32->Request, sizeof(arg64.Request));
  544. err |= copy_from_user(&arg64.error_info, &arg32->error_info, sizeof(arg64.error_info));
  545. err |= get_user(arg64.buf_size, &arg32->buf_size);
  546. err |= get_user(arg64.malloc_size, &arg32->malloc_size);
  547. err |= get_user(cp, &arg32->buf);
  548. arg64.buf = compat_ptr(cp);
  549. err |= copy_to_user(p, &arg64, sizeof(arg64));
  550. if (err)
  551. return -EFAULT;
  552. err = do_ioctl(file, CCISS_BIG_PASSTHRU, (unsigned long) p);
  553. if (err)
  554. return err;
  555. err |= copy_in_user(&arg32->error_info, &p->error_info, sizeof(arg32->error_info));
  556. if (err)
  557. return -EFAULT;
  558. return err;
  559. }
  560. #endif
  561. /*
  562. * ioctl
  563. */
  564. static int cciss_ioctl(struct inode *inode, struct file *filep,
  565. unsigned int cmd, unsigned long arg)
  566. {
  567. struct block_device *bdev = inode->i_bdev;
  568. struct gendisk *disk = bdev->bd_disk;
  569. ctlr_info_t *host = get_host(disk);
  570. drive_info_struct *drv = get_drv(disk);
  571. int ctlr = host->ctlr;
  572. void __user *argp = (void __user *)arg;
  573. #ifdef CCISS_DEBUG
  574. printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg);
  575. #endif /* CCISS_DEBUG */
  576. switch(cmd) {
  577. case HDIO_GETGEO:
  578. {
  579. struct hd_geometry driver_geo;
  580. if (drv->cylinders) {
  581. driver_geo.heads = drv->heads;
  582. driver_geo.sectors = drv->sectors;
  583. driver_geo.cylinders = drv->cylinders;
  584. } else
  585. return -ENXIO;
  586. driver_geo.start= get_start_sect(inode->i_bdev);
  587. if (copy_to_user(argp, &driver_geo, sizeof(struct hd_geometry)))
  588. return -EFAULT;
  589. return(0);
  590. }
  591. case CCISS_GETPCIINFO:
  592. {
  593. cciss_pci_info_struct pciinfo;
  594. if (!arg) return -EINVAL;
  595. pciinfo.domain = pci_domain_nr(host->pdev->bus);
  596. pciinfo.bus = host->pdev->bus->number;
  597. pciinfo.dev_fn = host->pdev->devfn;
  598. pciinfo.board_id = host->board_id;
  599. if (copy_to_user(argp, &pciinfo, sizeof( cciss_pci_info_struct )))
  600. return -EFAULT;
  601. return(0);
  602. }
  603. case CCISS_GETINTINFO:
  604. {
  605. cciss_coalint_struct intinfo;
  606. if (!arg) return -EINVAL;
  607. intinfo.delay = readl(&host->cfgtable->HostWrite.CoalIntDelay);
  608. intinfo.count = readl(&host->cfgtable->HostWrite.CoalIntCount);
  609. if (copy_to_user(argp, &intinfo, sizeof( cciss_coalint_struct )))
  610. return -EFAULT;
  611. return(0);
  612. }
  613. case CCISS_SETINTINFO:
  614. {
  615. cciss_coalint_struct intinfo;
  616. unsigned long flags;
  617. int i;
  618. if (!arg) return -EINVAL;
  619. if (!capable(CAP_SYS_ADMIN)) return -EPERM;
  620. if (copy_from_user(&intinfo, argp, sizeof( cciss_coalint_struct)))
  621. return -EFAULT;
  622. if ( (intinfo.delay == 0 ) && (intinfo.count == 0))
  623. {
  624. // printk("cciss_ioctl: delay and count cannot be 0\n");
  625. return( -EINVAL);
  626. }
  627. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  628. /* Update the field, and then ring the doorbell */
  629. writel( intinfo.delay,
  630. &(host->cfgtable->HostWrite.CoalIntDelay));
  631. writel( intinfo.count,
  632. &(host->cfgtable->HostWrite.CoalIntCount));
  633. writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
  634. for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
  635. if (!(readl(host->vaddr + SA5_DOORBELL)
  636. & CFGTBL_ChangeReq))
  637. break;
  638. /* delay and try again */
  639. udelay(1000);
  640. }
  641. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  642. if (i >= MAX_IOCTL_CONFIG_WAIT)
  643. return -EAGAIN;
  644. return(0);
  645. }
  646. case CCISS_GETNODENAME:
  647. {
  648. NodeName_type NodeName;
  649. int i;
  650. if (!arg) return -EINVAL;
  651. for(i=0;i<16;i++)
  652. NodeName[i] = readb(&host->cfgtable->ServerName[i]);
  653. if (copy_to_user(argp, NodeName, sizeof( NodeName_type)))
  654. return -EFAULT;
  655. return(0);
  656. }
  657. case CCISS_SETNODENAME:
  658. {
  659. NodeName_type NodeName;
  660. unsigned long flags;
  661. int i;
  662. if (!arg) return -EINVAL;
  663. if (!capable(CAP_SYS_ADMIN)) return -EPERM;
  664. if (copy_from_user(NodeName, argp, sizeof( NodeName_type)))
  665. return -EFAULT;
  666. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  667. /* Update the field, and then ring the doorbell */
  668. for(i=0;i<16;i++)
  669. writeb( NodeName[i], &host->cfgtable->ServerName[i]);
  670. writel( CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL);
  671. for(i=0;i<MAX_IOCTL_CONFIG_WAIT;i++) {
  672. if (!(readl(host->vaddr + SA5_DOORBELL)
  673. & CFGTBL_ChangeReq))
  674. break;
  675. /* delay and try again */
  676. udelay(1000);
  677. }
  678. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  679. if (i >= MAX_IOCTL_CONFIG_WAIT)
  680. return -EAGAIN;
  681. return(0);
  682. }
  683. case CCISS_GETHEARTBEAT:
  684. {
  685. Heartbeat_type heartbeat;
  686. if (!arg) return -EINVAL;
  687. heartbeat = readl(&host->cfgtable->HeartBeat);
  688. if (copy_to_user(argp, &heartbeat, sizeof( Heartbeat_type)))
  689. return -EFAULT;
  690. return(0);
  691. }
  692. case CCISS_GETBUSTYPES:
  693. {
  694. BusTypes_type BusTypes;
  695. if (!arg) return -EINVAL;
  696. BusTypes = readl(&host->cfgtable->BusTypes);
  697. if (copy_to_user(argp, &BusTypes, sizeof( BusTypes_type) ))
  698. return -EFAULT;
  699. return(0);
  700. }
  701. case CCISS_GETFIRMVER:
  702. {
  703. FirmwareVer_type firmware;
  704. if (!arg) return -EINVAL;
  705. memcpy(firmware, host->firm_ver, 4);
  706. if (copy_to_user(argp, firmware, sizeof( FirmwareVer_type)))
  707. return -EFAULT;
  708. return(0);
  709. }
  710. case CCISS_GETDRIVVER:
  711. {
  712. DriverVer_type DriverVer = DRIVER_VERSION;
  713. if (!arg) return -EINVAL;
  714. if (copy_to_user(argp, &DriverVer, sizeof( DriverVer_type) ))
  715. return -EFAULT;
  716. return(0);
  717. }
  718. case CCISS_REVALIDVOLS:
  719. if (bdev != bdev->bd_contains || drv != host->drv)
  720. return -ENXIO;
  721. return revalidate_allvol(host);
  722. case CCISS_GETLUNINFO: {
  723. LogvolInfo_struct luninfo;
  724. luninfo.LunID = drv->LunID;
  725. luninfo.num_opens = drv->usage_count;
  726. luninfo.num_parts = 0;
  727. if (copy_to_user(argp, &luninfo,
  728. sizeof(LogvolInfo_struct)))
  729. return -EFAULT;
  730. return(0);
  731. }
  732. case CCISS_DEREGDISK:
  733. return rebuild_lun_table(host, disk);
  734. case CCISS_REGNEWD:
  735. return rebuild_lun_table(host, NULL);
  736. case CCISS_PASSTHRU:
  737. {
  738. IOCTL_Command_struct iocommand;
  739. CommandList_struct *c;
  740. char *buff = NULL;
  741. u64bit temp64;
  742. unsigned long flags;
  743. DECLARE_COMPLETION(wait);
  744. if (!arg) return -EINVAL;
  745. if (!capable(CAP_SYS_RAWIO)) return -EPERM;
  746. if (copy_from_user(&iocommand, argp, sizeof( IOCTL_Command_struct) ))
  747. return -EFAULT;
  748. if((iocommand.buf_size < 1) &&
  749. (iocommand.Request.Type.Direction != XFER_NONE))
  750. {
  751. return -EINVAL;
  752. }
  753. #if 0 /* 'buf_size' member is 16-bits, and always smaller than kmalloc limit */
  754. /* Check kmalloc limits */
  755. if(iocommand.buf_size > 128000)
  756. return -EINVAL;
  757. #endif
  758. if(iocommand.buf_size > 0)
  759. {
  760. buff = kmalloc(iocommand.buf_size, GFP_KERNEL);
  761. if( buff == NULL)
  762. return -EFAULT;
  763. }
  764. if (iocommand.Request.Type.Direction == XFER_WRITE)
  765. {
  766. /* Copy the data into the buffer we created */
  767. if (copy_from_user(buff, iocommand.buf, iocommand.buf_size))
  768. {
  769. kfree(buff);
  770. return -EFAULT;
  771. }
  772. } else {
  773. memset(buff, 0, iocommand.buf_size);
  774. }
  775. if ((c = cmd_alloc(host , 0)) == NULL)
  776. {
  777. kfree(buff);
  778. return -ENOMEM;
  779. }
  780. // Fill in the command type
  781. c->cmd_type = CMD_IOCTL_PEND;
  782. // Fill in Command Header
  783. c->Header.ReplyQueue = 0; // unused in simple mode
  784. if( iocommand.buf_size > 0) // buffer to fill
  785. {
  786. c->Header.SGList = 1;
  787. c->Header.SGTotal= 1;
  788. } else // no buffers to fill
  789. {
  790. c->Header.SGList = 0;
  791. c->Header.SGTotal= 0;
  792. }
  793. c->Header.LUN = iocommand.LUN_info;
  794. c->Header.Tag.lower = c->busaddr; // use the kernel address the cmd block for tag
  795. // Fill in Request block
  796. c->Request = iocommand.Request;
  797. // Fill in the scatter gather information
  798. if (iocommand.buf_size > 0 )
  799. {
  800. temp64.val = pci_map_single( host->pdev, buff,
  801. iocommand.buf_size,
  802. PCI_DMA_BIDIRECTIONAL);
  803. c->SG[0].Addr.lower = temp64.val32.lower;
  804. c->SG[0].Addr.upper = temp64.val32.upper;
  805. c->SG[0].Len = iocommand.buf_size;
  806. c->SG[0].Ext = 0; // we are not chaining
  807. }
  808. c->waiting = &wait;
  809. /* Put the request on the tail of the request queue */
  810. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  811. addQ(&host->reqQ, c);
  812. host->Qdepth++;
  813. start_io(host);
  814. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  815. wait_for_completion(&wait);
  816. /* unlock the buffers from DMA */
  817. temp64.val32.lower = c->SG[0].Addr.lower;
  818. temp64.val32.upper = c->SG[0].Addr.upper;
  819. pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
  820. iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
  821. /* Copy the error information out */
  822. iocommand.error_info = *(c->err_info);
  823. if ( copy_to_user(argp, &iocommand, sizeof( IOCTL_Command_struct) ) )
  824. {
  825. kfree(buff);
  826. cmd_free(host, c, 0);
  827. return( -EFAULT);
  828. }
  829. if (iocommand.Request.Type.Direction == XFER_READ)
  830. {
  831. /* Copy the data out of the buffer we created */
  832. if (copy_to_user(iocommand.buf, buff, iocommand.buf_size))
  833. {
  834. kfree(buff);
  835. cmd_free(host, c, 0);
  836. return -EFAULT;
  837. }
  838. }
  839. kfree(buff);
  840. cmd_free(host, c, 0);
  841. return(0);
  842. }
  843. case CCISS_BIG_PASSTHRU: {
  844. BIG_IOCTL_Command_struct *ioc;
  845. CommandList_struct *c;
  846. unsigned char **buff = NULL;
  847. int *buff_size = NULL;
  848. u64bit temp64;
  849. unsigned long flags;
  850. BYTE sg_used = 0;
  851. int status = 0;
  852. int i;
  853. DECLARE_COMPLETION(wait);
  854. __u32 left;
  855. __u32 sz;
  856. BYTE __user *data_ptr;
  857. if (!arg)
  858. return -EINVAL;
  859. if (!capable(CAP_SYS_RAWIO))
  860. return -EPERM;
  861. ioc = (BIG_IOCTL_Command_struct *)
  862. kmalloc(sizeof(*ioc), GFP_KERNEL);
  863. if (!ioc) {
  864. status = -ENOMEM;
  865. goto cleanup1;
  866. }
  867. if (copy_from_user(ioc, argp, sizeof(*ioc))) {
  868. status = -EFAULT;
  869. goto cleanup1;
  870. }
  871. if ((ioc->buf_size < 1) &&
  872. (ioc->Request.Type.Direction != XFER_NONE)) {
  873. status = -EINVAL;
  874. goto cleanup1;
  875. }
  876. /* Check kmalloc limits using all SGs */
  877. if (ioc->malloc_size > MAX_KMALLOC_SIZE) {
  878. status = -EINVAL;
  879. goto cleanup1;
  880. }
  881. if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) {
  882. status = -EINVAL;
  883. goto cleanup1;
  884. }
  885. buff = (unsigned char **) kmalloc(MAXSGENTRIES *
  886. sizeof(char *), GFP_KERNEL);
  887. if (!buff) {
  888. status = -ENOMEM;
  889. goto cleanup1;
  890. }
  891. memset(buff, 0, MAXSGENTRIES);
  892. buff_size = (int *) kmalloc(MAXSGENTRIES * sizeof(int),
  893. GFP_KERNEL);
  894. if (!buff_size) {
  895. status = -ENOMEM;
  896. goto cleanup1;
  897. }
  898. left = ioc->buf_size;
  899. data_ptr = ioc->buf;
  900. while (left) {
  901. sz = (left > ioc->malloc_size) ? ioc->malloc_size : left;
  902. buff_size[sg_used] = sz;
  903. buff[sg_used] = kmalloc(sz, GFP_KERNEL);
  904. if (buff[sg_used] == NULL) {
  905. status = -ENOMEM;
  906. goto cleanup1;
  907. }
  908. if (ioc->Request.Type.Direction == XFER_WRITE &&
  909. copy_from_user(buff[sg_used], data_ptr, sz)) {
  910. status = -ENOMEM;
  911. goto cleanup1;
  912. } else {
  913. memset(buff[sg_used], 0, sz);
  914. }
  915. left -= sz;
  916. data_ptr += sz;
  917. sg_used++;
  918. }
  919. if ((c = cmd_alloc(host , 0)) == NULL) {
  920. status = -ENOMEM;
  921. goto cleanup1;
  922. }
  923. c->cmd_type = CMD_IOCTL_PEND;
  924. c->Header.ReplyQueue = 0;
  925. if( ioc->buf_size > 0) {
  926. c->Header.SGList = sg_used;
  927. c->Header.SGTotal= sg_used;
  928. } else {
  929. c->Header.SGList = 0;
  930. c->Header.SGTotal= 0;
  931. }
  932. c->Header.LUN = ioc->LUN_info;
  933. c->Header.Tag.lower = c->busaddr;
  934. c->Request = ioc->Request;
  935. if (ioc->buf_size > 0 ) {
  936. int i;
  937. for(i=0; i<sg_used; i++) {
  938. temp64.val = pci_map_single( host->pdev, buff[i],
  939. buff_size[i],
  940. PCI_DMA_BIDIRECTIONAL);
  941. c->SG[i].Addr.lower = temp64.val32.lower;
  942. c->SG[i].Addr.upper = temp64.val32.upper;
  943. c->SG[i].Len = buff_size[i];
  944. c->SG[i].Ext = 0; /* we are not chaining */
  945. }
  946. }
  947. c->waiting = &wait;
  948. /* Put the request on the tail of the request queue */
  949. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  950. addQ(&host->reqQ, c);
  951. host->Qdepth++;
  952. start_io(host);
  953. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  954. wait_for_completion(&wait);
  955. /* unlock the buffers from DMA */
  956. for(i=0; i<sg_used; i++) {
  957. temp64.val32.lower = c->SG[i].Addr.lower;
  958. temp64.val32.upper = c->SG[i].Addr.upper;
  959. pci_unmap_single( host->pdev, (dma_addr_t) temp64.val,
  960. buff_size[i], PCI_DMA_BIDIRECTIONAL);
  961. }
  962. /* Copy the error information out */
  963. ioc->error_info = *(c->err_info);
  964. if (copy_to_user(argp, ioc, sizeof(*ioc))) {
  965. cmd_free(host, c, 0);
  966. status = -EFAULT;
  967. goto cleanup1;
  968. }
  969. if (ioc->Request.Type.Direction == XFER_READ) {
  970. /* Copy the data out of the buffer we created */
  971. BYTE __user *ptr = ioc->buf;
  972. for(i=0; i< sg_used; i++) {
  973. if (copy_to_user(ptr, buff[i], buff_size[i])) {
  974. cmd_free(host, c, 0);
  975. status = -EFAULT;
  976. goto cleanup1;
  977. }
  978. ptr += buff_size[i];
  979. }
  980. }
  981. cmd_free(host, c, 0);
  982. status = 0;
  983. cleanup1:
  984. if (buff) {
  985. for(i=0; i<sg_used; i++)
  986. kfree(buff[i]);
  987. kfree(buff);
  988. }
  989. kfree(buff_size);
  990. kfree(ioc);
  991. return(status);
  992. }
  993. default:
  994. return -ENOTTY;
  995. }
  996. }
  997. /*
  998. * revalidate_allvol is for online array config utilities. After a
  999. * utility reconfigures the drives in the array, it can use this function
  1000. * (through an ioctl) to make the driver zap any previous disk structs for
  1001. * that controller and get new ones.
  1002. *
  1003. * Right now I'm using the getgeometry() function to do this, but this
  1004. * function should probably be finer grained and allow you to revalidate one
  1005. * particualar logical volume (instead of all of them on a particular
  1006. * controller).
  1007. */
  1008. static int revalidate_allvol(ctlr_info_t *host)
  1009. {
  1010. int ctlr = host->ctlr, i;
  1011. unsigned long flags;
  1012. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  1013. if (host->usage_count > 1) {
  1014. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  1015. printk(KERN_WARNING "cciss: Device busy for volume"
  1016. " revalidation (usage=%d)\n", host->usage_count);
  1017. return -EBUSY;
  1018. }
  1019. host->usage_count++;
  1020. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  1021. for(i=0; i< NWD; i++) {
  1022. struct gendisk *disk = host->gendisk[i];
  1023. if (disk->flags & GENHD_FL_UP)
  1024. del_gendisk(disk);
  1025. }
  1026. /*
  1027. * Set the partition and block size structures for all volumes
  1028. * on this controller to zero. We will reread all of this data
  1029. */
  1030. memset(host->drv, 0, sizeof(drive_info_struct)
  1031. * CISS_MAX_LUN);
  1032. /*
  1033. * Tell the array controller not to give us any interrupts while
  1034. * we check the new geometry. Then turn interrupts back on when
  1035. * we're done.
  1036. */
  1037. host->access.set_intr_mask(host, CCISS_INTR_OFF);
  1038. cciss_getgeometry(ctlr);
  1039. host->access.set_intr_mask(host, CCISS_INTR_ON);
  1040. /* Loop through each real device */
  1041. for (i = 0; i < NWD; i++) {
  1042. struct gendisk *disk = host->gendisk[i];
  1043. drive_info_struct *drv = &(host->drv[i]);
  1044. /* we must register the controller even if no disks exist */
  1045. /* this is for the online array utilities */
  1046. if (!drv->heads && i)
  1047. continue;
  1048. blk_queue_hardsect_size(drv->queue, drv->block_size);
  1049. set_capacity(disk, drv->nr_blocks);
  1050. add_disk(disk);
  1051. }
  1052. host->usage_count--;
  1053. return 0;
  1054. }
  1055. /* This function will check the usage_count of the drive to be updated/added.
  1056. * If the usage_count is zero then the drive information will be updated and
  1057. * the disk will be re-registered with the kernel. If not then it will be
  1058. * left alone for the next reboot. The exception to this is disk 0 which
  1059. * will always be left registered with the kernel since it is also the
  1060. * controller node. Any changes to disk 0 will show up on the next
  1061. * reboot.
  1062. */
  1063. static void cciss_update_drive_info(int ctlr, int drv_index)
  1064. {
  1065. ctlr_info_t *h = hba[ctlr];
  1066. struct gendisk *disk;
  1067. ReadCapdata_struct *size_buff = NULL;
  1068. InquiryData_struct *inq_buff = NULL;
  1069. unsigned int block_size;
  1070. unsigned int total_size;
  1071. unsigned long flags = 0;
  1072. int ret = 0;
  1073. /* if the disk already exists then deregister it before proceeding*/
  1074. if (h->drv[drv_index].raid_level != -1){
  1075. spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
  1076. h->drv[drv_index].busy_configuring = 1;
  1077. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  1078. ret = deregister_disk(h->gendisk[drv_index],
  1079. &h->drv[drv_index], 0);
  1080. h->drv[drv_index].busy_configuring = 0;
  1081. }
  1082. /* If the disk is in use return */
  1083. if (ret)
  1084. return;
  1085. /* Get information about the disk and modify the driver sturcture */
  1086. size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
  1087. if (size_buff == NULL)
  1088. goto mem_msg;
  1089. inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
  1090. if (inq_buff == NULL)
  1091. goto mem_msg;
  1092. cciss_read_capacity(ctlr, drv_index, size_buff, 1,
  1093. &total_size, &block_size);
  1094. cciss_geometry_inquiry(ctlr, drv_index, 1, total_size, block_size,
  1095. inq_buff, &h->drv[drv_index]);
  1096. ++h->num_luns;
  1097. disk = h->gendisk[drv_index];
  1098. set_capacity(disk, h->drv[drv_index].nr_blocks);
  1099. /* if it's the controller it's already added */
  1100. if (drv_index){
  1101. disk->queue = blk_init_queue(do_cciss_request, &h->lock);
  1102. /* Set up queue information */
  1103. disk->queue->backing_dev_info.ra_pages = READ_AHEAD;
  1104. blk_queue_bounce_limit(disk->queue, hba[ctlr]->pdev->dma_mask);
  1105. /* This is a hardware imposed limit. */
  1106. blk_queue_max_hw_segments(disk->queue, MAXSGENTRIES);
  1107. /* This is a limit in the driver and could be eliminated. */
  1108. blk_queue_max_phys_segments(disk->queue, MAXSGENTRIES);
  1109. blk_queue_max_sectors(disk->queue, 512);
  1110. disk->queue->queuedata = hba[ctlr];
  1111. blk_queue_hardsect_size(disk->queue,
  1112. hba[ctlr]->drv[drv_index].block_size);
  1113. h->drv[drv_index].queue = disk->queue;
  1114. add_disk(disk);
  1115. }
  1116. freeret:
  1117. kfree(size_buff);
  1118. kfree(inq_buff);
  1119. return;
  1120. mem_msg:
  1121. printk(KERN_ERR "cciss: out of memory\n");
  1122. goto freeret;
  1123. }
  1124. /* This function will find the first index of the controllers drive array
  1125. * that has a -1 for the raid_level and will return that index. This is
  1126. * where new drives will be added. If the index to be returned is greater
  1127. * than the highest_lun index for the controller then highest_lun is set
  1128. * to this new index. If there are no available indexes then -1 is returned.
  1129. */
  1130. static int cciss_find_free_drive_index(int ctlr)
  1131. {
  1132. int i;
  1133. for (i=0; i < CISS_MAX_LUN; i++){
  1134. if (hba[ctlr]->drv[i].raid_level == -1){
  1135. if (i > hba[ctlr]->highest_lun)
  1136. hba[ctlr]->highest_lun = i;
  1137. return i;
  1138. }
  1139. }
  1140. return -1;
  1141. }
  1142. /* This function will add and remove logical drives from the Logical
  1143. * drive array of the controller and maintain persistancy of ordering
  1144. * so that mount points are preserved until the next reboot. This allows
  1145. * for the removal of logical drives in the middle of the drive array
  1146. * without a re-ordering of those drives.
  1147. * INPUT
  1148. * h = The controller to perform the operations on
  1149. * del_disk = The disk to remove if specified. If the value given
  1150. * is NULL then no disk is removed.
  1151. */
  1152. static int rebuild_lun_table(ctlr_info_t *h, struct gendisk *del_disk)
  1153. {
  1154. int ctlr = h->ctlr;
  1155. int num_luns;
  1156. ReportLunData_struct *ld_buff = NULL;
  1157. drive_info_struct *drv = NULL;
  1158. int return_code;
  1159. int listlength = 0;
  1160. int i;
  1161. int drv_found;
  1162. int drv_index = 0;
  1163. __u32 lunid = 0;
  1164. unsigned long flags;
  1165. /* Set busy_configuring flag for this operation */
  1166. spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
  1167. if (h->num_luns >= CISS_MAX_LUN){
  1168. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  1169. return -EINVAL;
  1170. }
  1171. if (h->busy_configuring){
  1172. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  1173. return -EBUSY;
  1174. }
  1175. h->busy_configuring = 1;
  1176. /* if del_disk is NULL then we are being called to add a new disk
  1177. * and update the logical drive table. If it is not NULL then
  1178. * we will check if the disk is in use or not.
  1179. */
  1180. if (del_disk != NULL){
  1181. drv = get_drv(del_disk);
  1182. drv->busy_configuring = 1;
  1183. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  1184. return_code = deregister_disk(del_disk, drv, 1);
  1185. drv->busy_configuring = 0;
  1186. h->busy_configuring = 0;
  1187. return return_code;
  1188. } else {
  1189. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  1190. if (!capable(CAP_SYS_RAWIO))
  1191. return -EPERM;
  1192. ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
  1193. if (ld_buff == NULL)
  1194. goto mem_msg;
  1195. return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
  1196. sizeof(ReportLunData_struct), 0, 0, 0,
  1197. TYPE_CMD);
  1198. if (return_code == IO_OK){
  1199. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
  1200. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
  1201. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
  1202. listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
  1203. } else{ /* reading number of logical volumes failed */
  1204. printk(KERN_WARNING "cciss: report logical volume"
  1205. " command failed\n");
  1206. listlength = 0;
  1207. goto freeret;
  1208. }
  1209. num_luns = listlength / 8; /* 8 bytes per entry */
  1210. if (num_luns > CISS_MAX_LUN){
  1211. num_luns = CISS_MAX_LUN;
  1212. printk(KERN_WARNING "cciss: more luns configured"
  1213. " on controller than can be handled by"
  1214. " this driver.\n");
  1215. }
  1216. /* Compare controller drive array to drivers drive array.
  1217. * Check for updates in the drive information and any new drives
  1218. * on the controller.
  1219. */
  1220. for (i=0; i < num_luns; i++){
  1221. int j;
  1222. drv_found = 0;
  1223. lunid = (0xff &
  1224. (unsigned int)(ld_buff->LUN[i][3])) << 24;
  1225. lunid |= (0xff &
  1226. (unsigned int)(ld_buff->LUN[i][2])) << 16;
  1227. lunid |= (0xff &
  1228. (unsigned int)(ld_buff->LUN[i][1])) << 8;
  1229. lunid |= 0xff &
  1230. (unsigned int)(ld_buff->LUN[i][0]);
  1231. /* Find if the LUN is already in the drive array
  1232. * of the controller. If so then update its info
  1233. * if not is use. If it does not exist then find
  1234. * the first free index and add it.
  1235. */
  1236. for (j=0; j <= h->highest_lun; j++){
  1237. if (h->drv[j].LunID == lunid){
  1238. drv_index = j;
  1239. drv_found = 1;
  1240. }
  1241. }
  1242. /* check if the drive was found already in the array */
  1243. if (!drv_found){
  1244. drv_index = cciss_find_free_drive_index(ctlr);
  1245. if (drv_index == -1)
  1246. goto freeret;
  1247. }
  1248. h->drv[drv_index].LunID = lunid;
  1249. cciss_update_drive_info(ctlr, drv_index);
  1250. } /* end for */
  1251. } /* end else */
  1252. freeret:
  1253. kfree(ld_buff);
  1254. h->busy_configuring = 0;
  1255. /* We return -1 here to tell the ACU that we have registered/updated
  1256. * all of the drives that we can and to keep it from calling us
  1257. * additional times.
  1258. */
  1259. return -1;
  1260. mem_msg:
  1261. printk(KERN_ERR "cciss: out of memory\n");
  1262. goto freeret;
  1263. }
  1264. /* This function will deregister the disk and it's queue from the
  1265. * kernel. It must be called with the controller lock held and the
  1266. * drv structures busy_configuring flag set. It's parameters are:
  1267. *
  1268. * disk = This is the disk to be deregistered
  1269. * drv = This is the drive_info_struct associated with the disk to be
  1270. * deregistered. It contains information about the disk used
  1271. * by the driver.
  1272. * clear_all = This flag determines whether or not the disk information
  1273. * is going to be completely cleared out and the highest_lun
  1274. * reset. Sometimes we want to clear out information about
  1275. * the disk in preperation for re-adding it. In this case
  1276. * the highest_lun should be left unchanged and the LunID
  1277. * should not be cleared.
  1278. */
  1279. static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
  1280. int clear_all)
  1281. {
  1282. ctlr_info_t *h = get_host(disk);
  1283. if (!capable(CAP_SYS_RAWIO))
  1284. return -EPERM;
  1285. /* make sure logical volume is NOT is use */
  1286. if(clear_all || (h->gendisk[0] == disk)) {
  1287. if (drv->usage_count > 1)
  1288. return -EBUSY;
  1289. }
  1290. else
  1291. if( drv->usage_count > 0 )
  1292. return -EBUSY;
  1293. /* invalidate the devices and deregister the disk. If it is disk
  1294. * zero do not deregister it but just zero out it's values. This
  1295. * allows us to delete disk zero but keep the controller registered.
  1296. */
  1297. if (h->gendisk[0] != disk){
  1298. if (disk->flags & GENHD_FL_UP){
  1299. blk_cleanup_queue(disk->queue);
  1300. del_gendisk(disk);
  1301. drv->queue = NULL;
  1302. }
  1303. }
  1304. --h->num_luns;
  1305. /* zero out the disk size info */
  1306. drv->nr_blocks = 0;
  1307. drv->block_size = 0;
  1308. drv->heads = 0;
  1309. drv->sectors = 0;
  1310. drv->cylinders = 0;
  1311. drv->raid_level = -1; /* This can be used as a flag variable to
  1312. * indicate that this element of the drive
  1313. * array is free.
  1314. */
  1315. if (clear_all){
  1316. /* check to see if it was the last disk */
  1317. if (drv == h->drv + h->highest_lun) {
  1318. /* if so, find the new hightest lun */
  1319. int i, newhighest =-1;
  1320. for(i=0; i<h->highest_lun; i++) {
  1321. /* if the disk has size > 0, it is available */
  1322. if (h->drv[i].heads)
  1323. newhighest = i;
  1324. }
  1325. h->highest_lun = newhighest;
  1326. }
  1327. drv->LunID = 0;
  1328. }
  1329. return(0);
  1330. }
  1331. static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
  1332. size_t size,
  1333. unsigned int use_unit_num, /* 0: address the controller,
  1334. 1: address logical volume log_unit,
  1335. 2: periph device address is scsi3addr */
  1336. unsigned int log_unit, __u8 page_code, unsigned char *scsi3addr,
  1337. int cmd_type)
  1338. {
  1339. ctlr_info_t *h= hba[ctlr];
  1340. u64bit buff_dma_handle;
  1341. int status = IO_OK;
  1342. c->cmd_type = CMD_IOCTL_PEND;
  1343. c->Header.ReplyQueue = 0;
  1344. if( buff != NULL) {
  1345. c->Header.SGList = 1;
  1346. c->Header.SGTotal= 1;
  1347. } else {
  1348. c->Header.SGList = 0;
  1349. c->Header.SGTotal= 0;
  1350. }
  1351. c->Header.Tag.lower = c->busaddr;
  1352. c->Request.Type.Type = cmd_type;
  1353. if (cmd_type == TYPE_CMD) {
  1354. switch(cmd) {
  1355. case CISS_INQUIRY:
  1356. /* If the logical unit number is 0 then, this is going
  1357. to controller so It's a physical command
  1358. mode = 0 target = 0. So we have nothing to write.
  1359. otherwise, if use_unit_num == 1,
  1360. mode = 1(volume set addressing) target = LUNID
  1361. otherwise, if use_unit_num == 2,
  1362. mode = 0(periph dev addr) target = scsi3addr */
  1363. if (use_unit_num == 1) {
  1364. c->Header.LUN.LogDev.VolId=
  1365. h->drv[log_unit].LunID;
  1366. c->Header.LUN.LogDev.Mode = 1;
  1367. } else if (use_unit_num == 2) {
  1368. memcpy(c->Header.LUN.LunAddrBytes,scsi3addr,8);
  1369. c->Header.LUN.LogDev.Mode = 0;
  1370. }
  1371. /* are we trying to read a vital product page */
  1372. if(page_code != 0) {
  1373. c->Request.CDB[1] = 0x01;
  1374. c->Request.CDB[2] = page_code;
  1375. }
  1376. c->Request.CDBLen = 6;
  1377. c->Request.Type.Attribute = ATTR_SIMPLE;
  1378. c->Request.Type.Direction = XFER_READ;
  1379. c->Request.Timeout = 0;
  1380. c->Request.CDB[0] = CISS_INQUIRY;
  1381. c->Request.CDB[4] = size & 0xFF;
  1382. break;
  1383. case CISS_REPORT_LOG:
  1384. case CISS_REPORT_PHYS:
  1385. /* Talking to controller so It's a physical command
  1386. mode = 00 target = 0. Nothing to write.
  1387. */
  1388. c->Request.CDBLen = 12;
  1389. c->Request.Type.Attribute = ATTR_SIMPLE;
  1390. c->Request.Type.Direction = XFER_READ;
  1391. c->Request.Timeout = 0;
  1392. c->Request.CDB[0] = cmd;
  1393. c->Request.CDB[6] = (size >> 24) & 0xFF; //MSB
  1394. c->Request.CDB[7] = (size >> 16) & 0xFF;
  1395. c->Request.CDB[8] = (size >> 8) & 0xFF;
  1396. c->Request.CDB[9] = size & 0xFF;
  1397. break;
  1398. case CCISS_READ_CAPACITY:
  1399. c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
  1400. c->Header.LUN.LogDev.Mode = 1;
  1401. c->Request.CDBLen = 10;
  1402. c->Request.Type.Attribute = ATTR_SIMPLE;
  1403. c->Request.Type.Direction = XFER_READ;
  1404. c->Request.Timeout = 0;
  1405. c->Request.CDB[0] = cmd;
  1406. break;
  1407. case CCISS_CACHE_FLUSH:
  1408. c->Request.CDBLen = 12;
  1409. c->Request.Type.Attribute = ATTR_SIMPLE;
  1410. c->Request.Type.Direction = XFER_WRITE;
  1411. c->Request.Timeout = 0;
  1412. c->Request.CDB[0] = BMIC_WRITE;
  1413. c->Request.CDB[6] = BMIC_CACHE_FLUSH;
  1414. break;
  1415. default:
  1416. printk(KERN_WARNING
  1417. "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
  1418. return(IO_ERROR);
  1419. }
  1420. } else if (cmd_type == TYPE_MSG) {
  1421. switch (cmd) {
  1422. case 0: /* ABORT message */
  1423. c->Request.CDBLen = 12;
  1424. c->Request.Type.Attribute = ATTR_SIMPLE;
  1425. c->Request.Type.Direction = XFER_WRITE;
  1426. c->Request.Timeout = 0;
  1427. c->Request.CDB[0] = cmd; /* abort */
  1428. c->Request.CDB[1] = 0; /* abort a command */
  1429. /* buff contains the tag of the command to abort */
  1430. memcpy(&c->Request.CDB[4], buff, 8);
  1431. break;
  1432. case 1: /* RESET message */
  1433. c->Request.CDBLen = 12;
  1434. c->Request.Type.Attribute = ATTR_SIMPLE;
  1435. c->Request.Type.Direction = XFER_WRITE;
  1436. c->Request.Timeout = 0;
  1437. memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
  1438. c->Request.CDB[0] = cmd; /* reset */
  1439. c->Request.CDB[1] = 0x04; /* reset a LUN */
  1440. case 3: /* No-Op message */
  1441. c->Request.CDBLen = 1;
  1442. c->Request.Type.Attribute = ATTR_SIMPLE;
  1443. c->Request.Type.Direction = XFER_WRITE;
  1444. c->Request.Timeout = 0;
  1445. c->Request.CDB[0] = cmd;
  1446. break;
  1447. default:
  1448. printk(KERN_WARNING
  1449. "cciss%d: unknown message type %d\n",
  1450. ctlr, cmd);
  1451. return IO_ERROR;
  1452. }
  1453. } else {
  1454. printk(KERN_WARNING
  1455. "cciss%d: unknown command type %d\n", ctlr, cmd_type);
  1456. return IO_ERROR;
  1457. }
  1458. /* Fill in the scatter gather information */
  1459. if (size > 0) {
  1460. buff_dma_handle.val = (__u64) pci_map_single(h->pdev,
  1461. buff, size, PCI_DMA_BIDIRECTIONAL);
  1462. c->SG[0].Addr.lower = buff_dma_handle.val32.lower;
  1463. c->SG[0].Addr.upper = buff_dma_handle.val32.upper;
  1464. c->SG[0].Len = size;
  1465. c->SG[0].Ext = 0; /* we are not chaining */
  1466. }
  1467. return status;
  1468. }
  1469. static int sendcmd_withirq(__u8 cmd,
  1470. int ctlr,
  1471. void *buff,
  1472. size_t size,
  1473. unsigned int use_unit_num,
  1474. unsigned int log_unit,
  1475. __u8 page_code,
  1476. int cmd_type)
  1477. {
  1478. ctlr_info_t *h = hba[ctlr];
  1479. CommandList_struct *c;
  1480. u64bit buff_dma_handle;
  1481. unsigned long flags;
  1482. int return_status;
  1483. DECLARE_COMPLETION(wait);
  1484. if ((c = cmd_alloc(h , 0)) == NULL)
  1485. return -ENOMEM;
  1486. return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
  1487. log_unit, page_code, NULL, cmd_type);
  1488. if (return_status != IO_OK) {
  1489. cmd_free(h, c, 0);
  1490. return return_status;
  1491. }
  1492. resend_cmd2:
  1493. c->waiting = &wait;
  1494. /* Put the request on the tail of the queue and send it */
  1495. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  1496. addQ(&h->reqQ, c);
  1497. h->Qdepth++;
  1498. start_io(h);
  1499. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  1500. wait_for_completion(&wait);
  1501. if(c->err_info->CommandStatus != 0)
  1502. { /* an error has occurred */
  1503. switch(c->err_info->CommandStatus)
  1504. {
  1505. case CMD_TARGET_STATUS:
  1506. printk(KERN_WARNING "cciss: cmd %p has "
  1507. " completed with errors\n", c);
  1508. if( c->err_info->ScsiStatus)
  1509. {
  1510. printk(KERN_WARNING "cciss: cmd %p "
  1511. "has SCSI Status = %x\n",
  1512. c,
  1513. c->err_info->ScsiStatus);
  1514. }
  1515. break;
  1516. case CMD_DATA_UNDERRUN:
  1517. case CMD_DATA_OVERRUN:
  1518. /* expected for inquire and report lun commands */
  1519. break;
  1520. case CMD_INVALID:
  1521. printk(KERN_WARNING "cciss: Cmd %p is "
  1522. "reported invalid\n", c);
  1523. return_status = IO_ERROR;
  1524. break;
  1525. case CMD_PROTOCOL_ERR:
  1526. printk(KERN_WARNING "cciss: cmd %p has "
  1527. "protocol error \n", c);
  1528. return_status = IO_ERROR;
  1529. break;
  1530. case CMD_HARDWARE_ERR:
  1531. printk(KERN_WARNING "cciss: cmd %p had "
  1532. " hardware error\n", c);
  1533. return_status = IO_ERROR;
  1534. break;
  1535. case CMD_CONNECTION_LOST:
  1536. printk(KERN_WARNING "cciss: cmd %p had "
  1537. "connection lost\n", c);
  1538. return_status = IO_ERROR;
  1539. break;
  1540. case CMD_ABORTED:
  1541. printk(KERN_WARNING "cciss: cmd %p was "
  1542. "aborted\n", c);
  1543. return_status = IO_ERROR;
  1544. break;
  1545. case CMD_ABORT_FAILED:
  1546. printk(KERN_WARNING "cciss: cmd %p reports "
  1547. "abort failed\n", c);
  1548. return_status = IO_ERROR;
  1549. break;
  1550. case CMD_UNSOLICITED_ABORT:
  1551. printk(KERN_WARNING
  1552. "cciss%d: unsolicited abort %p\n",
  1553. ctlr, c);
  1554. if (c->retry_count < MAX_CMD_RETRIES) {
  1555. printk(KERN_WARNING
  1556. "cciss%d: retrying %p\n",
  1557. ctlr, c);
  1558. c->retry_count++;
  1559. /* erase the old error information */
  1560. memset(c->err_info, 0,
  1561. sizeof(ErrorInfo_struct));
  1562. return_status = IO_OK;
  1563. INIT_COMPLETION(wait);
  1564. goto resend_cmd2;
  1565. }
  1566. return_status = IO_ERROR;
  1567. break;
  1568. default:
  1569. printk(KERN_WARNING "cciss: cmd %p returned "
  1570. "unknown status %x\n", c,
  1571. c->err_info->CommandStatus);
  1572. return_status = IO_ERROR;
  1573. }
  1574. }
  1575. /* unlock the buffers from DMA */
  1576. buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
  1577. buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
  1578. pci_unmap_single( h->pdev, (dma_addr_t) buff_dma_handle.val,
  1579. c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
  1580. cmd_free(h, c, 0);
  1581. return(return_status);
  1582. }
  1583. static void cciss_geometry_inquiry(int ctlr, int logvol,
  1584. int withirq, unsigned int total_size,
  1585. unsigned int block_size, InquiryData_struct *inq_buff,
  1586. drive_info_struct *drv)
  1587. {
  1588. int return_code;
  1589. memset(inq_buff, 0, sizeof(InquiryData_struct));
  1590. if (withirq)
  1591. return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
  1592. inq_buff, sizeof(*inq_buff), 1, logvol ,0xC1, TYPE_CMD);
  1593. else
  1594. return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
  1595. sizeof(*inq_buff), 1, logvol ,0xC1, NULL, TYPE_CMD);
  1596. if (return_code == IO_OK) {
  1597. if(inq_buff->data_byte[8] == 0xFF) {
  1598. printk(KERN_WARNING
  1599. "cciss: reading geometry failed, volume "
  1600. "does not support reading geometry\n");
  1601. drv->block_size = block_size;
  1602. drv->nr_blocks = total_size;
  1603. drv->heads = 255;
  1604. drv->sectors = 32; // Sectors per track
  1605. drv->cylinders = total_size / 255 / 32;
  1606. } else {
  1607. unsigned int t;
  1608. drv->block_size = block_size;
  1609. drv->nr_blocks = total_size;
  1610. drv->heads = inq_buff->data_byte[6];
  1611. drv->sectors = inq_buff->data_byte[7];
  1612. drv->cylinders = (inq_buff->data_byte[4] & 0xff) << 8;
  1613. drv->cylinders += inq_buff->data_byte[5];
  1614. drv->raid_level = inq_buff->data_byte[8];
  1615. t = drv->heads * drv->sectors;
  1616. if (t > 1) {
  1617. drv->cylinders = total_size/t;
  1618. }
  1619. }
  1620. } else { /* Get geometry failed */
  1621. printk(KERN_WARNING "cciss: reading geometry failed\n");
  1622. }
  1623. printk(KERN_INFO " heads= %d, sectors= %d, cylinders= %d\n\n",
  1624. drv->heads, drv->sectors, drv->cylinders);
  1625. }
  1626. static void
  1627. cciss_read_capacity(int ctlr, int logvol, ReadCapdata_struct *buf,
  1628. int withirq, unsigned int *total_size, unsigned int *block_size)
  1629. {
  1630. int return_code;
  1631. memset(buf, 0, sizeof(*buf));
  1632. if (withirq)
  1633. return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
  1634. ctlr, buf, sizeof(*buf), 1, logvol, 0, TYPE_CMD);
  1635. else
  1636. return_code = sendcmd(CCISS_READ_CAPACITY,
  1637. ctlr, buf, sizeof(*buf), 1, logvol, 0, NULL, TYPE_CMD);
  1638. if (return_code == IO_OK) {
  1639. *total_size = be32_to_cpu(*((__be32 *) &buf->total_size[0]))+1;
  1640. *block_size = be32_to_cpu(*((__be32 *) &buf->block_size[0]));
  1641. } else { /* read capacity command failed */
  1642. printk(KERN_WARNING "cciss: read capacity failed\n");
  1643. *total_size = 0;
  1644. *block_size = BLOCK_SIZE;
  1645. }
  1646. printk(KERN_INFO " blocks= %u block_size= %d\n",
  1647. *total_size, *block_size);
  1648. return;
  1649. }
  1650. static int cciss_revalidate(struct gendisk *disk)
  1651. {
  1652. ctlr_info_t *h = get_host(disk);
  1653. drive_info_struct *drv = get_drv(disk);
  1654. int logvol;
  1655. int FOUND=0;
  1656. unsigned int block_size;
  1657. unsigned int total_size;
  1658. ReadCapdata_struct *size_buff = NULL;
  1659. InquiryData_struct *inq_buff = NULL;
  1660. for(logvol=0; logvol < CISS_MAX_LUN; logvol++)
  1661. {
  1662. if(h->drv[logvol].LunID == drv->LunID) {
  1663. FOUND=1;
  1664. break;
  1665. }
  1666. }
  1667. if (!FOUND) return 1;
  1668. size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
  1669. if (size_buff == NULL)
  1670. {
  1671. printk(KERN_WARNING "cciss: out of memory\n");
  1672. return 1;
  1673. }
  1674. inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
  1675. if (inq_buff == NULL)
  1676. {
  1677. printk(KERN_WARNING "cciss: out of memory\n");
  1678. kfree(size_buff);
  1679. return 1;
  1680. }
  1681. cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size, &block_size);
  1682. cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, inq_buff, drv);
  1683. blk_queue_hardsect_size(drv->queue, drv->block_size);
  1684. set_capacity(disk, drv->nr_blocks);
  1685. kfree(size_buff);
  1686. kfree(inq_buff);
  1687. return 0;
  1688. }
  1689. /*
  1690. * Wait polling for a command to complete.
  1691. * The memory mapped FIFO is polled for the completion.
  1692. * Used only at init time, interrupts from the HBA are disabled.
  1693. */
  1694. static unsigned long pollcomplete(int ctlr)
  1695. {
  1696. unsigned long done;
  1697. int i;
  1698. /* Wait (up to 20 seconds) for a command to complete */
  1699. for (i = 20 * HZ; i > 0; i--) {
  1700. done = hba[ctlr]->access.command_completed(hba[ctlr]);
  1701. if (done == FIFO_EMPTY)
  1702. schedule_timeout_uninterruptible(1);
  1703. else
  1704. return (done);
  1705. }
  1706. /* Invalid address to tell caller we ran out of time */
  1707. return 1;
  1708. }
  1709. static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete)
  1710. {
  1711. /* We get in here if sendcmd() is polling for completions
  1712. and gets some command back that it wasn't expecting --
  1713. something other than that which it just sent down.
  1714. Ordinarily, that shouldn't happen, but it can happen when
  1715. the scsi tape stuff gets into error handling mode, and
  1716. starts using sendcmd() to try to abort commands and
  1717. reset tape drives. In that case, sendcmd may pick up
  1718. completions of commands that were sent to logical drives
  1719. through the block i/o system, or cciss ioctls completing, etc.
  1720. In that case, we need to save those completions for later
  1721. processing by the interrupt handler.
  1722. */
  1723. #ifdef CONFIG_CISS_SCSI_TAPE
  1724. struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects;
  1725. /* If it's not the scsi tape stuff doing error handling, (abort */
  1726. /* or reset) then we don't expect anything weird. */
  1727. if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
  1728. #endif
  1729. printk( KERN_WARNING "cciss cciss%d: SendCmd "
  1730. "Invalid command list address returned! (%lx)\n",
  1731. ctlr, complete);
  1732. /* not much we can do. */
  1733. #ifdef CONFIG_CISS_SCSI_TAPE
  1734. return 1;
  1735. }
  1736. /* We've sent down an abort or reset, but something else
  1737. has completed */
  1738. if (srl->ncompletions >= (NR_CMDS + 2)) {
  1739. /* Uh oh. No room to save it for later... */
  1740. printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
  1741. "reject list overflow, command lost!\n", ctlr);
  1742. return 1;
  1743. }
  1744. /* Save it for later */
  1745. srl->complete[srl->ncompletions] = complete;
  1746. srl->ncompletions++;
  1747. #endif
  1748. return 0;
  1749. }
  1750. /*
  1751. * Send a command to the controller, and wait for it to complete.
  1752. * Only used at init time.
  1753. */
  1754. static int sendcmd(
  1755. __u8 cmd,
  1756. int ctlr,
  1757. void *buff,
  1758. size_t size,
  1759. unsigned int use_unit_num, /* 0: address the controller,
  1760. 1: address logical volume log_unit,
  1761. 2: periph device address is scsi3addr */
  1762. unsigned int log_unit,
  1763. __u8 page_code,
  1764. unsigned char *scsi3addr,
  1765. int cmd_type)
  1766. {
  1767. CommandList_struct *c;
  1768. int i;
  1769. unsigned long complete;
  1770. ctlr_info_t *info_p= hba[ctlr];
  1771. u64bit buff_dma_handle;
  1772. int status, done = 0;
  1773. if ((c = cmd_alloc(info_p, 1)) == NULL) {
  1774. printk(KERN_WARNING "cciss: unable to get memory");
  1775. return(IO_ERROR);
  1776. }
  1777. status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
  1778. log_unit, page_code, scsi3addr, cmd_type);
  1779. if (status != IO_OK) {
  1780. cmd_free(info_p, c, 1);
  1781. return status;
  1782. }
  1783. resend_cmd1:
  1784. /*
  1785. * Disable interrupt
  1786. */
  1787. #ifdef CCISS_DEBUG
  1788. printk(KERN_DEBUG "cciss: turning intr off\n");
  1789. #endif /* CCISS_DEBUG */
  1790. info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
  1791. /* Make sure there is room in the command FIFO */
  1792. /* Actually it should be completely empty at this time */
  1793. /* unless we are in here doing error handling for the scsi */
  1794. /* tape side of the driver. */
  1795. for (i = 200000; i > 0; i--)
  1796. {
  1797. /* if fifo isn't full go */
  1798. if (!(info_p->access.fifo_full(info_p)))
  1799. {
  1800. break;
  1801. }
  1802. udelay(10);
  1803. printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
  1804. " waiting!\n", ctlr);
  1805. }
  1806. /*
  1807. * Send the cmd
  1808. */
  1809. info_p->access.submit_command(info_p, c);
  1810. done = 0;
  1811. do {
  1812. complete = pollcomplete(ctlr);
  1813. #ifdef CCISS_DEBUG
  1814. printk(KERN_DEBUG "cciss: command completed\n");
  1815. #endif /* CCISS_DEBUG */
  1816. if (complete == 1) {
  1817. printk( KERN_WARNING
  1818. "cciss cciss%d: SendCmd Timeout out, "
  1819. "No command list address returned!\n",
  1820. ctlr);
  1821. status = IO_ERROR;
  1822. done = 1;
  1823. break;
  1824. }
  1825. /* This will need to change for direct lookup completions */
  1826. if ( (complete & CISS_ERROR_BIT)
  1827. && (complete & ~CISS_ERROR_BIT) == c->busaddr)
  1828. {
  1829. /* if data overrun or underun on Report command
  1830. ignore it
  1831. */
  1832. if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
  1833. (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
  1834. (c->Request.CDB[0] == CISS_INQUIRY)) &&
  1835. ((c->err_info->CommandStatus ==
  1836. CMD_DATA_OVERRUN) ||
  1837. (c->err_info->CommandStatus ==
  1838. CMD_DATA_UNDERRUN)
  1839. ))
  1840. {
  1841. complete = c->busaddr;
  1842. } else {
  1843. if (c->err_info->CommandStatus ==
  1844. CMD_UNSOLICITED_ABORT) {
  1845. printk(KERN_WARNING "cciss%d: "
  1846. "unsolicited abort %p\n",
  1847. ctlr, c);
  1848. if (c->retry_count < MAX_CMD_RETRIES) {
  1849. printk(KERN_WARNING
  1850. "cciss%d: retrying %p\n",
  1851. ctlr, c);
  1852. c->retry_count++;
  1853. /* erase the old error */
  1854. /* information */
  1855. memset(c->err_info, 0,
  1856. sizeof(ErrorInfo_struct));
  1857. goto resend_cmd1;
  1858. } else {
  1859. printk(KERN_WARNING
  1860. "cciss%d: retried %p too "
  1861. "many times\n", ctlr, c);
  1862. status = IO_ERROR;
  1863. goto cleanup1;
  1864. }
  1865. } else if (c->err_info->CommandStatus == CMD_UNABORTABLE) {
  1866. printk(KERN_WARNING "cciss%d: command could not be aborted.\n", ctlr);
  1867. status = IO_ERROR;
  1868. goto cleanup1;
  1869. }
  1870. printk(KERN_WARNING "ciss ciss%d: sendcmd"
  1871. " Error %x \n", ctlr,
  1872. c->err_info->CommandStatus);
  1873. printk(KERN_WARNING "ciss ciss%d: sendcmd"
  1874. " offensive info\n"
  1875. " size %x\n num %x value %x\n", ctlr,
  1876. c->err_info->MoreErrInfo.Invalid_Cmd.offense_size,
  1877. c->err_info->MoreErrInfo.Invalid_Cmd.offense_num,
  1878. c->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
  1879. status = IO_ERROR;
  1880. goto cleanup1;
  1881. }
  1882. }
  1883. /* This will need changing for direct lookup completions */
  1884. if (complete != c->busaddr) {
  1885. if (add_sendcmd_reject(cmd, ctlr, complete) != 0) {
  1886. BUG(); /* we are pretty much hosed if we get here. */
  1887. }
  1888. continue;
  1889. } else
  1890. done = 1;
  1891. } while (!done);
  1892. cleanup1:
  1893. /* unlock the data buffer from DMA */
  1894. buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
  1895. buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
  1896. pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val,
  1897. c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
  1898. #ifdef CONFIG_CISS_SCSI_TAPE
  1899. /* if we saved some commands for later, process them now. */
  1900. if (info_p->scsi_rejects.ncompletions > 0)
  1901. do_cciss_intr(0, info_p, NULL);
  1902. #endif
  1903. cmd_free(info_p, c, 1);
  1904. return (status);
  1905. }
  1906. /*
  1907. * Map (physical) PCI mem into (virtual) kernel space
  1908. */
  1909. static void __iomem *remap_pci_mem(ulong base, ulong size)
  1910. {
  1911. ulong page_base = ((ulong) base) & PAGE_MASK;
  1912. ulong page_offs = ((ulong) base) - page_base;
  1913. void __iomem *page_remapped = ioremap(page_base, page_offs+size);
  1914. return page_remapped ? (page_remapped + page_offs) : NULL;
  1915. }
  1916. /*
  1917. * Takes jobs of the Q and sends them to the hardware, then puts it on
  1918. * the Q to wait for completion.
  1919. */
  1920. static void start_io( ctlr_info_t *h)
  1921. {
  1922. CommandList_struct *c;
  1923. while(( c = h->reqQ) != NULL )
  1924. {
  1925. /* can't do anything if fifo is full */
  1926. if ((h->access.fifo_full(h))) {
  1927. printk(KERN_WARNING "cciss: fifo full\n");
  1928. break;
  1929. }
  1930. /* Get the frist entry from the Request Q */
  1931. removeQ(&(h->reqQ), c);
  1932. h->Qdepth--;
  1933. /* Tell the controller execute command */
  1934. h->access.submit_command(h, c);
  1935. /* Put job onto the completed Q */
  1936. addQ (&(h->cmpQ), c);
  1937. }
  1938. }
  1939. static inline void complete_buffers(struct bio *bio, int status)
  1940. {
  1941. while (bio) {
  1942. struct bio *xbh = bio->bi_next;
  1943. int nr_sectors = bio_sectors(bio);
  1944. bio->bi_next = NULL;
  1945. blk_finished_io(len);
  1946. bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
  1947. bio = xbh;
  1948. }
  1949. }
  1950. /* Assumes that CCISS_LOCK(h->ctlr) is held. */
  1951. /* Zeros out the error record and then resends the command back */
  1952. /* to the controller */
  1953. static inline void resend_cciss_cmd( ctlr_info_t *h, CommandList_struct *c)
  1954. {
  1955. /* erase the old error information */
  1956. memset(c->err_info, 0, sizeof(ErrorInfo_struct));
  1957. /* add it to software queue and then send it to the controller */
  1958. addQ(&(h->reqQ),c);
  1959. h->Qdepth++;
  1960. if(h->Qdepth > h->maxQsinceinit)
  1961. h->maxQsinceinit = h->Qdepth;
  1962. start_io(h);
  1963. }
  1964. /* checks the status of the job and calls complete buffers to mark all
  1965. * buffers for the completed job.
  1966. */
  1967. static inline void complete_command( ctlr_info_t *h, CommandList_struct *cmd,
  1968. int timeout)
  1969. {
  1970. int status = 1;
  1971. int i;
  1972. int retry_cmd = 0;
  1973. u64bit temp64;
  1974. if (timeout)
  1975. status = 0;
  1976. if(cmd->err_info->CommandStatus != 0)
  1977. { /* an error has occurred */
  1978. switch(cmd->err_info->CommandStatus)
  1979. {
  1980. unsigned char sense_key;
  1981. case CMD_TARGET_STATUS:
  1982. status = 0;
  1983. if( cmd->err_info->ScsiStatus == 0x02)
  1984. {
  1985. printk(KERN_WARNING "cciss: cmd %p "
  1986. "has CHECK CONDITION "
  1987. " byte 2 = 0x%x\n", cmd,
  1988. cmd->err_info->SenseInfo[2]
  1989. );
  1990. /* check the sense key */
  1991. sense_key = 0xf &
  1992. cmd->err_info->SenseInfo[2];
  1993. /* no status or recovered error */
  1994. if((sense_key == 0x0) ||
  1995. (sense_key == 0x1))
  1996. {
  1997. status = 1;
  1998. }
  1999. } else
  2000. {
  2001. printk(KERN_WARNING "cciss: cmd %p "
  2002. "has SCSI Status 0x%x\n",
  2003. cmd, cmd->err_info->ScsiStatus);
  2004. }
  2005. break;
  2006. case CMD_DATA_UNDERRUN:
  2007. printk(KERN_WARNING "cciss: cmd %p has"
  2008. " completed with data underrun "
  2009. "reported\n", cmd);
  2010. break;
  2011. case CMD_DATA_OVERRUN:
  2012. printk(KERN_WARNING "cciss: cmd %p has"
  2013. " completed with data overrun "
  2014. "reported\n", cmd);
  2015. break;
  2016. case CMD_INVALID:
  2017. printk(KERN_WARNING "cciss: cmd %p is "
  2018. "reported invalid\n", cmd);
  2019. status = 0;
  2020. break;
  2021. case CMD_PROTOCOL_ERR:
  2022. printk(KERN_WARNING "cciss: cmd %p has "
  2023. "protocol error \n", cmd);
  2024. status = 0;
  2025. break;
  2026. case CMD_HARDWARE_ERR:
  2027. printk(KERN_WARNING "cciss: cmd %p had "
  2028. " hardware error\n", cmd);
  2029. status = 0;
  2030. break;
  2031. case CMD_CONNECTION_LOST:
  2032. printk(KERN_WARNING "cciss: cmd %p had "
  2033. "connection lost\n", cmd);
  2034. status=0;
  2035. break;
  2036. case CMD_ABORTED:
  2037. printk(KERN_WARNING "cciss: cmd %p was "
  2038. "aborted\n", cmd);
  2039. status=0;
  2040. break;
  2041. case CMD_ABORT_FAILED:
  2042. printk(KERN_WARNING "cciss: cmd %p reports "
  2043. "abort failed\n", cmd);
  2044. status=0;
  2045. break;
  2046. case CMD_UNSOLICITED_ABORT:
  2047. printk(KERN_WARNING "cciss%d: unsolicited "
  2048. "abort %p\n", h->ctlr, cmd);
  2049. if (cmd->retry_count < MAX_CMD_RETRIES) {
  2050. retry_cmd=1;
  2051. printk(KERN_WARNING
  2052. "cciss%d: retrying %p\n",
  2053. h->ctlr, cmd);
  2054. cmd->retry_count++;
  2055. } else
  2056. printk(KERN_WARNING
  2057. "cciss%d: %p retried too "
  2058. "many times\n", h->ctlr, cmd);
  2059. status=0;
  2060. break;
  2061. case CMD_TIMEOUT:
  2062. printk(KERN_WARNING "cciss: cmd %p timedout\n",
  2063. cmd);
  2064. status=0;
  2065. break;
  2066. default:
  2067. printk(KERN_WARNING "cciss: cmd %p returned "
  2068. "unknown status %x\n", cmd,
  2069. cmd->err_info->CommandStatus);
  2070. status=0;
  2071. }
  2072. }
  2073. /* We need to return this command */
  2074. if(retry_cmd) {
  2075. resend_cciss_cmd(h,cmd);
  2076. return;
  2077. }
  2078. /* command did not need to be retried */
  2079. /* unmap the DMA mapping for all the scatter gather elements */
  2080. for(i=0; i<cmd->Header.SGList; i++) {
  2081. temp64.val32.lower = cmd->SG[i].Addr.lower;
  2082. temp64.val32.upper = cmd->SG[i].Addr.upper;
  2083. pci_unmap_page(hba[cmd->ctlr]->pdev,
  2084. temp64.val, cmd->SG[i].Len,
  2085. (cmd->Request.Type.Direction == XFER_READ) ?
  2086. PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
  2087. }
  2088. complete_buffers(cmd->rq->bio, status);
  2089. #ifdef CCISS_DEBUG
  2090. printk("Done with %p\n", cmd->rq);
  2091. #endif /* CCISS_DEBUG */
  2092. end_that_request_last(cmd->rq);
  2093. cmd_free(h,cmd,1);
  2094. }
  2095. /*
  2096. * Get a request and submit it to the controller.
  2097. */
  2098. static void do_cciss_request(request_queue_t *q)
  2099. {
  2100. ctlr_info_t *h= q->queuedata;
  2101. CommandList_struct *c;
  2102. int start_blk, seg;
  2103. struct request *creq;
  2104. u64bit temp64;
  2105. struct scatterlist tmp_sg[MAXSGENTRIES];
  2106. drive_info_struct *drv;
  2107. int i, dir;
  2108. /* We call start_io here in case there is a command waiting on the
  2109. * queue that has not been sent.
  2110. */
  2111. if (blk_queue_plugged(q))
  2112. goto startio;
  2113. queue:
  2114. creq = elv_next_request(q);
  2115. if (!creq)
  2116. goto startio;
  2117. if (creq->nr_phys_segments > MAXSGENTRIES)
  2118. BUG();
  2119. if (( c = cmd_alloc(h, 1)) == NULL)
  2120. goto full;
  2121. blkdev_dequeue_request(creq);
  2122. spin_unlock_irq(q->queue_lock);
  2123. c->cmd_type = CMD_RWREQ;
  2124. c->rq = creq;
  2125. /* fill in the request */
  2126. drv = creq->rq_disk->private_data;
  2127. c->Header.ReplyQueue = 0; // unused in simple mode
  2128. /* got command from pool, so use the command block index instead */
  2129. /* for direct lookups. */
  2130. /* The first 2 bits are reserved for controller error reporting. */
  2131. c->Header.Tag.lower = (c->cmdindex << 3);
  2132. c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */
  2133. c->Header.LUN.LogDev.VolId= drv->LunID;
  2134. c->Header.LUN.LogDev.Mode = 1;
  2135. c->Request.CDBLen = 10; // 12 byte commands not in FW yet;
  2136. c->Request.Type.Type = TYPE_CMD; // It is a command.
  2137. c->Request.Type.Attribute = ATTR_SIMPLE;
  2138. c->Request.Type.Direction =
  2139. (rq_data_dir(creq) == READ) ? XFER_READ: XFER_WRITE;
  2140. c->Request.Timeout = 0; // Don't time out
  2141. c->Request.CDB[0] = (rq_data_dir(creq) == READ) ? CCISS_READ : CCISS_WRITE;
  2142. start_blk = creq->sector;
  2143. #ifdef CCISS_DEBUG
  2144. printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",(int) creq->sector,
  2145. (int) creq->nr_sectors);
  2146. #endif /* CCISS_DEBUG */
  2147. seg = blk_rq_map_sg(q, creq, tmp_sg);
  2148. /* get the DMA records for the setup */
  2149. if (c->Request.Type.Direction == XFER_READ)
  2150. dir = PCI_DMA_FROMDEVICE;
  2151. else
  2152. dir = PCI_DMA_TODEVICE;
  2153. for (i=0; i<seg; i++)
  2154. {
  2155. c->SG[i].Len = tmp_sg[i].length;
  2156. temp64.val = (__u64) pci_map_page(h->pdev, tmp_sg[i].page,
  2157. tmp_sg[i].offset, tmp_sg[i].length,
  2158. dir);
  2159. c->SG[i].Addr.lower = temp64.val32.lower;
  2160. c->SG[i].Addr.upper = temp64.val32.upper;
  2161. c->SG[i].Ext = 0; // we are not chaining
  2162. }
  2163. /* track how many SG entries we are using */
  2164. if( seg > h->maxSG)
  2165. h->maxSG = seg;
  2166. #ifdef CCISS_DEBUG
  2167. printk(KERN_DEBUG "cciss: Submitting %d sectors in %d segments\n", creq->nr_sectors, seg);
  2168. #endif /* CCISS_DEBUG */
  2169. c->Header.SGList = c->Header.SGTotal = seg;
  2170. c->Request.CDB[1]= 0;
  2171. c->Request.CDB[2]= (start_blk >> 24) & 0xff; //MSB
  2172. c->Request.CDB[3]= (start_blk >> 16) & 0xff;
  2173. c->Request.CDB[4]= (start_blk >> 8) & 0xff;
  2174. c->Request.CDB[5]= start_blk & 0xff;
  2175. c->Request.CDB[6]= 0; // (sect >> 24) & 0xff; MSB
  2176. c->Request.CDB[7]= (creq->nr_sectors >> 8) & 0xff;
  2177. c->Request.CDB[8]= creq->nr_sectors & 0xff;
  2178. c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
  2179. spin_lock_irq(q->queue_lock);
  2180. addQ(&(h->reqQ),c);
  2181. h->Qdepth++;
  2182. if(h->Qdepth > h->maxQsinceinit)
  2183. h->maxQsinceinit = h->Qdepth;
  2184. goto queue;
  2185. full:
  2186. blk_stop_queue(q);
  2187. startio:
  2188. /* We will already have the driver lock here so not need
  2189. * to lock it.
  2190. */
  2191. start_io(h);
  2192. }
  2193. static inline unsigned long get_next_completion(ctlr_info_t *h)
  2194. {
  2195. #ifdef CONFIG_CISS_SCSI_TAPE
  2196. /* Any rejects from sendcmd() lying around? Process them first */
  2197. if (h->scsi_rejects.ncompletions == 0)
  2198. return h->access.command_completed(h);
  2199. else {
  2200. struct sendcmd_reject_list *srl;
  2201. int n;
  2202. srl = &h->scsi_rejects;
  2203. n = --srl->ncompletions;
  2204. /* printk("cciss%d: processing saved reject\n", h->ctlr); */
  2205. printk("p");
  2206. return srl->complete[n];
  2207. }
  2208. #else
  2209. return h->access.command_completed(h);
  2210. #endif
  2211. }
  2212. static inline int interrupt_pending(ctlr_info_t *h)
  2213. {
  2214. #ifdef CONFIG_CISS_SCSI_TAPE
  2215. return ( h->access.intr_pending(h)
  2216. || (h->scsi_rejects.ncompletions > 0));
  2217. #else
  2218. return h->access.intr_pending(h);
  2219. #endif
  2220. }
  2221. static inline long interrupt_not_for_us(ctlr_info_t *h)
  2222. {
  2223. #ifdef CONFIG_CISS_SCSI_TAPE
  2224. return (((h->access.intr_pending(h) == 0) ||
  2225. (h->interrupts_enabled == 0))
  2226. && (h->scsi_rejects.ncompletions == 0));
  2227. #else
  2228. return (((h->access.intr_pending(h) == 0) ||
  2229. (h->interrupts_enabled == 0)));
  2230. #endif
  2231. }
  2232. static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
  2233. {
  2234. ctlr_info_t *h = dev_id;
  2235. CommandList_struct *c;
  2236. unsigned long flags;
  2237. __u32 a, a1, a2;
  2238. int j;
  2239. int start_queue = h->next_to_run;
  2240. if (interrupt_not_for_us(h))
  2241. return IRQ_NONE;
  2242. /*
  2243. * If there are completed commands in the completion queue,
  2244. * we had better do something about it.
  2245. */
  2246. spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
  2247. while (interrupt_pending(h)) {
  2248. while((a = get_next_completion(h)) != FIFO_EMPTY) {
  2249. a1 = a;
  2250. if ((a & 0x04)) {
  2251. a2 = (a >> 3);
  2252. if (a2 >= NR_CMDS) {
  2253. printk(KERN_WARNING "cciss: controller cciss%d failed, stopping.\n", h->ctlr);
  2254. fail_all_cmds(h->ctlr);
  2255. return IRQ_HANDLED;
  2256. }
  2257. c = h->cmd_pool + a2;
  2258. a = c->busaddr;
  2259. } else {
  2260. a &= ~3;
  2261. if ((c = h->cmpQ) == NULL) {
  2262. printk(KERN_WARNING "cciss: Completion of %08x ignored\n", a1);
  2263. continue;
  2264. }
  2265. while(c->busaddr != a) {
  2266. c = c->next;
  2267. if (c == h->cmpQ)
  2268. break;
  2269. }
  2270. }
  2271. /*
  2272. * If we've found the command, take it off the
  2273. * completion Q and free it
  2274. */
  2275. if (c->busaddr == a) {
  2276. removeQ(&h->cmpQ, c);
  2277. if (c->cmd_type == CMD_RWREQ) {
  2278. complete_command(h, c, 0);
  2279. } else if (c->cmd_type == CMD_IOCTL_PEND) {
  2280. complete(c->waiting);
  2281. }
  2282. # ifdef CONFIG_CISS_SCSI_TAPE
  2283. else if (c->cmd_type == CMD_SCSI)
  2284. complete_scsi_command(c, 0, a1);
  2285. # endif
  2286. continue;
  2287. }
  2288. }
  2289. }
  2290. /* check to see if we have maxed out the number of commands that can
  2291. * be placed on the queue. If so then exit. We do this check here
  2292. * in case the interrupt we serviced was from an ioctl and did not
  2293. * free any new commands.
  2294. */
  2295. if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
  2296. goto cleanup;
  2297. /* We have room on the queue for more commands. Now we need to queue
  2298. * them up. We will also keep track of the next queue to run so
  2299. * that every queue gets a chance to be started first.
  2300. */
  2301. for (j=0; j < h->highest_lun + 1; j++){
  2302. int curr_queue = (start_queue + j) % (h->highest_lun + 1);
  2303. /* make sure the disk has been added and the drive is real
  2304. * because this can be called from the middle of init_one.
  2305. */
  2306. if(!(h->drv[curr_queue].queue) ||
  2307. !(h->drv[curr_queue].heads))
  2308. continue;
  2309. blk_start_queue(h->gendisk[curr_queue]->queue);
  2310. /* check to see if we have maxed out the number of commands
  2311. * that can be placed on the queue.
  2312. */
  2313. if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
  2314. {
  2315. if (curr_queue == start_queue){
  2316. h->next_to_run = (start_queue + 1) % (h->highest_lun + 1);
  2317. goto cleanup;
  2318. } else {
  2319. h->next_to_run = curr_queue;
  2320. goto cleanup;
  2321. }
  2322. } else {
  2323. curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
  2324. }
  2325. }
  2326. cleanup:
  2327. spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
  2328. return IRQ_HANDLED;
  2329. }
  2330. /*
  2331. * We cannot read the structure directly, for portablity we must use
  2332. * the io functions.
  2333. * This is for debug only.
  2334. */
  2335. #ifdef CCISS_DEBUG
  2336. static void print_cfg_table( CfgTable_struct *tb)
  2337. {
  2338. int i;
  2339. char temp_name[17];
  2340. printk("Controller Configuration information\n");
  2341. printk("------------------------------------\n");
  2342. for(i=0;i<4;i++)
  2343. temp_name[i] = readb(&(tb->Signature[i]));
  2344. temp_name[4]='\0';
  2345. printk(" Signature = %s\n", temp_name);
  2346. printk(" Spec Number = %d\n", readl(&(tb->SpecValence)));
  2347. printk(" Transport methods supported = 0x%x\n",
  2348. readl(&(tb-> TransportSupport)));
  2349. printk(" Transport methods active = 0x%x\n",
  2350. readl(&(tb->TransportActive)));
  2351. printk(" Requested transport Method = 0x%x\n",
  2352. readl(&(tb->HostWrite.TransportRequest)));
  2353. printk(" Coalese Interrupt Delay = 0x%x\n",
  2354. readl(&(tb->HostWrite.CoalIntDelay)));
  2355. printk(" Coalese Interrupt Count = 0x%x\n",
  2356. readl(&(tb->HostWrite.CoalIntCount)));
  2357. printk(" Max outstanding commands = 0x%d\n",
  2358. readl(&(tb->CmdsOutMax)));
  2359. printk(" Bus Types = 0x%x\n", readl(&(tb-> BusTypes)));
  2360. for(i=0;i<16;i++)
  2361. temp_name[i] = readb(&(tb->ServerName[i]));
  2362. temp_name[16] = '\0';
  2363. printk(" Server Name = %s\n", temp_name);
  2364. printk(" Heartbeat Counter = 0x%x\n\n\n",
  2365. readl(&(tb->HeartBeat)));
  2366. }
  2367. #endif /* CCISS_DEBUG */
  2368. static void release_io_mem(ctlr_info_t *c)
  2369. {
  2370. /* if IO mem was not protected do nothing */
  2371. if( c->io_mem_addr == 0)
  2372. return;
  2373. release_region(c->io_mem_addr, c->io_mem_length);
  2374. c->io_mem_addr = 0;
  2375. c->io_mem_length = 0;
  2376. }
  2377. static int find_PCI_BAR_index(struct pci_dev *pdev,
  2378. unsigned long pci_bar_addr)
  2379. {
  2380. int i, offset, mem_type, bar_type;
  2381. if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */
  2382. return 0;
  2383. offset = 0;
  2384. for (i=0; i<DEVICE_COUNT_RESOURCE; i++) {
  2385. bar_type = pci_resource_flags(pdev, i) &
  2386. PCI_BASE_ADDRESS_SPACE;
  2387. if (bar_type == PCI_BASE_ADDRESS_SPACE_IO)
  2388. offset += 4;
  2389. else {
  2390. mem_type = pci_resource_flags(pdev, i) &
  2391. PCI_BASE_ADDRESS_MEM_TYPE_MASK;
  2392. switch (mem_type) {
  2393. case PCI_BASE_ADDRESS_MEM_TYPE_32:
  2394. case PCI_BASE_ADDRESS_MEM_TYPE_1M:
  2395. offset += 4; /* 32 bit */
  2396. break;
  2397. case PCI_BASE_ADDRESS_MEM_TYPE_64:
  2398. offset += 8;
  2399. break;
  2400. default: /* reserved in PCI 2.2 */
  2401. printk(KERN_WARNING "Base address is invalid\n");
  2402. return -1;
  2403. break;
  2404. }
  2405. }
  2406. if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0)
  2407. return i+1;
  2408. }
  2409. return -1;
  2410. }
  2411. static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
  2412. {
  2413. ushort subsystem_vendor_id, subsystem_device_id, command;
  2414. __u32 board_id, scratchpad = 0;
  2415. __u64 cfg_offset;
  2416. __u32 cfg_base_addr;
  2417. __u64 cfg_base_addr_index;
  2418. int i;
  2419. /* check to see if controller has been disabled */
  2420. /* BEFORE trying to enable it */
  2421. (void) pci_read_config_word(pdev, PCI_COMMAND,&command);
  2422. if(!(command & 0x02))
  2423. {
  2424. printk(KERN_WARNING "cciss: controller appears to be disabled\n");
  2425. return(-1);
  2426. }
  2427. if (pci_enable_device(pdev))
  2428. {
  2429. printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
  2430. return( -1);
  2431. }
  2432. subsystem_vendor_id = pdev->subsystem_vendor;
  2433. subsystem_device_id = pdev->subsystem_device;
  2434. board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) |
  2435. subsystem_vendor_id);
  2436. /* search for our IO range so we can protect it */
  2437. for(i=0; i<DEVICE_COUNT_RESOURCE; i++)
  2438. {
  2439. /* is this an IO range */
  2440. if( pci_resource_flags(pdev, i) & 0x01 ) {
  2441. c->io_mem_addr = pci_resource_start(pdev, i);
  2442. c->io_mem_length = pci_resource_end(pdev, i) -
  2443. pci_resource_start(pdev, i) +1;
  2444. #ifdef CCISS_DEBUG
  2445. printk("IO value found base_addr[%d] %lx %lx\n", i,
  2446. c->io_mem_addr, c->io_mem_length);
  2447. #endif /* CCISS_DEBUG */
  2448. /* register the IO range */
  2449. if(!request_region( c->io_mem_addr,
  2450. c->io_mem_length, "cciss"))
  2451. {
  2452. printk(KERN_WARNING "cciss I/O memory range already in use addr=%lx length=%ld\n",
  2453. c->io_mem_addr, c->io_mem_length);
  2454. c->io_mem_addr= 0;
  2455. c->io_mem_length = 0;
  2456. }
  2457. break;
  2458. }
  2459. }
  2460. #ifdef CCISS_DEBUG
  2461. printk("command = %x\n", command);
  2462. printk("irq = %x\n", pdev->irq);
  2463. printk("board_id = %x\n", board_id);
  2464. #endif /* CCISS_DEBUG */
  2465. c->intr = pdev->irq;
  2466. /*
  2467. * Memory base addr is first addr , the second points to the config
  2468. * table
  2469. */
  2470. c->paddr = pci_resource_start(pdev, 0); /* addressing mode bits already removed */
  2471. #ifdef CCISS_DEBUG
  2472. printk("address 0 = %x\n", c->paddr);
  2473. #endif /* CCISS_DEBUG */
  2474. c->vaddr = remap_pci_mem(c->paddr, 200);
  2475. /* Wait for the board to become ready. (PCI hotplug needs this.)
  2476. * We poll for up to 120 secs, once per 100ms. */
  2477. for (i=0; i < 1200; i++) {
  2478. scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET);
  2479. if (scratchpad == CCISS_FIRMWARE_READY)
  2480. break;
  2481. set_current_state(TASK_INTERRUPTIBLE);
  2482. schedule_timeout(HZ / 10); /* wait 100ms */
  2483. }
  2484. if (scratchpad != CCISS_FIRMWARE_READY) {
  2485. printk(KERN_WARNING "cciss: Board not ready. Timed out.\n");
  2486. return -1;
  2487. }
  2488. /* get the address index number */
  2489. cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET);
  2490. cfg_base_addr &= (__u32) 0x0000ffff;
  2491. #ifdef CCISS_DEBUG
  2492. printk("cfg base address = %x\n", cfg_base_addr);
  2493. #endif /* CCISS_DEBUG */
  2494. cfg_base_addr_index =
  2495. find_PCI_BAR_index(pdev, cfg_base_addr);
  2496. #ifdef CCISS_DEBUG
  2497. printk("cfg base address index = %x\n", cfg_base_addr_index);
  2498. #endif /* CCISS_DEBUG */
  2499. if (cfg_base_addr_index == -1) {
  2500. printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
  2501. release_io_mem(c);
  2502. return -1;
  2503. }
  2504. cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
  2505. #ifdef CCISS_DEBUG
  2506. printk("cfg offset = %x\n", cfg_offset);
  2507. #endif /* CCISS_DEBUG */
  2508. c->cfgtable = remap_pci_mem(pci_resource_start(pdev,
  2509. cfg_base_addr_index) + cfg_offset,
  2510. sizeof(CfgTable_struct));
  2511. c->board_id = board_id;
  2512. #ifdef CCISS_DEBUG
  2513. print_cfg_table(c->cfgtable);
  2514. #endif /* CCISS_DEBUG */
  2515. for(i=0; i<NR_PRODUCTS; i++) {
  2516. if (board_id == products[i].board_id) {
  2517. c->product_name = products[i].product_name;
  2518. c->access = *(products[i].access);
  2519. break;
  2520. }
  2521. }
  2522. if (i == NR_PRODUCTS) {
  2523. printk(KERN_WARNING "cciss: Sorry, I don't know how"
  2524. " to access the Smart Array controller %08lx\n",
  2525. (unsigned long)board_id);
  2526. return -1;
  2527. }
  2528. if ( (readb(&c->cfgtable->Signature[0]) != 'C') ||
  2529. (readb(&c->cfgtable->Signature[1]) != 'I') ||
  2530. (readb(&c->cfgtable->Signature[2]) != 'S') ||
  2531. (readb(&c->cfgtable->Signature[3]) != 'S') )
  2532. {
  2533. printk("Does not appear to be a valid CISS config table\n");
  2534. return -1;
  2535. }
  2536. #ifdef CONFIG_X86
  2537. {
  2538. /* Need to enable prefetch in the SCSI core for 6400 in x86 */
  2539. __u32 prefetch;
  2540. prefetch = readl(&(c->cfgtable->SCSI_Prefetch));
  2541. prefetch |= 0x100;
  2542. writel(prefetch, &(c->cfgtable->SCSI_Prefetch));
  2543. }
  2544. #endif
  2545. #ifdef CCISS_DEBUG
  2546. printk("Trying to put board into Simple mode\n");
  2547. #endif /* CCISS_DEBUG */
  2548. c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
  2549. /* Update the field, and then ring the doorbell */
  2550. writel( CFGTBL_Trans_Simple,
  2551. &(c->cfgtable->HostWrite.TransportRequest));
  2552. writel( CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
  2553. /* under certain very rare conditions, this can take awhile.
  2554. * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
  2555. * as we enter this code.) */
  2556. for(i=0;i<MAX_CONFIG_WAIT;i++) {
  2557. if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
  2558. break;
  2559. /* delay and try again */
  2560. set_current_state(TASK_INTERRUPTIBLE);
  2561. schedule_timeout(10);
  2562. }
  2563. #ifdef CCISS_DEBUG
  2564. printk(KERN_DEBUG "I counter got to %d %x\n", i, readl(c->vaddr + SA5_DOORBELL));
  2565. #endif /* CCISS_DEBUG */
  2566. #ifdef CCISS_DEBUG
  2567. print_cfg_table(c->cfgtable);
  2568. #endif /* CCISS_DEBUG */
  2569. if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple))
  2570. {
  2571. printk(KERN_WARNING "cciss: unable to get board into"
  2572. " simple mode\n");
  2573. return -1;
  2574. }
  2575. return 0;
  2576. }
  2577. /*
  2578. * Gets information about the local volumes attached to the controller.
  2579. */
  2580. static void cciss_getgeometry(int cntl_num)
  2581. {
  2582. ReportLunData_struct *ld_buff;
  2583. ReadCapdata_struct *size_buff;
  2584. InquiryData_struct *inq_buff;
  2585. int return_code;
  2586. int i;
  2587. int listlength = 0;
  2588. __u32 lunid = 0;
  2589. int block_size;
  2590. int total_size;
  2591. ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
  2592. if (ld_buff == NULL)
  2593. {
  2594. printk(KERN_ERR "cciss: out of memory\n");
  2595. return;
  2596. }
  2597. memset(ld_buff, 0, sizeof(ReportLunData_struct));
  2598. size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
  2599. if (size_buff == NULL)
  2600. {
  2601. printk(KERN_ERR "cciss: out of memory\n");
  2602. kfree(ld_buff);
  2603. return;
  2604. }
  2605. inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
  2606. if (inq_buff == NULL)
  2607. {
  2608. printk(KERN_ERR "cciss: out of memory\n");
  2609. kfree(ld_buff);
  2610. kfree(size_buff);
  2611. return;
  2612. }
  2613. /* Get the firmware version */
  2614. return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
  2615. sizeof(InquiryData_struct), 0, 0 ,0, NULL, TYPE_CMD);
  2616. if (return_code == IO_OK)
  2617. {
  2618. hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32];
  2619. hba[cntl_num]->firm_ver[1] = inq_buff->data_byte[33];
  2620. hba[cntl_num]->firm_ver[2] = inq_buff->data_byte[34];
  2621. hba[cntl_num]->firm_ver[3] = inq_buff->data_byte[35];
  2622. } else /* send command failed */
  2623. {
  2624. printk(KERN_WARNING "cciss: unable to determine firmware"
  2625. " version of controller\n");
  2626. }
  2627. /* Get the number of logical volumes */
  2628. return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff,
  2629. sizeof(ReportLunData_struct), 0, 0, 0, NULL, TYPE_CMD);
  2630. if( return_code == IO_OK)
  2631. {
  2632. #ifdef CCISS_DEBUG
  2633. printk("LUN Data\n--------------------------\n");
  2634. #endif /* CCISS_DEBUG */
  2635. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[0])) << 24;
  2636. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[1])) << 16;
  2637. listlength |= (0xff & (unsigned int)(ld_buff->LUNListLength[2])) << 8;
  2638. listlength |= 0xff & (unsigned int)(ld_buff->LUNListLength[3]);
  2639. } else /* reading number of logical volumes failed */
  2640. {
  2641. printk(KERN_WARNING "cciss: report logical volume"
  2642. " command failed\n");
  2643. listlength = 0;
  2644. }
  2645. hba[cntl_num]->num_luns = listlength / 8; // 8 bytes pre entry
  2646. if (hba[cntl_num]->num_luns > CISS_MAX_LUN)
  2647. {
  2648. printk(KERN_ERR "ciss: only %d number of logical volumes supported\n",
  2649. CISS_MAX_LUN);
  2650. hba[cntl_num]->num_luns = CISS_MAX_LUN;
  2651. }
  2652. #ifdef CCISS_DEBUG
  2653. printk(KERN_DEBUG "Length = %x %x %x %x = %d\n", ld_buff->LUNListLength[0],
  2654. ld_buff->LUNListLength[1], ld_buff->LUNListLength[2],
  2655. ld_buff->LUNListLength[3], hba[cntl_num]->num_luns);
  2656. #endif /* CCISS_DEBUG */
  2657. hba[cntl_num]->highest_lun = hba[cntl_num]->num_luns-1;
  2658. // for(i=0; i< hba[cntl_num]->num_luns; i++)
  2659. for(i=0; i < CISS_MAX_LUN; i++)
  2660. {
  2661. if (i < hba[cntl_num]->num_luns){
  2662. lunid = (0xff & (unsigned int)(ld_buff->LUN[i][3]))
  2663. << 24;
  2664. lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][2]))
  2665. << 16;
  2666. lunid |= (0xff & (unsigned int)(ld_buff->LUN[i][1]))
  2667. << 8;
  2668. lunid |= 0xff & (unsigned int)(ld_buff->LUN[i][0]);
  2669. hba[cntl_num]->drv[i].LunID = lunid;
  2670. #ifdef CCISS_DEBUG
  2671. printk(KERN_DEBUG "LUN[%d]: %x %x %x %x = %x\n", i,
  2672. ld_buff->LUN[i][0], ld_buff->LUN[i][1],
  2673. ld_buff->LUN[i][2], ld_buff->LUN[i][3],
  2674. hba[cntl_num]->drv[i].LunID);
  2675. #endif /* CCISS_DEBUG */
  2676. cciss_read_capacity(cntl_num, i, size_buff, 0,
  2677. &total_size, &block_size);
  2678. cciss_geometry_inquiry(cntl_num, i, 0, total_size,
  2679. block_size, inq_buff, &hba[cntl_num]->drv[i]);
  2680. } else {
  2681. /* initialize raid_level to indicate a free space */
  2682. hba[cntl_num]->drv[i].raid_level = -1;
  2683. }
  2684. }
  2685. kfree(ld_buff);
  2686. kfree(size_buff);
  2687. kfree(inq_buff);
  2688. }
  2689. /* Function to find the first free pointer into our hba[] array */
  2690. /* Returns -1 if no free entries are left. */
  2691. static int alloc_cciss_hba(void)
  2692. {
  2693. struct gendisk *disk[NWD];
  2694. int i, n;
  2695. for (n = 0; n < NWD; n++) {
  2696. disk[n] = alloc_disk(1 << NWD_SHIFT);
  2697. if (!disk[n])
  2698. goto out;
  2699. }
  2700. for(i=0; i< MAX_CTLR; i++) {
  2701. if (!hba[i]) {
  2702. ctlr_info_t *p;
  2703. p = kmalloc(sizeof(ctlr_info_t), GFP_KERNEL);
  2704. if (!p)
  2705. goto Enomem;
  2706. memset(p, 0, sizeof(ctlr_info_t));
  2707. for (n = 0; n < NWD; n++)
  2708. p->gendisk[n] = disk[n];
  2709. hba[i] = p;
  2710. return i;
  2711. }
  2712. }
  2713. printk(KERN_WARNING "cciss: This driver supports a maximum"
  2714. " of %d controllers.\n", MAX_CTLR);
  2715. goto out;
  2716. Enomem:
  2717. printk(KERN_ERR "cciss: out of memory.\n");
  2718. out:
  2719. while (n--)
  2720. put_disk(disk[n]);
  2721. return -1;
  2722. }
  2723. static void free_hba(int i)
  2724. {
  2725. ctlr_info_t *p = hba[i];
  2726. int n;
  2727. hba[i] = NULL;
  2728. for (n = 0; n < NWD; n++)
  2729. put_disk(p->gendisk[n]);
  2730. kfree(p);
  2731. }
  2732. /*
  2733. * This is it. Find all the controllers and register them. I really hate
  2734. * stealing all these major device numbers.
  2735. * returns the number of block devices registered.
  2736. */
  2737. static int __devinit cciss_init_one(struct pci_dev *pdev,
  2738. const struct pci_device_id *ent)
  2739. {
  2740. request_queue_t *q;
  2741. int i;
  2742. int j;
  2743. int rc;
  2744. printk(KERN_DEBUG "cciss: Device 0x%x has been found at"
  2745. " bus %d dev %d func %d\n",
  2746. pdev->device, pdev->bus->number, PCI_SLOT(pdev->devfn),
  2747. PCI_FUNC(pdev->devfn));
  2748. i = alloc_cciss_hba();
  2749. if(i < 0)
  2750. return (-1);
  2751. hba[i]->busy_initializing = 1;
  2752. if (cciss_pci_init(hba[i], pdev) != 0)
  2753. goto clean1;
  2754. sprintf(hba[i]->devname, "cciss%d", i);
  2755. hba[i]->ctlr = i;
  2756. hba[i]->pdev = pdev;
  2757. /* configure PCI DMA stuff */
  2758. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK))
  2759. printk("cciss: using DAC cycles\n");
  2760. else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK))
  2761. printk("cciss: not using DAC cycles\n");
  2762. else {
  2763. printk("cciss: no suitable DMA available\n");
  2764. goto clean1;
  2765. }
  2766. /*
  2767. * register with the major number, or get a dynamic major number
  2768. * by passing 0 as argument. This is done for greater than
  2769. * 8 controller support.
  2770. */
  2771. if (i < MAX_CTLR_ORIG)
  2772. hba[i]->major = MAJOR_NR + i;
  2773. rc = register_blkdev(hba[i]->major, hba[i]->devname);
  2774. if(rc == -EBUSY || rc == -EINVAL) {
  2775. printk(KERN_ERR
  2776. "cciss: Unable to get major number %d for %s "
  2777. "on hba %d\n", hba[i]->major, hba[i]->devname, i);
  2778. goto clean1;
  2779. }
  2780. else {
  2781. if (i >= MAX_CTLR_ORIG)
  2782. hba[i]->major = rc;
  2783. }
  2784. /* make sure the board interrupts are off */
  2785. hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
  2786. if( request_irq(hba[i]->intr, do_cciss_intr,
  2787. SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
  2788. hba[i]->devname, hba[i])) {
  2789. printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
  2790. hba[i]->intr, hba[i]->devname);
  2791. goto clean2;
  2792. }
  2793. hba[i]->cmd_pool_bits = kmalloc(((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), GFP_KERNEL);
  2794. hba[i]->cmd_pool = (CommandList_struct *)pci_alloc_consistent(
  2795. hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
  2796. &(hba[i]->cmd_pool_dhandle));
  2797. hba[i]->errinfo_pool = (ErrorInfo_struct *)pci_alloc_consistent(
  2798. hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
  2799. &(hba[i]->errinfo_pool_dhandle));
  2800. if((hba[i]->cmd_pool_bits == NULL)
  2801. || (hba[i]->cmd_pool == NULL)
  2802. || (hba[i]->errinfo_pool == NULL)) {
  2803. printk( KERN_ERR "cciss: out of memory");
  2804. goto clean4;
  2805. }
  2806. #ifdef CONFIG_CISS_SCSI_TAPE
  2807. hba[i]->scsi_rejects.complete =
  2808. kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
  2809. (NR_CMDS + 5), GFP_KERNEL);
  2810. if (hba[i]->scsi_rejects.complete == NULL) {
  2811. printk( KERN_ERR "cciss: out of memory");
  2812. goto clean4;
  2813. }
  2814. #endif
  2815. spin_lock_init(&hba[i]->lock);
  2816. /* Initialize the pdev driver private data.
  2817. have it point to hba[i]. */
  2818. pci_set_drvdata(pdev, hba[i]);
  2819. /* command and error info recs zeroed out before
  2820. they are used */
  2821. memset(hba[i]->cmd_pool_bits, 0, ((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long));
  2822. #ifdef CCISS_DEBUG
  2823. printk(KERN_DEBUG "Scanning for drives on controller cciss%d\n",i);
  2824. #endif /* CCISS_DEBUG */
  2825. cciss_getgeometry(i);
  2826. cciss_scsi_setup(i);
  2827. /* Turn the interrupts on so we can service requests */
  2828. hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
  2829. cciss_procinit(i);
  2830. hba[i]->busy_initializing = 0;
  2831. for(j=0; j < NWD; j++) { /* mfm */
  2832. drive_info_struct *drv = &(hba[i]->drv[j]);
  2833. struct gendisk *disk = hba[i]->gendisk[j];
  2834. q = blk_init_queue(do_cciss_request, &hba[i]->lock);
  2835. if (!q) {
  2836. printk(KERN_ERR
  2837. "cciss: unable to allocate queue for disk %d\n",
  2838. j);
  2839. break;
  2840. }
  2841. drv->queue = q;
  2842. q->backing_dev_info.ra_pages = READ_AHEAD;
  2843. blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask);
  2844. /* This is a hardware imposed limit. */
  2845. blk_queue_max_hw_segments(q, MAXSGENTRIES);
  2846. /* This is a limit in the driver and could be eliminated. */
  2847. blk_queue_max_phys_segments(q, MAXSGENTRIES);
  2848. blk_queue_max_sectors(q, 512);
  2849. q->queuedata = hba[i];
  2850. sprintf(disk->disk_name, "cciss/c%dd%d", i, j);
  2851. sprintf(disk->devfs_name, "cciss/host%d/target%d", i, j);
  2852. disk->major = hba[i]->major;
  2853. disk->first_minor = j << NWD_SHIFT;
  2854. disk->fops = &cciss_fops;
  2855. disk->queue = q;
  2856. disk->private_data = drv;
  2857. /* we must register the controller even if no disks exist */
  2858. /* this is for the online array utilities */
  2859. if(!drv->heads && j)
  2860. continue;
  2861. blk_queue_hardsect_size(q, drv->block_size);
  2862. set_capacity(disk, drv->nr_blocks);
  2863. add_disk(disk);
  2864. }
  2865. return(1);
  2866. clean4:
  2867. #ifdef CONFIG_CISS_SCSI_TAPE
  2868. if(hba[i]->scsi_rejects.complete)
  2869. kfree(hba[i]->scsi_rejects.complete);
  2870. #endif
  2871. kfree(hba[i]->cmd_pool_bits);
  2872. if(hba[i]->cmd_pool)
  2873. pci_free_consistent(hba[i]->pdev,
  2874. NR_CMDS * sizeof(CommandList_struct),
  2875. hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
  2876. if(hba[i]->errinfo_pool)
  2877. pci_free_consistent(hba[i]->pdev,
  2878. NR_CMDS * sizeof( ErrorInfo_struct),
  2879. hba[i]->errinfo_pool,
  2880. hba[i]->errinfo_pool_dhandle);
  2881. free_irq(hba[i]->intr, hba[i]);
  2882. clean2:
  2883. unregister_blkdev(hba[i]->major, hba[i]->devname);
  2884. clean1:
  2885. release_io_mem(hba[i]);
  2886. free_hba(i);
  2887. hba[i]->busy_initializing = 0;
  2888. return(-1);
  2889. }
  2890. static void __devexit cciss_remove_one (struct pci_dev *pdev)
  2891. {
  2892. ctlr_info_t *tmp_ptr;
  2893. int i, j;
  2894. char flush_buf[4];
  2895. int return_code;
  2896. if (pci_get_drvdata(pdev) == NULL)
  2897. {
  2898. printk( KERN_ERR "cciss: Unable to remove device \n");
  2899. return;
  2900. }
  2901. tmp_ptr = pci_get_drvdata(pdev);
  2902. i = tmp_ptr->ctlr;
  2903. if (hba[i] == NULL)
  2904. {
  2905. printk(KERN_ERR "cciss: device appears to "
  2906. "already be removed \n");
  2907. return;
  2908. }
  2909. /* Turn board interrupts off and send the flush cache command */
  2910. /* sendcmd will turn off interrupt, and send the flush...
  2911. * To write all data in the battery backed cache to disks */
  2912. memset(flush_buf, 0, 4);
  2913. return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
  2914. TYPE_CMD);
  2915. if(return_code != IO_OK)
  2916. {
  2917. printk(KERN_WARNING "Error Flushing cache on controller %d\n",
  2918. i);
  2919. }
  2920. free_irq(hba[i]->intr, hba[i]);
  2921. pci_set_drvdata(pdev, NULL);
  2922. iounmap(hba[i]->vaddr);
  2923. cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
  2924. unregister_blkdev(hba[i]->major, hba[i]->devname);
  2925. remove_proc_entry(hba[i]->devname, proc_cciss);
  2926. /* remove it from the disk list */
  2927. for (j = 0; j < NWD; j++) {
  2928. struct gendisk *disk = hba[i]->gendisk[j];
  2929. if (disk->flags & GENHD_FL_UP) {
  2930. del_gendisk(disk);
  2931. blk_cleanup_queue(disk->queue);
  2932. }
  2933. }
  2934. pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
  2935. hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
  2936. pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
  2937. hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
  2938. kfree(hba[i]->cmd_pool_bits);
  2939. #ifdef CONFIG_CISS_SCSI_TAPE
  2940. kfree(hba[i]->scsi_rejects.complete);
  2941. #endif
  2942. release_io_mem(hba[i]);
  2943. free_hba(i);
  2944. }
  2945. static struct pci_driver cciss_pci_driver = {
  2946. .name = "cciss",
  2947. .probe = cciss_init_one,
  2948. .remove = __devexit_p(cciss_remove_one),
  2949. .id_table = cciss_pci_device_id, /* id_table */
  2950. };
  2951. /*
  2952. * This is it. Register the PCI driver information for the cards we control
  2953. * the OS will call our registered routines when it finds one of our cards.
  2954. */
  2955. static int __init cciss_init(void)
  2956. {
  2957. printk(KERN_INFO DRIVER_NAME "\n");
  2958. /* Register for our PCI devices */
  2959. return pci_module_init(&cciss_pci_driver);
  2960. }
  2961. static void __exit cciss_cleanup(void)
  2962. {
  2963. int i;
  2964. pci_unregister_driver(&cciss_pci_driver);
  2965. /* double check that all controller entrys have been removed */
  2966. for (i=0; i< MAX_CTLR; i++)
  2967. {
  2968. if (hba[i] != NULL)
  2969. {
  2970. printk(KERN_WARNING "cciss: had to remove"
  2971. " controller %d\n", i);
  2972. cciss_remove_one(hba[i]->pdev);
  2973. }
  2974. }
  2975. remove_proc_entry("cciss", proc_root_driver);
  2976. }
  2977. static void fail_all_cmds(unsigned long ctlr)
  2978. {
  2979. /* If we get here, the board is apparently dead. */
  2980. ctlr_info_t *h = hba[ctlr];
  2981. CommandList_struct *c;
  2982. unsigned long flags;
  2983. printk(KERN_WARNING "cciss%d: controller not responding.\n", h->ctlr);
  2984. h->alive = 0; /* the controller apparently died... */
  2985. spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
  2986. pci_disable_device(h->pdev); /* Make sure it is really dead. */
  2987. /* move everything off the request queue onto the completed queue */
  2988. while( (c = h->reqQ) != NULL ) {
  2989. removeQ(&(h->reqQ), c);
  2990. h->Qdepth--;
  2991. addQ (&(h->cmpQ), c);
  2992. }
  2993. /* Now, fail everything on the completed queue with a HW error */
  2994. while( (c = h->cmpQ) != NULL ) {
  2995. removeQ(&h->cmpQ, c);
  2996. c->err_info->CommandStatus = CMD_HARDWARE_ERR;
  2997. if (c->cmd_type == CMD_RWREQ) {
  2998. complete_command(h, c, 0);
  2999. } else if (c->cmd_type == CMD_IOCTL_PEND)
  3000. complete(c->waiting);
  3001. #ifdef CONFIG_CISS_SCSI_TAPE
  3002. else if (c->cmd_type == CMD_SCSI)
  3003. complete_scsi_command(c, 0, 0);
  3004. #endif
  3005. }
  3006. spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
  3007. return;
  3008. }
  3009. module_init(cciss_init);
  3010. module_exit(cciss_cleanup);