cciss_scsi.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. /*
  2. * Disk Array driver for HP Smart Array controllers, SCSI Tape module.
  3. * (C) Copyright 2001, 2007 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; version 2 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 300, Boston, MA
  17. * 02111-1307, USA.
  18. *
  19. * Questions/Comments/Bugfixes to iss_storagedev@hp.com
  20. *
  21. * Author: Stephen M. Cameron
  22. */
  23. #ifdef CONFIG_CISS_SCSI_TAPE
  24. /* Here we have code to present the driver as a scsi driver
  25. as it is simultaneously presented as a block driver. The
  26. reason for doing this is to allow access to SCSI tape drives
  27. through the array controller. Note in particular, neither
  28. physical nor logical disks are presented through the scsi layer. */
  29. #include <linux/timer.h>
  30. #include <linux/completion.h>
  31. #include <linux/slab.h>
  32. #include <linux/string.h>
  33. #include <asm/atomic.h>
  34. #include <scsi/scsi_cmnd.h>
  35. #include <scsi/scsi_device.h>
  36. #include <scsi/scsi_host.h>
  37. #include "cciss_scsi.h"
  38. #define CCISS_ABORT_MSG 0x00
  39. #define CCISS_RESET_MSG 0x01
  40. static int fill_cmd(ctlr_info_t *h, CommandList_struct *c, __u8 cmd, void *buff,
  41. size_t size,
  42. __u8 page_code, unsigned char *scsi3addr,
  43. int cmd_type);
  44. static CommandList_struct *cmd_alloc(ctlr_info_t *h);
  45. static CommandList_struct *cmd_special_alloc(ctlr_info_t *h);
  46. static void cmd_free(ctlr_info_t *h, CommandList_struct *c);
  47. static void cmd_special_free(ctlr_info_t *h, CommandList_struct *c);
  48. static int cciss_scsi_proc_info(
  49. struct Scsi_Host *sh,
  50. char *buffer, /* data buffer */
  51. char **start, /* where data in buffer starts */
  52. off_t offset, /* offset from start of imaginary file */
  53. int length, /* length of data in buffer */
  54. int func); /* 0 == read, 1 == write */
  55. static int cciss_scsi_queue_command (struct Scsi_Host *h,
  56. struct scsi_cmnd *cmd);
  57. static int cciss_eh_device_reset_handler(struct scsi_cmnd *);
  58. static int cciss_eh_abort_handler(struct scsi_cmnd *);
  59. static struct cciss_scsi_hba_t ccissscsi[MAX_CTLR] = {
  60. { .name = "cciss0", .ndevices = 0 },
  61. { .name = "cciss1", .ndevices = 0 },
  62. { .name = "cciss2", .ndevices = 0 },
  63. { .name = "cciss3", .ndevices = 0 },
  64. { .name = "cciss4", .ndevices = 0 },
  65. { .name = "cciss5", .ndevices = 0 },
  66. { .name = "cciss6", .ndevices = 0 },
  67. { .name = "cciss7", .ndevices = 0 },
  68. };
  69. static struct scsi_host_template cciss_driver_template = {
  70. .module = THIS_MODULE,
  71. .name = "cciss",
  72. .proc_name = "cciss",
  73. .proc_info = cciss_scsi_proc_info,
  74. .queuecommand = cciss_scsi_queue_command,
  75. .this_id = 7,
  76. .cmd_per_lun = 1,
  77. .use_clustering = DISABLE_CLUSTERING,
  78. /* Can't have eh_bus_reset_handler or eh_host_reset_handler for cciss */
  79. .eh_device_reset_handler= cciss_eh_device_reset_handler,
  80. .eh_abort_handler = cciss_eh_abort_handler,
  81. };
  82. #pragma pack(1)
  83. #define SCSI_PAD_32 8
  84. #define SCSI_PAD_64 8
  85. struct cciss_scsi_cmd_stack_elem_t {
  86. CommandList_struct cmd;
  87. ErrorInfo_struct Err;
  88. __u32 busaddr;
  89. int cmdindex;
  90. u8 pad[IS_32_BIT * SCSI_PAD_32 + IS_64_BIT * SCSI_PAD_64];
  91. };
  92. #pragma pack()
  93. #pragma pack(1)
  94. struct cciss_scsi_cmd_stack_t {
  95. struct cciss_scsi_cmd_stack_elem_t *pool;
  96. struct cciss_scsi_cmd_stack_elem_t **elem;
  97. dma_addr_t cmd_pool_handle;
  98. int top;
  99. int nelems;
  100. };
  101. #pragma pack()
  102. struct cciss_scsi_adapter_data_t {
  103. struct Scsi_Host *scsi_host;
  104. struct cciss_scsi_cmd_stack_t cmd_stack;
  105. SGDescriptor_struct **cmd_sg_list;
  106. int registered;
  107. spinlock_t lock; // to protect ccissscsi[ctlr];
  108. };
  109. #define CPQ_TAPE_LOCK(h, flags) spin_lock_irqsave( \
  110. &h->scsi_ctlr->lock, flags);
  111. #define CPQ_TAPE_UNLOCK(h, flags) spin_unlock_irqrestore( \
  112. &h->scsi_ctlr->lock, flags);
  113. static CommandList_struct *
  114. scsi_cmd_alloc(ctlr_info_t *h)
  115. {
  116. /* assume only one process in here at a time, locking done by caller. */
  117. /* use h->lock */
  118. /* might be better to rewrite how we allocate scsi commands in a way that */
  119. /* needs no locking at all. */
  120. /* take the top memory chunk off the stack and return it, if any. */
  121. struct cciss_scsi_cmd_stack_elem_t *c;
  122. struct cciss_scsi_adapter_data_t *sa;
  123. struct cciss_scsi_cmd_stack_t *stk;
  124. u64bit temp64;
  125. sa = h->scsi_ctlr;
  126. stk = &sa->cmd_stack;
  127. if (stk->top < 0)
  128. return NULL;
  129. c = stk->elem[stk->top];
  130. /* memset(c, 0, sizeof(*c)); */
  131. memset(&c->cmd, 0, sizeof(c->cmd));
  132. memset(&c->Err, 0, sizeof(c->Err));
  133. /* set physical addr of cmd and addr of scsi parameters */
  134. c->cmd.busaddr = c->busaddr;
  135. c->cmd.cmdindex = c->cmdindex;
  136. /* (__u32) (stk->cmd_pool_handle +
  137. (sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top)); */
  138. temp64.val = (__u64) (c->busaddr + sizeof(CommandList_struct));
  139. /* (__u64) (stk->cmd_pool_handle +
  140. (sizeof(struct cciss_scsi_cmd_stack_elem_t)*stk->top) +
  141. sizeof(CommandList_struct)); */
  142. stk->top--;
  143. c->cmd.ErrDesc.Addr.lower = temp64.val32.lower;
  144. c->cmd.ErrDesc.Addr.upper = temp64.val32.upper;
  145. c->cmd.ErrDesc.Len = sizeof(ErrorInfo_struct);
  146. c->cmd.ctlr = h->ctlr;
  147. c->cmd.err_info = &c->Err;
  148. return (CommandList_struct *) c;
  149. }
  150. static void
  151. scsi_cmd_free(ctlr_info_t *h, CommandList_struct *c)
  152. {
  153. /* assume only one process in here at a time, locking done by caller. */
  154. /* use h->lock */
  155. /* drop the free memory chunk on top of the stack. */
  156. struct cciss_scsi_adapter_data_t *sa;
  157. struct cciss_scsi_cmd_stack_t *stk;
  158. sa = h->scsi_ctlr;
  159. stk = &sa->cmd_stack;
  160. stk->top++;
  161. if (stk->top >= stk->nelems) {
  162. dev_err(&h->pdev->dev,
  163. "scsi_cmd_free called too many times.\n");
  164. BUG();
  165. }
  166. stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) c;
  167. }
  168. static int
  169. scsi_cmd_stack_setup(ctlr_info_t *h, struct cciss_scsi_adapter_data_t *sa)
  170. {
  171. int i;
  172. struct cciss_scsi_cmd_stack_t *stk;
  173. size_t size;
  174. stk = &sa->cmd_stack;
  175. stk->nelems = cciss_tape_cmds + 2;
  176. sa->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
  177. h->chainsize, stk->nelems);
  178. if (!sa->cmd_sg_list && h->chainsize > 0)
  179. return -ENOMEM;
  180. size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * stk->nelems;
  181. /* Check alignment, see cciss_cmd.h near CommandList_struct def. */
  182. BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0);
  183. /* pci_alloc_consistent guarantees 32-bit DMA address will be used */
  184. stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
  185. pci_alloc_consistent(h->pdev, size, &stk->cmd_pool_handle);
  186. if (stk->pool == NULL) {
  187. cciss_free_sg_chain_blocks(sa->cmd_sg_list, stk->nelems);
  188. sa->cmd_sg_list = NULL;
  189. return -ENOMEM;
  190. }
  191. stk->elem = kmalloc(sizeof(stk->elem[0]) * stk->nelems, GFP_KERNEL);
  192. if (!stk->elem) {
  193. pci_free_consistent(h->pdev, size, stk->pool,
  194. stk->cmd_pool_handle);
  195. return -1;
  196. }
  197. for (i = 0; i < stk->nelems; i++) {
  198. stk->elem[i] = &stk->pool[i];
  199. stk->elem[i]->busaddr = (__u32) (stk->cmd_pool_handle +
  200. (sizeof(struct cciss_scsi_cmd_stack_elem_t) * i));
  201. stk->elem[i]->cmdindex = i;
  202. }
  203. stk->top = stk->nelems-1;
  204. return 0;
  205. }
  206. static void
  207. scsi_cmd_stack_free(ctlr_info_t *h)
  208. {
  209. struct cciss_scsi_adapter_data_t *sa;
  210. struct cciss_scsi_cmd_stack_t *stk;
  211. size_t size;
  212. sa = h->scsi_ctlr;
  213. stk = &sa->cmd_stack;
  214. if (stk->top != stk->nelems-1) {
  215. dev_warn(&h->pdev->dev,
  216. "bug: %d scsi commands are still outstanding.\n",
  217. stk->nelems - stk->top);
  218. }
  219. size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * stk->nelems;
  220. pci_free_consistent(h->pdev, size, stk->pool, stk->cmd_pool_handle);
  221. stk->pool = NULL;
  222. cciss_free_sg_chain_blocks(sa->cmd_sg_list, stk->nelems);
  223. kfree(stk->elem);
  224. stk->elem = NULL;
  225. }
  226. #if 0
  227. static int xmargin=8;
  228. static int amargin=60;
  229. static void
  230. print_bytes (unsigned char *c, int len, int hex, int ascii)
  231. {
  232. int i;
  233. unsigned char *x;
  234. if (hex)
  235. {
  236. x = c;
  237. for (i=0;i<len;i++)
  238. {
  239. if ((i % xmargin) == 0 && i>0) printk("\n");
  240. if ((i % xmargin) == 0) printk("0x%04x:", i);
  241. printk(" %02x", *x);
  242. x++;
  243. }
  244. printk("\n");
  245. }
  246. if (ascii)
  247. {
  248. x = c;
  249. for (i=0;i<len;i++)
  250. {
  251. if ((i % amargin) == 0 && i>0) printk("\n");
  252. if ((i % amargin) == 0) printk("0x%04x:", i);
  253. if (*x > 26 && *x < 128) printk("%c", *x);
  254. else printk(".");
  255. x++;
  256. }
  257. printk("\n");
  258. }
  259. }
  260. static void
  261. print_cmd(CommandList_struct *cp)
  262. {
  263. printk("queue:%d\n", cp->Header.ReplyQueue);
  264. printk("sglist:%d\n", cp->Header.SGList);
  265. printk("sgtot:%d\n", cp->Header.SGTotal);
  266. printk("Tag:0x%08x/0x%08x\n", cp->Header.Tag.upper,
  267. cp->Header.Tag.lower);
  268. printk("LUN:0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
  269. cp->Header.LUN.LunAddrBytes[0],
  270. cp->Header.LUN.LunAddrBytes[1],
  271. cp->Header.LUN.LunAddrBytes[2],
  272. cp->Header.LUN.LunAddrBytes[3],
  273. cp->Header.LUN.LunAddrBytes[4],
  274. cp->Header.LUN.LunAddrBytes[5],
  275. cp->Header.LUN.LunAddrBytes[6],
  276. cp->Header.LUN.LunAddrBytes[7]);
  277. printk("CDBLen:%d\n", cp->Request.CDBLen);
  278. printk("Type:%d\n",cp->Request.Type.Type);
  279. printk("Attr:%d\n",cp->Request.Type.Attribute);
  280. printk(" Dir:%d\n",cp->Request.Type.Direction);
  281. printk("Timeout:%d\n",cp->Request.Timeout);
  282. printk( "CDB: %02x %02x %02x %02x %02x %02x %02x %02x"
  283. " %02x %02x %02x %02x %02x %02x %02x %02x\n",
  284. cp->Request.CDB[0], cp->Request.CDB[1],
  285. cp->Request.CDB[2], cp->Request.CDB[3],
  286. cp->Request.CDB[4], cp->Request.CDB[5],
  287. cp->Request.CDB[6], cp->Request.CDB[7],
  288. cp->Request.CDB[8], cp->Request.CDB[9],
  289. cp->Request.CDB[10], cp->Request.CDB[11],
  290. cp->Request.CDB[12], cp->Request.CDB[13],
  291. cp->Request.CDB[14], cp->Request.CDB[15]),
  292. printk("edesc.Addr: 0x%08x/0%08x, Len = %d\n",
  293. cp->ErrDesc.Addr.upper, cp->ErrDesc.Addr.lower,
  294. cp->ErrDesc.Len);
  295. printk("sgs..........Errorinfo:\n");
  296. printk("scsistatus:%d\n", cp->err_info->ScsiStatus);
  297. printk("senselen:%d\n", cp->err_info->SenseLen);
  298. printk("cmd status:%d\n", cp->err_info->CommandStatus);
  299. printk("resid cnt:%d\n", cp->err_info->ResidualCnt);
  300. printk("offense size:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
  301. printk("offense byte:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
  302. printk("offense value:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
  303. }
  304. #endif
  305. static int
  306. find_bus_target_lun(ctlr_info_t *h, int *bus, int *target, int *lun)
  307. {
  308. /* finds an unused bus, target, lun for a new device */
  309. /* assumes h->scsi_ctlr->lock is held */
  310. int i, found=0;
  311. unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA];
  312. memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA);
  313. target_taken[SELF_SCSI_ID] = 1;
  314. for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++)
  315. target_taken[ccissscsi[h->ctlr].dev[i].target] = 1;
  316. for (i = 0; i < CCISS_MAX_SCSI_DEVS_PER_HBA; i++) {
  317. if (!target_taken[i]) {
  318. *bus = 0; *target=i; *lun = 0; found=1;
  319. break;
  320. }
  321. }
  322. return (!found);
  323. }
  324. struct scsi2map {
  325. char scsi3addr[8];
  326. int bus, target, lun;
  327. };
  328. static int
  329. cciss_scsi_add_entry(ctlr_info_t *h, int hostno,
  330. struct cciss_scsi_dev_t *device,
  331. struct scsi2map *added, int *nadded)
  332. {
  333. /* assumes h->scsi_ctlr->lock is held */
  334. int n = ccissscsi[h->ctlr].ndevices;
  335. struct cciss_scsi_dev_t *sd;
  336. int i, bus, target, lun;
  337. unsigned char addr1[8], addr2[8];
  338. if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
  339. dev_warn(&h->pdev->dev, "Too many devices, "
  340. "some will be inaccessible.\n");
  341. return -1;
  342. }
  343. bus = target = -1;
  344. lun = 0;
  345. /* Is this device a non-zero lun of a multi-lun device */
  346. /* byte 4 of the 8-byte LUN addr will contain the logical unit no. */
  347. if (device->scsi3addr[4] != 0) {
  348. /* Search through our list and find the device which */
  349. /* has the same 8 byte LUN address, excepting byte 4. */
  350. /* Assign the same bus and target for this new LUN. */
  351. /* Use the logical unit number from the firmware. */
  352. memcpy(addr1, device->scsi3addr, 8);
  353. addr1[4] = 0;
  354. for (i = 0; i < n; i++) {
  355. sd = &ccissscsi[h->ctlr].dev[i];
  356. memcpy(addr2, sd->scsi3addr, 8);
  357. addr2[4] = 0;
  358. /* differ only in byte 4? */
  359. if (memcmp(addr1, addr2, 8) == 0) {
  360. bus = sd->bus;
  361. target = sd->target;
  362. lun = device->scsi3addr[4];
  363. break;
  364. }
  365. }
  366. }
  367. sd = &ccissscsi[h->ctlr].dev[n];
  368. if (lun == 0) {
  369. if (find_bus_target_lun(h,
  370. &sd->bus, &sd->target, &sd->lun) != 0)
  371. return -1;
  372. } else {
  373. sd->bus = bus;
  374. sd->target = target;
  375. sd->lun = lun;
  376. }
  377. added[*nadded].bus = sd->bus;
  378. added[*nadded].target = sd->target;
  379. added[*nadded].lun = sd->lun;
  380. (*nadded)++;
  381. memcpy(sd->scsi3addr, device->scsi3addr, 8);
  382. memcpy(sd->vendor, device->vendor, sizeof(sd->vendor));
  383. memcpy(sd->revision, device->revision, sizeof(sd->revision));
  384. memcpy(sd->device_id, device->device_id, sizeof(sd->device_id));
  385. sd->devtype = device->devtype;
  386. ccissscsi[h->ctlr].ndevices++;
  387. /* initially, (before registering with scsi layer) we don't
  388. know our hostno and we don't want to print anything first
  389. time anyway (the scsi layer's inquiries will show that info) */
  390. if (hostno != -1)
  391. dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d added.\n",
  392. scsi_device_type(sd->devtype), hostno,
  393. sd->bus, sd->target, sd->lun);
  394. return 0;
  395. }
  396. static void
  397. cciss_scsi_remove_entry(ctlr_info_t *h, int hostno, int entry,
  398. struct scsi2map *removed, int *nremoved)
  399. {
  400. /* assumes h->ctlr]->scsi_ctlr->lock is held */
  401. int i;
  402. struct cciss_scsi_dev_t sd;
  403. if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return;
  404. sd = ccissscsi[h->ctlr].dev[entry];
  405. removed[*nremoved].bus = sd.bus;
  406. removed[*nremoved].target = sd.target;
  407. removed[*nremoved].lun = sd.lun;
  408. (*nremoved)++;
  409. for (i = entry; i < ccissscsi[h->ctlr].ndevices-1; i++)
  410. ccissscsi[h->ctlr].dev[i] = ccissscsi[h->ctlr].dev[i+1];
  411. ccissscsi[h->ctlr].ndevices--;
  412. dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d removed.\n",
  413. scsi_device_type(sd.devtype), hostno,
  414. sd.bus, sd.target, sd.lun);
  415. }
  416. #define SCSI3ADDR_EQ(a,b) ( \
  417. (a)[7] == (b)[7] && \
  418. (a)[6] == (b)[6] && \
  419. (a)[5] == (b)[5] && \
  420. (a)[4] == (b)[4] && \
  421. (a)[3] == (b)[3] && \
  422. (a)[2] == (b)[2] && \
  423. (a)[1] == (b)[1] && \
  424. (a)[0] == (b)[0])
  425. static void fixup_botched_add(ctlr_info_t *h, char *scsi3addr)
  426. {
  427. /* called when scsi_add_device fails in order to re-adjust */
  428. /* ccissscsi[] to match the mid layer's view. */
  429. unsigned long flags;
  430. int i, j;
  431. CPQ_TAPE_LOCK(h, flags);
  432. for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
  433. if (memcmp(scsi3addr,
  434. ccissscsi[h->ctlr].dev[i].scsi3addr, 8) == 0) {
  435. for (j = i; j < ccissscsi[h->ctlr].ndevices-1; j++)
  436. ccissscsi[h->ctlr].dev[j] =
  437. ccissscsi[h->ctlr].dev[j+1];
  438. ccissscsi[h->ctlr].ndevices--;
  439. break;
  440. }
  441. }
  442. CPQ_TAPE_UNLOCK(h, flags);
  443. }
  444. static int device_is_the_same(struct cciss_scsi_dev_t *dev1,
  445. struct cciss_scsi_dev_t *dev2)
  446. {
  447. return dev1->devtype == dev2->devtype &&
  448. memcmp(dev1->scsi3addr, dev2->scsi3addr,
  449. sizeof(dev1->scsi3addr)) == 0 &&
  450. memcmp(dev1->device_id, dev2->device_id,
  451. sizeof(dev1->device_id)) == 0 &&
  452. memcmp(dev1->vendor, dev2->vendor,
  453. sizeof(dev1->vendor)) == 0 &&
  454. memcmp(dev1->model, dev2->model,
  455. sizeof(dev1->model)) == 0 &&
  456. memcmp(dev1->revision, dev2->revision,
  457. sizeof(dev1->revision)) == 0;
  458. }
  459. static int
  460. adjust_cciss_scsi_table(ctlr_info_t *h, int hostno,
  461. struct cciss_scsi_dev_t sd[], int nsds)
  462. {
  463. /* sd contains scsi3 addresses and devtypes, but
  464. bus target and lun are not filled in. This funciton
  465. takes what's in sd to be the current and adjusts
  466. ccissscsi[] to be in line with what's in sd. */
  467. int i,j, found, changes=0;
  468. struct cciss_scsi_dev_t *csd;
  469. unsigned long flags;
  470. struct scsi2map *added, *removed;
  471. int nadded, nremoved;
  472. struct Scsi_Host *sh = NULL;
  473. added = kzalloc(sizeof(*added) * CCISS_MAX_SCSI_DEVS_PER_HBA,
  474. GFP_KERNEL);
  475. removed = kzalloc(sizeof(*removed) * CCISS_MAX_SCSI_DEVS_PER_HBA,
  476. GFP_KERNEL);
  477. if (!added || !removed) {
  478. dev_warn(&h->pdev->dev,
  479. "Out of memory in adjust_cciss_scsi_table\n");
  480. goto free_and_out;
  481. }
  482. CPQ_TAPE_LOCK(h, flags);
  483. if (hostno != -1) /* if it's not the first time... */
  484. sh = h->scsi_ctlr->scsi_host;
  485. /* find any devices in ccissscsi[] that are not in
  486. sd[] and remove them from ccissscsi[] */
  487. i = 0;
  488. nremoved = 0;
  489. nadded = 0;
  490. while (i < ccissscsi[h->ctlr].ndevices) {
  491. csd = &ccissscsi[h->ctlr].dev[i];
  492. found=0;
  493. for (j=0;j<nsds;j++) {
  494. if (SCSI3ADDR_EQ(sd[j].scsi3addr,
  495. csd->scsi3addr)) {
  496. if (device_is_the_same(&sd[j], csd))
  497. found=2;
  498. else
  499. found=1;
  500. break;
  501. }
  502. }
  503. if (found == 0) { /* device no longer present. */
  504. changes++;
  505. cciss_scsi_remove_entry(h, hostno, i,
  506. removed, &nremoved);
  507. /* remove ^^^, hence i not incremented */
  508. } else if (found == 1) { /* device is different in some way */
  509. changes++;
  510. dev_info(&h->pdev->dev,
  511. "device c%db%dt%dl%d has changed.\n",
  512. hostno, csd->bus, csd->target, csd->lun);
  513. cciss_scsi_remove_entry(h, hostno, i,
  514. removed, &nremoved);
  515. /* remove ^^^, hence i not incremented */
  516. if (cciss_scsi_add_entry(h, hostno, &sd[j],
  517. added, &nadded) != 0)
  518. /* we just removed one, so add can't fail. */
  519. BUG();
  520. csd->devtype = sd[j].devtype;
  521. memcpy(csd->device_id, sd[j].device_id,
  522. sizeof(csd->device_id));
  523. memcpy(csd->vendor, sd[j].vendor,
  524. sizeof(csd->vendor));
  525. memcpy(csd->model, sd[j].model,
  526. sizeof(csd->model));
  527. memcpy(csd->revision, sd[j].revision,
  528. sizeof(csd->revision));
  529. } else /* device is same as it ever was, */
  530. i++; /* so just move along. */
  531. }
  532. /* Now, make sure every device listed in sd[] is also
  533. listed in ccissscsi[], adding them if they aren't found */
  534. for (i=0;i<nsds;i++) {
  535. found=0;
  536. for (j = 0; j < ccissscsi[h->ctlr].ndevices; j++) {
  537. csd = &ccissscsi[h->ctlr].dev[j];
  538. if (SCSI3ADDR_EQ(sd[i].scsi3addr,
  539. csd->scsi3addr)) {
  540. if (device_is_the_same(&sd[i], csd))
  541. found=2; /* found device */
  542. else
  543. found=1; /* found a bug. */
  544. break;
  545. }
  546. }
  547. if (!found) {
  548. changes++;
  549. if (cciss_scsi_add_entry(h, hostno, &sd[i],
  550. added, &nadded) != 0)
  551. break;
  552. } else if (found == 1) {
  553. /* should never happen... */
  554. changes++;
  555. dev_warn(&h->pdev->dev,
  556. "device unexpectedly changed\n");
  557. /* but if it does happen, we just ignore that device */
  558. }
  559. }
  560. CPQ_TAPE_UNLOCK(h, flags);
  561. /* Don't notify scsi mid layer of any changes the first time through */
  562. /* (or if there are no changes) scsi_scan_host will do it later the */
  563. /* first time through. */
  564. if (hostno == -1 || !changes)
  565. goto free_and_out;
  566. /* Notify scsi mid layer of any removed devices */
  567. for (i = 0; i < nremoved; i++) {
  568. struct scsi_device *sdev =
  569. scsi_device_lookup(sh, removed[i].bus,
  570. removed[i].target, removed[i].lun);
  571. if (sdev != NULL) {
  572. scsi_remove_device(sdev);
  573. scsi_device_put(sdev);
  574. } else {
  575. /* We don't expect to get here. */
  576. /* future cmds to this device will get selection */
  577. /* timeout as if the device was gone. */
  578. dev_warn(&h->pdev->dev, "didn't find "
  579. "c%db%dt%dl%d\n for removal.",
  580. hostno, removed[i].bus,
  581. removed[i].target, removed[i].lun);
  582. }
  583. }
  584. /* Notify scsi mid layer of any added devices */
  585. for (i = 0; i < nadded; i++) {
  586. int rc;
  587. rc = scsi_add_device(sh, added[i].bus,
  588. added[i].target, added[i].lun);
  589. if (rc == 0)
  590. continue;
  591. dev_warn(&h->pdev->dev, "scsi_add_device "
  592. "c%db%dt%dl%d failed, device not added.\n",
  593. hostno, added[i].bus, added[i].target, added[i].lun);
  594. /* now we have to remove it from ccissscsi, */
  595. /* since it didn't get added to scsi mid layer */
  596. fixup_botched_add(h, added[i].scsi3addr);
  597. }
  598. free_and_out:
  599. kfree(added);
  600. kfree(removed);
  601. return 0;
  602. }
  603. static int
  604. lookup_scsi3addr(ctlr_info_t *h, int bus, int target, int lun, char *scsi3addr)
  605. {
  606. int i;
  607. struct cciss_scsi_dev_t *sd;
  608. unsigned long flags;
  609. CPQ_TAPE_LOCK(h, flags);
  610. for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
  611. sd = &ccissscsi[h->ctlr].dev[i];
  612. if (sd->bus == bus &&
  613. sd->target == target &&
  614. sd->lun == lun) {
  615. memcpy(scsi3addr, &sd->scsi3addr[0], 8);
  616. CPQ_TAPE_UNLOCK(h, flags);
  617. return 0;
  618. }
  619. }
  620. CPQ_TAPE_UNLOCK(h, flags);
  621. return -1;
  622. }
  623. static void
  624. cciss_scsi_setup(ctlr_info_t *h)
  625. {
  626. struct cciss_scsi_adapter_data_t * shba;
  627. ccissscsi[h->ctlr].ndevices = 0;
  628. shba = (struct cciss_scsi_adapter_data_t *)
  629. kmalloc(sizeof(*shba), GFP_KERNEL);
  630. if (shba == NULL)
  631. return;
  632. shba->scsi_host = NULL;
  633. spin_lock_init(&shba->lock);
  634. shba->registered = 0;
  635. if (scsi_cmd_stack_setup(h, shba) != 0) {
  636. kfree(shba);
  637. shba = NULL;
  638. }
  639. h->scsi_ctlr = shba;
  640. return;
  641. }
  642. static void complete_scsi_command(CommandList_struct *c, int timeout,
  643. __u32 tag)
  644. {
  645. struct scsi_cmnd *cmd;
  646. ctlr_info_t *h;
  647. ErrorInfo_struct *ei;
  648. ei = c->err_info;
  649. /* First, see if it was a message rather than a command */
  650. if (c->Request.Type.Type == TYPE_MSG) {
  651. c->cmd_type = CMD_MSG_DONE;
  652. return;
  653. }
  654. cmd = (struct scsi_cmnd *) c->scsi_cmd;
  655. h = hba[c->ctlr];
  656. scsi_dma_unmap(cmd);
  657. if (c->Header.SGTotal > h->max_cmd_sgentries)
  658. cciss_unmap_sg_chain_block(h, c);
  659. cmd->result = (DID_OK << 16); /* host byte */
  660. cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
  661. /* cmd->result |= (GOOD < 1); */ /* status byte */
  662. cmd->result |= (ei->ScsiStatus);
  663. /* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus); */
  664. /* copy the sense data whether we need to or not. */
  665. memcpy(cmd->sense_buffer, ei->SenseInfo,
  666. ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
  667. SCSI_SENSE_BUFFERSIZE :
  668. ei->SenseLen);
  669. scsi_set_resid(cmd, ei->ResidualCnt);
  670. if(ei->CommandStatus != 0)
  671. { /* an error has occurred */
  672. switch(ei->CommandStatus)
  673. {
  674. case CMD_TARGET_STATUS:
  675. /* Pass it up to the upper layers... */
  676. if( ei->ScsiStatus)
  677. {
  678. #if 0
  679. printk(KERN_WARNING "cciss: cmd %p "
  680. "has SCSI Status = %x\n",
  681. c, ei->ScsiStatus);
  682. #endif
  683. cmd->result |= (ei->ScsiStatus << 1);
  684. }
  685. else { /* scsi status is zero??? How??? */
  686. /* Ordinarily, this case should never happen, but there is a bug
  687. in some released firmware revisions that allows it to happen
  688. if, for example, a 4100 backplane loses power and the tape
  689. drive is in it. We assume that it's a fatal error of some
  690. kind because we can't show that it wasn't. We will make it
  691. look like selection timeout since that is the most common
  692. reason for this to occur, and it's severe enough. */
  693. cmd->result = DID_NO_CONNECT << 16;
  694. }
  695. break;
  696. case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
  697. break;
  698. case CMD_DATA_OVERRUN:
  699. dev_warn(&h->pdev->dev, "%p has"
  700. " completed with data overrun "
  701. "reported\n", c);
  702. break;
  703. case CMD_INVALID: {
  704. /* print_bytes(c, sizeof(*c), 1, 0);
  705. print_cmd(c); */
  706. /* We get CMD_INVALID if you address a non-existent tape drive instead
  707. of a selection timeout (no response). You will see this if you yank
  708. out a tape drive, then try to access it. This is kind of a shame
  709. because it means that any other CMD_INVALID (e.g. driver bug) will
  710. get interpreted as a missing target. */
  711. cmd->result = DID_NO_CONNECT << 16;
  712. }
  713. break;
  714. case CMD_PROTOCOL_ERR:
  715. dev_warn(&h->pdev->dev,
  716. "%p has protocol error\n", c);
  717. break;
  718. case CMD_HARDWARE_ERR:
  719. cmd->result = DID_ERROR << 16;
  720. dev_warn(&h->pdev->dev,
  721. "%p had hardware error\n", c);
  722. break;
  723. case CMD_CONNECTION_LOST:
  724. cmd->result = DID_ERROR << 16;
  725. dev_warn(&h->pdev->dev,
  726. "%p had connection lost\n", c);
  727. break;
  728. case CMD_ABORTED:
  729. cmd->result = DID_ABORT << 16;
  730. dev_warn(&h->pdev->dev, "%p was aborted\n", c);
  731. break;
  732. case CMD_ABORT_FAILED:
  733. cmd->result = DID_ERROR << 16;
  734. dev_warn(&h->pdev->dev,
  735. "%p reports abort failed\n", c);
  736. break;
  737. case CMD_UNSOLICITED_ABORT:
  738. cmd->result = DID_ABORT << 16;
  739. dev_warn(&h->pdev->dev, "%p aborted due to an "
  740. "unsolicited abort\n", c);
  741. break;
  742. case CMD_TIMEOUT:
  743. cmd->result = DID_TIME_OUT << 16;
  744. dev_warn(&h->pdev->dev, "%p timedout\n", c);
  745. break;
  746. case CMD_UNABORTABLE:
  747. cmd->result = DID_ERROR << 16;
  748. dev_warn(&h->pdev->dev, "c %p command "
  749. "unabortable\n", c);
  750. break;
  751. default:
  752. cmd->result = DID_ERROR << 16;
  753. dev_warn(&h->pdev->dev,
  754. "%p returned unknown status %x\n", c,
  755. ei->CommandStatus);
  756. }
  757. }
  758. cmd->scsi_done(cmd);
  759. scsi_cmd_free(h, c);
  760. }
  761. static int
  762. cciss_scsi_detect(ctlr_info_t *h)
  763. {
  764. struct Scsi_Host *sh;
  765. int error;
  766. sh = scsi_host_alloc(&cciss_driver_template, sizeof(struct ctlr_info *));
  767. if (sh == NULL)
  768. goto fail;
  769. sh->io_port = 0; // good enough? FIXME,
  770. sh->n_io_port = 0; // I don't think we use these two...
  771. sh->this_id = SELF_SCSI_ID;
  772. sh->can_queue = cciss_tape_cmds;
  773. sh->sg_tablesize = h->maxsgentries;
  774. sh->max_cmd_len = MAX_COMMAND_SIZE;
  775. sh->max_sectors = h->cciss_max_sectors;
  776. ((struct cciss_scsi_adapter_data_t *)
  777. h->scsi_ctlr)->scsi_host = sh;
  778. sh->hostdata[0] = (unsigned long) h;
  779. sh->irq = h->intr[SIMPLE_MODE_INT];
  780. sh->unique_id = sh->irq;
  781. error = scsi_add_host(sh, &h->pdev->dev);
  782. if (error)
  783. goto fail_host_put;
  784. scsi_scan_host(sh);
  785. return 1;
  786. fail_host_put:
  787. scsi_host_put(sh);
  788. fail:
  789. return 0;
  790. }
  791. static void
  792. cciss_unmap_one(struct pci_dev *pdev,
  793. CommandList_struct *c,
  794. size_t buflen,
  795. int data_direction)
  796. {
  797. u64bit addr64;
  798. addr64.val32.lower = c->SG[0].Addr.lower;
  799. addr64.val32.upper = c->SG[0].Addr.upper;
  800. pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction);
  801. }
  802. static void
  803. cciss_map_one(struct pci_dev *pdev,
  804. CommandList_struct *c,
  805. unsigned char *buf,
  806. size_t buflen,
  807. int data_direction)
  808. {
  809. __u64 addr64;
  810. addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction);
  811. c->SG[0].Addr.lower =
  812. (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
  813. c->SG[0].Addr.upper =
  814. (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
  815. c->SG[0].Len = buflen;
  816. c->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */
  817. c->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */
  818. }
  819. static int
  820. cciss_scsi_do_simple_cmd(ctlr_info_t *h,
  821. CommandList_struct *c,
  822. unsigned char *scsi3addr,
  823. unsigned char *cdb,
  824. unsigned char cdblen,
  825. unsigned char *buf, int bufsize,
  826. int direction)
  827. {
  828. DECLARE_COMPLETION_ONSTACK(wait);
  829. c->cmd_type = CMD_IOCTL_PEND; /* treat this like an ioctl */
  830. c->scsi_cmd = NULL;
  831. c->Header.ReplyQueue = 0; /* unused in simple mode */
  832. memcpy(&c->Header.LUN, scsi3addr, sizeof(c->Header.LUN));
  833. c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
  834. // Fill in the request block...
  835. /* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
  836. scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
  837. scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
  838. memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
  839. memcpy(c->Request.CDB, cdb, cdblen);
  840. c->Request.Timeout = 0;
  841. c->Request.CDBLen = cdblen;
  842. c->Request.Type.Type = TYPE_CMD;
  843. c->Request.Type.Attribute = ATTR_SIMPLE;
  844. c->Request.Type.Direction = direction;
  845. /* Fill in the SG list and do dma mapping */
  846. cciss_map_one(h->pdev, c, (unsigned char *) buf,
  847. bufsize, DMA_FROM_DEVICE);
  848. c->waiting = &wait;
  849. enqueue_cmd_and_start_io(h, c);
  850. wait_for_completion(&wait);
  851. /* undo the dma mapping */
  852. cciss_unmap_one(h->pdev, c, bufsize, DMA_FROM_DEVICE);
  853. return(0);
  854. }
  855. static void
  856. cciss_scsi_interpret_error(ctlr_info_t *h, CommandList_struct *c)
  857. {
  858. ErrorInfo_struct *ei;
  859. ei = c->err_info;
  860. switch(ei->CommandStatus)
  861. {
  862. case CMD_TARGET_STATUS:
  863. dev_warn(&h->pdev->dev,
  864. "cmd %p has completed with errors\n", c);
  865. dev_warn(&h->pdev->dev,
  866. "cmd %p has SCSI Status = %x\n",
  867. c, ei->ScsiStatus);
  868. if (ei->ScsiStatus == 0)
  869. dev_warn(&h->pdev->dev,
  870. "SCSI status is abnormally zero. "
  871. "(probably indicates selection timeout "
  872. "reported incorrectly due to a known "
  873. "firmware bug, circa July, 2001.)\n");
  874. break;
  875. case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
  876. dev_info(&h->pdev->dev, "UNDERRUN\n");
  877. break;
  878. case CMD_DATA_OVERRUN:
  879. dev_warn(&h->pdev->dev, "%p has"
  880. " completed with data overrun "
  881. "reported\n", c);
  882. break;
  883. case CMD_INVALID: {
  884. /* controller unfortunately reports SCSI passthru's */
  885. /* to non-existent targets as invalid commands. */
  886. dev_warn(&h->pdev->dev,
  887. "%p is reported invalid (probably means "
  888. "target device no longer present)\n", c);
  889. /* print_bytes((unsigned char *) c, sizeof(*c), 1, 0);
  890. print_cmd(c); */
  891. }
  892. break;
  893. case CMD_PROTOCOL_ERR:
  894. dev_warn(&h->pdev->dev, "%p has protocol error\n", c);
  895. break;
  896. case CMD_HARDWARE_ERR:
  897. /* cmd->result = DID_ERROR << 16; */
  898. dev_warn(&h->pdev->dev, "%p had hardware error\n", c);
  899. break;
  900. case CMD_CONNECTION_LOST:
  901. dev_warn(&h->pdev->dev, "%p had connection lost\n", c);
  902. break;
  903. case CMD_ABORTED:
  904. dev_warn(&h->pdev->dev, "%p was aborted\n", c);
  905. break;
  906. case CMD_ABORT_FAILED:
  907. dev_warn(&h->pdev->dev,
  908. "%p reports abort failed\n", c);
  909. break;
  910. case CMD_UNSOLICITED_ABORT:
  911. dev_warn(&h->pdev->dev,
  912. "%p aborted due to an unsolicited abort\n", c);
  913. break;
  914. case CMD_TIMEOUT:
  915. dev_warn(&h->pdev->dev, "%p timedout\n", c);
  916. break;
  917. case CMD_UNABORTABLE:
  918. dev_warn(&h->pdev->dev,
  919. "%p unabortable\n", c);
  920. break;
  921. default:
  922. dev_warn(&h->pdev->dev,
  923. "%p returned unknown status %x\n",
  924. c, ei->CommandStatus);
  925. }
  926. }
  927. static int
  928. cciss_scsi_do_inquiry(ctlr_info_t *h, unsigned char *scsi3addr,
  929. unsigned char page, unsigned char *buf,
  930. unsigned char bufsize)
  931. {
  932. int rc;
  933. CommandList_struct *c;
  934. char cdb[6];
  935. ErrorInfo_struct *ei;
  936. unsigned long flags;
  937. spin_lock_irqsave(&h->lock, flags);
  938. c = scsi_cmd_alloc(h);
  939. spin_unlock_irqrestore(&h->lock, flags);
  940. if (c == NULL) { /* trouble... */
  941. printk("cmd_alloc returned NULL!\n");
  942. return -1;
  943. }
  944. ei = c->err_info;
  945. cdb[0] = CISS_INQUIRY;
  946. cdb[1] = (page != 0);
  947. cdb[2] = page;
  948. cdb[3] = 0;
  949. cdb[4] = bufsize;
  950. cdb[5] = 0;
  951. rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr, cdb,
  952. 6, buf, bufsize, XFER_READ);
  953. if (rc != 0) return rc; /* something went wrong */
  954. if (ei->CommandStatus != 0 &&
  955. ei->CommandStatus != CMD_DATA_UNDERRUN) {
  956. cciss_scsi_interpret_error(h, c);
  957. rc = -1;
  958. }
  959. spin_lock_irqsave(&h->lock, flags);
  960. scsi_cmd_free(h, c);
  961. spin_unlock_irqrestore(&h->lock, flags);
  962. return rc;
  963. }
  964. /* Get the device id from inquiry page 0x83 */
  965. static int cciss_scsi_get_device_id(ctlr_info_t *h, unsigned char *scsi3addr,
  966. unsigned char *device_id, int buflen)
  967. {
  968. int rc;
  969. unsigned char *buf;
  970. if (buflen > 16)
  971. buflen = 16;
  972. buf = kzalloc(64, GFP_KERNEL);
  973. if (!buf)
  974. return -1;
  975. rc = cciss_scsi_do_inquiry(h, scsi3addr, 0x83, buf, 64);
  976. if (rc == 0)
  977. memcpy(device_id, &buf[8], buflen);
  978. kfree(buf);
  979. return rc != 0;
  980. }
  981. static int
  982. cciss_scsi_do_report_phys_luns(ctlr_info_t *h,
  983. ReportLunData_struct *buf, int bufsize)
  984. {
  985. int rc;
  986. CommandList_struct *c;
  987. unsigned char cdb[12];
  988. unsigned char scsi3addr[8];
  989. ErrorInfo_struct *ei;
  990. unsigned long flags;
  991. spin_lock_irqsave(&h->lock, flags);
  992. c = scsi_cmd_alloc(h);
  993. spin_unlock_irqrestore(&h->lock, flags);
  994. if (c == NULL) { /* trouble... */
  995. printk("cmd_alloc returned NULL!\n");
  996. return -1;
  997. }
  998. memset(&scsi3addr[0], 0, 8); /* address the controller */
  999. cdb[0] = CISS_REPORT_PHYS;
  1000. cdb[1] = 0;
  1001. cdb[2] = 0;
  1002. cdb[3] = 0;
  1003. cdb[4] = 0;
  1004. cdb[5] = 0;
  1005. cdb[6] = (bufsize >> 24) & 0xFF; //MSB
  1006. cdb[7] = (bufsize >> 16) & 0xFF;
  1007. cdb[8] = (bufsize >> 8) & 0xFF;
  1008. cdb[9] = bufsize & 0xFF;
  1009. cdb[10] = 0;
  1010. cdb[11] = 0;
  1011. rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr,
  1012. cdb, 12,
  1013. (unsigned char *) buf,
  1014. bufsize, XFER_READ);
  1015. if (rc != 0) return rc; /* something went wrong */
  1016. ei = c->err_info;
  1017. if (ei->CommandStatus != 0 &&
  1018. ei->CommandStatus != CMD_DATA_UNDERRUN) {
  1019. cciss_scsi_interpret_error(h, c);
  1020. rc = -1;
  1021. }
  1022. spin_lock_irqsave(&h->lock, flags);
  1023. scsi_cmd_free(h, c);
  1024. spin_unlock_irqrestore(&h->lock, flags);
  1025. return rc;
  1026. }
  1027. static void
  1028. cciss_update_non_disk_devices(ctlr_info_t *h, int hostno)
  1029. {
  1030. /* the idea here is we could get notified from /proc
  1031. that some devices have changed, so we do a report
  1032. physical luns cmd, and adjust our list of devices
  1033. accordingly. (We can't rely on the scsi-mid layer just
  1034. doing inquiries, because the "busses" that the scsi
  1035. mid-layer probes are totally fabricated by this driver,
  1036. so new devices wouldn't show up.
  1037. the scsi3addr's of devices won't change so long as the
  1038. adapter is not reset. That means we can rescan and
  1039. tell which devices we already know about, vs. new
  1040. devices, vs. disappearing devices.
  1041. Also, if you yank out a tape drive, then put in a disk
  1042. in it's place, (say, a configured volume from another
  1043. array controller for instance) _don't_ poke this driver
  1044. (so it thinks it's still a tape, but _do_ poke the scsi
  1045. mid layer, so it does an inquiry... the scsi mid layer
  1046. will see the physical disk. This would be bad. Need to
  1047. think about how to prevent that. One idea would be to
  1048. snoop all scsi responses and if an inquiry repsonse comes
  1049. back that reports a disk, chuck it an return selection
  1050. timeout instead and adjust our table... Not sure i like
  1051. that though.
  1052. */
  1053. #define OBDR_TAPE_INQ_SIZE 49
  1054. #define OBDR_TAPE_SIG "$DR-10"
  1055. ReportLunData_struct *ld_buff;
  1056. unsigned char *inq_buff;
  1057. unsigned char scsi3addr[8];
  1058. __u32 num_luns=0;
  1059. unsigned char *ch;
  1060. struct cciss_scsi_dev_t *currentsd, *this_device;
  1061. int ncurrent=0;
  1062. int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
  1063. int i;
  1064. ld_buff = kzalloc(reportlunsize, GFP_KERNEL);
  1065. inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
  1066. currentsd = kzalloc(sizeof(*currentsd) *
  1067. (CCISS_MAX_SCSI_DEVS_PER_HBA+1), GFP_KERNEL);
  1068. if (ld_buff == NULL || inq_buff == NULL || currentsd == NULL) {
  1069. printk(KERN_ERR "cciss: out of memory\n");
  1070. goto out;
  1071. }
  1072. this_device = &currentsd[CCISS_MAX_SCSI_DEVS_PER_HBA];
  1073. if (cciss_scsi_do_report_phys_luns(h, ld_buff, reportlunsize) == 0) {
  1074. ch = &ld_buff->LUNListLength[0];
  1075. num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8;
  1076. if (num_luns > CISS_MAX_PHYS_LUN) {
  1077. printk(KERN_WARNING
  1078. "cciss: Maximum physical LUNs (%d) exceeded. "
  1079. "%d LUNs ignored.\n", CISS_MAX_PHYS_LUN,
  1080. num_luns - CISS_MAX_PHYS_LUN);
  1081. num_luns = CISS_MAX_PHYS_LUN;
  1082. }
  1083. }
  1084. else {
  1085. printk(KERN_ERR "cciss: Report physical LUNs failed.\n");
  1086. goto out;
  1087. }
  1088. /* adjust our table of devices */
  1089. for (i = 0; i < num_luns; i++) {
  1090. /* for each physical lun, do an inquiry */
  1091. if (ld_buff->LUN[i][3] & 0xC0) continue;
  1092. memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE);
  1093. memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8);
  1094. if (cciss_scsi_do_inquiry(h, scsi3addr, 0, inq_buff,
  1095. (unsigned char) OBDR_TAPE_INQ_SIZE) != 0)
  1096. /* Inquiry failed (msg printed already) */
  1097. continue; /* so we will skip this device. */
  1098. this_device->devtype = (inq_buff[0] & 0x1f);
  1099. this_device->bus = -1;
  1100. this_device->target = -1;
  1101. this_device->lun = -1;
  1102. memcpy(this_device->scsi3addr, scsi3addr, 8);
  1103. memcpy(this_device->vendor, &inq_buff[8],
  1104. sizeof(this_device->vendor));
  1105. memcpy(this_device->model, &inq_buff[16],
  1106. sizeof(this_device->model));
  1107. memcpy(this_device->revision, &inq_buff[32],
  1108. sizeof(this_device->revision));
  1109. memset(this_device->device_id, 0,
  1110. sizeof(this_device->device_id));
  1111. cciss_scsi_get_device_id(h, scsi3addr,
  1112. this_device->device_id, sizeof(this_device->device_id));
  1113. switch (this_device->devtype)
  1114. {
  1115. case 0x05: /* CD-ROM */ {
  1116. /* We don't *really* support actual CD-ROM devices,
  1117. * just this "One Button Disaster Recovery" tape drive
  1118. * which temporarily pretends to be a CD-ROM drive.
  1119. * So we check that the device is really an OBDR tape
  1120. * device by checking for "$DR-10" in bytes 43-48 of
  1121. * the inquiry data.
  1122. */
  1123. char obdr_sig[7];
  1124. strncpy(obdr_sig, &inq_buff[43], 6);
  1125. obdr_sig[6] = '\0';
  1126. if (strncmp(obdr_sig, OBDR_TAPE_SIG, 6) != 0)
  1127. /* Not OBDR device, ignore it. */
  1128. break;
  1129. }
  1130. /* fall through . . . */
  1131. case 0x01: /* sequential access, (tape) */
  1132. case 0x08: /* medium changer */
  1133. if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
  1134. printk(KERN_INFO "cciss%d: %s ignored, "
  1135. "too many devices.\n", h->ctlr,
  1136. scsi_device_type(this_device->devtype));
  1137. break;
  1138. }
  1139. currentsd[ncurrent] = *this_device;
  1140. ncurrent++;
  1141. break;
  1142. default:
  1143. break;
  1144. }
  1145. }
  1146. adjust_cciss_scsi_table(h, hostno, currentsd, ncurrent);
  1147. out:
  1148. kfree(inq_buff);
  1149. kfree(ld_buff);
  1150. kfree(currentsd);
  1151. return;
  1152. }
  1153. static int
  1154. is_keyword(char *ptr, int len, char *verb) // Thanks to ncr53c8xx.c
  1155. {
  1156. int verb_len = strlen(verb);
  1157. if (len >= verb_len && !memcmp(verb,ptr,verb_len))
  1158. return verb_len;
  1159. else
  1160. return 0;
  1161. }
  1162. static int
  1163. cciss_scsi_user_command(ctlr_info_t *h, int hostno, char *buffer, int length)
  1164. {
  1165. int arg_len;
  1166. if ((arg_len = is_keyword(buffer, length, "rescan")) != 0)
  1167. cciss_update_non_disk_devices(h, hostno);
  1168. else
  1169. return -EINVAL;
  1170. return length;
  1171. }
  1172. static int
  1173. cciss_scsi_proc_info(struct Scsi_Host *sh,
  1174. char *buffer, /* data buffer */
  1175. char **start, /* where data in buffer starts */
  1176. off_t offset, /* offset from start of imaginary file */
  1177. int length, /* length of data in buffer */
  1178. int func) /* 0 == read, 1 == write */
  1179. {
  1180. int buflen, datalen;
  1181. ctlr_info_t *h;
  1182. int i;
  1183. h = (ctlr_info_t *) sh->hostdata[0];
  1184. if (h == NULL) /* This really shouldn't ever happen. */
  1185. return -EINVAL;
  1186. if (func == 0) { /* User is reading from /proc/scsi/ciss*?/?* */
  1187. buflen = sprintf(buffer, "cciss%d: SCSI host: %d\n",
  1188. h->ctlr, sh->host_no);
  1189. /* this information is needed by apps to know which cciss
  1190. device corresponds to which scsi host number without
  1191. having to open a scsi target device node. The device
  1192. information is not a duplicate of /proc/scsi/scsi because
  1193. the two may be out of sync due to scsi hotplug, rather
  1194. this info is for an app to be able to use to know how to
  1195. get them back in sync. */
  1196. for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
  1197. struct cciss_scsi_dev_t *sd =
  1198. &ccissscsi[h->ctlr].dev[i];
  1199. buflen += sprintf(&buffer[buflen], "c%db%dt%dl%d %02d "
  1200. "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
  1201. sh->host_no, sd->bus, sd->target, sd->lun,
  1202. sd->devtype,
  1203. sd->scsi3addr[0], sd->scsi3addr[1],
  1204. sd->scsi3addr[2], sd->scsi3addr[3],
  1205. sd->scsi3addr[4], sd->scsi3addr[5],
  1206. sd->scsi3addr[6], sd->scsi3addr[7]);
  1207. }
  1208. datalen = buflen - offset;
  1209. if (datalen < 0) { /* they're reading past EOF. */
  1210. datalen = 0;
  1211. *start = buffer+buflen;
  1212. } else
  1213. *start = buffer + offset;
  1214. return(datalen);
  1215. } else /* User is writing to /proc/scsi/cciss*?/?* ... */
  1216. return cciss_scsi_user_command(h, sh->host_no,
  1217. buffer, length);
  1218. }
  1219. /* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
  1220. dma mapping and fills in the scatter gather entries of the
  1221. cciss command, c. */
  1222. static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
  1223. struct scsi_cmnd *cmd)
  1224. {
  1225. unsigned int len;
  1226. struct scatterlist *sg;
  1227. __u64 addr64;
  1228. int request_nsgs, i, chained, sg_index;
  1229. struct cciss_scsi_adapter_data_t *sa = h->scsi_ctlr;
  1230. SGDescriptor_struct *curr_sg;
  1231. BUG_ON(scsi_sg_count(cmd) > h->maxsgentries);
  1232. chained = 0;
  1233. sg_index = 0;
  1234. curr_sg = c->SG;
  1235. request_nsgs = scsi_dma_map(cmd);
  1236. if (request_nsgs) {
  1237. scsi_for_each_sg(cmd, sg, request_nsgs, i) {
  1238. if (sg_index + 1 == h->max_cmd_sgentries &&
  1239. !chained && request_nsgs - i > 1) {
  1240. chained = 1;
  1241. sg_index = 0;
  1242. curr_sg = sa->cmd_sg_list[c->cmdindex];
  1243. }
  1244. addr64 = (__u64) sg_dma_address(sg);
  1245. len = sg_dma_len(sg);
  1246. curr_sg[sg_index].Addr.lower =
  1247. (__u32) (addr64 & 0x0FFFFFFFFULL);
  1248. curr_sg[sg_index].Addr.upper =
  1249. (__u32) ((addr64 >> 32) & 0x0FFFFFFFFULL);
  1250. curr_sg[sg_index].Len = len;
  1251. curr_sg[sg_index].Ext = 0;
  1252. ++sg_index;
  1253. }
  1254. if (chained)
  1255. cciss_map_sg_chain_block(h, c,
  1256. sa->cmd_sg_list[c->cmdindex],
  1257. (request_nsgs - (h->max_cmd_sgentries - 1)) *
  1258. sizeof(SGDescriptor_struct));
  1259. }
  1260. /* track how many SG entries we are using */
  1261. if (request_nsgs > h->maxSG)
  1262. h->maxSG = request_nsgs;
  1263. c->Header.SGTotal = (u16) request_nsgs + chained;
  1264. if (request_nsgs > h->max_cmd_sgentries)
  1265. c->Header.SGList = h->max_cmd_sgentries;
  1266. else
  1267. c->Header.SGList = c->Header.SGTotal;
  1268. return;
  1269. }
  1270. static int
  1271. cciss_scsi_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  1272. {
  1273. ctlr_info_t *h;
  1274. int rc;
  1275. unsigned char scsi3addr[8];
  1276. CommandList_struct *c;
  1277. unsigned long flags;
  1278. // Get the ptr to our adapter structure (hba[i]) out of cmd->host.
  1279. // We violate cmd->host privacy here. (Is there another way?)
  1280. h = (ctlr_info_t *) cmd->device->host->hostdata[0];
  1281. rc = lookup_scsi3addr(h, cmd->device->channel, cmd->device->id,
  1282. cmd->device->lun, scsi3addr);
  1283. if (rc != 0) {
  1284. /* the scsi nexus does not match any that we presented... */
  1285. /* pretend to mid layer that we got selection timeout */
  1286. cmd->result = DID_NO_CONNECT << 16;
  1287. done(cmd);
  1288. /* we might want to think about registering controller itself
  1289. as a processor device on the bus so sg binds to it. */
  1290. return 0;
  1291. }
  1292. /* Ok, we have a reasonable scsi nexus, so send the cmd down, and
  1293. see what the device thinks of it. */
  1294. spin_lock_irqsave(&h->lock, flags);
  1295. c = scsi_cmd_alloc(h);
  1296. spin_unlock_irqrestore(&h->lock, flags);
  1297. if (c == NULL) { /* trouble... */
  1298. dev_warn(&h->pdev->dev, "scsi_cmd_alloc returned NULL!\n");
  1299. /* FIXME: next 3 lines are -> BAD! <- */
  1300. cmd->result = DID_NO_CONNECT << 16;
  1301. done(cmd);
  1302. return 0;
  1303. }
  1304. // Fill in the command list header
  1305. cmd->scsi_done = done; // save this for use by completion code
  1306. /* save c in case we have to abort it */
  1307. cmd->host_scribble = (unsigned char *) c;
  1308. c->cmd_type = CMD_SCSI;
  1309. c->scsi_cmd = cmd;
  1310. c->Header.ReplyQueue = 0; /* unused in simple mode */
  1311. memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
  1312. c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
  1313. // Fill in the request block...
  1314. c->Request.Timeout = 0;
  1315. memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
  1316. BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB));
  1317. c->Request.CDBLen = cmd->cmd_len;
  1318. memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len);
  1319. c->Request.Type.Type = TYPE_CMD;
  1320. c->Request.Type.Attribute = ATTR_SIMPLE;
  1321. switch(cmd->sc_data_direction)
  1322. {
  1323. case DMA_TO_DEVICE:
  1324. c->Request.Type.Direction = XFER_WRITE;
  1325. break;
  1326. case DMA_FROM_DEVICE:
  1327. c->Request.Type.Direction = XFER_READ;
  1328. break;
  1329. case DMA_NONE:
  1330. c->Request.Type.Direction = XFER_NONE;
  1331. break;
  1332. case DMA_BIDIRECTIONAL:
  1333. // This can happen if a buggy application does a scsi passthru
  1334. // and sets both inlen and outlen to non-zero. ( see
  1335. // ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
  1336. c->Request.Type.Direction = XFER_RSVD;
  1337. // This is technically wrong, and cciss controllers should
  1338. // reject it with CMD_INVALID, which is the most correct
  1339. // response, but non-fibre backends appear to let it
  1340. // slide by, and give the same results as if this field
  1341. // were set correctly. Either way is acceptable for
  1342. // our purposes here.
  1343. break;
  1344. default:
  1345. dev_warn(&h->pdev->dev, "unknown data direction: %d\n",
  1346. cmd->sc_data_direction);
  1347. BUG();
  1348. break;
  1349. }
  1350. cciss_scatter_gather(h, c, cmd);
  1351. enqueue_cmd_and_start_io(h, c);
  1352. /* the cmd'll come back via intr handler in complete_scsi_command() */
  1353. return 0;
  1354. }
  1355. static DEF_SCSI_QCMD(cciss_scsi_queue_command)
  1356. static void cciss_unregister_scsi(ctlr_info_t *h)
  1357. {
  1358. struct cciss_scsi_adapter_data_t *sa;
  1359. struct cciss_scsi_cmd_stack_t *stk;
  1360. unsigned long flags;
  1361. /* we are being forcibly unloaded, and may not refuse. */
  1362. spin_lock_irqsave(&h->lock, flags);
  1363. sa = h->scsi_ctlr;
  1364. stk = &sa->cmd_stack;
  1365. /* if we weren't ever actually registered, don't unregister */
  1366. if (sa->registered) {
  1367. spin_unlock_irqrestore(&h->lock, flags);
  1368. scsi_remove_host(sa->scsi_host);
  1369. scsi_host_put(sa->scsi_host);
  1370. spin_lock_irqsave(&h->lock, flags);
  1371. }
  1372. /* set scsi_host to NULL so our detect routine will
  1373. find us on register */
  1374. sa->scsi_host = NULL;
  1375. spin_unlock_irqrestore(&h->lock, flags);
  1376. scsi_cmd_stack_free(h);
  1377. kfree(sa);
  1378. }
  1379. static int cciss_engage_scsi(ctlr_info_t *h)
  1380. {
  1381. struct cciss_scsi_adapter_data_t *sa;
  1382. struct cciss_scsi_cmd_stack_t *stk;
  1383. unsigned long flags;
  1384. spin_lock_irqsave(&h->lock, flags);
  1385. sa = h->scsi_ctlr;
  1386. stk = &sa->cmd_stack;
  1387. if (sa->registered) {
  1388. dev_info(&h->pdev->dev, "SCSI subsystem already engaged.\n");
  1389. spin_unlock_irqrestore(&h->lock, flags);
  1390. return -ENXIO;
  1391. }
  1392. sa->registered = 1;
  1393. spin_unlock_irqrestore(&h->lock, flags);
  1394. cciss_update_non_disk_devices(h, -1);
  1395. cciss_scsi_detect(h);
  1396. return 0;
  1397. }
  1398. static void
  1399. cciss_seq_tape_report(struct seq_file *seq, ctlr_info_t *h)
  1400. {
  1401. unsigned long flags;
  1402. CPQ_TAPE_LOCK(h, flags);
  1403. seq_printf(seq,
  1404. "Sequential access devices: %d\n\n",
  1405. ccissscsi[h->ctlr].ndevices);
  1406. CPQ_TAPE_UNLOCK(h, flags);
  1407. }
  1408. static int wait_for_device_to_become_ready(ctlr_info_t *h,
  1409. unsigned char lunaddr[])
  1410. {
  1411. int rc;
  1412. int count = 0;
  1413. int waittime = HZ;
  1414. CommandList_struct *c;
  1415. c = cmd_alloc(h);
  1416. if (!c) {
  1417. dev_warn(&h->pdev->dev, "out of memory in "
  1418. "wait_for_device_to_become_ready.\n");
  1419. return IO_ERROR;
  1420. }
  1421. /* Send test unit ready until device ready, or give up. */
  1422. while (count < 20) {
  1423. /* Wait for a bit. do this first, because if we send
  1424. * the TUR right away, the reset will just abort it.
  1425. */
  1426. schedule_timeout_uninterruptible(waittime);
  1427. count++;
  1428. /* Increase wait time with each try, up to a point. */
  1429. if (waittime < (HZ * 30))
  1430. waittime = waittime * 2;
  1431. /* Send the Test Unit Ready */
  1432. rc = fill_cmd(h, c, TEST_UNIT_READY, NULL, 0, 0,
  1433. lunaddr, TYPE_CMD);
  1434. if (rc == 0)
  1435. rc = sendcmd_withirq_core(h, c, 0);
  1436. (void) process_sendcmd_error(h, c);
  1437. if (rc != 0)
  1438. goto retry_tur;
  1439. if (c->err_info->CommandStatus == CMD_SUCCESS)
  1440. break;
  1441. if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
  1442. c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
  1443. if (c->err_info->SenseInfo[2] == NO_SENSE)
  1444. break;
  1445. if (c->err_info->SenseInfo[2] == UNIT_ATTENTION) {
  1446. unsigned char asc;
  1447. asc = c->err_info->SenseInfo[12];
  1448. check_for_unit_attention(h, c);
  1449. if (asc == POWER_OR_RESET)
  1450. break;
  1451. }
  1452. }
  1453. retry_tur:
  1454. dev_warn(&h->pdev->dev, "Waiting %d secs "
  1455. "for device to become ready.\n",
  1456. waittime / HZ);
  1457. rc = 1; /* device not ready. */
  1458. }
  1459. if (rc)
  1460. dev_warn(&h->pdev->dev, "giving up on device.\n");
  1461. else
  1462. dev_warn(&h->pdev->dev, "device is ready.\n");
  1463. cmd_free(h, c);
  1464. return rc;
  1465. }
  1466. /* Need at least one of these error handlers to keep ../scsi/hosts.c from
  1467. * complaining. Doing a host- or bus-reset can't do anything good here.
  1468. * Despite what it might say in scsi_error.c, there may well be commands
  1469. * on the controller, as the cciss driver registers twice, once as a block
  1470. * device for the logical drives, and once as a scsi device, for any tape
  1471. * drives. So we know there are no commands out on the tape drives, but we
  1472. * don't know there are no commands on the controller, and it is likely
  1473. * that there probably are, as the cciss block device is most commonly used
  1474. * as a boot device (embedded controller on HP/Compaq systems.)
  1475. */
  1476. static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
  1477. {
  1478. int rc;
  1479. CommandList_struct *cmd_in_trouble;
  1480. unsigned char lunaddr[8];
  1481. ctlr_info_t *h;
  1482. /* find the controller to which the command to be aborted was sent */
  1483. h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
  1484. if (h == NULL) /* paranoia */
  1485. return FAILED;
  1486. dev_warn(&h->pdev->dev, "resetting tape drive or medium changer.\n");
  1487. /* find the command that's giving us trouble */
  1488. cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
  1489. if (cmd_in_trouble == NULL) /* paranoia */
  1490. return FAILED;
  1491. memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
  1492. /* send a reset to the SCSI LUN which the command was sent to */
  1493. rc = sendcmd_withirq(h, CCISS_RESET_MSG, NULL, 0, 0, lunaddr,
  1494. TYPE_MSG);
  1495. if (rc == 0 && wait_for_device_to_become_ready(h, lunaddr) == 0)
  1496. return SUCCESS;
  1497. dev_warn(&h->pdev->dev, "resetting device failed.\n");
  1498. return FAILED;
  1499. }
  1500. static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
  1501. {
  1502. int rc;
  1503. CommandList_struct *cmd_to_abort;
  1504. unsigned char lunaddr[8];
  1505. ctlr_info_t *h;
  1506. /* find the controller to which the command to be aborted was sent */
  1507. h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
  1508. if (h == NULL) /* paranoia */
  1509. return FAILED;
  1510. dev_warn(&h->pdev->dev, "aborting tardy SCSI cmd\n");
  1511. /* find the command to be aborted */
  1512. cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
  1513. if (cmd_to_abort == NULL) /* paranoia */
  1514. return FAILED;
  1515. memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
  1516. rc = sendcmd_withirq(h, CCISS_ABORT_MSG, &cmd_to_abort->Header.Tag,
  1517. 0, 0, lunaddr, TYPE_MSG);
  1518. if (rc == 0)
  1519. return SUCCESS;
  1520. return FAILED;
  1521. }
  1522. #else /* no CONFIG_CISS_SCSI_TAPE */
  1523. /* If no tape support, then these become defined out of existence */
  1524. #define cciss_scsi_setup(cntl_num)
  1525. #endif /* CONFIG_CISS_SCSI_TAPE */