1 // SPDX-License-Identifier: GPL-2.0-only 2 3 /* 4 5 Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters 6 7 Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com> 8 9 10 The author respectfully requests that any modifications to this software be 11 sent directly to him for evaluation and testing. 12 13 Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose 14 advice has been invaluable, to David Gentzel, for writing the original Linux 15 BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site. 16 17 Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB 18 Manager available as freely redistributable source code. 19 20 */ 21 22 #define blogic_drvr_version "2.1.17" 23 #define blogic_drvr_date "12 September 2013" 24 25 #include <linux/module.h> 26 #include <linux/init.h> 27 #include <linux/interrupt.h> 28 #include <linux/types.h> 29 #include <linux/blkdev.h> 30 #include <linux/delay.h> 31 #include <linux/ioport.h> 32 #include <linux/mm.h> 33 #include <linux/stat.h> 34 #include <linux/pci.h> 35 #include <linux/spinlock.h> 36 #include <linux/jiffies.h> 37 #include <linux/dma-mapping.h> 38 #include <linux/slab.h> 39 #include <linux/msdos_partition.h> 40 #include <scsi/scsicam.h> 41 42 #include <asm/dma.h> 43 #include <asm/io.h> 44 45 #include <scsi/scsi.h> 46 #include <scsi/scsi_cmnd.h> 47 #include <scsi/scsi_device.h> 48 #include <scsi/scsi_host.h> 49 #include <scsi/scsi_tcq.h> 50 #include "BusLogic.h" 51 #include "FlashPoint.c" 52 53 #ifndef FAILURE 54 #define FAILURE (-1) 55 #endif 56 57 static const struct scsi_host_template blogic_template; 58 59 /* 60 blogic_drvr_options_count is a count of the number of BusLogic Driver 61 Options specifications provided via the Linux Kernel Command Line or via 62 the Loadable Kernel Module Installation Facility. 63 */ 64 65 static int blogic_drvr_options_count; 66 67 68 /* 69 blogic_drvr_options is an array of Driver Options structures representing 70 BusLogic Driver Options specifications provided via the Linux Kernel Command 71 Line or via the Loadable Kernel Module Installation Facility. 72 */ 73 74 static struct blogic_drvr_options blogic_drvr_options[BLOGIC_MAX_ADAPTERS]; 75 76 77 /* 78 BusLogic can be assigned a string by insmod. 79 */ 80 81 MODULE_DESCRIPTION("BusLogic MultiMaster and FlashPoint SCSI Host Adapter driver"); 82 MODULE_LICENSE("GPL"); 83 #ifdef MODULE 84 static char *BusLogic; 85 module_param(BusLogic, charp, 0); 86 #endif 87 88 89 /* 90 blogic_probe_options is a set of Probe Options to be applied across 91 all BusLogic Host Adapters. 92 */ 93 94 static struct blogic_probe_options blogic_probe_options; 95 96 97 /* 98 blogic_global_options is a set of Global Options to be applied across 99 all BusLogic Host Adapters. 100 */ 101 102 static struct blogic_global_options blogic_global_options; 103 104 static LIST_HEAD(blogic_host_list); 105 106 /* 107 blogic_probeinfo_count is the number of entries in blogic_probeinfo_list. 108 */ 109 110 static int blogic_probeinfo_count; 111 112 113 /* 114 blogic_probeinfo_list is the list of I/O Addresses and Bus Probe Information 115 to be checked for potential BusLogic Host Adapters. It is initialized by 116 interrogating the PCI Configuration Space on PCI machines as well as from the 117 list of standard BusLogic I/O Addresses. 118 */ 119 120 static struct blogic_probeinfo *blogic_probeinfo_list; 121 122 123 /* 124 blogic_cmd_failure_reason holds a string identifying the reason why a 125 call to blogic_cmd failed. It is only non-NULL when blogic_cmd 126 returns a failure code. 127 */ 128 129 static char *blogic_cmd_failure_reason; 130 131 /* 132 blogic_announce_drvr announces the Driver Version and Date, Author's 133 Name, Copyright Notice, and Electronic Mail Address. 134 */ 135 136 static void blogic_announce_drvr(struct blogic_adapter *adapter) 137 { 138 blogic_announce("***** BusLogic SCSI Driver Version " blogic_drvr_version " of " blogic_drvr_date " *****\n", adapter); 139 blogic_announce("Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>\n", adapter); 140 } 141 142 143 /* 144 blogic_drvr_info returns the Host Adapter Name to identify this SCSI 145 Driver and Host Adapter. 146 */ 147 148 static const char *blogic_drvr_info(struct Scsi_Host *host) 149 { 150 struct blogic_adapter *adapter = 151 (struct blogic_adapter *) host->hostdata; 152 return adapter->full_model; 153 } 154 155 /* 156 blogic_init_ccbs initializes a group of Command Control Blocks (CCBs) 157 for Host Adapter from the blk_size bytes located at blk_pointer. The newly 158 created CCBs are added to Host Adapter's free list. 159 */ 160 161 static void blogic_init_ccbs(struct blogic_adapter *adapter, void *blk_pointer, 162 int blk_size, dma_addr_t blkp) 163 { 164 struct blogic_ccb *ccb = (struct blogic_ccb *) blk_pointer; 165 unsigned int offset = 0; 166 memset(blk_pointer, 0, blk_size); 167 ccb->allocgrp_head = blkp; 168 ccb->allocgrp_size = blk_size; 169 while ((blk_size -= sizeof(struct blogic_ccb)) >= 0) { 170 ccb->status = BLOGIC_CCB_FREE; 171 ccb->adapter = adapter; 172 ccb->dma_handle = (u32) blkp + offset; 173 if (blogic_flashpoint_type(adapter)) { 174 ccb->callback = blogic_qcompleted_ccb; 175 ccb->base_addr = adapter->fpinfo.base_addr; 176 } 177 ccb->next = adapter->free_ccbs; 178 ccb->next_all = adapter->all_ccbs; 179 adapter->free_ccbs = ccb; 180 adapter->all_ccbs = ccb; 181 adapter->alloc_ccbs++; 182 ccb++; 183 offset += sizeof(struct blogic_ccb); 184 } 185 } 186 187 188 /* 189 blogic_create_initccbs allocates the initial CCBs for Host Adapter. 190 */ 191 192 static bool __init blogic_create_initccbs(struct blogic_adapter *adapter) 193 { 194 int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); 195 void *blk_pointer; 196 dma_addr_t blkp; 197 198 while (adapter->alloc_ccbs < adapter->initccbs) { 199 blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, 200 blk_size, &blkp, GFP_KERNEL); 201 if (blk_pointer == NULL) { 202 blogic_err("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n", 203 adapter); 204 return false; 205 } 206 blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); 207 } 208 return true; 209 } 210 211 212 /* 213 blogic_destroy_ccbs deallocates the CCBs for Host Adapter. 214 */ 215 216 static void blogic_destroy_ccbs(struct blogic_adapter *adapter) 217 { 218 struct blogic_ccb *next_ccb = adapter->all_ccbs, *ccb, *lastccb = NULL; 219 adapter->all_ccbs = NULL; 220 adapter->free_ccbs = NULL; 221 while ((ccb = next_ccb) != NULL) { 222 next_ccb = ccb->next_all; 223 if (ccb->allocgrp_head) { 224 if (lastccb) 225 dma_free_coherent(&adapter->pci_device->dev, 226 lastccb->allocgrp_size, lastccb, 227 lastccb->allocgrp_head); 228 lastccb = ccb; 229 } 230 } 231 if (lastccb) 232 dma_free_coherent(&adapter->pci_device->dev, 233 lastccb->allocgrp_size, lastccb, 234 lastccb->allocgrp_head); 235 } 236 237 238 /* 239 blogic_create_addlccbs allocates Additional CCBs for Host Adapter. If 240 allocation fails and there are no remaining CCBs available, the Driver Queue 241 Depth is decreased to a known safe value to avoid potential deadlocks when 242 multiple host adapters share the same IRQ Channel. 243 */ 244 245 static void blogic_create_addlccbs(struct blogic_adapter *adapter, 246 int addl_ccbs, bool print_success) 247 { 248 int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); 249 int prev_alloc = adapter->alloc_ccbs; 250 void *blk_pointer; 251 dma_addr_t blkp; 252 if (addl_ccbs <= 0) 253 return; 254 while (adapter->alloc_ccbs - prev_alloc < addl_ccbs) { 255 blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, 256 blk_size, &blkp, GFP_KERNEL); 257 if (blk_pointer == NULL) 258 break; 259 blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); 260 } 261 if (adapter->alloc_ccbs > prev_alloc) { 262 if (print_success) 263 blogic_notice("Allocated %d additional CCBs (total now %d)\n", adapter, adapter->alloc_ccbs - prev_alloc, adapter->alloc_ccbs); 264 return; 265 } 266 blogic_notice("Failed to allocate additional CCBs\n", adapter); 267 if (adapter->drvr_qdepth > adapter->alloc_ccbs - adapter->tgt_count) { 268 adapter->drvr_qdepth = adapter->alloc_ccbs - adapter->tgt_count; 269 adapter->scsi_host->can_queue = adapter->drvr_qdepth; 270 } 271 } 272 273 /* 274 blogic_alloc_ccb allocates a CCB from Host Adapter's free list, 275 allocating more memory from the Kernel if necessary. The Host Adapter's 276 Lock should already have been acquired by the caller. 277 */ 278 279 static struct blogic_ccb *blogic_alloc_ccb(struct Scsi_Host *host) 280 __must_hold(&host->host_lock) 281 { 282 struct blogic_adapter *adapter = (void *)host->hostdata; 283 static unsigned long serial; 284 struct blogic_ccb *ccb; 285 ccb = adapter->free_ccbs; 286 if (ccb != NULL) { 287 ccb->serial = ++serial; 288 adapter->free_ccbs = ccb->next; 289 ccb->next = NULL; 290 if (adapter->free_ccbs == NULL) 291 blogic_create_addlccbs(adapter, adapter->inc_ccbs, 292 true); 293 return ccb; 294 } 295 blogic_create_addlccbs(adapter, adapter->inc_ccbs, true); 296 ccb = adapter->free_ccbs; 297 if (ccb == NULL) 298 return NULL; 299 ccb->serial = ++serial; 300 adapter->free_ccbs = ccb->next; 301 ccb->next = NULL; 302 return ccb; 303 } 304 305 306 /* 307 blogic_dealloc_ccb deallocates a CCB, returning it to the Host Adapter's 308 free list. The Host Adapter's Lock should already have been acquired by the 309 caller. 310 */ 311 312 static void blogic_dealloc_ccb(struct Scsi_Host *host, struct blogic_ccb *ccb, 313 int dma_unmap) 314 __must_hold(&host->host_lock) 315 { 316 struct blogic_adapter *adapter = ccb->adapter; 317 318 if (ccb->command != NULL) 319 scsi_dma_unmap(ccb->command); 320 if (dma_unmap) 321 dma_unmap_single(&adapter->pci_device->dev, ccb->sensedata, 322 ccb->sense_datalen, DMA_FROM_DEVICE); 323 324 ccb->command = NULL; 325 ccb->status = BLOGIC_CCB_FREE; 326 ccb->next = adapter->free_ccbs; 327 adapter->free_ccbs = ccb; 328 } 329 330 331 /* 332 blogic_cmd sends the command opcode to adapter, optionally 333 providing paramlen bytes of param and receiving at most 334 replylen bytes of reply; any excess reply data is received but 335 discarded. 336 337 On success, this function returns the number of reply bytes read from 338 the Host Adapter (including any discarded data); on failure, it returns 339 -1 if the command was invalid, or -2 if a timeout occurred. 340 341 blogic_cmd is called exclusively during host adapter detection and 342 initialization, so performance and latency are not critical, and exclusive 343 access to the Host Adapter hardware is assumed. Once the host adapter and 344 driver are initialized, the only Host Adapter command that is issued is the 345 single byte Execute Mailbox Command operation code, which does not require 346 waiting for the Host Adapter Ready bit to be set in the Status Register. 347 */ 348 349 static int blogic_cmd(struct blogic_adapter *adapter, enum blogic_opcode opcode, 350 void *param, int paramlen, void *reply, int replylen) 351 { 352 unsigned char *param_p = (unsigned char *) param; 353 unsigned char *reply_p = (unsigned char *) reply; 354 union blogic_stat_reg statusreg; 355 union blogic_int_reg intreg; 356 unsigned long processor_flag = 0; 357 int reply_b = 0, result; 358 long timeout; 359 /* 360 Clear out the Reply Data if provided. 361 */ 362 if (replylen > 0) 363 memset(reply, 0, replylen); 364 /* 365 If the IRQ Channel has not yet been acquired, then interrupts 366 must be disabled while issuing host adapter commands since a 367 Command Complete interrupt could occur if the IRQ Channel was 368 previously enabled by another BusLogic Host Adapter or another 369 driver sharing the same IRQ Channel. 370 */ 371 if (!adapter->irq_acquired) 372 local_irq_save(processor_flag); 373 /* 374 Wait for the Host Adapter Ready bit to be set and the 375 Command/Parameter Register Busy bit to be reset in the Status 376 Register. 377 */ 378 timeout = 10000; 379 while (--timeout >= 0) { 380 statusreg.all = blogic_rdstatus(adapter); 381 if (statusreg.sr.adapter_ready && !statusreg.sr.cmd_param_busy) 382 break; 383 udelay(100); 384 } 385 if (timeout < 0) { 386 blogic_cmd_failure_reason = 387 "Timeout waiting for Host Adapter Ready"; 388 result = -2; 389 goto done; 390 } 391 /* 392 Write the opcode to the Command/Parameter Register. 393 */ 394 adapter->adapter_cmd_complete = false; 395 blogic_setcmdparam(adapter, opcode); 396 /* 397 Write any additional Parameter Bytes. 398 */ 399 timeout = 10000; 400 while (paramlen > 0 && --timeout >= 0) { 401 /* 402 Wait 100 microseconds to give the Host Adapter enough 403 time to determine whether the last value written to the 404 Command/Parameter Register was valid or not. If the 405 Command Complete bit is set in the Interrupt Register, 406 then the Command Invalid bit in the Status Register will 407 be reset if the Operation Code or Parameter was valid 408 and the command has completed, or set if the Operation 409 Code or Parameter was invalid. If the Data In Register 410 Ready bit is set in the Status Register, then the 411 Operation Code was valid, and data is waiting to be read 412 back from the Host Adapter. Otherwise, wait for the 413 Command/Parameter Register Busy bit in the Status 414 Register to be reset. 415 */ 416 udelay(100); 417 intreg.all = blogic_rdint(adapter); 418 statusreg.all = blogic_rdstatus(adapter); 419 if (intreg.ir.cmd_complete) 420 break; 421 if (adapter->adapter_cmd_complete) 422 break; 423 if (statusreg.sr.datain_ready) 424 break; 425 if (statusreg.sr.cmd_param_busy) 426 continue; 427 blogic_setcmdparam(adapter, *param_p++); 428 paramlen--; 429 } 430 if (timeout < 0) { 431 blogic_cmd_failure_reason = 432 "Timeout waiting for Parameter Acceptance"; 433 result = -2; 434 goto done; 435 } 436 /* 437 The Modify I/O Address command does not cause a Command Complete 438 Interrupt. 439 */ 440 if (opcode == BLOGIC_MOD_IOADDR) { 441 statusreg.all = blogic_rdstatus(adapter); 442 if (statusreg.sr.cmd_invalid) { 443 blogic_cmd_failure_reason = 444 "Modify I/O Address Invalid"; 445 result = -1; 446 goto done; 447 } 448 if (blogic_global_options.trace_config) 449 blogic_notice("blogic_cmd(%02X) Status = %02X: (Modify I/O Address)\n", adapter, opcode, statusreg.all); 450 result = 0; 451 goto done; 452 } 453 /* 454 Select an appropriate timeout value for awaiting command completion. 455 */ 456 switch (opcode) { 457 case BLOGIC_INQ_DEV0TO7: 458 case BLOGIC_INQ_DEV8TO15: 459 case BLOGIC_INQ_DEV: 460 /* Approximately 60 seconds. */ 461 timeout = 60 * 10000; 462 break; 463 default: 464 /* Approximately 1 second. */ 465 timeout = 10000; 466 break; 467 } 468 /* 469 Receive any Reply Bytes, waiting for either the Command 470 Complete bit to be set in the Interrupt Register, or for the 471 Interrupt Handler to set the Host Adapter Command Completed 472 bit in the Host Adapter structure. 473 */ 474 while (--timeout >= 0) { 475 intreg.all = blogic_rdint(adapter); 476 statusreg.all = blogic_rdstatus(adapter); 477 if (intreg.ir.cmd_complete) 478 break; 479 if (adapter->adapter_cmd_complete) 480 break; 481 if (statusreg.sr.datain_ready) { 482 if (++reply_b <= replylen) 483 *reply_p++ = blogic_rddatain(adapter); 484 else 485 blogic_rddatain(adapter); 486 } 487 if (opcode == BLOGIC_FETCH_LOCALRAM && 488 statusreg.sr.adapter_ready) 489 break; 490 udelay(100); 491 } 492 if (timeout < 0) { 493 blogic_cmd_failure_reason = 494 "Timeout waiting for Command Complete"; 495 result = -2; 496 goto done; 497 } 498 /* 499 Clear any pending Command Complete Interrupt. 500 */ 501 blogic_intreset(adapter); 502 /* 503 Provide tracing information if requested. 504 */ 505 if (blogic_global_options.trace_config) { 506 int i; 507 blogic_notice("blogic_cmd(%02X) Status = %02X: %2d ==> %2d:", 508 adapter, opcode, statusreg.all, replylen, 509 reply_b); 510 if (replylen > reply_b) 511 replylen = reply_b; 512 for (i = 0; i < replylen; i++) 513 blogic_notice(" %02X", adapter, 514 ((unsigned char *) reply)[i]); 515 blogic_notice("\n", adapter); 516 } 517 /* 518 Process Command Invalid conditions. 519 */ 520 if (statusreg.sr.cmd_invalid) { 521 /* 522 Some early BusLogic Host Adapters may not recover 523 properly from a Command Invalid condition, so if this 524 appears to be the case, a Soft Reset is issued to the 525 Host Adapter. Potentially invalid commands are never 526 attempted after Mailbox Initialization is performed, 527 so there should be no Host Adapter state lost by a 528 Soft Reset in response to a Command Invalid condition. 529 */ 530 udelay(1000); 531 statusreg.all = blogic_rdstatus(adapter); 532 if (statusreg.sr.cmd_invalid || statusreg.sr.rsvd || 533 statusreg.sr.datain_ready || 534 statusreg.sr.cmd_param_busy || 535 !statusreg.sr.adapter_ready || 536 !statusreg.sr.init_reqd || 537 statusreg.sr.diag_active || 538 statusreg.sr.diag_failed) { 539 blogic_softreset(adapter); 540 udelay(1000); 541 } 542 blogic_cmd_failure_reason = "Command Invalid"; 543 result = -1; 544 goto done; 545 } 546 /* 547 Handle Excess Parameters Supplied conditions. 548 */ 549 if (paramlen > 0) { 550 blogic_cmd_failure_reason = "Excess Parameters Supplied"; 551 result = -1; 552 goto done; 553 } 554 /* 555 Indicate the command completed successfully. 556 */ 557 blogic_cmd_failure_reason = NULL; 558 result = reply_b; 559 /* 560 Restore the interrupt status if necessary and return. 561 */ 562 done: 563 if (!adapter->irq_acquired) 564 local_irq_restore(processor_flag); 565 return result; 566 } 567 568 569 /* 570 blogic_sort_probeinfo sorts a section of blogic_probeinfo_list in order 571 of increasing PCI Bus and Device Number. 572 */ 573 574 static void __init blogic_sort_probeinfo(struct blogic_probeinfo 575 *probeinfo_list, int probeinfo_cnt) 576 { 577 int last_exchange = probeinfo_cnt - 1, bound, j; 578 579 while (last_exchange > 0) { 580 bound = last_exchange; 581 last_exchange = 0; 582 for (j = 0; j < bound; j++) { 583 struct blogic_probeinfo *probeinfo1 = 584 &probeinfo_list[j]; 585 struct blogic_probeinfo *probeinfo2 = 586 &probeinfo_list[j + 1]; 587 if (probeinfo1->bus > probeinfo2->bus || 588 (probeinfo1->bus == probeinfo2->bus && 589 (probeinfo1->dev > probeinfo2->dev))) { 590 struct blogic_probeinfo tmp_probeinfo; 591 592 memcpy(&tmp_probeinfo, probeinfo1, 593 sizeof(struct blogic_probeinfo)); 594 memcpy(probeinfo1, probeinfo2, 595 sizeof(struct blogic_probeinfo)); 596 memcpy(probeinfo2, &tmp_probeinfo, 597 sizeof(struct blogic_probeinfo)); 598 last_exchange = j; 599 } 600 } 601 } 602 } 603 604 605 /* 606 blogic_init_mm_probeinfo initializes the list of I/O Address 607 and Bus Probe Information to be checked for potential BusLogic MultiMaster 608 SCSI Host Adapters by interrogating the PCI Configuration Space on PCI 609 machines as well as from the list of standard BusLogic MultiMaster ISA 610 I/O Addresses. It returns the number of PCI MultiMaster Host Adapters found. 611 */ 612 613 static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter) 614 { 615 struct blogic_probeinfo *pr_probeinfo = 616 &blogic_probeinfo_list[blogic_probeinfo_count]; 617 int nonpr_mmindex = blogic_probeinfo_count + 1; 618 int nonpr_mmcount = 0, mmcount = 0; 619 bool force_scan_order = false; 620 bool force_scan_order_checked = false; 621 struct pci_dev *pci_device = NULL; 622 int i; 623 if (blogic_probeinfo_count >= BLOGIC_MAX_ADAPTERS) 624 return 0; 625 blogic_probeinfo_count++; 626 /* 627 Iterate over the MultiMaster PCI Host Adapters. For each 628 enumerated host adapter, determine whether its ISA Compatible 629 I/O Port is enabled and if so, whether it is assigned the 630 Primary I/O Address. A host adapter that is assigned the 631 Primary I/O Address will always be the preferred boot device. 632 The MultiMaster BIOS will first recognize a host adapter at 633 the Primary I/O Address, then any other PCI host adapters, 634 and finally any host adapters located at the remaining 635 standard ISA I/O Addresses. When a PCI host adapter is found 636 with its ISA Compatible I/O Port enabled, a command is issued 637 to disable the ISA Compatible I/O Port, and it is noted that the 638 particular standard ISA I/O Address need not be probed. 639 */ 640 pr_probeinfo->io_addr = 0; 641 while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, 642 PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, 643 pci_device)) != NULL) { 644 struct blogic_adapter *host_adapter = adapter; 645 struct blogic_adapter_info adapter_info; 646 enum blogic_isa_ioport mod_ioaddr_req; 647 unsigned char bus; 648 unsigned char device; 649 unsigned int irq_ch; 650 unsigned long base_addr0; 651 unsigned long base_addr1; 652 unsigned long io_addr; 653 unsigned long pci_addr; 654 655 if (pci_enable_device(pci_device)) 656 continue; 657 658 if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32))) 659 continue; 660 661 bus = pci_device->bus->number; 662 device = pci_device->devfn >> 3; 663 irq_ch = pci_device->irq; 664 io_addr = base_addr0 = pci_resource_start(pci_device, 0); 665 pci_addr = base_addr1 = pci_resource_start(pci_device, 1); 666 667 if (pci_resource_flags(pci_device, 0) & IORESOURCE_MEM) { 668 blogic_err("BusLogic: Base Address0 0x%lX not I/O for MultiMaster Host Adapter\n", NULL, base_addr0); 669 blogic_err("at PCI Bus %d Device %d I/O Address 0x%lX\n", NULL, bus, device, io_addr); 670 continue; 671 } 672 if (pci_resource_flags(pci_device, 1) & IORESOURCE_IO) { 673 blogic_err("BusLogic: Base Address1 0x%lX not Memory for MultiMaster Host Adapter\n", NULL, base_addr1); 674 blogic_err("at PCI Bus %d Device %d PCI Address 0x%lX\n", NULL, bus, device, pci_addr); 675 continue; 676 } 677 if (irq_ch == 0) { 678 blogic_err("BusLogic: IRQ Channel %d invalid for MultiMaster Host Adapter\n", NULL, irq_ch); 679 blogic_err("at PCI Bus %d Device %d I/O Address 0x%lX\n", NULL, bus, device, io_addr); 680 continue; 681 } 682 if (blogic_global_options.trace_probe) { 683 blogic_notice("BusLogic: PCI MultiMaster Host Adapter detected at\n", NULL); 684 blogic_notice("BusLogic: PCI Bus %d Device %d I/O Address 0x%lX PCI Address 0x%lX\n", NULL, bus, device, io_addr, pci_addr); 685 } 686 /* 687 Issue the Inquire PCI Host Adapter Information command to determine 688 the ISA Compatible I/O Port. If the ISA Compatible I/O Port is 689 known and enabled, note that the particular Standard ISA I/O 690 Address should not be probed. 691 */ 692 host_adapter->io_addr = io_addr; 693 blogic_intreset(host_adapter); 694 if (blogic_cmd(host_adapter, BLOGIC_INQ_PCI_INFO, NULL, 0, 695 &adapter_info, sizeof(adapter_info)) != 696 sizeof(adapter_info)) 697 adapter_info.isa_port = BLOGIC_IO_DISABLE; 698 /* 699 Issue the Modify I/O Address command to disable the 700 ISA Compatible I/O Port. On PCI Host Adapters, the 701 Modify I/O Address command allows modification of the 702 ISA compatible I/O Address that the Host Adapter 703 responds to; it does not affect the PCI compliant 704 I/O Address assigned at system initialization. 705 */ 706 mod_ioaddr_req = BLOGIC_IO_DISABLE; 707 blogic_cmd(host_adapter, BLOGIC_MOD_IOADDR, &mod_ioaddr_req, 708 sizeof(mod_ioaddr_req), NULL, 0); 709 /* 710 For the first MultiMaster Host Adapter enumerated, 711 issue the Fetch Host Adapter Local RAM command to read 712 byte 45 of the AutoSCSI area, for the setting of the 713 "Use Bus And Device # For PCI Scanning Seq." option. 714 Issue the Inquire Board ID command since this option is 715 only valid for the BT-948/958/958D. 716 */ 717 if (!force_scan_order_checked) { 718 struct blogic_fetch_localram fetch_localram; 719 struct blogic_autoscsi_byte45 autoscsi_byte45; 720 struct blogic_board_id id; 721 722 fetch_localram.offset = BLOGIC_AUTOSCSI_BASE + 45; 723 fetch_localram.count = sizeof(autoscsi_byte45); 724 blogic_cmd(host_adapter, BLOGIC_FETCH_LOCALRAM, 725 &fetch_localram, sizeof(fetch_localram), 726 &autoscsi_byte45, 727 sizeof(autoscsi_byte45)); 728 blogic_cmd(host_adapter, BLOGIC_GET_BOARD_ID, NULL, 0, 729 &id, sizeof(id)); 730 if (id.fw_ver_digit1 == '5') 731 force_scan_order = 732 autoscsi_byte45.force_scan_order; 733 force_scan_order_checked = true; 734 } 735 /* 736 Determine whether this MultiMaster Host Adapter has its 737 ISA Compatible I/O Port enabled and is assigned the 738 Primary I/O Address. If it does, then it is the Primary 739 MultiMaster Host Adapter and must be recognized first. 740 If it does not, then it is added to the list for probing 741 after any Primary MultiMaster Host Adapter is probed. 742 */ 743 if (adapter_info.isa_port == BLOGIC_IO_330) { 744 pr_probeinfo->adapter_type = BLOGIC_MULTIMASTER; 745 pr_probeinfo->adapter_bus_type = BLOGIC_PCI_BUS; 746 pr_probeinfo->io_addr = io_addr; 747 pr_probeinfo->pci_addr = pci_addr; 748 pr_probeinfo->bus = bus; 749 pr_probeinfo->dev = device; 750 pr_probeinfo->irq_ch = irq_ch; 751 pr_probeinfo->pci_device = pci_dev_get(pci_device); 752 mmcount++; 753 } else if (blogic_probeinfo_count < BLOGIC_MAX_ADAPTERS) { 754 struct blogic_probeinfo *probeinfo = 755 &blogic_probeinfo_list[blogic_probeinfo_count++]; 756 probeinfo->adapter_type = BLOGIC_MULTIMASTER; 757 probeinfo->adapter_bus_type = BLOGIC_PCI_BUS; 758 probeinfo->io_addr = io_addr; 759 probeinfo->pci_addr = pci_addr; 760 probeinfo->bus = bus; 761 probeinfo->dev = device; 762 probeinfo->irq_ch = irq_ch; 763 probeinfo->pci_device = pci_dev_get(pci_device); 764 nonpr_mmcount++; 765 mmcount++; 766 } else 767 blogic_warn("BusLogic: Too many Host Adapters detected\n", NULL); 768 } 769 /* 770 If the AutoSCSI "Use Bus And Device # For PCI Scanning Seq." 771 option is ON for the first enumerated MultiMaster Host Adapter, 772 and if that host adapter is a BT-948/958/958D, then the 773 MultiMaster BIOS will recognize MultiMaster Host Adapters in 774 the order of increasing PCI Bus and Device Number. In that case, 775 sort the probe information into the same order the BIOS uses. 776 If this option is OFF, then the MultiMaster BIOS will recognize 777 MultiMaster Host Adapters in the order they are enumerated by 778 the PCI BIOS, and hence no sorting is necessary. 779 */ 780 if (force_scan_order) 781 blogic_sort_probeinfo(&blogic_probeinfo_list[nonpr_mmindex], 782 nonpr_mmcount); 783 /* 784 Iterate over the older non-compliant MultiMaster PCI Host Adapters, 785 noting the PCI bus location and assigned IRQ Channel. 786 */ 787 pci_device = NULL; 788 while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, 789 PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC, 790 pci_device)) != NULL) { 791 unsigned char bus; 792 unsigned char device; 793 unsigned int irq_ch; 794 unsigned long io_addr; 795 796 if (pci_enable_device(pci_device)) 797 continue; 798 799 if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32))) 800 continue; 801 802 bus = pci_device->bus->number; 803 device = pci_device->devfn >> 3; 804 irq_ch = pci_device->irq; 805 io_addr = pci_resource_start(pci_device, 0); 806 807 if (io_addr == 0 || irq_ch == 0) 808 continue; 809 for (i = 0; i < blogic_probeinfo_count; i++) { 810 struct blogic_probeinfo *probeinfo = 811 &blogic_probeinfo_list[i]; 812 if (probeinfo->io_addr == io_addr && 813 probeinfo->adapter_type == BLOGIC_MULTIMASTER) { 814 probeinfo->adapter_bus_type = BLOGIC_PCI_BUS; 815 probeinfo->pci_addr = 0; 816 probeinfo->bus = bus; 817 probeinfo->dev = device; 818 probeinfo->irq_ch = irq_ch; 819 probeinfo->pci_device = pci_dev_get(pci_device); 820 break; 821 } 822 } 823 } 824 return mmcount; 825 } 826 827 828 /* 829 blogic_init_fp_probeinfo initializes the list of I/O Address 830 and Bus Probe Information to be checked for potential BusLogic FlashPoint 831 Host Adapters by interrogating the PCI Configuration Space. It returns the 832 number of FlashPoint Host Adapters found. 833 */ 834 835 static int __init blogic_init_fp_probeinfo(struct blogic_adapter *adapter) 836 { 837 int fpindex = blogic_probeinfo_count, fpcount = 0; 838 struct pci_dev *pci_device = NULL; 839 /* 840 Interrogate PCI Configuration Space for any FlashPoint Host Adapters. 841 */ 842 while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, 843 PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT, 844 pci_device)) != NULL) { 845 unsigned char bus; 846 unsigned char device; 847 unsigned int irq_ch; 848 unsigned long base_addr0; 849 unsigned long base_addr1; 850 unsigned long io_addr; 851 unsigned long pci_addr; 852 853 if (pci_enable_device(pci_device)) 854 continue; 855 856 if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32))) 857 continue; 858 859 bus = pci_device->bus->number; 860 device = pci_device->devfn >> 3; 861 irq_ch = pci_device->irq; 862 io_addr = base_addr0 = pci_resource_start(pci_device, 0); 863 pci_addr = base_addr1 = pci_resource_start(pci_device, 1); 864 #ifdef CONFIG_SCSI_FLASHPOINT 865 if (pci_resource_flags(pci_device, 0) & IORESOURCE_MEM) { 866 blogic_err("BusLogic: Base Address0 0x%lX not I/O for FlashPoint Host Adapter\n", NULL, base_addr0); 867 blogic_err("at PCI Bus %d Device %d I/O Address 0x%lX\n", NULL, bus, device, io_addr); 868 continue; 869 } 870 if (pci_resource_flags(pci_device, 1) & IORESOURCE_IO) { 871 blogic_err("BusLogic: Base Address1 0x%lX not Memory for FlashPoint Host Adapter\n", NULL, base_addr1); 872 blogic_err("at PCI Bus %d Device %d PCI Address 0x%lX\n", NULL, bus, device, pci_addr); 873 continue; 874 } 875 if (irq_ch == 0) { 876 blogic_err("BusLogic: IRQ Channel %d invalid for FlashPoint Host Adapter\n", NULL, irq_ch); 877 blogic_err("at PCI Bus %d Device %d I/O Address 0x%lX\n", NULL, bus, device, io_addr); 878 continue; 879 } 880 if (blogic_global_options.trace_probe) { 881 blogic_notice("BusLogic: FlashPoint Host Adapter detected at\n", NULL); 882 blogic_notice("BusLogic: PCI Bus %d Device %d I/O Address 0x%lX PCI Address 0x%lX\n", NULL, bus, device, io_addr, pci_addr); 883 } 884 if (blogic_probeinfo_count < BLOGIC_MAX_ADAPTERS) { 885 struct blogic_probeinfo *probeinfo = 886 &blogic_probeinfo_list[blogic_probeinfo_count++]; 887 probeinfo->adapter_type = BLOGIC_FLASHPOINT; 888 probeinfo->adapter_bus_type = BLOGIC_PCI_BUS; 889 probeinfo->io_addr = io_addr; 890 probeinfo->pci_addr = pci_addr; 891 probeinfo->bus = bus; 892 probeinfo->dev = device; 893 probeinfo->irq_ch = irq_ch; 894 probeinfo->pci_device = pci_dev_get(pci_device); 895 fpcount++; 896 } else 897 blogic_warn("BusLogic: Too many Host Adapters detected\n", NULL); 898 #else 899 blogic_err("BusLogic: FlashPoint Host Adapter detected at PCI Bus %d Device %d\n", NULL, bus, device); 900 blogic_err("BusLogic: I/O Address 0x%lX PCI Address 0x%lX, irq %d, but FlashPoint\n", NULL, io_addr, pci_addr, irq_ch); 901 blogic_err("BusLogic: support was omitted in this kernel configuration.\n", NULL); 902 #endif 903 } 904 /* 905 The FlashPoint BIOS will scan for FlashPoint Host Adapters in the order of 906 increasing PCI Bus and Device Number, so sort the probe information into 907 the same order the BIOS uses. 908 */ 909 blogic_sort_probeinfo(&blogic_probeinfo_list[fpindex], fpcount); 910 return fpcount; 911 } 912 913 914 /* 915 blogic_init_probeinfo_list initializes the list of I/O Address and Bus 916 Probe Information to be checked for potential BusLogic SCSI Host Adapters by 917 interrogating the PCI Configuration Space on PCI machines as well as from the 918 list of standard BusLogic MultiMaster ISA I/O Addresses. By default, if both 919 FlashPoint and PCI MultiMaster Host Adapters are present, this driver will 920 probe for FlashPoint Host Adapters first unless the BIOS primary disk is 921 controlled by the first PCI MultiMaster Host Adapter, in which case 922 MultiMaster Host Adapters will be probed first. The BusLogic Driver Options 923 specifications "MultiMasterFirst" and "FlashPointFirst" can be used to force 924 a particular probe order. 925 */ 926 927 static noinline_for_stack void __init 928 blogic_init_probeinfo_list(struct blogic_adapter *adapter) 929 { 930 /* 931 If a PCI BIOS is present, interrogate it for MultiMaster and 932 FlashPoint Host Adapters; otherwise, default to the standard 933 ISA MultiMaster probe. 934 */ 935 if (!blogic_probe_options.noprobe_pci) { 936 if (blogic_probe_options.multimaster_first) { 937 blogic_init_mm_probeinfo(adapter); 938 blogic_init_fp_probeinfo(adapter); 939 } else if (blogic_probe_options.flashpoint_first) { 940 blogic_init_fp_probeinfo(adapter); 941 blogic_init_mm_probeinfo(adapter); 942 } else { 943 int fpcount = blogic_init_fp_probeinfo(adapter); 944 int mmcount = blogic_init_mm_probeinfo(adapter); 945 if (fpcount > 0 && mmcount > 0) { 946 struct blogic_probeinfo *probeinfo = 947 &blogic_probeinfo_list[fpcount]; 948 struct blogic_adapter *myadapter = adapter; 949 struct blogic_fetch_localram fetch_localram; 950 struct blogic_bios_drvmap d0_mapbyte; 951 952 while (probeinfo->adapter_bus_type != 953 BLOGIC_PCI_BUS) 954 probeinfo++; 955 myadapter->io_addr = probeinfo->io_addr; 956 fetch_localram.offset = 957 BLOGIC_BIOS_BASE + BLOGIC_BIOS_DRVMAP; 958 fetch_localram.count = sizeof(d0_mapbyte); 959 blogic_cmd(myadapter, BLOGIC_FETCH_LOCALRAM, 960 &fetch_localram, 961 sizeof(fetch_localram), 962 &d0_mapbyte, 963 sizeof(d0_mapbyte)); 964 /* 965 If the Map Byte for BIOS Drive 0 indicates 966 that BIOS Drive 0 is controlled by this 967 PCI MultiMaster Host Adapter, then reverse 968 the probe order so that MultiMaster Host 969 Adapters are probed before FlashPoint Host 970 Adapters. 971 */ 972 if (d0_mapbyte.diskgeom != BLOGIC_BIOS_NODISK) { 973 struct blogic_probeinfo saved_probeinfo[BLOGIC_MAX_ADAPTERS]; 974 int mmcount = blogic_probeinfo_count - fpcount; 975 976 memcpy(saved_probeinfo, 977 blogic_probeinfo_list, 978 blogic_probeinfo_count * sizeof(struct blogic_probeinfo)); 979 memcpy(&blogic_probeinfo_list[0], 980 &saved_probeinfo[fpcount], 981 mmcount * sizeof(struct blogic_probeinfo)); 982 memcpy(&blogic_probeinfo_list[mmcount], 983 &saved_probeinfo[0], 984 fpcount * sizeof(struct blogic_probeinfo)); 985 } 986 } 987 } 988 } 989 } 990 991 992 /* 993 blogic_failure prints a standardized error message, and then returns false. 994 */ 995 996 static bool blogic_failure(struct blogic_adapter *adapter, char *msg) 997 { 998 blogic_announce_drvr(adapter); 999 if (adapter->adapter_bus_type == BLOGIC_PCI_BUS) { 1000 blogic_err("While configuring BusLogic PCI Host Adapter at\n", 1001 adapter); 1002 blogic_err("Bus %d Device %d I/O Address 0x%lX PCI Address 0x%lX:\n", adapter, adapter->bus, adapter->dev, adapter->io_addr, adapter->pci_addr); 1003 } else 1004 blogic_err("While configuring BusLogic Host Adapter at I/O Address 0x%lX:\n", adapter, adapter->io_addr); 1005 blogic_err("%s FAILED - DETACHING\n", adapter, msg); 1006 if (blogic_cmd_failure_reason != NULL) 1007 blogic_err("ADDITIONAL FAILURE INFO - %s\n", adapter, 1008 blogic_cmd_failure_reason); 1009 return false; 1010 } 1011 1012 1013 /* 1014 blogic_probe probes for a BusLogic Host Adapter. 1015 */ 1016 1017 static bool __init blogic_probe(struct blogic_adapter *adapter) 1018 { 1019 union blogic_stat_reg statusreg; 1020 union blogic_int_reg intreg; 1021 union blogic_geo_reg georeg; 1022 /* 1023 FlashPoint Host Adapters are Probed by the FlashPoint SCCB Manager. 1024 */ 1025 if (blogic_flashpoint_type(adapter)) { 1026 struct fpoint_info *fpinfo = &adapter->fpinfo; 1027 fpinfo->base_addr = (u32) adapter->io_addr; 1028 fpinfo->irq_ch = adapter->irq_ch; 1029 fpinfo->present = false; 1030 if (!(FlashPoint_ProbeHostAdapter(fpinfo) == 0 && 1031 fpinfo->present)) { 1032 blogic_err("BusLogic: FlashPoint Host Adapter detected at PCI Bus %d Device %d\n", adapter, adapter->bus, adapter->dev); 1033 blogic_err("BusLogic: I/O Address 0x%lX PCI Address 0x%lX, but FlashPoint\n", adapter, adapter->io_addr, adapter->pci_addr); 1034 blogic_err("BusLogic: Probe Function failed to validate it.\n", adapter); 1035 return false; 1036 } 1037 if (blogic_global_options.trace_probe) 1038 blogic_notice("BusLogic_Probe(0x%lX): FlashPoint Found\n", adapter, adapter->io_addr); 1039 /* 1040 Indicate the Host Adapter Probe completed successfully. 1041 */ 1042 return true; 1043 } 1044 /* 1045 Read the Status, Interrupt, and Geometry Registers to test if there are I/O 1046 ports that respond, and to check the values to determine if they are from a 1047 BusLogic Host Adapter. A nonexistent I/O port will return 0xFF, in which 1048 case there is definitely no BusLogic Host Adapter at this base I/O Address. 1049 The test here is a subset of that used by the BusLogic Host Adapter BIOS. 1050 */ 1051 statusreg.all = blogic_rdstatus(adapter); 1052 intreg.all = blogic_rdint(adapter); 1053 georeg.all = blogic_rdgeom(adapter); 1054 if (blogic_global_options.trace_probe) 1055 blogic_notice("BusLogic_Probe(0x%lX): Status 0x%02X, Interrupt 0x%02X, Geometry 0x%02X\n", adapter, adapter->io_addr, statusreg.all, intreg.all, georeg.all); 1056 if (statusreg.all == 0 || statusreg.sr.diag_active || 1057 statusreg.sr.cmd_param_busy || statusreg.sr.rsvd || 1058 statusreg.sr.cmd_invalid || intreg.ir.rsvd != 0) 1059 return false; 1060 /* 1061 Check the undocumented Geometry Register to test if there is 1062 an I/O port that responded. Adaptec Host Adapters do not 1063 implement the Geometry Register, so this test helps serve to 1064 avoid incorrectly recognizing an Adaptec 1542A or 1542B as a 1065 BusLogic. Unfortunately, the Adaptec 1542C series does respond 1066 to the Geometry Register I/O port, but it will be rejected 1067 later when the Inquire Extended Setup Information command is 1068 issued in blogic_checkadapter. The AMI FastDisk Host Adapter 1069 is a BusLogic clone that implements the same interface as 1070 earlier BusLogic Host Adapters, including the undocumented 1071 commands, and is therefore supported by this driver. However, 1072 the AMI FastDisk always returns 0x00 upon reading the Geometry 1073 Register, so the extended translation option should always be 1074 left disabled on the AMI FastDisk. 1075 */ 1076 if (georeg.all == 0xFF) 1077 return false; 1078 /* 1079 Indicate the Host Adapter Probe completed successfully. 1080 */ 1081 return true; 1082 } 1083 1084 1085 /* 1086 blogic_hwreset issues a Hardware Reset to the Host Adapter 1087 and waits for Host Adapter Diagnostics to complete. If hard_reset is true, a 1088 Hard Reset is performed which also initiates a SCSI Bus Reset. Otherwise, a 1089 Soft Reset is performed which only resets the Host Adapter without forcing a 1090 SCSI Bus Reset. 1091 */ 1092 1093 static bool blogic_hwreset(struct blogic_adapter *adapter, bool hard_reset) 1094 { 1095 union blogic_stat_reg statusreg; 1096 int timeout; 1097 /* 1098 FlashPoint Host Adapters are Hard Reset by the FlashPoint 1099 SCCB Manager. 1100 */ 1101 if (blogic_flashpoint_type(adapter)) { 1102 struct fpoint_info *fpinfo = &adapter->fpinfo; 1103 fpinfo->softreset = !hard_reset; 1104 fpinfo->report_underrun = true; 1105 adapter->cardhandle = 1106 FlashPoint_HardwareResetHostAdapter(fpinfo); 1107 if (adapter->cardhandle == (void *)FPOINT_BADCARD_HANDLE) 1108 return false; 1109 /* 1110 Indicate the Host Adapter Hard Reset completed successfully. 1111 */ 1112 return true; 1113 } 1114 /* 1115 Issue a Hard Reset or Soft Reset Command to the Host Adapter. 1116 The Host Adapter should respond by setting Diagnostic Active in 1117 the Status Register. 1118 */ 1119 if (hard_reset) 1120 blogic_hardreset(adapter); 1121 else 1122 blogic_softreset(adapter); 1123 /* 1124 Wait until Diagnostic Active is set in the Status Register. 1125 */ 1126 timeout = 5 * 10000; 1127 while (--timeout >= 0) { 1128 statusreg.all = blogic_rdstatus(adapter); 1129 if (statusreg.sr.diag_active) 1130 break; 1131 udelay(100); 1132 } 1133 if (blogic_global_options.trace_hw_reset) 1134 blogic_notice("BusLogic_HardwareReset(0x%lX): Diagnostic Active, Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all); 1135 if (timeout < 0) 1136 return false; 1137 /* 1138 Wait 100 microseconds to allow completion of any initial diagnostic 1139 activity which might leave the contents of the Status Register 1140 unpredictable. 1141 */ 1142 udelay(100); 1143 /* 1144 Wait until Diagnostic Active is reset in the Status Register. 1145 */ 1146 timeout = 10 * 10000; 1147 while (--timeout >= 0) { 1148 statusreg.all = blogic_rdstatus(adapter); 1149 if (!statusreg.sr.diag_active) 1150 break; 1151 udelay(100); 1152 } 1153 if (blogic_global_options.trace_hw_reset) 1154 blogic_notice("BusLogic_HardwareReset(0x%lX): Diagnostic Completed, Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all); 1155 if (timeout < 0) 1156 return false; 1157 /* 1158 Wait until at least one of the Diagnostic Failure, Host Adapter 1159 Ready, or Data In Register Ready bits is set in the Status Register. 1160 */ 1161 timeout = 10000; 1162 while (--timeout >= 0) { 1163 statusreg.all = blogic_rdstatus(adapter); 1164 if (statusreg.sr.diag_failed || statusreg.sr.adapter_ready || 1165 statusreg.sr.datain_ready) 1166 break; 1167 udelay(100); 1168 } 1169 if (blogic_global_options.trace_hw_reset) 1170 blogic_notice("BusLogic_HardwareReset(0x%lX): Host Adapter Ready, Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all); 1171 if (timeout < 0) 1172 return false; 1173 /* 1174 If Diagnostic Failure is set or Host Adapter Ready is reset, 1175 then an error occurred during the Host Adapter diagnostics. 1176 If Data In Register Ready is set, then there is an Error Code 1177 available. 1178 */ 1179 if (statusreg.sr.diag_failed || !statusreg.sr.adapter_ready) { 1180 blogic_cmd_failure_reason = NULL; 1181 blogic_failure(adapter, "HARD RESET DIAGNOSTICS"); 1182 blogic_err("HOST ADAPTER STATUS REGISTER = %02X\n", adapter, 1183 statusreg.all); 1184 if (statusreg.sr.datain_ready) 1185 blogic_err("HOST ADAPTER ERROR CODE = %d\n", adapter, 1186 blogic_rddatain(adapter)); 1187 return false; 1188 } 1189 /* 1190 Indicate the Host Adapter Hard Reset completed successfully. 1191 */ 1192 return true; 1193 } 1194 1195 1196 /* 1197 blogic_checkadapter checks to be sure this really is a BusLogic 1198 Host Adapter. 1199 */ 1200 1201 static bool __init blogic_checkadapter(struct blogic_adapter *adapter) 1202 { 1203 struct blogic_ext_setup ext_setupinfo; 1204 unsigned char req_replylen; 1205 bool result = true; 1206 /* 1207 FlashPoint Host Adapters do not require this protection. 1208 */ 1209 if (blogic_flashpoint_type(adapter)) 1210 return true; 1211 /* 1212 Issue the Inquire Extended Setup Information command. Only genuine 1213 BusLogic Host Adapters and true clones support this command. 1214 Adaptec 1542C series Host Adapters that respond to the Geometry 1215 Register I/O port will fail this command. 1216 */ 1217 req_replylen = sizeof(ext_setupinfo); 1218 if (blogic_cmd(adapter, BLOGIC_INQ_EXTSETUP, &req_replylen, 1219 sizeof(req_replylen), &ext_setupinfo, 1220 sizeof(ext_setupinfo)) != sizeof(ext_setupinfo)) 1221 result = false; 1222 /* 1223 Provide tracing information if requested and return. 1224 */ 1225 if (blogic_global_options.trace_probe) 1226 blogic_notice("BusLogic_Check(0x%lX): MultiMaster %s\n", adapter, 1227 adapter->io_addr, 1228 (result ? "Found" : "Not Found")); 1229 return result; 1230 } 1231 1232 1233 /* 1234 blogic_rdconfig reads the Configuration Information 1235 from Host Adapter and initializes the Host Adapter structure. 1236 */ 1237 1238 static bool __init blogic_rdconfig(struct blogic_adapter *adapter) 1239 { 1240 struct blogic_board_id id; 1241 struct blogic_config config; 1242 struct blogic_setup_info setupinfo; 1243 struct blogic_ext_setup ext_setupinfo; 1244 unsigned char model[5]; 1245 unsigned char fw_ver_digit3; 1246 unsigned char fw_ver_letter; 1247 struct blogic_adapter_info adapter_info; 1248 struct blogic_fetch_localram fetch_localram; 1249 struct blogic_autoscsi autoscsi; 1250 union blogic_geo_reg georeg; 1251 unsigned char req_replylen; 1252 unsigned char *tgt, ch; 1253 int tgt_id, i; 1254 /* 1255 Configuration Information for FlashPoint Host Adapters is 1256 provided in the fpoint_info structure by the FlashPoint 1257 SCCB Manager's Probe Function. Initialize fields in the 1258 Host Adapter structure from the fpoint_info structure. 1259 */ 1260 if (blogic_flashpoint_type(adapter)) { 1261 struct fpoint_info *fpinfo = &adapter->fpinfo; 1262 tgt = adapter->model; 1263 *tgt++ = 'B'; 1264 *tgt++ = 'T'; 1265 *tgt++ = '-'; 1266 for (i = 0; i < sizeof(fpinfo->model); i++) 1267 *tgt++ = fpinfo->model[i]; 1268 *tgt++ = '\0'; 1269 strcpy(adapter->fw_ver, FLASHPOINT_FW_VER); 1270 adapter->scsi_id = fpinfo->scsi_id; 1271 adapter->ext_trans_enable = fpinfo->ext_trans_enable; 1272 adapter->parity = fpinfo->parity; 1273 adapter->reset_enabled = !fpinfo->softreset; 1274 adapter->level_int = true; 1275 adapter->wide = fpinfo->wide; 1276 adapter->differential = false; 1277 adapter->scam = true; 1278 adapter->ultra = true; 1279 adapter->ext_lun = true; 1280 adapter->terminfo_valid = true; 1281 adapter->low_term = fpinfo->low_term; 1282 adapter->high_term = fpinfo->high_term; 1283 adapter->scam_enabled = fpinfo->scam_enabled; 1284 adapter->scam_lev2 = fpinfo->scam_lev2; 1285 adapter->drvr_sglimit = BLOGIC_SG_LIMIT; 1286 adapter->maxdev = (adapter->wide ? 16 : 8); 1287 adapter->maxlun = 32; 1288 adapter->initccbs = 4 * BLOGIC_CCB_GRP_ALLOCSIZE; 1289 adapter->inc_ccbs = BLOGIC_CCB_GRP_ALLOCSIZE; 1290 adapter->drvr_qdepth = 255; 1291 adapter->adapter_qdepth = adapter->drvr_qdepth; 1292 adapter->sync_ok = fpinfo->sync_ok; 1293 adapter->fast_ok = fpinfo->fast_ok; 1294 adapter->ultra_ok = fpinfo->ultra_ok; 1295 adapter->wide_ok = fpinfo->wide_ok; 1296 adapter->discon_ok = fpinfo->discon_ok; 1297 adapter->tagq_ok = 0xFFFF; 1298 goto common; 1299 } 1300 /* 1301 Issue the Inquire Board ID command. 1302 */ 1303 if (blogic_cmd(adapter, BLOGIC_GET_BOARD_ID, NULL, 0, &id, 1304 sizeof(id)) != sizeof(id)) 1305 return blogic_failure(adapter, "INQUIRE BOARD ID"); 1306 /* 1307 Issue the Inquire Configuration command. 1308 */ 1309 if (blogic_cmd(adapter, BLOGIC_INQ_CONFIG, NULL, 0, &config, 1310 sizeof(config)) 1311 != sizeof(config)) 1312 return blogic_failure(adapter, "INQUIRE CONFIGURATION"); 1313 /* 1314 Issue the Inquire Setup Information command. 1315 */ 1316 req_replylen = sizeof(setupinfo); 1317 if (blogic_cmd(adapter, BLOGIC_INQ_SETUPINFO, &req_replylen, 1318 sizeof(req_replylen), &setupinfo, 1319 sizeof(setupinfo)) != sizeof(setupinfo)) 1320 return blogic_failure(adapter, "INQUIRE SETUP INFORMATION"); 1321 /* 1322 Issue the Inquire Extended Setup Information command. 1323 */ 1324 req_replylen = sizeof(ext_setupinfo); 1325 if (blogic_cmd(adapter, BLOGIC_INQ_EXTSETUP, &req_replylen, 1326 sizeof(req_replylen), &ext_setupinfo, 1327 sizeof(ext_setupinfo)) != sizeof(ext_setupinfo)) 1328 return blogic_failure(adapter, 1329 "INQUIRE EXTENDED SETUP INFORMATION"); 1330 /* 1331 Issue the Inquire Firmware Version 3rd Digit command. 1332 */ 1333 fw_ver_digit3 = '\0'; 1334 if (id.fw_ver_digit1 > '0') 1335 if (blogic_cmd(adapter, BLOGIC_INQ_FWVER_D3, NULL, 0, 1336 &fw_ver_digit3, 1337 sizeof(fw_ver_digit3)) != sizeof(fw_ver_digit3)) 1338 return blogic_failure(adapter, 1339 "INQUIRE FIRMWARE 3RD DIGIT"); 1340 /* 1341 Issue the Inquire Host Adapter Model Number command. 1342 */ 1343 if (ext_setupinfo.bus_type == 'A' && id.fw_ver_digit1 == '2') 1344 /* BusLogic BT-542B ISA 2.xx */ 1345 strcpy(model, "542B"); 1346 else if (ext_setupinfo.bus_type == 'E' && id.fw_ver_digit1 == '2' && 1347 (id.fw_ver_digit2 <= '1' || (id.fw_ver_digit2 == '2' && 1348 fw_ver_digit3 == '0'))) 1349 /* BusLogic BT-742A EISA 2.1x or 2.20 */ 1350 strcpy(model, "742A"); 1351 else if (ext_setupinfo.bus_type == 'E' && id.fw_ver_digit1 == '0') 1352 /* AMI FastDisk EISA Series 441 0.x */ 1353 strcpy(model, "747A"); 1354 else { 1355 req_replylen = sizeof(model); 1356 if (blogic_cmd(adapter, BLOGIC_INQ_MODELNO, &req_replylen, 1357 sizeof(req_replylen), &model, 1358 sizeof(model)) != sizeof(model)) 1359 return blogic_failure(adapter, 1360 "INQUIRE HOST ADAPTER MODEL NUMBER"); 1361 } 1362 /* 1363 BusLogic MultiMaster Host Adapters can be identified by their 1364 model number and the major version number of their firmware 1365 as follows: 1366 1367 5.xx BusLogic "W" Series Host Adapters: 1368 BT-948/958/958D 1369 4.xx BusLogic "C" Series Host Adapters: 1370 BT-946C/956C/956CD/747C/757C/757CD/445C/545C/540CF 1371 3.xx BusLogic "S" Series Host Adapters: 1372 BT-747S/747D/757S/757D/445S/545S/542D 1373 BT-542B/742A (revision H) 1374 2.xx BusLogic "A" Series Host Adapters: 1375 BT-542B/742A (revision G and below) 1376 0.xx AMI FastDisk VLB/EISA BusLogic Clone Host Adapter 1377 */ 1378 /* 1379 Save the Model Name and Host Adapter Name in the Host Adapter 1380 structure. 1381 */ 1382 tgt = adapter->model; 1383 *tgt++ = 'B'; 1384 *tgt++ = 'T'; 1385 *tgt++ = '-'; 1386 for (i = 0; i < sizeof(model); i++) { 1387 ch = model[i]; 1388 if (ch == ' ' || ch == '\0') 1389 break; 1390 *tgt++ = ch; 1391 } 1392 *tgt++ = '\0'; 1393 /* 1394 Save the Firmware Version in the Host Adapter structure. 1395 */ 1396 tgt = adapter->fw_ver; 1397 *tgt++ = id.fw_ver_digit1; 1398 *tgt++ = '.'; 1399 *tgt++ = id.fw_ver_digit2; 1400 if (fw_ver_digit3 != ' ' && fw_ver_digit3 != '\0') 1401 *tgt++ = fw_ver_digit3; 1402 *tgt = '\0'; 1403 /* 1404 Issue the Inquire Firmware Version Letter command. 1405 */ 1406 if (strcmp(adapter->fw_ver, "3.3") >= 0) { 1407 if (blogic_cmd(adapter, BLOGIC_INQ_FWVER_LETTER, NULL, 0, 1408 &fw_ver_letter, 1409 sizeof(fw_ver_letter)) != sizeof(fw_ver_letter)) 1410 return blogic_failure(adapter, 1411 "INQUIRE FIRMWARE VERSION LETTER"); 1412 if (fw_ver_letter != ' ' && fw_ver_letter != '\0') 1413 *tgt++ = fw_ver_letter; 1414 *tgt = '\0'; 1415 } 1416 /* 1417 Save the Host Adapter SCSI ID in the Host Adapter structure. 1418 */ 1419 adapter->scsi_id = config.id; 1420 /* 1421 Determine the Bus Type and save it in the Host Adapter structure, 1422 determine and save the IRQ Channel if necessary, and determine 1423 and save the DMA Channel for ISA Host Adapters. 1424 */ 1425 adapter->adapter_bus_type = 1426 blogic_adater_bus_types[adapter->model[3] - '4']; 1427 if (adapter->irq_ch == 0) { 1428 if (config.irq_ch9) 1429 adapter->irq_ch = 9; 1430 else if (config.irq_ch10) 1431 adapter->irq_ch = 10; 1432 else if (config.irq_ch11) 1433 adapter->irq_ch = 11; 1434 else if (config.irq_ch12) 1435 adapter->irq_ch = 12; 1436 else if (config.irq_ch14) 1437 adapter->irq_ch = 14; 1438 else if (config.irq_ch15) 1439 adapter->irq_ch = 15; 1440 } 1441 /* 1442 Determine whether Extended Translation is enabled and save it in 1443 the Host Adapter structure. 1444 */ 1445 georeg.all = blogic_rdgeom(adapter); 1446 adapter->ext_trans_enable = georeg.gr.ext_trans_enable; 1447 /* 1448 Save the Scatter Gather Limits, Level Sensitive Interrupt flag, Wide 1449 SCSI flag, Differential SCSI flag, SCAM Supported flag, and 1450 Ultra SCSI flag in the Host Adapter structure. 1451 */ 1452 adapter->adapter_sglimit = ext_setupinfo.sg_limit; 1453 adapter->drvr_sglimit = adapter->adapter_sglimit; 1454 if (adapter->adapter_sglimit > BLOGIC_SG_LIMIT) 1455 adapter->drvr_sglimit = BLOGIC_SG_LIMIT; 1456 if (ext_setupinfo.misc.level_int) 1457 adapter->level_int = true; 1458 adapter->wide = ext_setupinfo.wide; 1459 adapter->differential = ext_setupinfo.differential; 1460 adapter->scam = ext_setupinfo.scam; 1461 adapter->ultra = ext_setupinfo.ultra; 1462 /* 1463 Determine whether Extended LUN Format CCBs are supported and save the 1464 information in the Host Adapter structure. 1465 */ 1466 if (adapter->fw_ver[0] == '5' || (adapter->fw_ver[0] == '4' && 1467 adapter->wide)) 1468 adapter->ext_lun = true; 1469 /* 1470 Issue the Inquire PCI Host Adapter Information command to read the 1471 Termination Information from "W" series MultiMaster Host Adapters. 1472 */ 1473 if (adapter->fw_ver[0] == '5') { 1474 if (blogic_cmd(adapter, BLOGIC_INQ_PCI_INFO, NULL, 0, 1475 &adapter_info, 1476 sizeof(adapter_info)) != sizeof(adapter_info)) 1477 return blogic_failure(adapter, 1478 "INQUIRE PCI HOST ADAPTER INFORMATION"); 1479 /* 1480 Save the Termination Information in the Host Adapter 1481 structure. 1482 */ 1483 if (adapter_info.genericinfo_valid) { 1484 adapter->terminfo_valid = true; 1485 adapter->low_term = adapter_info.low_term; 1486 adapter->high_term = adapter_info.high_term; 1487 } 1488 } 1489 /* 1490 Issue the Fetch Host Adapter Local RAM command to read the 1491 AutoSCSI data from "W" and "C" series MultiMaster Host Adapters. 1492 */ 1493 if (adapter->fw_ver[0] >= '4') { 1494 fetch_localram.offset = BLOGIC_AUTOSCSI_BASE; 1495 fetch_localram.count = sizeof(autoscsi); 1496 if (blogic_cmd(adapter, BLOGIC_FETCH_LOCALRAM, &fetch_localram, 1497 sizeof(fetch_localram), &autoscsi, 1498 sizeof(autoscsi)) != sizeof(autoscsi)) 1499 return blogic_failure(adapter, 1500 "FETCH HOST ADAPTER LOCAL RAM"); 1501 /* 1502 Save the Parity Checking Enabled, Bus Reset Enabled, 1503 and Termination Information in the Host Adapter structure. 1504 */ 1505 adapter->parity = autoscsi.parity; 1506 adapter->reset_enabled = autoscsi.reset_enabled; 1507 if (adapter->fw_ver[0] == '4') { 1508 adapter->terminfo_valid = true; 1509 adapter->low_term = autoscsi.low_term; 1510 adapter->high_term = autoscsi.high_term; 1511 } 1512 /* 1513 Save the Wide Permitted, Fast Permitted, Synchronous 1514 Permitted, Disconnect Permitted, Ultra Permitted, and 1515 SCAM Information in the Host Adapter structure. 1516 */ 1517 adapter->wide_ok = autoscsi.wide_ok; 1518 adapter->fast_ok = autoscsi.fast_ok; 1519 adapter->sync_ok = autoscsi.sync_ok; 1520 adapter->discon_ok = autoscsi.discon_ok; 1521 if (adapter->ultra) 1522 adapter->ultra_ok = autoscsi.ultra_ok; 1523 if (adapter->scam) { 1524 adapter->scam_enabled = autoscsi.scam_enabled; 1525 adapter->scam_lev2 = autoscsi.scam_lev2; 1526 } 1527 } 1528 /* 1529 Initialize fields in the Host Adapter structure for "S" and "A" 1530 series MultiMaster Host Adapters. 1531 */ 1532 if (adapter->fw_ver[0] < '4') { 1533 if (setupinfo.sync) { 1534 adapter->sync_ok = 0xFF; 1535 if (adapter->adapter_bus_type == BLOGIC_EISA_BUS) { 1536 if (ext_setupinfo.misc.fast_on_eisa) 1537 adapter->fast_ok = 0xFF; 1538 if (strcmp(adapter->model, "BT-757") == 0) 1539 adapter->wide_ok = 0xFF; 1540 } 1541 } 1542 adapter->discon_ok = 0xFF; 1543 adapter->parity = setupinfo.parity; 1544 adapter->reset_enabled = true; 1545 } 1546 /* 1547 Determine the maximum number of Target IDs and Logical Units 1548 supported by this driver for Wide and Narrow Host Adapters. 1549 */ 1550 adapter->maxdev = (adapter->wide ? 16 : 8); 1551 adapter->maxlun = (adapter->ext_lun ? 32 : 8); 1552 /* 1553 Select appropriate values for the Mailbox Count, Driver Queue Depth, 1554 Initial CCBs, and Incremental CCBs variables based on whether 1555 or not Strict Round Robin Mode is supported. If Strict Round 1556 Robin Mode is supported, then there is no performance degradation 1557 in using the maximum possible number of Outgoing and Incoming 1558 Mailboxes and allowing the Tagged and Untagged Queue Depths to 1559 determine the actual utilization. If Strict Round Robin Mode is 1560 not supported, then the Host Adapter must scan all the Outgoing 1561 Mailboxes whenever an Outgoing Mailbox entry is made, which can 1562 cause a substantial performance penalty. The host adapters 1563 actually have room to store the following number of CCBs 1564 internally; that is, they can internally queue and manage this 1565 many active commands on the SCSI bus simultaneously. Performance 1566 measurements demonstrate that the Driver Queue Depth should be 1567 set to the Mailbox Count, rather than the Host Adapter Queue 1568 Depth (internal CCB capacity), as it is more efficient to have the 1569 queued commands waiting in Outgoing Mailboxes if necessary than 1570 to block the process in the higher levels of the SCSI Subsystem. 1571 1572 192 BT-948/958/958D 1573 100 BT-946C/956C/956CD/747C/757C/757CD/445C 1574 50 BT-545C/540CF 1575 30 BT-747S/747D/757S/757D/445S/545S/542D/542B/742A 1576 */ 1577 if (adapter->fw_ver[0] == '5') 1578 adapter->adapter_qdepth = 192; 1579 else if (adapter->fw_ver[0] == '4') 1580 adapter->adapter_qdepth = 100; 1581 else 1582 adapter->adapter_qdepth = 30; 1583 if (strcmp(adapter->fw_ver, "3.31") >= 0) { 1584 adapter->strict_rr = true; 1585 adapter->mbox_count = BLOGIC_MAX_MAILBOX; 1586 } else { 1587 adapter->strict_rr = false; 1588 adapter->mbox_count = 32; 1589 } 1590 adapter->drvr_qdepth = adapter->mbox_count; 1591 adapter->initccbs = 4 * BLOGIC_CCB_GRP_ALLOCSIZE; 1592 adapter->inc_ccbs = BLOGIC_CCB_GRP_ALLOCSIZE; 1593 /* 1594 Tagged Queuing support is available and operates properly on 1595 all "W" series MultiMaster Host Adapters, on "C" series 1596 MultiMaster Host Adapters with firmware version 4.22 and above, 1597 and on "S" series MultiMaster Host Adapters with firmware version 1598 3.35 and above. 1599 */ 1600 adapter->tagq_ok = 0; 1601 switch (adapter->fw_ver[0]) { 1602 case '5': 1603 adapter->tagq_ok = 0xFFFF; 1604 break; 1605 case '4': 1606 if (strcmp(adapter->fw_ver, "4.22") >= 0) 1607 adapter->tagq_ok = 0xFFFF; 1608 break; 1609 case '3': 1610 if (strcmp(adapter->fw_ver, "3.35") >= 0) 1611 adapter->tagq_ok = 0xFFFF; 1612 break; 1613 } 1614 /* 1615 Determine the Host Adapter BIOS Address if the BIOS is enabled and 1616 save it in the Host Adapter structure. The BIOS is disabled if the 1617 bios_addr is 0. 1618 */ 1619 adapter->bios_addr = ext_setupinfo.bios_addr << 12; 1620 /* 1621 BusLogic BT-445S Host Adapters prior to board revision E have a 1622 hardware bug whereby when the BIOS is enabled, transfers to/from 1623 the same address range the BIOS occupies modulo 16MB are handled 1624 incorrectly. Only properly functioning BT-445S Host Adapters 1625 have firmware version 3.37. 1626 */ 1627 if (adapter->bios_addr > 0 && 1628 strcmp(adapter->model, "BT-445S") == 0 && 1629 strcmp(adapter->fw_ver, "3.37") < 0) 1630 return blogic_failure(adapter, "Too old firmware"); 1631 /* 1632 Initialize parameters common to MultiMaster and FlashPoint 1633 Host Adapters. 1634 */ 1635 common: 1636 /* 1637 Initialize the Host Adapter Full Model Name from the Model Name. 1638 */ 1639 scnprintf(adapter->full_model, sizeof(adapter->full_model), 1640 "BusLogic %s", adapter->model); 1641 /* 1642 Select an appropriate value for the Tagged Queue Depth either from a 1643 BusLogic Driver Options specification, or based on whether this Host 1644 Adapter requires that ISA Bounce Buffers be used. The Tagged Queue 1645 Depth is left at 0 for automatic determination in 1646 BusLogic_SelectQueueDepths. Initialize the Untagged Queue Depth. 1647 */ 1648 for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) { 1649 unsigned char qdepth = 0; 1650 if (adapter->drvr_opts != NULL && 1651 adapter->drvr_opts->qdepth[tgt_id] > 0) 1652 qdepth = adapter->drvr_opts->qdepth[tgt_id]; 1653 adapter->qdepth[tgt_id] = qdepth; 1654 } 1655 adapter->untag_qdepth = BLOGIC_UNTAG_DEPTH; 1656 if (adapter->drvr_opts != NULL) 1657 adapter->common_qdepth = adapter->drvr_opts->common_qdepth; 1658 if (adapter->common_qdepth > 0 && 1659 adapter->common_qdepth < adapter->untag_qdepth) 1660 adapter->untag_qdepth = adapter->common_qdepth; 1661 /* 1662 Tagged Queuing is only allowed if Disconnect/Reconnect is permitted. 1663 Therefore, mask the Tagged Queuing Permitted Default bits with the 1664 Disconnect/Reconnect Permitted bits. 1665 */ 1666 adapter->tagq_ok &= adapter->discon_ok; 1667 /* 1668 Combine the default Tagged Queuing Permitted bits with any 1669 BusLogic Driver Options Tagged Queuing specification. 1670 */ 1671 if (adapter->drvr_opts != NULL) 1672 adapter->tagq_ok = (adapter->drvr_opts->tagq_ok & 1673 adapter->drvr_opts->tagq_ok_mask) | 1674 (adapter->tagq_ok & ~adapter->drvr_opts->tagq_ok_mask); 1675 1676 /* 1677 Select an appropriate value for Bus Settle Time either from a 1678 BusLogic Driver Options specification, or from 1679 BLOGIC_BUS_SETTLE_TIME. 1680 */ 1681 if (adapter->drvr_opts != NULL && 1682 adapter->drvr_opts->bus_settle_time > 0) 1683 adapter->bus_settle_time = adapter->drvr_opts->bus_settle_time; 1684 else 1685 adapter->bus_settle_time = BLOGIC_BUS_SETTLE_TIME; 1686 /* 1687 Indicate reading the Host Adapter Configuration completed 1688 successfully. 1689 */ 1690 return true; 1691 } 1692 1693 1694 /* 1695 blogic_reportconfig reports the configuration of Host Adapter. 1696 */ 1697 1698 static noinline_for_stack bool __init 1699 blogic_reportconfig(struct blogic_adapter *adapter) 1700 { 1701 unsigned short alltgt_mask = (1 << adapter->maxdev) - 1; 1702 unsigned short sync_ok, fast_ok; 1703 unsigned short ultra_ok, wide_ok; 1704 unsigned short discon_ok, tagq_ok; 1705 bool common_syncneg, common_tagq_depth; 1706 char syncstr[BLOGIC_MAXDEV + 1]; 1707 char widestr[BLOGIC_MAXDEV + 1]; 1708 char discon_str[BLOGIC_MAXDEV + 1]; 1709 char tagq_str[BLOGIC_MAXDEV + 1]; 1710 char *syncmsg = syncstr; 1711 char *widemsg = widestr; 1712 char *discon_msg = discon_str; 1713 char *tagq_msg = tagq_str; 1714 int tgt_id; 1715 1716 blogic_info("Configuring BusLogic Model %s %s%s%s%s SCSI Host Adapter\n", adapter, adapter->model, blogic_adapter_busnames[adapter->adapter_bus_type], (adapter->wide ? " Wide" : ""), (adapter->differential ? " Differential" : ""), (adapter->ultra ? " Ultra" : "")); 1717 blogic_info(" Firmware Version: %s, I/O Address: 0x%lX, IRQ Channel: %d/%s\n", adapter, adapter->fw_ver, adapter->io_addr, adapter->irq_ch, (adapter->level_int ? "Level" : "Edge")); 1718 if (adapter->adapter_bus_type != BLOGIC_PCI_BUS) { 1719 blogic_info(" DMA Channel: None, ", adapter); 1720 if (adapter->bios_addr > 0) 1721 blogic_info("BIOS Address: 0x%X, ", adapter, 1722 adapter->bios_addr); 1723 else 1724 blogic_info("BIOS Address: None, ", adapter); 1725 } else { 1726 blogic_info(" PCI Bus: %d, Device: %d, Address: ", adapter, 1727 adapter->bus, adapter->dev); 1728 if (adapter->pci_addr > 0) 1729 blogic_info("0x%lX, ", adapter, adapter->pci_addr); 1730 else 1731 blogic_info("Unassigned, ", adapter); 1732 } 1733 blogic_info("Host Adapter SCSI ID: %d\n", adapter, adapter->scsi_id); 1734 blogic_info(" Parity Checking: %s, Extended Translation: %s\n", 1735 adapter, (adapter->parity ? "Enabled" : "Disabled"), 1736 (adapter->ext_trans_enable ? "Enabled" : "Disabled")); 1737 alltgt_mask &= ~(1 << adapter->scsi_id); 1738 sync_ok = adapter->sync_ok & alltgt_mask; 1739 fast_ok = adapter->fast_ok & alltgt_mask; 1740 ultra_ok = adapter->ultra_ok & alltgt_mask; 1741 if ((blogic_multimaster_type(adapter) && 1742 (adapter->fw_ver[0] >= '4' || 1743 adapter->adapter_bus_type == BLOGIC_EISA_BUS)) || 1744 blogic_flashpoint_type(adapter)) { 1745 common_syncneg = false; 1746 if (sync_ok == 0) { 1747 syncmsg = "Disabled"; 1748 common_syncneg = true; 1749 } else if (sync_ok == alltgt_mask) { 1750 if (fast_ok == 0) { 1751 syncmsg = "Slow"; 1752 common_syncneg = true; 1753 } else if (fast_ok == alltgt_mask) { 1754 if (ultra_ok == 0) { 1755 syncmsg = "Fast"; 1756 common_syncneg = true; 1757 } else if (ultra_ok == alltgt_mask) { 1758 syncmsg = "Ultra"; 1759 common_syncneg = true; 1760 } 1761 } 1762 } 1763 if (!common_syncneg) { 1764 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 1765 syncstr[tgt_id] = ((!(sync_ok & (1 << tgt_id))) ? 'N' : (!(fast_ok & (1 << tgt_id)) ? 'S' : (!(ultra_ok & (1 << tgt_id)) ? 'F' : 'U'))); 1766 syncstr[adapter->scsi_id] = '#'; 1767 syncstr[adapter->maxdev] = '\0'; 1768 } 1769 } else 1770 syncmsg = (sync_ok == 0 ? "Disabled" : "Enabled"); 1771 wide_ok = adapter->wide_ok & alltgt_mask; 1772 if (wide_ok == 0) 1773 widemsg = "Disabled"; 1774 else if (wide_ok == alltgt_mask) 1775 widemsg = "Enabled"; 1776 else { 1777 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 1778 widestr[tgt_id] = ((wide_ok & (1 << tgt_id)) ? 'Y' : 'N'); 1779 widestr[adapter->scsi_id] = '#'; 1780 widestr[adapter->maxdev] = '\0'; 1781 } 1782 discon_ok = adapter->discon_ok & alltgt_mask; 1783 if (discon_ok == 0) 1784 discon_msg = "Disabled"; 1785 else if (discon_ok == alltgt_mask) 1786 discon_msg = "Enabled"; 1787 else { 1788 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 1789 discon_str[tgt_id] = ((discon_ok & (1 << tgt_id)) ? 'Y' : 'N'); 1790 discon_str[adapter->scsi_id] = '#'; 1791 discon_str[adapter->maxdev] = '\0'; 1792 } 1793 tagq_ok = adapter->tagq_ok & alltgt_mask; 1794 if (tagq_ok == 0) 1795 tagq_msg = "Disabled"; 1796 else if (tagq_ok == alltgt_mask) 1797 tagq_msg = "Enabled"; 1798 else { 1799 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 1800 tagq_str[tgt_id] = ((tagq_ok & (1 << tgt_id)) ? 'Y' : 'N'); 1801 tagq_str[adapter->scsi_id] = '#'; 1802 tagq_str[adapter->maxdev] = '\0'; 1803 } 1804 blogic_info(" Synchronous Negotiation: %s, Wide Negotiation: %s\n", 1805 adapter, syncmsg, widemsg); 1806 blogic_info(" Disconnect/Reconnect: %s, Tagged Queuing: %s\n", adapter, 1807 discon_msg, tagq_msg); 1808 if (blogic_multimaster_type(adapter)) { 1809 blogic_info(" Scatter/Gather Limit: %d of %d segments, Mailboxes: %d\n", adapter, adapter->drvr_sglimit, adapter->adapter_sglimit, adapter->mbox_count); 1810 blogic_info(" Driver Queue Depth: %d, Host Adapter Queue Depth: %d\n", adapter, adapter->drvr_qdepth, adapter->adapter_qdepth); 1811 } else 1812 blogic_info(" Driver Queue Depth: %d, Scatter/Gather Limit: %d segments\n", adapter, adapter->drvr_qdepth, adapter->drvr_sglimit); 1813 blogic_info(" Tagged Queue Depth: ", adapter); 1814 common_tagq_depth = true; 1815 for (tgt_id = 1; tgt_id < adapter->maxdev; tgt_id++) 1816 if (adapter->qdepth[tgt_id] != adapter->qdepth[0]) { 1817 common_tagq_depth = false; 1818 break; 1819 } 1820 if (common_tagq_depth) { 1821 if (adapter->qdepth[0] > 0) 1822 blogic_info("%d", adapter, adapter->qdepth[0]); 1823 else 1824 blogic_info("Automatic", adapter); 1825 } else 1826 blogic_info("Individual", adapter); 1827 blogic_info(", Untagged Queue Depth: %d\n", adapter, 1828 adapter->untag_qdepth); 1829 if (adapter->terminfo_valid) { 1830 if (adapter->wide) 1831 blogic_info(" SCSI Bus Termination: %s", adapter, 1832 (adapter->low_term ? (adapter->high_term ? "Both Enabled" : "Low Enabled") : (adapter->high_term ? "High Enabled" : "Both Disabled"))); 1833 else 1834 blogic_info(" SCSI Bus Termination: %s", adapter, 1835 (adapter->low_term ? "Enabled" : "Disabled")); 1836 if (adapter->scam) 1837 blogic_info(", SCAM: %s", adapter, 1838 (adapter->scam_enabled ? (adapter->scam_lev2 ? "Enabled, Level 2" : "Enabled, Level 1") : "Disabled")); 1839 blogic_info("\n", adapter); 1840 } 1841 /* 1842 Indicate reporting the Host Adapter configuration completed 1843 successfully. 1844 */ 1845 return true; 1846 } 1847 1848 1849 /* 1850 blogic_getres acquires the system resources necessary to use 1851 Host Adapter. 1852 */ 1853 1854 static bool __init blogic_getres(struct blogic_adapter *adapter) 1855 { 1856 if (adapter->irq_ch == 0) { 1857 blogic_err("NO LEGAL INTERRUPT CHANNEL ASSIGNED - DETACHING\n", 1858 adapter); 1859 return false; 1860 } 1861 /* 1862 Acquire shared access to the IRQ Channel. 1863 */ 1864 if (request_irq(adapter->irq_ch, blogic_inthandler, IRQF_SHARED, 1865 adapter->full_model, adapter) < 0) { 1866 blogic_err("UNABLE TO ACQUIRE IRQ CHANNEL %d - DETACHING\n", 1867 adapter, adapter->irq_ch); 1868 return false; 1869 } 1870 adapter->irq_acquired = true; 1871 /* 1872 Indicate the System Resource Acquisition completed successfully, 1873 */ 1874 return true; 1875 } 1876 1877 1878 /* 1879 blogic_relres releases any system resources previously acquired 1880 by blogic_getres. 1881 */ 1882 1883 static void blogic_relres(struct blogic_adapter *adapter) 1884 { 1885 /* 1886 Release shared access to the IRQ Channel. 1887 */ 1888 if (adapter->irq_acquired) 1889 free_irq(adapter->irq_ch, adapter); 1890 /* 1891 Release any allocated memory structs not released elsewhere 1892 */ 1893 if (adapter->mbox_space) 1894 dma_free_coherent(&adapter->pci_device->dev, adapter->mbox_sz, 1895 adapter->mbox_space, adapter->mbox_space_handle); 1896 pci_dev_put(adapter->pci_device); 1897 adapter->mbox_space = NULL; 1898 adapter->mbox_space_handle = 0; 1899 adapter->mbox_sz = 0; 1900 } 1901 1902 1903 /* 1904 blogic_initadapter initializes Host Adapter. This is the only 1905 function called during SCSI Host Adapter detection which modifies the state 1906 of the Host Adapter from its initial power on or hard reset state. 1907 */ 1908 1909 static bool blogic_initadapter(struct blogic_adapter *adapter) 1910 { 1911 struct blogic_extmbox_req extmbox_req; 1912 enum blogic_rr_req rr_req; 1913 enum blogic_setccb_fmt setccb_fmt; 1914 int tgt_id; 1915 1916 /* 1917 Initialize the pointers to the first and last CCBs that are 1918 queued for completion processing. 1919 */ 1920 adapter->firstccb = NULL; 1921 adapter->lastccb = NULL; 1922 1923 /* 1924 Initialize the Bus Device Reset Pending CCB, Tagged Queuing Active, 1925 Command Successful Flag, Active Commands, and Commands Since Reset 1926 for each Target Device. 1927 */ 1928 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) { 1929 adapter->bdr_pend[tgt_id] = NULL; 1930 adapter->tgt_flags[tgt_id].tagq_active = false; 1931 adapter->tgt_flags[tgt_id].cmd_good = false; 1932 adapter->active_cmds[tgt_id] = 0; 1933 adapter->cmds_since_rst[tgt_id] = 0; 1934 } 1935 1936 /* 1937 FlashPoint Host Adapters do not use Outgoing and Incoming Mailboxes. 1938 */ 1939 if (blogic_flashpoint_type(adapter)) 1940 goto done; 1941 1942 /* 1943 Initialize the Outgoing and Incoming Mailbox pointers. 1944 */ 1945 adapter->mbox_sz = adapter->mbox_count * (sizeof(struct blogic_outbox) + sizeof(struct blogic_inbox)); 1946 adapter->mbox_space = dma_alloc_coherent(&adapter->pci_device->dev, 1947 adapter->mbox_sz, &adapter->mbox_space_handle, 1948 GFP_KERNEL); 1949 if (adapter->mbox_space == NULL) 1950 return blogic_failure(adapter, "MAILBOX ALLOCATION"); 1951 adapter->first_outbox = (struct blogic_outbox *) adapter->mbox_space; 1952 adapter->last_outbox = adapter->first_outbox + adapter->mbox_count - 1; 1953 adapter->next_outbox = adapter->first_outbox; 1954 adapter->first_inbox = (struct blogic_inbox *) (adapter->last_outbox + 1); 1955 adapter->last_inbox = adapter->first_inbox + adapter->mbox_count - 1; 1956 adapter->next_inbox = adapter->first_inbox; 1957 1958 /* 1959 Initialize the Outgoing and Incoming Mailbox structures. 1960 */ 1961 memset(adapter->first_outbox, 0, 1962 adapter->mbox_count * sizeof(struct blogic_outbox)); 1963 memset(adapter->first_inbox, 0, 1964 adapter->mbox_count * sizeof(struct blogic_inbox)); 1965 1966 /* 1967 Initialize the Host Adapter's Pointer to the Outgoing/Incoming 1968 Mailboxes. 1969 */ 1970 extmbox_req.mbox_count = adapter->mbox_count; 1971 extmbox_req.base_mbox_addr = (u32) adapter->mbox_space_handle; 1972 if (blogic_cmd(adapter, BLOGIC_INIT_EXT_MBOX, &extmbox_req, 1973 sizeof(extmbox_req), NULL, 0) < 0) 1974 return blogic_failure(adapter, "MAILBOX INITIALIZATION"); 1975 /* 1976 Enable Strict Round Robin Mode if supported by the Host Adapter. In 1977 Strict Round Robin Mode, the Host Adapter only looks at the next 1978 Outgoing Mailbox for each new command, rather than scanning 1979 through all the Outgoing Mailboxes to find any that have new 1980 commands in them. Strict Round Robin Mode is significantly more 1981 efficient. 1982 */ 1983 if (adapter->strict_rr) { 1984 rr_req = BLOGIC_STRICT_RR_MODE; 1985 if (blogic_cmd(adapter, BLOGIC_STRICT_RR, &rr_req, 1986 sizeof(rr_req), NULL, 0) < 0) 1987 return blogic_failure(adapter, 1988 "ENABLE STRICT ROUND ROBIN MODE"); 1989 } 1990 1991 /* 1992 For Host Adapters that support Extended LUN Format CCBs, issue the 1993 Set CCB Format command to allow 32 Logical Units per Target Device. 1994 */ 1995 if (adapter->ext_lun) { 1996 setccb_fmt = BLOGIC_EXT_LUN_CCB; 1997 if (blogic_cmd(adapter, BLOGIC_SETCCB_FMT, &setccb_fmt, 1998 sizeof(setccb_fmt), NULL, 0) < 0) 1999 return blogic_failure(adapter, "SET CCB FORMAT"); 2000 } 2001 2002 /* 2003 Announce Successful Initialization. 2004 */ 2005 done: 2006 if (!adapter->adapter_initd) { 2007 blogic_info("*** %s Initialized Successfully ***\n", adapter, 2008 adapter->full_model); 2009 blogic_info("\n", adapter); 2010 } else 2011 blogic_warn("*** %s Initialized Successfully ***\n", adapter, 2012 adapter->full_model); 2013 adapter->adapter_initd = true; 2014 2015 /* 2016 Indicate the Host Adapter Initialization completed successfully. 2017 */ 2018 return true; 2019 } 2020 2021 2022 /* 2023 blogic_inquiry inquires about the Target Devices accessible 2024 through Host Adapter. 2025 */ 2026 2027 static bool __init blogic_inquiry(struct blogic_adapter *adapter) 2028 { 2029 u16 installed_devs; 2030 u8 installed_devs0to7[8]; 2031 struct blogic_setup_info setupinfo; 2032 u8 sync_period[BLOGIC_MAXDEV]; 2033 unsigned char req_replylen; 2034 int tgt_id; 2035 2036 /* 2037 Wait a few seconds between the Host Adapter Hard Reset which 2038 initiates a SCSI Bus Reset and issuing any SCSI Commands. Some 2039 SCSI devices get confused if they receive SCSI Commands too soon 2040 after a SCSI Bus Reset. 2041 */ 2042 blogic_delay(adapter->bus_settle_time); 2043 /* 2044 FlashPoint Host Adapters do not provide for Target Device Inquiry. 2045 */ 2046 if (blogic_flashpoint_type(adapter)) 2047 return true; 2048 /* 2049 Inhibit the Target Device Inquiry if requested. 2050 */ 2051 if (adapter->drvr_opts != NULL && adapter->drvr_opts->stop_tgt_inquiry) 2052 return true; 2053 /* 2054 Issue the Inquire Target Devices command for host adapters with 2055 firmware version 4.25 or later, or the Inquire Installed Devices 2056 ID 0 to 7 command for older host adapters. This is necessary to 2057 force Synchronous Transfer Negotiation so that the Inquire Setup 2058 Information and Inquire Synchronous Period commands will return 2059 valid data. The Inquire Target Devices command is preferable to 2060 Inquire Installed Devices ID 0 to 7 since it only probes Logical 2061 Unit 0 of each Target Device. 2062 */ 2063 if (strcmp(adapter->fw_ver, "4.25") >= 0) { 2064 2065 /* 2066 Issue a Inquire Target Devices command. Inquire Target 2067 Devices only tests Logical Unit 0 of each Target Device 2068 unlike the Inquire Installed Devices commands which test 2069 Logical Units 0 - 7. Two bytes are returned, where byte 2070 0 bit 0 set indicates that Target Device 0 exists, and so on. 2071 */ 2072 2073 if (blogic_cmd(adapter, BLOGIC_INQ_DEV, NULL, 0, 2074 &installed_devs, sizeof(installed_devs)) 2075 != sizeof(installed_devs)) 2076 return blogic_failure(adapter, "INQUIRE TARGET DEVICES"); 2077 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2078 adapter->tgt_flags[tgt_id].tgt_exists = 2079 (installed_devs & (1 << tgt_id) ? true : false); 2080 } else { 2081 2082 /* 2083 Issue an Inquire Installed Devices command. For each 2084 Target Device, a byte is returned where bit 0 set 2085 indicates that Logical Unit 0 * exists, bit 1 set 2086 indicates that Logical Unit 1 exists, and so on. 2087 */ 2088 2089 if (blogic_cmd(adapter, BLOGIC_INQ_DEV0TO7, NULL, 0, 2090 &installed_devs0to7, sizeof(installed_devs0to7)) 2091 != sizeof(installed_devs0to7)) 2092 return blogic_failure(adapter, 2093 "INQUIRE INSTALLED DEVICES ID 0 TO 7"); 2094 for (tgt_id = 0; tgt_id < 8; tgt_id++) 2095 adapter->tgt_flags[tgt_id].tgt_exists = 2096 installed_devs0to7[tgt_id] != 0; 2097 } 2098 /* 2099 Issue the Inquire Setup Information command. 2100 */ 2101 req_replylen = sizeof(setupinfo); 2102 if (blogic_cmd(adapter, BLOGIC_INQ_SETUPINFO, &req_replylen, 2103 sizeof(req_replylen), &setupinfo, sizeof(setupinfo)) 2104 != sizeof(setupinfo)) 2105 return blogic_failure(adapter, "INQUIRE SETUP INFORMATION"); 2106 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2107 adapter->sync_offset[tgt_id] = (tgt_id < 8 ? setupinfo.sync0to7[tgt_id].offset : setupinfo.sync8to15[tgt_id - 8].offset); 2108 if (strcmp(adapter->fw_ver, "5.06L") >= 0) 2109 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2110 adapter->tgt_flags[tgt_id].wide_active = (tgt_id < 8 ? (setupinfo.wide_tx_active0to7 & (1 << tgt_id) ? true : false) : (setupinfo.wide_tx_active8to15 & (1 << (tgt_id - 8)) ? true : false)); 2111 /* 2112 Issue the Inquire Synchronous Period command. 2113 */ 2114 if (adapter->fw_ver[0] >= '3') { 2115 2116 /* Issue a Inquire Synchronous Period command. For each 2117 Target Device, a byte is returned which represents the 2118 Synchronous Transfer Period in units of 10 nanoseconds. 2119 */ 2120 2121 req_replylen = sizeof(sync_period); 2122 if (blogic_cmd(adapter, BLOGIC_INQ_SYNC_PERIOD, &req_replylen, 2123 sizeof(req_replylen), &sync_period, 2124 sizeof(sync_period)) != sizeof(sync_period)) 2125 return blogic_failure(adapter, 2126 "INQUIRE SYNCHRONOUS PERIOD"); 2127 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2128 adapter->sync_period[tgt_id] = sync_period[tgt_id]; 2129 } else 2130 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2131 if (setupinfo.sync0to7[tgt_id].offset > 0) 2132 adapter->sync_period[tgt_id] = 20 + 5 * setupinfo.sync0to7[tgt_id].tx_period; 2133 /* 2134 Indicate the Target Device Inquiry completed successfully. 2135 */ 2136 return true; 2137 } 2138 2139 /* 2140 blogic_inithoststruct initializes the fields in the SCSI Host 2141 structure. The base, io_port, n_io_ports, irq, and dma_channel fields in the 2142 SCSI Host structure are intentionally left uninitialized, as this driver 2143 handles acquisition and release of these resources explicitly, as well as 2144 ensuring exclusive access to the Host Adapter hardware and data structures 2145 through explicit acquisition and release of the Host Adapter's Lock. 2146 */ 2147 2148 static void __init blogic_inithoststruct(struct blogic_adapter *adapter, 2149 struct Scsi_Host *host) 2150 { 2151 host->max_id = adapter->maxdev; 2152 host->max_lun = adapter->maxlun; 2153 host->max_channel = 0; 2154 host->unique_id = adapter->io_addr; 2155 host->this_id = adapter->scsi_id; 2156 host->can_queue = adapter->drvr_qdepth; 2157 host->sg_tablesize = adapter->drvr_sglimit; 2158 host->cmd_per_lun = adapter->untag_qdepth; 2159 } 2160 2161 /* 2162 blogic_sdev_configure will actually set the queue depth on individual 2163 scsi devices as they are permanently added to the device chain. We 2164 shamelessly rip off the SelectQueueDepths code to make this work mostly 2165 like it used to. Since we don't get called once at the end of the scan 2166 but instead get called for each device, we have to do things a bit 2167 differently. 2168 */ 2169 static int blogic_sdev_configure(struct scsi_device *dev, 2170 struct queue_limits *lim) 2171 { 2172 struct blogic_adapter *adapter = 2173 (struct blogic_adapter *) dev->host->hostdata; 2174 int tgt_id = dev->id; 2175 int qdepth = adapter->qdepth[tgt_id]; 2176 2177 if (adapter->tgt_flags[tgt_id].tagq_ok && 2178 (adapter->tagq_ok & (1 << tgt_id))) { 2179 if (qdepth == 0) 2180 qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH; 2181 adapter->qdepth[tgt_id] = qdepth; 2182 scsi_change_queue_depth(dev, qdepth); 2183 } else { 2184 adapter->tagq_ok &= ~(1 << tgt_id); 2185 qdepth = adapter->untag_qdepth; 2186 adapter->qdepth[tgt_id] = qdepth; 2187 scsi_change_queue_depth(dev, qdepth); 2188 } 2189 qdepth = 0; 2190 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2191 if (adapter->tgt_flags[tgt_id].tgt_exists) 2192 qdepth += adapter->qdepth[tgt_id]; 2193 if (qdepth > adapter->alloc_ccbs) 2194 blogic_create_addlccbs(adapter, qdepth - adapter->alloc_ccbs, 2195 false); 2196 return 0; 2197 } 2198 2199 /* 2200 blogic_init probes for BusLogic Host Adapters at the standard 2201 I/O Addresses where they may be located, initializing, registering, and 2202 reporting the configuration of each BusLogic Host Adapter it finds. It 2203 returns the number of BusLogic Host Adapters successfully initialized and 2204 registered. 2205 */ 2206 2207 static int __init blogic_init(void) 2208 { 2209 int drvr_optindex = 0, probeindex; 2210 struct blogic_adapter *adapter; 2211 int ret = 0; 2212 2213 #ifdef MODULE 2214 if (BusLogic) 2215 blogic_setup(BusLogic); 2216 #endif 2217 2218 if (blogic_probe_options.noprobe) 2219 return -ENODEV; 2220 blogic_probeinfo_list = 2221 kzalloc_objs(struct blogic_probeinfo, BLOGIC_MAX_ADAPTERS); 2222 if (blogic_probeinfo_list == NULL) { 2223 blogic_err("BusLogic: Unable to allocate Probe Info List\n", 2224 NULL); 2225 return -ENOMEM; 2226 } 2227 2228 adapter = kzalloc_obj(struct blogic_adapter); 2229 if (adapter == NULL) { 2230 kfree(blogic_probeinfo_list); 2231 blogic_err("BusLogic: Unable to allocate Prototype Host Adapter\n", NULL); 2232 return -ENOMEM; 2233 } 2234 2235 #ifdef MODULE 2236 if (BusLogic != NULL) 2237 blogic_setup(BusLogic); 2238 #endif 2239 blogic_init_probeinfo_list(adapter); 2240 for (probeindex = 0; probeindex < blogic_probeinfo_count; probeindex++) { 2241 struct blogic_probeinfo *probeinfo = 2242 &blogic_probeinfo_list[probeindex]; 2243 struct blogic_adapter *myadapter = adapter; 2244 struct Scsi_Host *host; 2245 2246 if (probeinfo->io_addr == 0) 2247 continue; 2248 memset(myadapter, 0, sizeof(struct blogic_adapter)); 2249 myadapter->adapter_type = probeinfo->adapter_type; 2250 myadapter->adapter_bus_type = probeinfo->adapter_bus_type; 2251 myadapter->io_addr = probeinfo->io_addr; 2252 myadapter->pci_addr = probeinfo->pci_addr; 2253 myadapter->bus = probeinfo->bus; 2254 myadapter->dev = probeinfo->dev; 2255 myadapter->pci_device = probeinfo->pci_device; 2256 myadapter->irq_ch = probeinfo->irq_ch; 2257 myadapter->addr_count = 2258 blogic_adapter_addr_count[myadapter->adapter_type]; 2259 2260 /* 2261 Make sure region is free prior to probing. 2262 */ 2263 if (!request_region(myadapter->io_addr, myadapter->addr_count, 2264 "BusLogic")) 2265 continue; 2266 /* 2267 Probe the Host Adapter. If unsuccessful, abort further 2268 initialization. 2269 */ 2270 if (!blogic_probe(myadapter)) { 2271 release_region(myadapter->io_addr, 2272 myadapter->addr_count); 2273 continue; 2274 } 2275 /* 2276 Hard Reset the Host Adapter. If unsuccessful, abort further 2277 initialization. 2278 */ 2279 if (!blogic_hwreset(myadapter, true)) { 2280 release_region(myadapter->io_addr, 2281 myadapter->addr_count); 2282 continue; 2283 } 2284 /* 2285 Check the Host Adapter. If unsuccessful, abort further 2286 initialization. 2287 */ 2288 if (!blogic_checkadapter(myadapter)) { 2289 release_region(myadapter->io_addr, 2290 myadapter->addr_count); 2291 continue; 2292 } 2293 /* 2294 Initialize the Driver Options field if provided. 2295 */ 2296 if (drvr_optindex < blogic_drvr_options_count) 2297 myadapter->drvr_opts = 2298 &blogic_drvr_options[drvr_optindex++]; 2299 /* 2300 Announce the Driver Version and Date, Author's Name, 2301 Copyright Notice, and Electronic Mail Address. 2302 */ 2303 blogic_announce_drvr(myadapter); 2304 /* 2305 Register the SCSI Host structure. 2306 */ 2307 2308 host = scsi_host_alloc(&blogic_template, 2309 sizeof(struct blogic_adapter)); 2310 if (host == NULL) { 2311 release_region(myadapter->io_addr, 2312 myadapter->addr_count); 2313 continue; 2314 } 2315 myadapter = (struct blogic_adapter *) host->hostdata; 2316 memcpy(myadapter, adapter, sizeof(struct blogic_adapter)); 2317 myadapter->scsi_host = host; 2318 myadapter->host_no = host->host_no; 2319 /* 2320 Add Host Adapter to the end of the list of registered 2321 BusLogic Host Adapters. 2322 */ 2323 list_add_tail(&myadapter->host_list, &blogic_host_list); 2324 2325 /* 2326 Read the Host Adapter Configuration, Configure the Host 2327 Adapter, Acquire the System Resources necessary to use 2328 the Host Adapter, then Create the Initial CCBs, Initialize 2329 the Host Adapter, and finally perform Target Device 2330 Inquiry. From this point onward, any failure will be 2331 assumed to be due to a problem with the Host Adapter, 2332 rather than due to having mistakenly identified this port 2333 as belonging to a BusLogic Host Adapter. The I/O Address 2334 range will not be released, thereby preventing it from 2335 being incorrectly identified as any other type of Host 2336 Adapter. 2337 */ 2338 if (blogic_rdconfig(myadapter) && 2339 blogic_reportconfig(myadapter) && 2340 blogic_getres(myadapter) && 2341 blogic_create_initccbs(myadapter) && 2342 blogic_initadapter(myadapter) && 2343 blogic_inquiry(myadapter)) { 2344 /* 2345 Initialization has been completed successfully. 2346 Release and re-register usage of the I/O Address 2347 range so that the Model Name of the Host Adapter 2348 will appear, and initialize the SCSI Host structure. 2349 */ 2350 release_region(myadapter->io_addr, 2351 myadapter->addr_count); 2352 if (!request_region(myadapter->io_addr, 2353 myadapter->addr_count, 2354 myadapter->full_model)) { 2355 printk(KERN_WARNING 2356 "BusLogic: Release and re-register of " 2357 "port 0x%04lx failed \n", 2358 (unsigned long)myadapter->io_addr); 2359 blogic_destroy_ccbs(myadapter); 2360 blogic_relres(myadapter); 2361 list_del(&myadapter->host_list); 2362 scsi_host_put(host); 2363 ret = -ENOMEM; 2364 } else { 2365 blogic_inithoststruct(myadapter, 2366 host); 2367 if (scsi_add_host(host, myadapter->pci_device 2368 ? &myadapter->pci_device->dev 2369 : NULL)) { 2370 printk(KERN_WARNING 2371 "BusLogic: scsi_add_host()" 2372 "failed!\n"); 2373 blogic_destroy_ccbs(myadapter); 2374 blogic_relres(myadapter); 2375 list_del(&myadapter->host_list); 2376 scsi_host_put(host); 2377 ret = -ENODEV; 2378 } else 2379 scsi_scan_host(host); 2380 } 2381 } else { 2382 /* 2383 An error occurred during Host Adapter Configuration 2384 Querying, Host Adapter Configuration, Resource 2385 Acquisition, CCB Creation, Host Adapter 2386 Initialization, or Target Device Inquiry, so 2387 remove Host Adapter from the list of registered 2388 BusLogic Host Adapters, destroy the CCBs, Release 2389 the System Resources, and Unregister the SCSI 2390 Host. 2391 */ 2392 blogic_destroy_ccbs(myadapter); 2393 blogic_relres(myadapter); 2394 list_del(&myadapter->host_list); 2395 scsi_host_put(host); 2396 ret = -ENODEV; 2397 } 2398 } 2399 kfree(adapter); 2400 kfree(blogic_probeinfo_list); 2401 blogic_probeinfo_list = NULL; 2402 return ret; 2403 } 2404 2405 2406 /* 2407 blogic_deladapter releases all resources previously acquired to 2408 support a specific Host Adapter, including the I/O Address range, and 2409 unregisters the BusLogic Host Adapter. 2410 */ 2411 2412 static int __exit blogic_deladapter(struct blogic_adapter *adapter) 2413 { 2414 struct Scsi_Host *host = adapter->scsi_host; 2415 2416 scsi_remove_host(host); 2417 2418 /* 2419 FlashPoint Host Adapters must first be released by the FlashPoint 2420 SCCB Manager. 2421 */ 2422 if (blogic_flashpoint_type(adapter)) 2423 FlashPoint_ReleaseHostAdapter(adapter->cardhandle); 2424 /* 2425 Destroy the CCBs and release any system resources acquired to 2426 support Host Adapter. 2427 */ 2428 blogic_destroy_ccbs(adapter); 2429 blogic_relres(adapter); 2430 /* 2431 Release usage of the I/O Address range. 2432 */ 2433 release_region(adapter->io_addr, adapter->addr_count); 2434 /* 2435 Remove Host Adapter from the list of registered BusLogic 2436 Host Adapters. 2437 */ 2438 list_del(&adapter->host_list); 2439 2440 scsi_host_put(host); 2441 return 0; 2442 } 2443 2444 2445 /* 2446 blogic_qcompleted_ccb queues CCB for completion processing. 2447 */ 2448 2449 static void blogic_qcompleted_ccb(struct blogic_ccb *ccb) 2450 { 2451 struct blogic_adapter *adapter = ccb->adapter; 2452 2453 ccb->status = BLOGIC_CCB_COMPLETE; 2454 ccb->next = NULL; 2455 if (adapter->firstccb == NULL) { 2456 adapter->firstccb = ccb; 2457 adapter->lastccb = ccb; 2458 } else { 2459 adapter->lastccb->next = ccb; 2460 adapter->lastccb = ccb; 2461 } 2462 adapter->active_cmds[ccb->tgt_id]--; 2463 } 2464 2465 2466 /* 2467 blogic_resultcode computes a SCSI Subsystem Result Code from 2468 the Host Adapter Status and Target Device Status. 2469 */ 2470 2471 static int blogic_resultcode(struct blogic_adapter *adapter, 2472 enum blogic_adapter_status adapter_status, 2473 enum blogic_tgt_status tgt_status) 2474 { 2475 int hoststatus; 2476 2477 switch (adapter_status) { 2478 case BLOGIC_CMD_CMPLT_NORMAL: 2479 case BLOGIC_LINK_CMD_CMPLT: 2480 case BLOGIC_LINK_CMD_CMPLT_FLAG: 2481 hoststatus = DID_OK; 2482 break; 2483 case BLOGIC_SELECT_TIMEOUT: 2484 hoststatus = DID_TIME_OUT; 2485 break; 2486 case BLOGIC_INVALID_OUTBOX_CODE: 2487 case BLOGIC_INVALID_CMD_CODE: 2488 case BLOGIC_BAD_CMD_PARAM: 2489 blogic_warn("BusLogic Driver Protocol Error 0x%02X\n", 2490 adapter, adapter_status); 2491 fallthrough; 2492 case BLOGIC_DATA_UNDERRUN: 2493 case BLOGIC_DATA_OVERRUN: 2494 case BLOGIC_NOEXPECT_BUSFREE: 2495 case BLOGIC_LINKCCB_BADLUN: 2496 case BLOGIC_AUTOREQSENSE_FAIL: 2497 case BLOGIC_TAGQUEUE_REJECT: 2498 case BLOGIC_BAD_MSG_RCVD: 2499 case BLOGIC_HW_FAIL: 2500 case BLOGIC_BAD_RECONNECT: 2501 case BLOGIC_ABRT_QUEUE: 2502 case BLOGIC_ADAPTER_SW_ERROR: 2503 case BLOGIC_HW_TIMEOUT: 2504 case BLOGIC_PARITY_ERR: 2505 hoststatus = DID_ERROR; 2506 break; 2507 case BLOGIC_INVALID_BUSPHASE: 2508 case BLOGIC_NORESPONSE_TO_ATN: 2509 case BLOGIC_HW_RESET: 2510 case BLOGIC_RST_FROM_OTHERDEV: 2511 case BLOGIC_HW_BDR: 2512 hoststatus = DID_RESET; 2513 break; 2514 default: 2515 blogic_warn("Unknown Host Adapter Status 0x%02X\n", adapter, 2516 adapter_status); 2517 hoststatus = DID_ERROR; 2518 break; 2519 } 2520 return (hoststatus << 16) | tgt_status; 2521 } 2522 2523 /* 2524 * turn the dma address from an inbox into a ccb pointer 2525 * This is rather inefficient. 2526 */ 2527 static struct blogic_ccb * 2528 blogic_inbox_to_ccb(struct blogic_adapter *adapter, struct blogic_inbox *inbox) 2529 { 2530 struct blogic_ccb *ccb; 2531 2532 for (ccb = adapter->all_ccbs; ccb; ccb = ccb->next_all) 2533 if (inbox->ccb == ccb->dma_handle) 2534 break; 2535 2536 return ccb; 2537 } 2538 2539 /* 2540 blogic_scan_inbox scans the Incoming Mailboxes saving any 2541 Incoming Mailbox entries for completion processing. 2542 */ 2543 static void blogic_scan_inbox(struct blogic_adapter *adapter) 2544 { 2545 /* 2546 Scan through the Incoming Mailboxes in Strict Round Robin 2547 fashion, saving any completed CCBs for further processing. It 2548 is essential that for each CCB and SCSI Command issued, command 2549 completion processing is performed exactly once. Therefore, 2550 only Incoming Mailboxes with completion code Command Completed 2551 Without Error, Command Completed With Error, or Command Aborted 2552 At Host Request are saved for completion processing. When an 2553 Incoming Mailbox has a completion code of Aborted Command Not 2554 Found, the CCB had already completed or been aborted before the 2555 current Abort request was processed, and so completion processing 2556 has already occurred and no further action should be taken. 2557 */ 2558 struct blogic_inbox *next_inbox = adapter->next_inbox; 2559 enum blogic_cmplt_code comp_code; 2560 2561 while ((comp_code = next_inbox->comp_code) != BLOGIC_INBOX_FREE) { 2562 struct blogic_ccb *ccb = blogic_inbox_to_ccb(adapter, next_inbox); 2563 if (!ccb) { 2564 /* 2565 * This should never happen, unless the CCB list is 2566 * corrupted in memory. 2567 */ 2568 blogic_warn("Could not find CCB for dma address %x\n", adapter, next_inbox->ccb); 2569 } else if (comp_code != BLOGIC_CMD_NOTFOUND) { 2570 if (ccb->status == BLOGIC_CCB_ACTIVE || 2571 ccb->status == BLOGIC_CCB_RESET) { 2572 /* 2573 Save the Completion Code for this CCB and 2574 queue the CCB for completion processing. 2575 */ 2576 ccb->comp_code = comp_code; 2577 blogic_qcompleted_ccb(ccb); 2578 } else { 2579 /* 2580 If a CCB ever appears in an Incoming Mailbox 2581 and is not marked as status Active or Reset, 2582 then there is most likely a bug in 2583 the Host Adapter firmware. 2584 */ 2585 blogic_warn("Illegal CCB #%ld status %d in Incoming Mailbox\n", adapter, ccb->serial, ccb->status); 2586 } 2587 } 2588 next_inbox->comp_code = BLOGIC_INBOX_FREE; 2589 if (++next_inbox > adapter->last_inbox) 2590 next_inbox = adapter->first_inbox; 2591 } 2592 adapter->next_inbox = next_inbox; 2593 } 2594 2595 2596 /* 2597 blogic_process_ccbs iterates over the completed CCBs for Host 2598 Adapter setting the SCSI Command Result Codes, deallocating the CCBs, and 2599 calling the SCSI Subsystem Completion Routines. The Host Adapter's Lock 2600 should already have been acquired by the caller. 2601 */ 2602 2603 static void blogic_process_ccbs(struct Scsi_Host *host) 2604 __must_hold(&host->host_lock) 2605 { 2606 struct blogic_adapter *adapter = (void *)host->hostdata; 2607 2608 if (adapter->processing_ccbs) 2609 return; 2610 adapter->processing_ccbs = true; 2611 while (adapter->firstccb != NULL) { 2612 struct blogic_ccb *ccb = adapter->firstccb; 2613 struct scsi_cmnd *command = ccb->command; 2614 adapter->firstccb = ccb->next; 2615 if (adapter->firstccb == NULL) 2616 adapter->lastccb = NULL; 2617 /* 2618 Process the Completed CCB. 2619 */ 2620 if (ccb->opcode == BLOGIC_BDR) { 2621 int tgt_id = ccb->tgt_id; 2622 2623 blogic_warn("Bus Device Reset CCB #%ld to Target %d Completed\n", adapter, ccb->serial, tgt_id); 2624 blogic_inc_count(&adapter->tgt_stats[tgt_id].bdr_done); 2625 adapter->tgt_flags[tgt_id].tagq_active = false; 2626 adapter->cmds_since_rst[tgt_id] = 0; 2627 adapter->last_resetdone[tgt_id] = jiffies; 2628 /* 2629 Place CCB back on the Host Adapter's free list. 2630 */ 2631 blogic_dealloc_ccb(host, ccb, 1); 2632 #if 0 /* this needs to be redone different for new EH */ 2633 /* 2634 Bus Device Reset CCBs have the command field 2635 non-NULL only when a Bus Device Reset was requested 2636 for a command that did not have a currently active 2637 CCB in the Host Adapter (i.e., a Synchronous Bus 2638 Device Reset), and hence would not have its 2639 Completion Routine called otherwise. 2640 */ 2641 while (command != NULL) { 2642 struct scsi_cmnd *nxt_cmd = 2643 command->reset_chain; 2644 command->reset_chain = NULL; 2645 command->result = DID_RESET << 16; 2646 scsi_done(command); 2647 command = nxt_cmd; 2648 } 2649 #endif 2650 /* 2651 Iterate over the CCBs for this Host Adapter 2652 performing completion processing for any CCBs 2653 marked as Reset for this Target. 2654 */ 2655 for (ccb = adapter->all_ccbs; ccb != NULL; 2656 ccb = ccb->next_all) 2657 if (ccb->status == BLOGIC_CCB_RESET && 2658 ccb->tgt_id == tgt_id) { 2659 command = ccb->command; 2660 blogic_dealloc_ccb(host, ccb, 1); 2661 adapter->active_cmds[tgt_id]--; 2662 command->result = DID_RESET << 16; 2663 scsi_done(command); 2664 } 2665 adapter->bdr_pend[tgt_id] = NULL; 2666 } else { 2667 /* 2668 Translate the Completion Code, Host Adapter Status, 2669 and Target Device Status into a SCSI Subsystem 2670 Result Code. 2671 */ 2672 switch (ccb->comp_code) { 2673 case BLOGIC_INBOX_FREE: 2674 case BLOGIC_CMD_NOTFOUND: 2675 case BLOGIC_INVALID_CCB: 2676 blogic_warn("CCB #%ld to Target %d Impossible State\n", adapter, ccb->serial, ccb->tgt_id); 2677 break; 2678 case BLOGIC_CMD_COMPLETE_GOOD: 2679 adapter->tgt_stats[ccb->tgt_id] 2680 .cmds_complete++; 2681 adapter->tgt_flags[ccb->tgt_id] 2682 .cmd_good = true; 2683 command->result = DID_OK << 16; 2684 break; 2685 case BLOGIC_CMD_ABORT_BY_HOST: 2686 blogic_warn("CCB #%ld to Target %d Aborted\n", 2687 adapter, ccb->serial, ccb->tgt_id); 2688 blogic_inc_count(&adapter->tgt_stats[ccb->tgt_id].aborts_done); 2689 command->result = DID_ABORT << 16; 2690 break; 2691 case BLOGIC_CMD_COMPLETE_ERROR: 2692 command->result = blogic_resultcode(adapter, 2693 ccb->adapter_status, ccb->tgt_status); 2694 if (ccb->adapter_status != BLOGIC_SELECT_TIMEOUT) { 2695 adapter->tgt_stats[ccb->tgt_id] 2696 .cmds_complete++; 2697 if (blogic_global_options.trace_err) { 2698 int i; 2699 blogic_notice("CCB #%ld Target %d: Result %X Host " 2700 "Adapter Status %02X Target Status %02X\n", adapter, ccb->serial, ccb->tgt_id, command->result, ccb->adapter_status, ccb->tgt_status); 2701 blogic_notice("CDB ", adapter); 2702 for (i = 0; i < ccb->cdblen; i++) 2703 blogic_notice(" %02X", adapter, ccb->cdb[i]); 2704 blogic_notice("\n", adapter); 2705 blogic_notice("Sense ", adapter); 2706 for (i = 0; i < ccb->sense_datalen; i++) 2707 blogic_notice(" %02X", adapter, command->sense_buffer[i]); 2708 blogic_notice("\n", adapter); 2709 } 2710 } 2711 break; 2712 } 2713 /* 2714 When an INQUIRY command completes normally, save the 2715 CmdQue (Tagged Queuing Supported) and WBus16 (16 Bit 2716 Wide Data Transfers Supported) bits. 2717 */ 2718 if (ccb->cdb[0] == INQUIRY && ccb->cdb[1] == 0 && 2719 ccb->adapter_status == BLOGIC_CMD_CMPLT_NORMAL) { 2720 struct blogic_tgt_flags *tgt_flags = 2721 &adapter->tgt_flags[ccb->tgt_id]; 2722 struct scsi_inquiry *inquiry = 2723 (struct scsi_inquiry *) scsi_sglist(command); 2724 tgt_flags->tgt_exists = true; 2725 tgt_flags->tagq_ok = inquiry->CmdQue; 2726 tgt_flags->wide_ok = inquiry->WBus16; 2727 } 2728 /* 2729 Place CCB back on the Host Adapter's free list. 2730 */ 2731 blogic_dealloc_ccb(host, ccb, 1); 2732 /* 2733 Call the SCSI Command Completion Routine. 2734 */ 2735 scsi_done(command); 2736 } 2737 } 2738 adapter->processing_ccbs = false; 2739 } 2740 2741 2742 /* 2743 blogic_inthandler handles hardware interrupts from BusLogic Host 2744 Adapters. 2745 */ 2746 2747 static irqreturn_t blogic_inthandler(int irq_ch, void *devid) 2748 { 2749 struct blogic_adapter *adapter = (struct blogic_adapter *) devid; 2750 struct Scsi_Host *host = adapter->scsi_host; 2751 unsigned long processor_flag; 2752 /* 2753 Acquire exclusive access to Host Adapter. 2754 */ 2755 spin_lock_irqsave(&host->host_lock, processor_flag); 2756 /* 2757 Handle Interrupts appropriately for each Host Adapter type. 2758 */ 2759 if (blogic_multimaster_type(adapter)) { 2760 union blogic_int_reg intreg; 2761 /* 2762 Read the Host Adapter Interrupt Register. 2763 */ 2764 intreg.all = blogic_rdint(adapter); 2765 if (intreg.ir.int_valid) { 2766 /* 2767 Acknowledge the interrupt and reset the Host Adapter 2768 Interrupt Register. 2769 */ 2770 blogic_intreset(adapter); 2771 /* 2772 Process valid External SCSI Bus Reset and Incoming 2773 Mailbox Loaded Interrupts. Command Complete 2774 Interrupts are noted, and Outgoing Mailbox Available 2775 Interrupts are ignored, as they are never enabled. 2776 */ 2777 if (intreg.ir.ext_busreset) 2778 adapter->adapter_extreset = true; 2779 else if (intreg.ir.mailin_loaded) 2780 blogic_scan_inbox(adapter); 2781 else if (intreg.ir.cmd_complete) 2782 adapter->adapter_cmd_complete = true; 2783 } 2784 } else { 2785 /* 2786 Check if there is a pending interrupt for this Host Adapter. 2787 */ 2788 if (FlashPoint_InterruptPending(adapter->cardhandle)) 2789 switch (FlashPoint_HandleInterrupt(adapter->cardhandle)) { 2790 case FPOINT_NORMAL_INT: 2791 break; 2792 case FPOINT_EXT_RESET: 2793 adapter->adapter_extreset = true; 2794 break; 2795 case FPOINT_INTERN_ERR: 2796 blogic_warn("Internal FlashPoint Error detected - Resetting Host Adapter\n", adapter); 2797 adapter->adapter_intern_err = true; 2798 break; 2799 } 2800 } 2801 /* 2802 Process any completed CCBs. 2803 */ 2804 if (adapter->firstccb != NULL) 2805 blogic_process_ccbs(host); 2806 /* 2807 Reset the Host Adapter if requested. 2808 */ 2809 if (adapter->adapter_extreset) { 2810 blogic_warn("Resetting %s due to External SCSI Bus Reset\n", adapter, adapter->full_model); 2811 blogic_inc_count(&adapter->ext_resets); 2812 blogic_resetadapter(host, false); 2813 adapter->adapter_extreset = false; 2814 } else if (adapter->adapter_intern_err) { 2815 blogic_warn("Resetting %s due to Host Adapter Internal Error\n", adapter, adapter->full_model); 2816 blogic_inc_count(&adapter->adapter_intern_errors); 2817 blogic_resetadapter(host, true); 2818 adapter->adapter_intern_err = false; 2819 } 2820 /* 2821 Release exclusive access to Host Adapter. 2822 */ 2823 spin_unlock_irqrestore(&host->host_lock, processor_flag); 2824 return IRQ_HANDLED; 2825 } 2826 2827 2828 /* 2829 blogic_write_outbox places CCB and Action Code into an Outgoing 2830 Mailbox for execution by Host Adapter. The Host Adapter's Lock should 2831 already have been acquired by the caller. 2832 */ 2833 2834 static bool blogic_write_outbox(struct Scsi_Host *host, 2835 enum blogic_action action, struct blogic_ccb *ccb) 2836 __must_hold(&host->host_lock) 2837 { 2838 struct blogic_adapter *adapter = (void *)host->hostdata; 2839 struct blogic_outbox *next_outbox; 2840 2841 next_outbox = adapter->next_outbox; 2842 if (next_outbox->action == BLOGIC_OUTBOX_FREE) { 2843 ccb->status = BLOGIC_CCB_ACTIVE; 2844 /* 2845 The CCB field must be written before the Action Code field 2846 since the Host Adapter is operating asynchronously and the 2847 locking code does not protect against simultaneous access 2848 by the Host Adapter. 2849 */ 2850 next_outbox->ccb = ccb->dma_handle; 2851 next_outbox->action = action; 2852 blogic_execmbox(adapter); 2853 if (++next_outbox > adapter->last_outbox) 2854 next_outbox = adapter->first_outbox; 2855 adapter->next_outbox = next_outbox; 2856 if (action == BLOGIC_MBOX_START) { 2857 adapter->active_cmds[ccb->tgt_id]++; 2858 if (ccb->opcode != BLOGIC_BDR) 2859 adapter->tgt_stats[ccb->tgt_id].cmds_tried++; 2860 } 2861 return true; 2862 } 2863 return false; 2864 } 2865 2866 /* Error Handling (EH) support */ 2867 2868 static int blogic_hostreset(struct scsi_cmnd *SCpnt) 2869 { 2870 struct blogic_adapter *adapter = 2871 (struct blogic_adapter *) SCpnt->device->host->hostdata; 2872 struct Scsi_Host *shost = adapter->scsi_host; 2873 unsigned int id = SCpnt->device->id; 2874 struct blogic_tgt_stats *stats = &adapter->tgt_stats[id]; 2875 int rc; 2876 2877 spin_lock_irq(&shost->host_lock); 2878 blogic_inc_count(&stats->adapter_reset_req); 2879 rc = blogic_resetadapter(shost, false); 2880 spin_unlock_irq(&shost->host_lock); 2881 2882 return rc; 2883 } 2884 2885 /* 2886 blogic_qcmd creates a CCB for Command and places it into an 2887 Outgoing Mailbox for execution by the associated Host Adapter. 2888 */ 2889 2890 static enum scsi_qc_status blogic_qcmd_lck(struct Scsi_Host *shost, struct scsi_cmnd *command) 2891 __must_hold(&shost->host_lock) 2892 { 2893 void (*comp_cb)(struct scsi_cmnd *) = scsi_done; 2894 struct blogic_adapter *adapter = 2895 (struct blogic_adapter *) shost->hostdata; 2896 struct blogic_tgt_flags *tgt_flags = 2897 &adapter->tgt_flags[command->device->id]; 2898 struct blogic_tgt_stats *tgt_stats = adapter->tgt_stats; 2899 unsigned char *cdb = command->cmnd; 2900 int cdblen = command->cmd_len; 2901 int tgt_id = command->device->id; 2902 int lun = command->device->lun; 2903 int buflen = scsi_bufflen(command); 2904 int count; 2905 struct blogic_ccb *ccb; 2906 dma_addr_t sense_buf; 2907 2908 /* 2909 SCSI REQUEST_SENSE commands will be executed automatically by the 2910 Host Adapter for any errors, so they should not be executed 2911 explicitly unless the Sense Data is zero indicating that no error 2912 occurred. 2913 */ 2914 if (cdb[0] == REQUEST_SENSE && command->sense_buffer[0] != 0) { 2915 command->result = DID_OK << 16; 2916 comp_cb(command); 2917 return 0; 2918 } 2919 /* 2920 Allocate a CCB from the Host Adapter's free list. In the unlikely 2921 event that there are none available and memory allocation fails, 2922 wait 1 second and try again. If that fails, the Host Adapter is 2923 probably hung so signal an error as a Host Adapter Hard Reset 2924 should be initiated soon. 2925 */ 2926 ccb = blogic_alloc_ccb(shost); 2927 if (ccb == NULL) { 2928 spin_unlock_irq(&shost->host_lock); 2929 blogic_delay(1); 2930 spin_lock_irq(&shost->host_lock); 2931 ccb = blogic_alloc_ccb(shost); 2932 if (ccb == NULL) { 2933 command->result = DID_ERROR << 16; 2934 comp_cb(command); 2935 return 0; 2936 } 2937 } 2938 2939 /* 2940 Initialize the fields in the BusLogic Command Control Block (CCB). 2941 */ 2942 count = scsi_dma_map(command); 2943 BUG_ON(count < 0); 2944 if (count) { 2945 struct scatterlist *sg; 2946 int i; 2947 2948 ccb->opcode = BLOGIC_INITIATOR_CCB_SG; 2949 ccb->datalen = count * sizeof(struct blogic_sg_seg); 2950 if (blogic_multimaster_type(adapter)) 2951 ccb->data = (unsigned int) ccb->dma_handle + 2952 ((unsigned long) &ccb->sglist - 2953 (unsigned long) ccb); 2954 else 2955 ccb->data = virt_to_32bit_virt(ccb->sglist); 2956 2957 scsi_for_each_sg(command, sg, count, i) { 2958 ccb->sglist[i].segbytes = sg_dma_len(sg); 2959 ccb->sglist[i].segdata = sg_dma_address(sg); 2960 } 2961 } else if (!count) { 2962 ccb->opcode = BLOGIC_INITIATOR_CCB; 2963 ccb->datalen = buflen; 2964 ccb->data = 0; 2965 } 2966 2967 switch (cdb[0]) { 2968 case READ_6: 2969 case READ_10: 2970 ccb->datadir = BLOGIC_DATAIN_CHECKED; 2971 tgt_stats[tgt_id].read_cmds++; 2972 blogic_addcount(&tgt_stats[tgt_id].bytesread, buflen); 2973 blogic_incszbucket(tgt_stats[tgt_id].read_sz_buckets, buflen); 2974 break; 2975 case WRITE_6: 2976 case WRITE_10: 2977 ccb->datadir = BLOGIC_DATAOUT_CHECKED; 2978 tgt_stats[tgt_id].write_cmds++; 2979 blogic_addcount(&tgt_stats[tgt_id].byteswritten, buflen); 2980 blogic_incszbucket(tgt_stats[tgt_id].write_sz_buckets, buflen); 2981 break; 2982 default: 2983 ccb->datadir = BLOGIC_UNCHECKED_TX; 2984 break; 2985 } 2986 ccb->cdblen = cdblen; 2987 ccb->adapter_status = 0; 2988 ccb->tgt_status = 0; 2989 ccb->tgt_id = tgt_id; 2990 ccb->lun = lun; 2991 ccb->tag_enable = false; 2992 ccb->legacytag_enable = false; 2993 /* 2994 BusLogic recommends that after a Reset the first couple of 2995 commands that are sent to a Target Device be sent in a non 2996 Tagged Queue fashion so that the Host Adapter and Target Device 2997 can establish Synchronous and Wide Transfer before Queue Tag 2998 messages can interfere with the Synchronous and Wide Negotiation 2999 messages. By waiting to enable Tagged Queuing until after the 3000 first BLOGIC_MAX_TAG_DEPTH commands have been queued, it is 3001 assured that after a Reset any pending commands are requeued 3002 before Tagged Queuing is enabled and that the Tagged Queuing 3003 message will not occur while the partition table is being printed. 3004 In addition, some devices do not properly handle the transition 3005 from non-tagged to tagged commands, so it is necessary to wait 3006 until there are no pending commands for a target device 3007 before queuing tagged commands. 3008 */ 3009 if (adapter->cmds_since_rst[tgt_id]++ >= BLOGIC_MAX_TAG_DEPTH && 3010 !tgt_flags->tagq_active && 3011 adapter->active_cmds[tgt_id] == 0 3012 && tgt_flags->tagq_ok && 3013 (adapter->tagq_ok & (1 << tgt_id))) { 3014 tgt_flags->tagq_active = true; 3015 blogic_notice("Tagged Queuing now active for Target %d\n", 3016 adapter, tgt_id); 3017 } 3018 if (tgt_flags->tagq_active) { 3019 enum blogic_queuetag queuetag = BLOGIC_SIMPLETAG; 3020 /* 3021 When using Tagged Queuing with Simple Queue Tags, it 3022 appears that disk drive controllers do not guarantee that 3023 a queued command will not remain in a disconnected state 3024 indefinitely if commands that read or write nearer the 3025 head position continue to arrive without interruption. 3026 Therefore, for each Target Device this driver keeps track 3027 of the last time either the queue was empty or an Ordered 3028 Queue Tag was issued. If more than 4 seconds (one fifth 3029 of the 20 second disk timeout) have elapsed since this 3030 last sequence point, this command will be issued with an 3031 Ordered Queue Tag rather than a Simple Queue Tag, which 3032 forces the Target Device to complete all previously 3033 queued commands before this command may be executed. 3034 */ 3035 if (adapter->active_cmds[tgt_id] == 0) 3036 adapter->last_seqpoint[tgt_id] = jiffies; 3037 else if (time_after(jiffies, 3038 adapter->last_seqpoint[tgt_id] + 4 * HZ)) { 3039 adapter->last_seqpoint[tgt_id] = jiffies; 3040 queuetag = BLOGIC_ORDEREDTAG; 3041 } 3042 if (adapter->ext_lun) { 3043 ccb->tag_enable = true; 3044 ccb->queuetag = queuetag; 3045 } else { 3046 ccb->legacytag_enable = true; 3047 ccb->legacy_tag = queuetag; 3048 } 3049 } 3050 memcpy(ccb->cdb, cdb, cdblen); 3051 ccb->sense_datalen = SCSI_SENSE_BUFFERSIZE; 3052 ccb->command = command; 3053 sense_buf = dma_map_single(&adapter->pci_device->dev, 3054 command->sense_buffer, ccb->sense_datalen, 3055 DMA_FROM_DEVICE); 3056 if (dma_mapping_error(&adapter->pci_device->dev, sense_buf)) { 3057 blogic_err("DMA mapping for sense data buffer failed\n", 3058 adapter); 3059 blogic_dealloc_ccb(shost, ccb, 0); 3060 return SCSI_MLQUEUE_HOST_BUSY; 3061 } 3062 ccb->sensedata = sense_buf; 3063 if (blogic_multimaster_type(adapter)) { 3064 /* 3065 Place the CCB in an Outgoing Mailbox. The higher levels 3066 of the SCSI Subsystem should not attempt to queue more 3067 commands than can be placed in Outgoing Mailboxes, so 3068 there should always be one free. In the unlikely event 3069 that there are none available, wait 1 second and try 3070 again. If that fails, the Host Adapter is probably hung 3071 so signal an error as a Host Adapter Hard Reset should 3072 be initiated soon. 3073 */ 3074 if (!blogic_write_outbox(shost, BLOGIC_MBOX_START, ccb)) { 3075 spin_unlock_irq(&shost->host_lock); 3076 blogic_warn("Unable to write Outgoing Mailbox - Pausing for 1 second\n", adapter); 3077 blogic_delay(1); 3078 spin_lock_irq(&shost->host_lock); 3079 if (!blogic_write_outbox(shost, BLOGIC_MBOX_START, 3080 ccb)) { 3081 blogic_warn("Still unable to write Outgoing Mailbox - Host Adapter Dead?\n", adapter); 3082 blogic_dealloc_ccb(shost, ccb, 1); 3083 command->result = DID_ERROR << 16; 3084 scsi_done(command); 3085 } 3086 } 3087 } else { 3088 /* 3089 Call the FlashPoint SCCB Manager to start execution of 3090 the CCB. 3091 */ 3092 ccb->status = BLOGIC_CCB_ACTIVE; 3093 adapter->active_cmds[tgt_id]++; 3094 tgt_stats[tgt_id].cmds_tried++; 3095 FlashPoint_StartCCB(adapter->cardhandle, ccb); 3096 /* 3097 The Command may have already completed and 3098 blogic_qcompleted_ccb been called, or it may still be 3099 pending. 3100 */ 3101 if (ccb->status == BLOGIC_CCB_COMPLETE) 3102 blogic_process_ccbs(shost); 3103 } 3104 return 0; 3105 } 3106 3107 static enum scsi_qc_status blogic_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) 3108 { 3109 enum scsi_qc_status rc; 3110 3111 spin_lock_irq(&shost->host_lock); 3112 rc = blogic_qcmd_lck(shost, cmd); 3113 spin_unlock_irq(&shost->host_lock); 3114 return rc; 3115 } 3116 3117 #if 0 3118 /* 3119 blogic_abort aborts Command if possible. 3120 */ 3121 3122 static int blogic_abort(struct scsi_cmnd *command) 3123 { 3124 struct Scsi_Host *const shost = command->device->host; 3125 struct blogic_adapter *adapter = (void *) shost->hostdata; 3126 int tgt_id = command->device->id; 3127 struct blogic_ccb *ccb; 3128 blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_request); 3129 3130 /* 3131 Attempt to find an Active CCB for this Command. If no Active 3132 CCB for this Command is found, then no Abort is necessary. 3133 */ 3134 for (ccb = adapter->all_ccbs; ccb != NULL; ccb = ccb->next_all) 3135 if (ccb->command == command) 3136 break; 3137 if (ccb == NULL) { 3138 blogic_warn("Unable to Abort Command to Target %d - No CCB Found\n", adapter, tgt_id); 3139 return SUCCESS; 3140 } else if (ccb->status == BLOGIC_CCB_COMPLETE) { 3141 blogic_warn("Unable to Abort Command to Target %d - CCB Completed\n", adapter, tgt_id); 3142 return SUCCESS; 3143 } else if (ccb->status == BLOGIC_CCB_RESET) { 3144 blogic_warn("Unable to Abort Command to Target %d - CCB Reset\n", adapter, tgt_id); 3145 return SUCCESS; 3146 } 3147 if (blogic_multimaster_type(adapter)) { 3148 /* 3149 Attempt to Abort this CCB. MultiMaster Firmware versions 3150 prior to 5.xx do not generate Abort Tag messages, but only 3151 generate the non-tagged Abort message. Since non-tagged 3152 commands are not sent by the Host Adapter until the queue 3153 of outstanding tagged commands has completed, and the 3154 Abort message is treated as a non-tagged command, it is 3155 effectively impossible to abort commands when Tagged 3156 Queuing is active. Firmware version 5.xx does generate 3157 Abort Tag messages, so it is possible to abort commands 3158 when Tagged Queuing is active. 3159 */ 3160 if (adapter->tgt_flags[tgt_id].tagq_active && 3161 adapter->fw_ver[0] < '5') { 3162 blogic_warn("Unable to Abort CCB #%ld to Target %d - Abort Tag Not Supported\n", adapter, ccb->serial, tgt_id); 3163 return FAILURE; 3164 } else if (blogic_write_outbox(shost, BLOGIC_MBOX_ABORT, 3165 ccb)) { 3166 blogic_warn("Aborting CCB #%ld to Target %d\n", 3167 adapter, ccb->serial, tgt_id); 3168 blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_tried); 3169 return SUCCESS; 3170 } else { 3171 blogic_warn("Unable to Abort CCB #%ld to Target %d - No Outgoing Mailboxes\n", adapter, ccb->serial, tgt_id); 3172 return FAILURE; 3173 } 3174 } else { 3175 /* 3176 Call the FlashPoint SCCB Manager to abort execution of 3177 the CCB. 3178 */ 3179 blogic_warn("Aborting CCB #%ld to Target %d\n", adapter, 3180 ccb->serial, tgt_id); 3181 blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_tried); 3182 FlashPoint_AbortCCB(adapter->cardhandle, ccb); 3183 /* 3184 The Abort may have already been completed and 3185 blogic_qcompleted_ccb been called, or it 3186 may still be pending. 3187 */ 3188 if (ccb->status == BLOGIC_CCB_COMPLETE) 3189 blogic_process_ccbs(shost); 3190 return SUCCESS; 3191 } 3192 return SUCCESS; 3193 } 3194 3195 #endif 3196 /* 3197 blogic_resetadapter resets Host Adapter if possible, marking all 3198 currently executing SCSI Commands as having been Reset. 3199 */ 3200 3201 static int blogic_resetadapter(struct Scsi_Host *host, bool hard_reset) 3202 __must_hold(&host->host_lock) 3203 { 3204 struct blogic_adapter *adapter = (void *)host->hostdata; 3205 struct blogic_ccb *ccb; 3206 int tgt_id; 3207 3208 /* 3209 * Attempt to Reset and Reinitialize the Host Adapter. 3210 */ 3211 3212 if (!(blogic_hwreset(adapter, hard_reset) && 3213 blogic_initadapter(adapter))) { 3214 blogic_err("Resetting %s Failed\n", adapter, 3215 adapter->full_model); 3216 return FAILURE; 3217 } 3218 3219 /* 3220 * Deallocate all currently executing CCBs. 3221 */ 3222 3223 for (ccb = adapter->all_ccbs; ccb != NULL; ccb = ccb->next_all) 3224 if (ccb->status == BLOGIC_CCB_ACTIVE) 3225 blogic_dealloc_ccb(host, ccb, 1); 3226 /* 3227 * Wait a few seconds between the Host Adapter Hard Reset which 3228 * initiates a SCSI Bus Reset and issuing any SCSI Commands. Some 3229 * SCSI devices get confused if they receive SCSI Commands too soon 3230 * after a SCSI Bus Reset. 3231 */ 3232 3233 if (hard_reset) { 3234 spin_unlock_irq(&host->host_lock); 3235 blogic_delay(adapter->bus_settle_time); 3236 spin_lock_irq(&host->host_lock); 3237 } 3238 3239 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) { 3240 adapter->last_resettried[tgt_id] = jiffies; 3241 adapter->last_resetdone[tgt_id] = jiffies; 3242 } 3243 return SUCCESS; 3244 } 3245 3246 /* 3247 blogic_diskparam returns the Heads/Sectors/Cylinders BIOS Disk 3248 Parameters for Disk. The default disk geometry is 64 heads, 32 sectors, and 3249 the appropriate number of cylinders so as not to exceed drive capacity. In 3250 order for disks equal to or larger than 1 GB to be addressable by the BIOS 3251 without exceeding the BIOS limitation of 1024 cylinders, Extended Translation 3252 may be enabled in AutoSCSI on FlashPoint Host Adapters and on "W" and "C" 3253 series MultiMaster Host Adapters, or by a dip switch setting on "S" and "A" 3254 series MultiMaster Host Adapters. With Extended Translation enabled, drives 3255 between 1 GB inclusive and 2 GB exclusive are given a disk geometry of 128 3256 heads and 32 sectors, and drives above 2 GB inclusive are given a disk 3257 geometry of 255 heads and 63 sectors. However, if the BIOS detects that the 3258 Extended Translation setting does not match the geometry in the partition 3259 table, then the translation inferred from the partition table will be used by 3260 the BIOS, and a warning may be displayed. 3261 */ 3262 3263 static int blogic_diskparam(struct scsi_device *sdev, struct gendisk *disk, 3264 sector_t capacity, int *params) 3265 { 3266 struct blogic_adapter *adapter = 3267 (struct blogic_adapter *) sdev->host->hostdata; 3268 struct bios_diskparam *diskparam = (struct bios_diskparam *) params; 3269 unsigned char *buf; 3270 3271 if (adapter->ext_trans_enable && capacity >= 2 * 1024 * 1024 /* 1 GB in 512 byte sectors */) { 3272 if (capacity >= 4 * 1024 * 1024 /* 2 GB in 512 byte sectors */) { 3273 diskparam->heads = 255; 3274 diskparam->sectors = 63; 3275 } else { 3276 diskparam->heads = 128; 3277 diskparam->sectors = 32; 3278 } 3279 } else { 3280 diskparam->heads = 64; 3281 diskparam->sectors = 32; 3282 } 3283 diskparam->cylinders = (unsigned long) capacity / (diskparam->heads * diskparam->sectors); 3284 buf = scsi_bios_ptable(disk); 3285 if (buf == NULL) 3286 return 0; 3287 /* 3288 If the boot sector partition table flag is valid, search for 3289 a partition table entry whose end_head matches one of the 3290 standard BusLogic geometry translations (64/32, 128/32, or 255/63). 3291 */ 3292 if (*(unsigned short *) (buf + 64) == MSDOS_LABEL_MAGIC) { 3293 struct msdos_partition *part1_entry = 3294 (struct msdos_partition *)buf; 3295 struct msdos_partition *part_entry = part1_entry; 3296 int saved_cyl = diskparam->cylinders, part_no; 3297 unsigned char part_end_head = 0, part_end_sector = 0; 3298 3299 for (part_no = 0; part_no < 4; part_no++) { 3300 part_end_head = part_entry->end_head; 3301 part_end_sector = part_entry->end_sector & 0x3F; 3302 if (part_end_head == 64 - 1) { 3303 diskparam->heads = 64; 3304 diskparam->sectors = 32; 3305 break; 3306 } else if (part_end_head == 128 - 1) { 3307 diskparam->heads = 128; 3308 diskparam->sectors = 32; 3309 break; 3310 } else if (part_end_head == 255 - 1) { 3311 diskparam->heads = 255; 3312 diskparam->sectors = 63; 3313 break; 3314 } 3315 part_entry++; 3316 } 3317 if (part_no == 4) { 3318 part_end_head = part1_entry->end_head; 3319 part_end_sector = part1_entry->end_sector & 0x3F; 3320 } 3321 diskparam->cylinders = (unsigned long) capacity / (diskparam->heads * diskparam->sectors); 3322 if (part_no < 4 && part_end_sector == diskparam->sectors) { 3323 if (diskparam->cylinders != saved_cyl) 3324 blogic_warn("Adopting Geometry %d/%d from Partition Table\n", adapter, diskparam->heads, diskparam->sectors); 3325 } else if (part_end_head > 0 || part_end_sector > 0) { 3326 blogic_warn("Warning: Partition Table appears to have Geometry %d/%d which is\n", adapter, part_end_head + 1, part_end_sector); 3327 blogic_warn("not compatible with current BusLogic Host Adapter Geometry %d/%d\n", adapter, diskparam->heads, diskparam->sectors); 3328 } 3329 } 3330 kfree(buf); 3331 return 0; 3332 } 3333 3334 3335 /* 3336 BugLogic_ProcDirectoryInfo implements /proc/scsi/BusLogic/<N>. 3337 */ 3338 3339 static int blogic_write_info(struct Scsi_Host *shost, char *procbuf, 3340 int bytes_avail) 3341 { 3342 struct blogic_adapter *adapter = 3343 (struct blogic_adapter *) shost->hostdata; 3344 struct blogic_tgt_stats *tgt_stats; 3345 3346 tgt_stats = adapter->tgt_stats; 3347 adapter->ext_resets = 0; 3348 adapter->adapter_intern_errors = 0; 3349 memset(tgt_stats, 0, BLOGIC_MAXDEV * sizeof(struct blogic_tgt_stats)); 3350 return 0; 3351 } 3352 3353 static int blogic_show_info(struct seq_file *m, struct Scsi_Host *shost) 3354 { 3355 struct blogic_adapter *adapter = (struct blogic_adapter *) shost->hostdata; 3356 struct blogic_tgt_stats *tgt_stats; 3357 int tgt; 3358 3359 tgt_stats = adapter->tgt_stats; 3360 seq_write(m, adapter->msgbuf, adapter->msgbuflen); 3361 seq_printf(m, "\n\ 3362 Current Driver Queue Depth: %d\n\ 3363 Currently Allocated CCBs: %d\n", adapter->drvr_qdepth, adapter->alloc_ccbs); 3364 seq_puts(m, "\n\n\ 3365 DATA TRANSFER STATISTICS\n\ 3366 \n\ 3367 Target Tagged Queuing Queue Depth Active Attempted Completed\n\ 3368 ====== ============== =========== ====== ========= =========\n"); 3369 for (tgt = 0; tgt < adapter->maxdev; tgt++) { 3370 struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt]; 3371 if (!tgt_flags->tgt_exists) 3372 continue; 3373 seq_printf(m, " %2d %s", tgt, (tgt_flags->tagq_ok ? (tgt_flags->tagq_active ? " Active" : (adapter->tagq_ok & (1 << tgt) 3374 ? " Permitted" : " Disabled")) 3375 : "Not Supported")); 3376 seq_printf(m, 3377 " %3d %3u %9u %9u\n", adapter->qdepth[tgt], adapter->active_cmds[tgt], tgt_stats[tgt].cmds_tried, tgt_stats[tgt].cmds_complete); 3378 } 3379 seq_puts(m, "\n\ 3380 Target Read Commands Write Commands Total Bytes Read Total Bytes Written\n\ 3381 ====== ============= ============== =================== ===================\n"); 3382 for (tgt = 0; tgt < adapter->maxdev; tgt++) { 3383 struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt]; 3384 if (!tgt_flags->tgt_exists) 3385 continue; 3386 seq_printf(m, " %2d %9u %9u", tgt, tgt_stats[tgt].read_cmds, tgt_stats[tgt].write_cmds); 3387 if (tgt_stats[tgt].bytesread.billions > 0) 3388 seq_printf(m, " %9u%09u", tgt_stats[tgt].bytesread.billions, tgt_stats[tgt].bytesread.units); 3389 else 3390 seq_printf(m, " %9u", tgt_stats[tgt].bytesread.units); 3391 if (tgt_stats[tgt].byteswritten.billions > 0) 3392 seq_printf(m, " %9u%09u\n", tgt_stats[tgt].byteswritten.billions, tgt_stats[tgt].byteswritten.units); 3393 else 3394 seq_printf(m, " %9u\n", tgt_stats[tgt].byteswritten.units); 3395 } 3396 seq_puts(m, "\n\ 3397 Target Command 0-1KB 1-2KB 2-4KB 4-8KB 8-16KB\n\ 3398 ====== ======= ========= ========= ========= ========= =========\n"); 3399 for (tgt = 0; tgt < adapter->maxdev; tgt++) { 3400 struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt]; 3401 if (!tgt_flags->tgt_exists) 3402 continue; 3403 seq_printf(m, 3404 " %2d Read %9u %9u %9u %9u %9u\n", tgt, 3405 tgt_stats[tgt].read_sz_buckets[0], 3406 tgt_stats[tgt].read_sz_buckets[1], tgt_stats[tgt].read_sz_buckets[2], tgt_stats[tgt].read_sz_buckets[3], tgt_stats[tgt].read_sz_buckets[4]); 3407 seq_printf(m, 3408 " %2d Write %9u %9u %9u %9u %9u\n", tgt, 3409 tgt_stats[tgt].write_sz_buckets[0], 3410 tgt_stats[tgt].write_sz_buckets[1], tgt_stats[tgt].write_sz_buckets[2], tgt_stats[tgt].write_sz_buckets[3], tgt_stats[tgt].write_sz_buckets[4]); 3411 } 3412 seq_puts(m, "\n\ 3413 Target Command 16-32KB 32-64KB 64-128KB 128-256KB 256KB+\n\ 3414 ====== ======= ========= ========= ========= ========= =========\n"); 3415 for (tgt = 0; tgt < adapter->maxdev; tgt++) { 3416 struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt]; 3417 if (!tgt_flags->tgt_exists) 3418 continue; 3419 seq_printf(m, 3420 " %2d Read %9u %9u %9u %9u %9u\n", tgt, 3421 tgt_stats[tgt].read_sz_buckets[5], 3422 tgt_stats[tgt].read_sz_buckets[6], tgt_stats[tgt].read_sz_buckets[7], tgt_stats[tgt].read_sz_buckets[8], tgt_stats[tgt].read_sz_buckets[9]); 3423 seq_printf(m, 3424 " %2d Write %9u %9u %9u %9u %9u\n", tgt, 3425 tgt_stats[tgt].write_sz_buckets[5], 3426 tgt_stats[tgt].write_sz_buckets[6], tgt_stats[tgt].write_sz_buckets[7], tgt_stats[tgt].write_sz_buckets[8], tgt_stats[tgt].write_sz_buckets[9]); 3427 } 3428 seq_puts(m, "\n\n\ 3429 ERROR RECOVERY STATISTICS\n\ 3430 \n\ 3431 Command Aborts Bus Device Resets Host Adapter Resets\n\ 3432 Target Requested Completed Requested Completed Requested Completed\n\ 3433 ID \\\\\\\\ Attempted //// \\\\\\\\ Attempted //// \\\\\\\\ Attempted ////\n\ 3434 ====== ===== ===== ===== ===== ===== ===== ===== ===== =====\n"); 3435 for (tgt = 0; tgt < adapter->maxdev; tgt++) { 3436 struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt]; 3437 if (!tgt_flags->tgt_exists) 3438 continue; 3439 seq_printf(m, " %2d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", 3440 tgt, tgt_stats[tgt].aborts_request, 3441 tgt_stats[tgt].aborts_tried, 3442 tgt_stats[tgt].aborts_done, 3443 tgt_stats[tgt].bdr_request, 3444 tgt_stats[tgt].bdr_tried, 3445 tgt_stats[tgt].bdr_done, 3446 tgt_stats[tgt].adapter_reset_req, 3447 tgt_stats[tgt].adapter_reset_attempt, 3448 tgt_stats[tgt].adapter_reset_done); 3449 } 3450 seq_printf(m, "\nExternal Host Adapter Resets: %d\n", adapter->ext_resets); 3451 seq_printf(m, "Host Adapter Internal Errors: %d\n", adapter->adapter_intern_errors); 3452 return 0; 3453 } 3454 3455 3456 /* 3457 blogic_msg prints Driver Messages. 3458 */ 3459 __printf(2, 4) 3460 static void blogic_msg(enum blogic_msglevel msglevel, char *fmt, 3461 struct blogic_adapter *adapter, ...) 3462 { 3463 static char buf[BLOGIC_LINEBUF_SIZE]; 3464 static bool begin = true; 3465 va_list args; 3466 int len = 0; 3467 3468 va_start(args, adapter); 3469 len = vscnprintf(buf, sizeof(buf), fmt, args); 3470 va_end(args); 3471 if (msglevel == BLOGIC_ANNOUNCE_LEVEL) { 3472 static int msglines = 0; 3473 strcpy(&adapter->msgbuf[adapter->msgbuflen], buf); 3474 adapter->msgbuflen += len; 3475 if (++msglines <= 2) 3476 printk("%sscsi: %s", blogic_msglevelmap[msglevel], buf); 3477 } else if (msglevel == BLOGIC_INFO_LEVEL) { 3478 strcpy(&adapter->msgbuf[adapter->msgbuflen], buf); 3479 adapter->msgbuflen += len; 3480 if (begin) { 3481 if (buf[0] != '\n' || len > 1) 3482 printk("%sscsi%d: %s", blogic_msglevelmap[msglevel], adapter->host_no, buf); 3483 } else 3484 pr_cont("%s", buf); 3485 } else { 3486 if (begin) { 3487 if (adapter != NULL && adapter->adapter_initd) 3488 printk("%sscsi%d: %s", blogic_msglevelmap[msglevel], adapter->host_no, buf); 3489 else 3490 printk("%s%s", blogic_msglevelmap[msglevel], buf); 3491 } else 3492 pr_cont("%s", buf); 3493 } 3494 begin = (buf[len - 1] == '\n'); 3495 } 3496 3497 3498 /* 3499 blogic_parse parses an individual option keyword. It returns true 3500 and updates the pointer if the keyword is recognized and false otherwise. 3501 */ 3502 3503 static bool __init blogic_parse(char **str, char *keyword) 3504 { 3505 char *pointer = *str; 3506 while (*keyword != '\0') { 3507 char strch = *pointer++; 3508 char keywordch = *keyword++; 3509 if (strch >= 'A' && strch <= 'Z') 3510 strch += 'a' - 'Z'; 3511 if (keywordch >= 'A' && keywordch <= 'Z') 3512 keywordch += 'a' - 'Z'; 3513 if (strch != keywordch) 3514 return false; 3515 } 3516 *str = pointer; 3517 return true; 3518 } 3519 3520 3521 /* 3522 blogic_parseopts handles processing of BusLogic Driver Options 3523 specifications. 3524 3525 BusLogic Driver Options may be specified either via the Linux Kernel Command 3526 Line or via the Loadable Kernel Module Installation Facility. Driver Options 3527 for multiple host adapters may be specified either by separating the option 3528 strings by a semicolon, or by specifying multiple "BusLogic=" strings on the 3529 command line. Individual option specifications for a single host adapter are 3530 separated by commas. The Probing and Debugging Options apply to all host 3531 adapters whereas the remaining options apply individually only to the 3532 selected host adapter. 3533 3534 The BusLogic Driver Probing Options are described in 3535 <file:Documentation/scsi/BusLogic.rst>. 3536 */ 3537 3538 static int __init blogic_parseopts(char *options) 3539 { 3540 while (true) { 3541 struct blogic_drvr_options *drvr_opts = 3542 &blogic_drvr_options[blogic_drvr_options_count++]; 3543 int tgt_id; 3544 3545 memset(drvr_opts, 0, sizeof(struct blogic_drvr_options)); 3546 while (*options != '\0' && *options != ';') { 3547 if (blogic_parse(&options, "NoProbePCI")) 3548 blogic_probe_options.noprobe_pci = true; 3549 else if (blogic_parse(&options, "NoProbe")) 3550 blogic_probe_options.noprobe = true; 3551 else if (blogic_parse(&options, "NoSortPCI")) 3552 blogic_probe_options.nosort_pci = true; 3553 else if (blogic_parse(&options, "MultiMasterFirst")) 3554 blogic_probe_options.multimaster_first = true; 3555 else if (blogic_parse(&options, "FlashPointFirst")) 3556 blogic_probe_options.flashpoint_first = true; 3557 /* Tagged Queuing Options. */ 3558 else if (blogic_parse(&options, "QueueDepth:[") || 3559 blogic_parse(&options, "QD:[")) { 3560 for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) { 3561 unsigned short qdepth = simple_strtoul(options, &options, 0); 3562 if (qdepth > BLOGIC_MAX_TAG_DEPTH) { 3563 blogic_err("BusLogic: Invalid Driver Options (invalid Queue Depth %d)\n", NULL, qdepth); 3564 return 0; 3565 } 3566 drvr_opts->qdepth[tgt_id] = qdepth; 3567 if (*options == ',') 3568 options++; 3569 else if (*options == ']') 3570 break; 3571 else { 3572 blogic_err("BusLogic: Invalid Driver Options (',' or ']' expected at '%s')\n", NULL, options); 3573 return 0; 3574 } 3575 } 3576 if (*options != ']') { 3577 blogic_err("BusLogic: Invalid Driver Options (']' expected at '%s')\n", NULL, options); 3578 return 0; 3579 } else 3580 options++; 3581 } else if (blogic_parse(&options, "QueueDepth:") || blogic_parse(&options, "QD:")) { 3582 unsigned short qdepth = simple_strtoul(options, &options, 0); 3583 if (qdepth == 0 || 3584 qdepth > BLOGIC_MAX_TAG_DEPTH) { 3585 blogic_err("BusLogic: Invalid Driver Options (invalid Queue Depth %d)\n", NULL, qdepth); 3586 return 0; 3587 } 3588 drvr_opts->common_qdepth = qdepth; 3589 for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) 3590 drvr_opts->qdepth[tgt_id] = qdepth; 3591 } else if (blogic_parse(&options, "TaggedQueuing:") || 3592 blogic_parse(&options, "TQ:")) { 3593 if (blogic_parse(&options, "Default")) { 3594 drvr_opts->tagq_ok = 0x0000; 3595 drvr_opts->tagq_ok_mask = 0x0000; 3596 } else if (blogic_parse(&options, "Enable")) { 3597 drvr_opts->tagq_ok = 0xFFFF; 3598 drvr_opts->tagq_ok_mask = 0xFFFF; 3599 } else if (blogic_parse(&options, "Disable")) { 3600 drvr_opts->tagq_ok = 0x0000; 3601 drvr_opts->tagq_ok_mask = 0xFFFF; 3602 } else { 3603 unsigned short tgt_bit; 3604 for (tgt_id = 0, tgt_bit = 1; 3605 tgt_id < BLOGIC_MAXDEV; 3606 tgt_id++, tgt_bit <<= 1) 3607 switch (*options++) { 3608 case 'Y': 3609 drvr_opts->tagq_ok |= tgt_bit; 3610 drvr_opts->tagq_ok_mask |= tgt_bit; 3611 break; 3612 case 'N': 3613 drvr_opts->tagq_ok &= ~tgt_bit; 3614 drvr_opts->tagq_ok_mask |= tgt_bit; 3615 break; 3616 case 'X': 3617 break; 3618 default: 3619 options--; 3620 tgt_id = BLOGIC_MAXDEV; 3621 break; 3622 } 3623 } 3624 } 3625 /* Miscellaneous Options. */ 3626 else if (blogic_parse(&options, "BusSettleTime:") || 3627 blogic_parse(&options, "BST:")) { 3628 unsigned short bus_settle_time = 3629 simple_strtoul(options, &options, 0); 3630 if (bus_settle_time > 5 * 60) { 3631 blogic_err("BusLogic: Invalid Driver Options (invalid Bus Settle Time %d)\n", NULL, bus_settle_time); 3632 return 0; 3633 } 3634 drvr_opts->bus_settle_time = bus_settle_time; 3635 } else if (blogic_parse(&options, 3636 "InhibitTargetInquiry")) 3637 drvr_opts->stop_tgt_inquiry = true; 3638 /* Debugging Options. */ 3639 else if (blogic_parse(&options, "TraceProbe")) 3640 blogic_global_options.trace_probe = true; 3641 else if (blogic_parse(&options, "TraceHardwareReset")) 3642 blogic_global_options.trace_hw_reset = true; 3643 else if (blogic_parse(&options, "TraceConfiguration")) 3644 blogic_global_options.trace_config = true; 3645 else if (blogic_parse(&options, "TraceErrors")) 3646 blogic_global_options.trace_err = true; 3647 else if (blogic_parse(&options, "Debug")) { 3648 blogic_global_options.trace_probe = true; 3649 blogic_global_options.trace_hw_reset = true; 3650 blogic_global_options.trace_config = true; 3651 blogic_global_options.trace_err = true; 3652 } 3653 if (*options == ',') 3654 options++; 3655 else if (*options != ';' && *options != '\0') { 3656 blogic_err("BusLogic: Unexpected Driver Option '%s' ignored\n", NULL, options); 3657 *options = '\0'; 3658 } 3659 } 3660 if (!(blogic_drvr_options_count == 0 || 3661 blogic_probeinfo_count == 0 || 3662 blogic_drvr_options_count == blogic_probeinfo_count)) { 3663 blogic_err("BusLogic: Invalid Driver Options (all or no I/O Addresses must be specified)\n", NULL); 3664 return 0; 3665 } 3666 /* 3667 Tagged Queuing is disabled when the Queue Depth is 1 since queuing 3668 multiple commands is not possible. 3669 */ 3670 for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) 3671 if (drvr_opts->qdepth[tgt_id] == 1) { 3672 unsigned short tgt_bit = 1 << tgt_id; 3673 drvr_opts->tagq_ok &= ~tgt_bit; 3674 drvr_opts->tagq_ok_mask |= tgt_bit; 3675 } 3676 if (*options == ';') 3677 options++; 3678 if (*options == '\0') 3679 return 0; 3680 } 3681 return 1; 3682 } 3683 3684 /* 3685 Get it all started 3686 */ 3687 3688 static const struct scsi_host_template blogic_template = { 3689 .module = THIS_MODULE, 3690 .proc_name = "BusLogic", 3691 .write_info = blogic_write_info, 3692 .show_info = blogic_show_info, 3693 .name = "BusLogic", 3694 .info = blogic_drvr_info, 3695 .queuecommand = blogic_qcmd, 3696 .sdev_configure = blogic_sdev_configure, 3697 .bios_param = blogic_diskparam, 3698 .eh_host_reset_handler = blogic_hostreset, 3699 #if 0 3700 .eh_abort_handler = blogic_abort, 3701 #endif 3702 .max_sectors = 128, 3703 }; 3704 3705 /* 3706 blogic_setup handles processing of Kernel Command Line Arguments. 3707 */ 3708 3709 static int __init blogic_setup(char *str) 3710 { 3711 int ints[3]; 3712 3713 (void) get_options(str, ARRAY_SIZE(ints), ints); 3714 3715 if (ints[0] != 0) { 3716 blogic_err("BusLogic: Obsolete Command Line Entry Format Ignored\n", NULL); 3717 return 0; 3718 } 3719 if (str == NULL || *str == '\0') 3720 return 0; 3721 return blogic_parseopts(str); 3722 } 3723 3724 /* 3725 * Exit function. Deletes all hosts associated with this driver. 3726 */ 3727 3728 static void __exit blogic_exit(void) 3729 { 3730 struct blogic_adapter *ha, *next; 3731 3732 list_for_each_entry_safe(ha, next, &blogic_host_list, host_list) 3733 blogic_deladapter(ha); 3734 } 3735 3736 __setup("BusLogic=", blogic_setup); 3737 3738 /*static const struct pci_device_id blogic_pci_tbl[] = { 3739 { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, 3740 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 3741 { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC, 3742 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 3743 { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT, 3744 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 3745 { } 3746 };*/ 3747 static const struct pci_device_id blogic_pci_tbl[] __maybe_unused = { 3748 {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER)}, 3749 {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC)}, 3750 {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, 3751 {0, }, 3752 }; 3753 MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); 3754 3755 module_init(blogic_init); 3756 module_exit(blogic_exit); 3757