1 /* 2 ***************************************************************************************** 3 ** O.S : FreeBSD 4 ** FILE NAME : arcmsr.c 5 ** BY : Erich Chen 6 ** Description: SCSI RAID Device Driver for 7 ** ARECA (ARC11XX/ARC12XX/ARC13XX/ARC16XX) SATA/SAS RAID HOST Adapter 8 ** ARCMSR RAID Host adapter 9 ** [RAID controller:INTEL 331(PCI-X) 341(PCI-EXPRESS) chip set] 10 ****************************************************************************************** 11 ************************************************************************ 12 ** 13 ** Copyright (c) 2004-2006 ARECA Co. Ltd. 14 ** Erich Chen, Taipei Taiwan All rights reserved. 15 ** 16 ** Redistribution and use in source and binary forms, with or without 17 ** modification, are permitted provided that the following conditions 18 ** are met: 19 ** 1. Redistributions of source code must retain the above copyright 20 ** notice, this list of conditions and the following disclaimer. 21 ** 2. Redistributions in binary form must reproduce the above copyright 22 ** notice, this list of conditions and the following disclaimer in the 23 ** documentation and/or other materials provided with the distribution. 24 ** 3. The name of the author may not be used to endorse or promote products 25 ** derived from this software without specific prior written permission. 26 ** 27 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 28 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 29 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 30 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 31 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT 32 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 **(INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF 36 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 ************************************************************************** 38 ** History 39 ** 40 ** REV# DATE NAME DESCRIPTION 41 ** 1.00.00.00 3/31/2004 Erich Chen First release 42 ** 1.20.00.02 11/29/2004 Erich Chen bug fix with arcmsr_bus_reset when PHY error 43 ** 1.20.00.03 4/19/2005 Erich Chen add SATA 24 Ports adapter type support 44 ** clean unused function 45 ** 1.20.00.12 9/12/2005 Erich Chen bug fix with abort command handling, 46 ** firmware version check 47 ** and firmware update notify for hardware bug fix 48 ** handling if none zero high part physical address 49 ** of srb resource 50 ** 1.20.00.13 8/18/2006 Erich Chen remove pending srb and report busy 51 ** add iop message xfer 52 ** with scsi pass-through command 53 ** add new device id of sas raid adapters 54 ** code fit for SPARC64 & PPC 55 ** 1.20.00.14 02/05/2007 Erich Chen bug fix for incorrect ccb_h.status report 56 ** and cause g_vfs_done() read write error 57 ** 1.20.00.15 10/10/2007 Erich Chen support new RAID adapter type ARC120x 58 ****************************************************************************************** 59 * $FreeBSD$ 60 */ 61 #include <sys/param.h> 62 #include <sys/systm.h> 63 #include <sys/malloc.h> 64 #include <sys/kernel.h> 65 #include <sys/bus.h> 66 #include <sys/queue.h> 67 #include <sys/stat.h> 68 #include <sys/devicestat.h> 69 #include <sys/kthread.h> 70 #include <sys/module.h> 71 #include <sys/proc.h> 72 #include <sys/lock.h> 73 #include <sys/sysctl.h> 74 #include <sys/poll.h> 75 #include <sys/ioccom.h> 76 #include <vm/vm.h> 77 #include <vm/vm_param.h> 78 #include <vm/pmap.h> 79 80 #include <isa/rtc.h> 81 82 #include <machine/bus.h> 83 #include <machine/resource.h> 84 #include <machine/atomic.h> 85 #include <sys/conf.h> 86 #include <sys/rman.h> 87 88 #include <cam/cam.h> 89 #include <cam/cam_ccb.h> 90 #include <cam/cam_sim.h> 91 #include <cam/cam_xpt_sim.h> 92 #include <cam/cam_debug.h> 93 #include <cam/scsi/scsi_all.h> 94 #include <cam/scsi/scsi_message.h> 95 /* 96 ************************************************************************** 97 ************************************************************************** 98 */ 99 #if __FreeBSD_version >= 500005 100 #include <sys/selinfo.h> 101 #include <sys/mutex.h> 102 #include <sys/endian.h> 103 #include <dev/pci/pcivar.h> 104 #include <dev/pci/pcireg.h> 105 #define ARCMSR_LOCK_INIT(l, s) mtx_init(l, s, NULL, MTX_DEF) 106 #define ARCMSR_LOCK_DESTROY(l) mtx_destroy(l) 107 #define ARCMSR_LOCK_ACQUIRE(l) mtx_lock(l) 108 #define ARCMSR_LOCK_RELEASE(l) mtx_unlock(l) 109 #define ARCMSR_LOCK_TRY(l) mtx_trylock(l) 110 #define arcmsr_htole32(x) htole32(x) 111 typedef struct mtx arcmsr_lock_t; 112 #else 113 #include <sys/select.h> 114 #include <pci/pcivar.h> 115 #include <pci/pcireg.h> 116 #define ARCMSR_LOCK_INIT(l, s) simple_lock_init(l) 117 #define ARCMSR_LOCK_DESTROY(l) 118 #define ARCMSR_LOCK_ACQUIRE(l) simple_lock(l) 119 #define ARCMSR_LOCK_RELEASE(l) simple_unlock(l) 120 #define ARCMSR_LOCK_TRY(l) simple_lock_try(l) 121 #define arcmsr_htole32(x) (x) 122 typedef struct simplelock arcmsr_lock_t; 123 #endif 124 125 #if !defined(CAM_NEW_TRAN_CODE) && __FreeBSD_version >= 700025 126 #define CAM_NEW_TRAN_CODE 1 127 #endif 128 129 #include <dev/arcmsr/arcmsr.h> 130 #define ARCMSR_SRBS_POOL_SIZE ((sizeof(struct CommandControlBlock) * ARCMSR_MAX_FREESRB_NUM)) 131 /* 132 ************************************************************************** 133 ************************************************************************** 134 */ 135 #define CHIP_REG_READ32(s, b, r) bus_space_read_4(acb->btag[b], acb->bhandle[b], offsetof(struct s, r)) 136 #define CHIP_REG_WRITE32(s, b, r, d) bus_space_write_4(acb->btag[b], acb->bhandle[b], offsetof(struct s, r), d) 137 /* 138 ************************************************************************** 139 ************************************************************************** 140 */ 141 static struct CommandControlBlock * arcmsr_get_freesrb(struct AdapterControlBlock *acb); 142 static u_int8_t arcmsr_seek_cmd2abort(union ccb * abortccb); 143 static int arcmsr_probe(device_t dev); 144 static int arcmsr_attach(device_t dev); 145 static int arcmsr_detach(device_t dev); 146 static u_int32_t arcmsr_iop_ioctlcmd(struct AdapterControlBlock *acb, u_int32_t ioctl_cmd, caddr_t arg); 147 static void arcmsr_iop_parking(struct AdapterControlBlock *acb); 148 static int arcmsr_shutdown(device_t dev); 149 static void arcmsr_interrupt(struct AdapterControlBlock *acb); 150 static void arcmsr_polling_srbdone(struct AdapterControlBlock *acb, struct CommandControlBlock *poll_srb); 151 static void arcmsr_free_resource(struct AdapterControlBlock *acb); 152 static void arcmsr_bus_reset(struct AdapterControlBlock *acb); 153 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb); 154 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock *acb); 155 static void arcmsr_iop_init(struct AdapterControlBlock *acb); 156 static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb); 157 static void arcmsr_post_ioctldata2iop(struct AdapterControlBlock *acb); 158 static void arcmsr_abort_allcmd(struct AdapterControlBlock *acb); 159 static void arcmsr_srb_complete(struct CommandControlBlock *srb, int stand_flag); 160 static void arcmsr_iop_reset(struct AdapterControlBlock *acb); 161 static void arcmsr_report_sense_info(struct CommandControlBlock *srb); 162 static void arcmsr_build_srb(struct CommandControlBlock *srb, bus_dma_segment_t * dm_segs, u_int32_t nseg); 163 static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, union ccb * pccb); 164 static int arcmsr_resume(device_t dev); 165 static int arcmsr_suspend(device_t dev); 166 /* 167 ************************************************************************** 168 ************************************************************************** 169 */ 170 static void UDELAY(u_int32_t us) { DELAY(us); } 171 /* 172 ************************************************************************** 173 ************************************************************************** 174 */ 175 static bus_dmamap_callback_t arcmsr_map_freesrb; 176 static bus_dmamap_callback_t arcmsr_executesrb; 177 /* 178 ************************************************************************** 179 ************************************************************************** 180 */ 181 static d_open_t arcmsr_open; 182 static d_close_t arcmsr_close; 183 static d_ioctl_t arcmsr_ioctl; 184 185 static device_method_t arcmsr_methods[]={ 186 DEVMETHOD(device_probe, arcmsr_probe), 187 DEVMETHOD(device_attach, arcmsr_attach), 188 DEVMETHOD(device_detach, arcmsr_detach), 189 DEVMETHOD(device_shutdown, arcmsr_shutdown), 190 DEVMETHOD(device_suspend, arcmsr_suspend), 191 DEVMETHOD(device_resume, arcmsr_resume), 192 193 DEVMETHOD(bus_print_child, bus_generic_print_child), 194 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 195 { 0, 0 } 196 }; 197 198 static driver_t arcmsr_driver={ 199 "arcmsr", arcmsr_methods, sizeof(struct AdapterControlBlock) 200 }; 201 202 static devclass_t arcmsr_devclass; 203 DRIVER_MODULE(arcmsr, pci, arcmsr_driver, arcmsr_devclass, 0, 0); 204 MODULE_DEPEND(arcmsr, pci, 1, 1, 1); 205 MODULE_DEPEND(arcmsr, cam, 1, 1, 1); 206 #ifndef BUS_DMA_COHERENT 207 #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ 208 #endif 209 #if __FreeBSD_version >= 501000 210 #ifndef D_NEEDGIANT 211 #define D_NEEDGIANT 0x00400000 /* driver want Giant */ 212 #endif 213 #ifndef D_VERSION 214 #define D_VERSION 0x20011966 215 #endif 216 static struct cdevsw arcmsr_cdevsw={ 217 #if __FreeBSD_version > 502010 218 .d_version = D_VERSION, 219 #endif 220 .d_flags = D_NEEDGIANT, 221 .d_open = arcmsr_open, /* open */ 222 .d_close = arcmsr_close, /* close */ 223 .d_ioctl = arcmsr_ioctl, /* ioctl */ 224 .d_name = "arcmsr", /* name */ 225 }; 226 #else 227 #define ARCMSR_CDEV_MAJOR 180 228 229 static struct cdevsw arcmsr_cdevsw = { 230 arcmsr_open, /* open */ 231 arcmsr_close, /* close */ 232 noread, /* read */ 233 nowrite, /* write */ 234 arcmsr_ioctl, /* ioctl */ 235 nopoll, /* poll */ 236 nommap, /* mmap */ 237 nostrategy, /* strategy */ 238 "arcmsr", /* name */ 239 ARCMSR_CDEV_MAJOR, /* major */ 240 nodump, /* dump */ 241 nopsize, /* psize */ 242 0 /* flags */ 243 }; 244 #endif 245 246 #if __FreeBSD_version < 500005 247 static int arcmsr_open(dev_t dev, int flags, int fmt, struct proc *proc) 248 #else 249 #if __FreeBSD_version < 503000 250 static int arcmsr_open(dev_t dev, int flags, int fmt, struct thread *proc) 251 #else 252 static int arcmsr_open(struct cdev *dev, int flags, int fmt, d_thread_t *proc) 253 #endif 254 #endif 255 { 256 #if __FreeBSD_version < 503000 257 struct AdapterControlBlock *acb=dev->si_drv1; 258 #else 259 int unit = dev2unit(dev); 260 struct AdapterControlBlock *acb = devclass_get_softc(arcmsr_devclass, unit); 261 #endif 262 if(acb==NULL) { 263 return ENXIO; 264 } 265 return 0; 266 } 267 /* 268 ************************************************************************** 269 ************************************************************************** 270 */ 271 #if __FreeBSD_version < 500005 272 static int arcmsr_close(dev_t dev, int flags, int fmt, struct proc *proc) 273 #else 274 #if __FreeBSD_version < 503000 275 static int arcmsr_close(dev_t dev, int flags, int fmt, struct thread *proc) 276 #else 277 static int arcmsr_close(struct cdev *dev, int flags, int fmt, d_thread_t *proc) 278 #endif 279 #endif 280 { 281 #if __FreeBSD_version < 503000 282 struct AdapterControlBlock *acb=dev->si_drv1; 283 #else 284 int unit = dev2unit(dev); 285 struct AdapterControlBlock *acb = devclass_get_softc(arcmsr_devclass, unit); 286 #endif 287 if(acb==NULL) { 288 return ENXIO; 289 } 290 return 0; 291 } 292 /* 293 ************************************************************************** 294 ************************************************************************** 295 */ 296 #if __FreeBSD_version < 500005 297 static int arcmsr_ioctl(dev_t dev, u_long ioctl_cmd, caddr_t arg, int flags, struct proc *proc) 298 #else 299 #if __FreeBSD_version < 503000 300 static int arcmsr_ioctl(dev_t dev, u_long ioctl_cmd, caddr_t arg, int flags, struct thread *proc) 301 #else 302 static int arcmsr_ioctl(struct cdev *dev, u_long ioctl_cmd, caddr_t arg, int flags, d_thread_t *proc) 303 #endif 304 #endif 305 { 306 #if __FreeBSD_version < 503000 307 struct AdapterControlBlock *acb=dev->si_drv1; 308 #else 309 int unit = dev2unit(dev); 310 struct AdapterControlBlock *acb = devclass_get_softc(arcmsr_devclass, unit); 311 #endif 312 313 if(acb==NULL) { 314 return ENXIO; 315 } 316 return(arcmsr_iop_ioctlcmd(acb, ioctl_cmd, arg)); 317 } 318 /* 319 ********************************************************************** 320 ********************************************************************** 321 */ 322 static u_int32_t arcmsr_disable_allintr( struct AdapterControlBlock *acb) 323 { 324 u_int32_t intmask_org=0; 325 326 switch (acb->adapter_type) { 327 case ACB_ADAPTER_TYPE_A: { 328 /* disable all outbound interrupt */ 329 intmask_org=CHIP_REG_READ32(HBA_MessageUnit, 330 0, outbound_intmask)|ARCMSR_MU_OUTBOUND_MESSAGE0_INTMASKENABLE; /* disable outbound message0 int */ 331 CHIP_REG_WRITE32(HBA_MessageUnit, 332 0, outbound_intmask, intmask_org|ARCMSR_MU_OUTBOUND_ALL_INTMASKENABLE); 333 } 334 break; 335 case ACB_ADAPTER_TYPE_B: { 336 /* disable all outbound interrupt */ 337 intmask_org=CHIP_REG_READ32(HBB_DOORBELL, 338 0, iop2drv_doorbell_mask) & (~ARCMSR_IOP2DRV_MESSAGE_CMD_DONE); /* disable outbound message0 int */ 339 CHIP_REG_WRITE32(HBB_DOORBELL, 340 0, iop2drv_doorbell_mask, 0); /* disable all interrupt */ 341 } 342 break; 343 } 344 return(intmask_org); 345 } 346 /* 347 ********************************************************************** 348 ********************************************************************** 349 */ 350 static void arcmsr_enable_allintr( struct AdapterControlBlock *acb, u_int32_t intmask_org) 351 { 352 u_int32_t mask; 353 354 switch (acb->adapter_type) { 355 case ACB_ADAPTER_TYPE_A: { 356 /* enable outbound Post Queue, outbound doorbell Interrupt */ 357 mask=~(ARCMSR_MU_OUTBOUND_POSTQUEUE_INTMASKENABLE|ARCMSR_MU_OUTBOUND_DOORBELL_INTMASKENABLE); 358 CHIP_REG_WRITE32(HBA_MessageUnit, 0, outbound_intmask, intmask_org & mask); 359 acb->outbound_int_enable = ~(intmask_org & mask) & 0x000000ff; 360 } 361 break; 362 case ACB_ADAPTER_TYPE_B: { 363 /* disable ARCMSR_IOP2DRV_MESSAGE_CMD_DONE */ 364 mask=(ARCMSR_IOP2DRV_DATA_WRITE_OK|ARCMSR_IOP2DRV_DATA_READ_OK|ARCMSR_IOP2DRV_CDB_DONE); 365 CHIP_REG_WRITE32(HBB_DOORBELL, 366 0, iop2drv_doorbell_mask, intmask_org | mask); /*1=interrupt enable, 0=interrupt disable*/ 367 acb->outbound_int_enable = (intmask_org | mask) & 0x0000000f; 368 } 369 break; 370 } 371 return; 372 } 373 /* 374 ********************************************************************** 375 ********************************************************************** 376 */ 377 static u_int8_t arcmsr_hba_wait_msgint_ready(struct AdapterControlBlock *acb) 378 { 379 u_int32_t Index; 380 u_int8_t Retries=0x00; 381 382 do { 383 for(Index=0; Index < 100; Index++) { 384 if(CHIP_REG_READ32(HBA_MessageUnit, 385 0, outbound_intstatus) & ARCMSR_MU_OUTBOUND_MESSAGE0_INT) { 386 CHIP_REG_WRITE32(HBA_MessageUnit, 387 0, outbound_intstatus, ARCMSR_MU_OUTBOUND_MESSAGE0_INT);/*clear interrupt*/ 388 return TRUE; 389 } 390 UDELAY(10000); 391 }/*max 1 seconds*/ 392 }while(Retries++ < 20);/*max 20 sec*/ 393 return FALSE; 394 } 395 /* 396 ********************************************************************** 397 ********************************************************************** 398 */ 399 static u_int8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock *acb) 400 { 401 u_int32_t Index; 402 u_int8_t Retries=0x00; 403 404 do { 405 for(Index=0; Index < 100; Index++) { 406 if(CHIP_REG_READ32(HBB_DOORBELL, 407 0, iop2drv_doorbell) & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) { 408 CHIP_REG_WRITE32(HBB_DOORBELL, 409 0, iop2drv_doorbell, ARCMSR_MESSAGE_INT_CLEAR_PATTERN);/*clear interrupt*/ 410 CHIP_REG_WRITE32(HBB_DOORBELL, 411 0, drv2iop_doorbell, ARCMSR_DRV2IOP_END_OF_INTERRUPT); 412 return TRUE; 413 } 414 UDELAY(10000); 415 }/*max 1 seconds*/ 416 }while(Retries++ < 20);/*max 20 sec*/ 417 return FALSE; 418 } 419 /* 420 ************************************************************************ 421 ************************************************************************ 422 */ 423 static void arcmsr_flush_hba_cache(struct AdapterControlBlock *acb) 424 { 425 int retry_count=30;/* enlarge wait flush adapter cache time: 10 minute */ 426 427 CHIP_REG_WRITE32(HBA_MessageUnit, 428 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_FLUSH_CACHE); 429 do { 430 if(arcmsr_hba_wait_msgint_ready(acb)) { 431 break; 432 } else { 433 retry_count--; 434 } 435 }while(retry_count!=0); 436 return; 437 } 438 /* 439 ************************************************************************ 440 ************************************************************************ 441 */ 442 static void arcmsr_flush_hbb_cache(struct AdapterControlBlock *acb) 443 { 444 int retry_count=30;/* enlarge wait flush adapter cache time: 10 minute */ 445 446 CHIP_REG_WRITE32(HBB_DOORBELL, 447 0, drv2iop_doorbell, ARCMSR_MESSAGE_FLUSH_CACHE); 448 do { 449 if(arcmsr_hbb_wait_msgint_ready(acb)) { 450 break; 451 } else { 452 retry_count--; 453 } 454 }while(retry_count!=0); 455 return; 456 } 457 /* 458 ************************************************************************ 459 ************************************************************************ 460 */ 461 static void arcmsr_flush_adapter_cache(struct AdapterControlBlock *acb) 462 { 463 switch (acb->adapter_type) { 464 case ACB_ADAPTER_TYPE_A: { 465 arcmsr_flush_hba_cache(acb); 466 } 467 break; 468 case ACB_ADAPTER_TYPE_B: { 469 arcmsr_flush_hbb_cache(acb); 470 } 471 break; 472 } 473 return; 474 } 475 /* 476 ******************************************************************************* 477 ******************************************************************************* 478 */ 479 static int arcmsr_suspend(device_t dev) 480 { 481 struct AdapterControlBlock *acb = device_get_softc(dev); 482 483 /* disable all outbound interrupt */ 484 arcmsr_disable_allintr(acb); 485 /* flush controller */ 486 arcmsr_iop_parking(acb); 487 return(0); 488 } 489 /* 490 ******************************************************************************* 491 ******************************************************************************* 492 */ 493 static int arcmsr_resume(device_t dev) 494 { 495 struct AdapterControlBlock *acb = device_get_softc(dev); 496 497 arcmsr_iop_init(acb); 498 return(0); 499 } 500 /* 501 ********************************************************************************* 502 ********************************************************************************* 503 */ 504 static void arcmsr_async(void *cb_arg, u_int32_t code, struct cam_path *path, void *arg) 505 { 506 struct AdapterControlBlock *acb; 507 u_int8_t target_id, target_lun; 508 struct cam_sim * sim; 509 510 sim=(struct cam_sim *) cb_arg; 511 acb =(struct AdapterControlBlock *) cam_sim_softc(sim); 512 switch (code) { 513 case AC_LOST_DEVICE: 514 target_id=xpt_path_target_id(path); 515 target_lun=xpt_path_lun_id(path); 516 if((target_id > ARCMSR_MAX_TARGETID) 517 || (target_lun > ARCMSR_MAX_TARGETLUN)) { 518 break; 519 } 520 printf("%s:scsi id%d lun%d device lost \n" 521 , device_get_name(acb->pci_dev), target_id, target_lun); 522 break; 523 default: 524 break; 525 } 526 } 527 /* 528 ********************************************************************** 529 ********************************************************************** 530 */ 531 static void arcmsr_srb_complete(struct CommandControlBlock *srb, int stand_flag) 532 { 533 struct AdapterControlBlock *acb=srb->acb; 534 union ccb * pccb=srb->pccb; 535 536 if((pccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 537 bus_dmasync_op_t op; 538 539 if((pccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 540 op = BUS_DMASYNC_POSTREAD; 541 } else { 542 op = BUS_DMASYNC_POSTWRITE; 543 } 544 bus_dmamap_sync(acb->dm_segs_dmat, srb->dm_segs_dmamap, op); 545 bus_dmamap_unload(acb->dm_segs_dmat, srb->dm_segs_dmamap); 546 } 547 if(stand_flag==1) { 548 atomic_subtract_int(&acb->srboutstandingcount, 1); 549 if((acb->acb_flags & ACB_F_CAM_DEV_QFRZN) && ( 550 acb->srboutstandingcount < ARCMSR_RELEASE_SIMQ_LEVEL)) { 551 acb->acb_flags &= ~ACB_F_CAM_DEV_QFRZN; 552 pccb->ccb_h.status |= CAM_RELEASE_SIMQ; 553 } 554 } 555 srb->startdone=ARCMSR_SRB_DONE; 556 srb->srb_flags=0; 557 acb->srbworkingQ[acb->workingsrb_doneindex]=srb; 558 acb->workingsrb_doneindex++; 559 acb->workingsrb_doneindex %= ARCMSR_MAX_FREESRB_NUM; 560 xpt_done(pccb); 561 return; 562 } 563 /* 564 ********************************************************************** 565 ********************************************************************** 566 */ 567 static void arcmsr_report_sense_info(struct CommandControlBlock *srb) 568 { 569 union ccb * pccb=srb->pccb; 570 571 pccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR; 572 pccb->csio.scsi_status = SCSI_STATUS_CHECK_COND; 573 if(&pccb->csio.sense_data) { 574 memset(&pccb->csio.sense_data, 0, sizeof(pccb->csio.sense_data)); 575 memcpy(&pccb->csio.sense_data, srb->arcmsr_cdb.SenseData, 576 get_min(sizeof(struct SENSE_DATA), sizeof(pccb->csio.sense_data))); 577 ((u_int8_t *)&pccb->csio.sense_data)[0] = (0x1 << 7 | 0x70); /* Valid,ErrorCode */ 578 pccb->ccb_h.status |= CAM_AUTOSNS_VALID; 579 } 580 return; 581 } 582 /* 583 ********************************************************************* 584 ********************************************************************* 585 */ 586 static void arcmsr_abort_hba_allcmd(struct AdapterControlBlock *acb) 587 { 588 CHIP_REG_WRITE32(HBA_MessageUnit, 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_ABORT_CMD); 589 if(!arcmsr_hba_wait_msgint_ready(acb)) { 590 printf("arcmsr%d: wait 'abort all outstanding command' timeout \n" 591 , acb->pci_unit); 592 } 593 return; 594 } 595 /* 596 ********************************************************************* 597 ********************************************************************* 598 */ 599 static void arcmsr_abort_hbb_allcmd(struct AdapterControlBlock *acb) 600 { 601 CHIP_REG_WRITE32(HBB_DOORBELL, 0, drv2iop_doorbell, ARCMSR_MESSAGE_ABORT_CMD); 602 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 603 printf("arcmsr%d: wait 'abort all outstanding command' timeout \n" 604 , acb->pci_unit); 605 } 606 return; 607 } 608 /* 609 ********************************************************************* 610 ********************************************************************* 611 */ 612 static void arcmsr_abort_allcmd(struct AdapterControlBlock *acb) 613 { 614 switch (acb->adapter_type) { 615 case ACB_ADAPTER_TYPE_A: { 616 arcmsr_abort_hba_allcmd(acb); 617 } 618 break; 619 case ACB_ADAPTER_TYPE_B: { 620 arcmsr_abort_hbb_allcmd(acb); 621 } 622 break; 623 } 624 return; 625 } 626 /* 627 ************************************************************************** 628 ************************************************************************** 629 */ 630 static void arcmsr_report_srb_state(struct AdapterControlBlock *acb, 631 struct CommandControlBlock *srb, u_int32_t flag_srb) 632 { 633 int target, lun; 634 635 target=srb->pccb->ccb_h.target_id; 636 lun=srb->pccb->ccb_h.target_lun; 637 if((flag_srb & ARCMSR_SRBREPLY_FLAG_ERROR)==0) { 638 if(acb->devstate[target][lun]==ARECA_RAID_GONE) { 639 acb->devstate[target][lun]=ARECA_RAID_GOOD; 640 } 641 srb->pccb->ccb_h.status |= CAM_REQ_CMP; 642 arcmsr_srb_complete(srb, 1); 643 } else { 644 switch(srb->arcmsr_cdb.DeviceStatus) { 645 case ARCMSR_DEV_SELECT_TIMEOUT: { 646 if(acb->devstate[target][lun]==ARECA_RAID_GOOD) { 647 printf( "arcmsr%d: select timeout" 648 ", raid volume was kicked out \n" 649 , acb->pci_unit); 650 } 651 acb->devstate[target][lun]=ARECA_RAID_GONE; 652 srb->pccb->ccb_h.status |= CAM_SEL_TIMEOUT; 653 arcmsr_srb_complete(srb, 1); 654 } 655 break; 656 case ARCMSR_DEV_ABORTED: 657 case ARCMSR_DEV_INIT_FAIL: { 658 acb->devstate[target][lun]=ARECA_RAID_GONE; 659 srb->pccb->ccb_h.status |= CAM_DEV_NOT_THERE; 660 arcmsr_srb_complete(srb, 1); 661 } 662 break; 663 case SCSISTAT_CHECK_CONDITION: { 664 acb->devstate[target][lun]=ARECA_RAID_GOOD; 665 arcmsr_report_sense_info(srb); 666 arcmsr_srb_complete(srb, 1); 667 } 668 break; 669 default: 670 printf("arcmsr%d: scsi id=%d lun=%d" 671 "isr get command error done," 672 "but got unknow DeviceStatus=0x%x \n" 673 , acb->pci_unit, target, lun 674 ,srb->arcmsr_cdb.DeviceStatus); 675 acb->devstate[target][lun]=ARECA_RAID_GONE; 676 srb->pccb->ccb_h.status |= CAM_UNCOR_PARITY; 677 /*unknow error or crc error just for retry*/ 678 arcmsr_srb_complete(srb, 1); 679 break; 680 } 681 } 682 return; 683 } 684 /* 685 ************************************************************************** 686 ************************************************************************** 687 */ 688 static void arcmsr_drain_donequeue(struct AdapterControlBlock *acb, u_int32_t flag_srb) 689 { 690 struct CommandControlBlock *srb; 691 692 /* check if command done with no error*/ 693 srb=(struct CommandControlBlock *) 694 (acb->vir2phy_offset+(flag_srb << 5));/*frame must be 32 bytes aligned*/ 695 if((srb->acb!=acb) || (srb->startdone!=ARCMSR_SRB_START)) { 696 if(srb->startdone==ARCMSR_SRB_ABORTED) { 697 printf("arcmsr%d: srb='%p' isr got aborted command \n" 698 , acb->pci_unit, srb); 699 srb->pccb->ccb_h.status |= CAM_REQ_ABORTED; 700 arcmsr_srb_complete(srb, 1); 701 return; 702 } 703 printf("arcmsr%d: isr get an illegal srb command done" 704 "acb='%p' srb='%p' srbacb='%p' startdone=0x%x" 705 "srboutstandingcount=%d \n", 706 acb->pci_unit, acb, srb, srb->acb, 707 srb->startdone, acb->srboutstandingcount); 708 return; 709 } 710 arcmsr_report_srb_state(acb, srb, flag_srb); 711 return; 712 } 713 /* 714 ********************************************************************** 715 ********************************************************************** 716 */ 717 static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb) 718 { 719 int i=0; 720 u_int32_t flag_srb; 721 722 switch (acb->adapter_type) { 723 case ACB_ADAPTER_TYPE_A: { 724 u_int32_t outbound_intstatus; 725 726 /*clear and abort all outbound posted Q*/ 727 outbound_intstatus=CHIP_REG_READ32(HBA_MessageUnit, 728 0, outbound_intstatus) & acb->outbound_int_enable; 729 CHIP_REG_WRITE32(HBA_MessageUnit, 730 0, outbound_intstatus, outbound_intstatus);/*clear interrupt*/ 731 while(((flag_srb=CHIP_REG_READ32(HBA_MessageUnit, 732 0, outbound_queueport)) != 0xFFFFFFFF) 733 && (i++ < ARCMSR_MAX_OUTSTANDING_CMD)) { 734 arcmsr_drain_donequeue(acb, flag_srb); 735 } 736 } 737 break; 738 case ACB_ADAPTER_TYPE_B: { 739 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 740 741 /*clear all outbound posted Q*/ 742 CHIP_REG_WRITE32(HBB_DOORBELL, 743 0, iop2drv_doorbell, 744 ARCMSR_DOORBELL_INT_CLEAR_PATTERN); /* clear doorbell interrupt */ 745 for(i=0; i < ARCMSR_MAX_HBB_POSTQUEUE; i++) { 746 if((flag_srb=phbbmu->done_qbuffer[i])!=0) { 747 phbbmu->done_qbuffer[i]=0; 748 arcmsr_drain_donequeue(acb, flag_srb); 749 } 750 phbbmu->post_qbuffer[i]=0; 751 }/*drain reply FIFO*/ 752 phbbmu->doneq_index=0; 753 phbbmu->postq_index=0; 754 } 755 break; 756 } 757 return; 758 } 759 /* 760 **************************************************************************** 761 **************************************************************************** 762 */ 763 static void arcmsr_iop_reset(struct AdapterControlBlock *acb) 764 { 765 struct CommandControlBlock *srb; 766 u_int32_t intmask_org; 767 u_int32_t i=0; 768 769 if(acb->srboutstandingcount>0) { 770 /* disable all outbound interrupt */ 771 intmask_org=arcmsr_disable_allintr(acb); 772 /*clear and abort all outbound posted Q*/ 773 arcmsr_done4abort_postqueue(acb); 774 /* talk to iop 331 outstanding command aborted*/ 775 arcmsr_abort_allcmd(acb); 776 for(i=0;i<ARCMSR_MAX_FREESRB_NUM;i++) { 777 srb=acb->psrb_pool[i]; 778 if(srb->startdone==ARCMSR_SRB_START) { 779 srb->startdone=ARCMSR_SRB_ABORTED; 780 srb->pccb->ccb_h.status |= CAM_REQ_ABORTED; 781 arcmsr_srb_complete(srb, 1); 782 } 783 } 784 /* enable all outbound interrupt */ 785 arcmsr_enable_allintr(acb, intmask_org); 786 } 787 atomic_set_int(&acb->srboutstandingcount, 0); 788 acb->workingsrb_doneindex=0; 789 acb->workingsrb_startindex=0; 790 return; 791 } 792 /* 793 ********************************************************************** 794 ********************************************************************** 795 */ 796 static void arcmsr_build_srb(struct CommandControlBlock *srb, 797 bus_dma_segment_t *dm_segs, u_int32_t nseg) 798 { 799 struct ARCMSR_CDB * arcmsr_cdb= &srb->arcmsr_cdb; 800 u_int8_t * psge=(u_int8_t *)&arcmsr_cdb->u; 801 u_int32_t address_lo, address_hi; 802 union ccb * pccb=srb->pccb; 803 struct ccb_scsiio * pcsio= &pccb->csio; 804 u_int32_t arccdbsize=0x30; 805 806 memset(arcmsr_cdb, 0, sizeof(struct ARCMSR_CDB)); 807 arcmsr_cdb->Bus=0; 808 arcmsr_cdb->TargetID=pccb->ccb_h.target_id; 809 arcmsr_cdb->LUN=pccb->ccb_h.target_lun; 810 arcmsr_cdb->Function=1; 811 arcmsr_cdb->CdbLength=(u_int8_t)pcsio->cdb_len; 812 arcmsr_cdb->Context=0; 813 bcopy(pcsio->cdb_io.cdb_bytes, arcmsr_cdb->Cdb, pcsio->cdb_len); 814 if(nseg != 0) { 815 struct AdapterControlBlock *acb=srb->acb; 816 bus_dmasync_op_t op; 817 u_int32_t length, i, cdb_sgcount=0; 818 819 if((pccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 820 op=BUS_DMASYNC_PREREAD; 821 } else { 822 op=BUS_DMASYNC_PREWRITE; 823 arcmsr_cdb->Flags|=ARCMSR_CDB_FLAG_WRITE; 824 srb->srb_flags|=SRB_FLAG_WRITE; 825 } 826 bus_dmamap_sync(acb->dm_segs_dmat, srb->dm_segs_dmamap, op); 827 for(i=0;i<nseg;i++) { 828 /* Get the physical address of the current data pointer */ 829 length=arcmsr_htole32(dm_segs[i].ds_len); 830 address_lo=arcmsr_htole32(dma_addr_lo32(dm_segs[i].ds_addr)); 831 address_hi=arcmsr_htole32(dma_addr_hi32(dm_segs[i].ds_addr)); 832 if(address_hi==0) { 833 struct SG32ENTRY * pdma_sg=(struct SG32ENTRY *)psge; 834 pdma_sg->address=address_lo; 835 pdma_sg->length=length; 836 psge += sizeof(struct SG32ENTRY); 837 arccdbsize += sizeof(struct SG32ENTRY); 838 } else { 839 u_int32_t sg64s_size=0, tmplength=length; 840 841 while(1) { 842 u_int64_t span4G, length0; 843 struct SG64ENTRY * pdma_sg=(struct SG64ENTRY *)psge; 844 845 span4G=(u_int64_t)address_lo + tmplength; 846 pdma_sg->addresshigh=address_hi; 847 pdma_sg->address=address_lo; 848 if(span4G > 0x100000000) { 849 /*see if cross 4G boundary*/ 850 length0=0x100000000-address_lo; 851 pdma_sg->length=(u_int32_t)length0|IS_SG64_ADDR; 852 address_hi=address_hi+1; 853 address_lo=0; 854 tmplength=tmplength-(u_int32_t)length0; 855 sg64s_size += sizeof(struct SG64ENTRY); 856 psge += sizeof(struct SG64ENTRY); 857 cdb_sgcount++; 858 } else { 859 pdma_sg->length=tmplength|IS_SG64_ADDR; 860 sg64s_size += sizeof(struct SG64ENTRY); 861 psge += sizeof(struct SG64ENTRY); 862 break; 863 } 864 } 865 arccdbsize += sg64s_size; 866 } 867 cdb_sgcount++; 868 } 869 arcmsr_cdb->sgcount=(u_int8_t)cdb_sgcount; 870 arcmsr_cdb->DataLength=pcsio->dxfer_len; 871 if( arccdbsize > 256) { 872 arcmsr_cdb->Flags|=ARCMSR_CDB_FLAG_SGL_BSIZE; 873 } 874 } 875 return; 876 } 877 /* 878 ************************************************************************** 879 ************************************************************************** 880 */ 881 static void arcmsr_post_srb(struct AdapterControlBlock *acb, struct CommandControlBlock *srb) 882 { 883 u_int32_t cdb_shifted_phyaddr=(u_int32_t) srb->cdb_shifted_phyaddr; 884 struct ARCMSR_CDB * arcmsr_cdb=(struct ARCMSR_CDB *)&srb->arcmsr_cdb; 885 886 bus_dmamap_sync(acb->srb_dmat, acb->srb_dmamap, 887 (srb->srb_flags & SRB_FLAG_WRITE) ? BUS_DMASYNC_POSTWRITE:BUS_DMASYNC_POSTREAD); 888 atomic_add_int(&acb->srboutstandingcount, 1); 889 srb->startdone=ARCMSR_SRB_START; 890 switch (acb->adapter_type) { 891 case ACB_ADAPTER_TYPE_A: { 892 if(arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) { 893 CHIP_REG_WRITE32(HBA_MessageUnit, 894 0, inbound_queueport, 895 cdb_shifted_phyaddr|ARCMSR_SRBPOST_FLAG_SGL_BSIZE); 896 } else { 897 CHIP_REG_WRITE32(HBA_MessageUnit, 898 0, inbound_queueport, cdb_shifted_phyaddr); 899 } 900 } 901 break; 902 case ACB_ADAPTER_TYPE_B: { 903 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 904 int ending_index, index; 905 906 index=phbbmu->postq_index; 907 ending_index=((index+1)%ARCMSR_MAX_HBB_POSTQUEUE); 908 phbbmu->post_qbuffer[ending_index]=0; 909 if(arcmsr_cdb->Flags & ARCMSR_CDB_FLAG_SGL_BSIZE) { 910 phbbmu->post_qbuffer[index]= 911 cdb_shifted_phyaddr|ARCMSR_SRBPOST_FLAG_SGL_BSIZE; 912 } else { 913 phbbmu->post_qbuffer[index]= 914 cdb_shifted_phyaddr; 915 } 916 index++; 917 index %= ARCMSR_MAX_HBB_POSTQUEUE; /*if last index number set it to 0 */ 918 phbbmu->postq_index=index; 919 CHIP_REG_WRITE32(HBB_DOORBELL, 920 0, drv2iop_doorbell, ARCMSR_DRV2IOP_CDB_POSTED); 921 } 922 break; 923 } 924 return; 925 } 926 /* 927 ************************************************************************ 928 ************************************************************************ 929 */ 930 static struct QBUFFER * arcmsr_get_iop_rqbuffer( struct AdapterControlBlock *acb) 931 { 932 struct QBUFFER *qbuffer=NULL; 933 934 switch (acb->adapter_type) { 935 case ACB_ADAPTER_TYPE_A: { 936 struct HBA_MessageUnit *phbamu=(struct HBA_MessageUnit *)acb->pmu; 937 938 qbuffer=(struct QBUFFER *)&phbamu->message_rbuffer; 939 } 940 break; 941 case ACB_ADAPTER_TYPE_B: { 942 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 943 944 qbuffer=(struct QBUFFER *)&phbbmu->hbb_rwbuffer->message_rbuffer; 945 } 946 break; 947 } 948 return(qbuffer); 949 } 950 /* 951 ************************************************************************ 952 ************************************************************************ 953 */ 954 static struct QBUFFER * arcmsr_get_iop_wqbuffer( struct AdapterControlBlock *acb) 955 { 956 struct QBUFFER *qbuffer=NULL; 957 958 switch (acb->adapter_type) { 959 case ACB_ADAPTER_TYPE_A: { 960 struct HBA_MessageUnit *phbamu=(struct HBA_MessageUnit *)acb->pmu; 961 962 qbuffer=(struct QBUFFER *)&phbamu->message_wbuffer; 963 } 964 break; 965 case ACB_ADAPTER_TYPE_B: { 966 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 967 968 qbuffer=(struct QBUFFER *)&phbbmu->hbb_rwbuffer->message_wbuffer; 969 } 970 break; 971 } 972 return(qbuffer); 973 } 974 /* 975 ************************************************************************** 976 ************************************************************************** 977 */ 978 static void arcmsr_iop_message_read(struct AdapterControlBlock *acb) 979 { 980 switch (acb->adapter_type) { 981 case ACB_ADAPTER_TYPE_A: { 982 /* let IOP know data has been read */ 983 CHIP_REG_WRITE32(HBA_MessageUnit, 984 0, inbound_doorbell, ARCMSR_INBOUND_DRIVER_DATA_READ_OK); 985 } 986 break; 987 case ACB_ADAPTER_TYPE_B: { 988 /* let IOP know data has been read */ 989 CHIP_REG_WRITE32(HBB_DOORBELL, 990 0, drv2iop_doorbell, ARCMSR_DRV2IOP_DATA_READ_OK); 991 } 992 break; 993 } 994 return; 995 } 996 /* 997 ************************************************************************** 998 ************************************************************************** 999 */ 1000 static void arcmsr_iop_message_wrote(struct AdapterControlBlock *acb) 1001 { 1002 switch (acb->adapter_type) { 1003 case ACB_ADAPTER_TYPE_A: { 1004 /* 1005 ** push inbound doorbell tell iop, driver data write ok 1006 ** and wait reply on next hwinterrupt for next Qbuffer post 1007 */ 1008 CHIP_REG_WRITE32(HBA_MessageUnit, 1009 0, inbound_doorbell, ARCMSR_INBOUND_DRIVER_DATA_WRITE_OK); 1010 } 1011 break; 1012 case ACB_ADAPTER_TYPE_B: { 1013 /* 1014 ** push inbound doorbell tell iop, driver data write ok 1015 ** and wait reply on next hwinterrupt for next Qbuffer post 1016 */ 1017 CHIP_REG_WRITE32(HBB_DOORBELL, 1018 0, drv2iop_doorbell, ARCMSR_DRV2IOP_DATA_WRITE_OK); 1019 } 1020 break; 1021 } 1022 } 1023 /* 1024 ********************************************************************** 1025 ********************************************************************** 1026 */ 1027 static void arcmsr_post_ioctldata2iop(struct AdapterControlBlock *acb) 1028 { 1029 u_int8_t *pQbuffer; 1030 struct QBUFFER *pwbuffer; 1031 u_int8_t * iop_data; 1032 int32_t allxfer_len=0; 1033 1034 pwbuffer=arcmsr_get_iop_wqbuffer(acb); 1035 iop_data=(u_int8_t *)pwbuffer->data; 1036 if(acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_READ) { 1037 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READ); 1038 while((acb->wqbuf_firstindex!=acb->wqbuf_lastindex) 1039 && (allxfer_len<124)) { 1040 pQbuffer=&acb->wqbuffer[acb->wqbuf_firstindex]; 1041 memcpy(iop_data, pQbuffer, 1); 1042 acb->wqbuf_firstindex++; 1043 acb->wqbuf_firstindex %=ARCMSR_MAX_QBUFFER; /*if last index number set it to 0 */ 1044 iop_data++; 1045 allxfer_len++; 1046 } 1047 pwbuffer->data_len=allxfer_len; 1048 /* 1049 ** push inbound doorbell and wait reply at hwinterrupt routine for next Qbuffer post 1050 */ 1051 arcmsr_iop_message_wrote(acb); 1052 } 1053 return; 1054 } 1055 /* 1056 ************************************************************************ 1057 ************************************************************************ 1058 */ 1059 static void arcmsr_stop_hba_bgrb(struct AdapterControlBlock *acb) 1060 { 1061 acb->acb_flags &=~ACB_F_MSG_START_BGRB; 1062 CHIP_REG_WRITE32(HBA_MessageUnit, 1063 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_STOP_BGRB); 1064 if(!arcmsr_hba_wait_msgint_ready(acb)) { 1065 printf("arcmsr%d: wait 'stop adapter rebulid' timeout \n" 1066 , acb->pci_unit); 1067 } 1068 return; 1069 } 1070 /* 1071 ************************************************************************ 1072 ************************************************************************ 1073 */ 1074 static void arcmsr_stop_hbb_bgrb(struct AdapterControlBlock *acb) 1075 { 1076 acb->acb_flags &= ~ACB_F_MSG_START_BGRB; 1077 CHIP_REG_WRITE32(HBB_DOORBELL, 1078 0, drv2iop_doorbell, ARCMSR_MESSAGE_STOP_BGRB); 1079 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 1080 printf( "arcmsr%d: wait 'stop adapter rebulid' timeout \n" 1081 , acb->pci_unit); 1082 } 1083 return; 1084 } 1085 /* 1086 ************************************************************************ 1087 ************************************************************************ 1088 */ 1089 static void arcmsr_stop_adapter_bgrb(struct AdapterControlBlock *acb) 1090 { 1091 switch (acb->adapter_type) { 1092 case ACB_ADAPTER_TYPE_A: { 1093 arcmsr_stop_hba_bgrb(acb); 1094 } 1095 break; 1096 case ACB_ADAPTER_TYPE_B: { 1097 arcmsr_stop_hbb_bgrb(acb); 1098 } 1099 break; 1100 } 1101 return; 1102 } 1103 /* 1104 ************************************************************************ 1105 ************************************************************************ 1106 */ 1107 static void arcmsr_poll(struct cam_sim * psim) 1108 { 1109 struct AdapterControlBlock *acb; 1110 1111 acb = (struct AdapterControlBlock *)cam_sim_softc(psim); 1112 #if __FreeBSD_version < 700025 1113 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 1114 #endif 1115 arcmsr_interrupt(acb); 1116 #if __FreeBSD_version < 700025 1117 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 1118 #endif 1119 return; 1120 } 1121 /* 1122 ********************************************************************** 1123 ********************************************************************** 1124 */ 1125 static void arcmsr_intr_handler(void *arg) 1126 { 1127 struct AdapterControlBlock *acb=(struct AdapterControlBlock *)arg; 1128 1129 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 1130 arcmsr_interrupt(acb); 1131 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 1132 } 1133 /* 1134 ************************************************************************** 1135 ************************************************************************** 1136 */ 1137 static void arcmsr_iop2drv_data_wrote_handle(struct AdapterControlBlock *acb) 1138 { 1139 struct QBUFFER *prbuffer; 1140 u_int8_t *pQbuffer; 1141 u_int8_t *iop_data; 1142 int my_empty_len, iop_len, rqbuf_firstindex, rqbuf_lastindex; 1143 1144 /*check this iop data if overflow my rqbuffer*/ 1145 rqbuf_lastindex=acb->rqbuf_lastindex; 1146 rqbuf_firstindex=acb->rqbuf_firstindex; 1147 prbuffer=arcmsr_get_iop_rqbuffer(acb); 1148 iop_data=(u_int8_t *)prbuffer->data; 1149 iop_len=prbuffer->data_len; 1150 my_empty_len=(rqbuf_firstindex-rqbuf_lastindex-1)&(ARCMSR_MAX_QBUFFER-1); 1151 if(my_empty_len>=iop_len) { 1152 while(iop_len > 0) { 1153 pQbuffer=&acb->rqbuffer[rqbuf_lastindex]; 1154 memcpy(pQbuffer, iop_data, 1); 1155 rqbuf_lastindex++; 1156 rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;/*if last index number set it to 0 */ 1157 iop_data++; 1158 iop_len--; 1159 } 1160 acb->rqbuf_lastindex=rqbuf_lastindex; 1161 arcmsr_iop_message_read(acb); 1162 /*signature, let IOP know data has been read */ 1163 } else { 1164 acb->acb_flags|=ACB_F_IOPDATA_OVERFLOW; 1165 } 1166 return; 1167 } 1168 /* 1169 ************************************************************************** 1170 ************************************************************************** 1171 */ 1172 static void arcmsr_iop2drv_data_read_handle(struct AdapterControlBlock *acb) 1173 { 1174 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_READ; 1175 /* 1176 ***************************************************************** 1177 ** check if there are any mail packages from user space program 1178 ** in my post bag, now is the time to send them into Areca's firmware 1179 ***************************************************************** 1180 */ 1181 if(acb->wqbuf_firstindex!=acb->wqbuf_lastindex) { 1182 u_int8_t *pQbuffer; 1183 struct QBUFFER *pwbuffer; 1184 u_int8_t *iop_data; 1185 int allxfer_len=0; 1186 1187 acb->acb_flags &= (~ACB_F_MESSAGE_WQBUFFER_READ); 1188 pwbuffer=arcmsr_get_iop_wqbuffer(acb); 1189 iop_data=(u_int8_t *)pwbuffer->data; 1190 while((acb->wqbuf_firstindex!=acb->wqbuf_lastindex) 1191 && (allxfer_len<124)) { 1192 pQbuffer=&acb->wqbuffer[acb->wqbuf_firstindex]; 1193 memcpy(iop_data, pQbuffer, 1); 1194 acb->wqbuf_firstindex++; 1195 acb->wqbuf_firstindex %=ARCMSR_MAX_QBUFFER; /*if last index number set it to 0 */ 1196 iop_data++; 1197 allxfer_len++; 1198 } 1199 pwbuffer->data_len=allxfer_len; 1200 /* 1201 ** push inbound doorbell tell iop driver data write ok 1202 ** and wait reply on next hwinterrupt for next Qbuffer post 1203 */ 1204 arcmsr_iop_message_wrote(acb); 1205 } 1206 if(acb->wqbuf_firstindex==acb->wqbuf_lastindex) { 1207 acb->acb_flags |= ACB_F_MESSAGE_WQBUFFER_CLEARED; 1208 } 1209 return; 1210 } 1211 /* 1212 ************************************************************************** 1213 ************************************************************************** 1214 */ 1215 static void arcmsr_hba_doorbell_isr(struct AdapterControlBlock *acb) 1216 { 1217 u_int32_t outbound_doorbell; 1218 1219 /* 1220 ******************************************************************* 1221 ** Maybe here we need to check wrqbuffer_lock is lock or not 1222 ** DOORBELL: din! don! 1223 ** check if there are any mail need to pack from firmware 1224 ******************************************************************* 1225 */ 1226 outbound_doorbell=CHIP_REG_READ32(HBA_MessageUnit, 1227 0, outbound_doorbell); 1228 CHIP_REG_WRITE32(HBA_MessageUnit, 1229 0, outbound_doorbell, outbound_doorbell); /* clear doorbell interrupt */ 1230 if(outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_WRITE_OK) { 1231 arcmsr_iop2drv_data_wrote_handle(acb); 1232 } 1233 if(outbound_doorbell & ARCMSR_OUTBOUND_IOP331_DATA_READ_OK) { 1234 arcmsr_iop2drv_data_read_handle(acb); 1235 } 1236 return; 1237 } 1238 /* 1239 ************************************************************************** 1240 ************************************************************************** 1241 */ 1242 static void arcmsr_hba_postqueue_isr(struct AdapterControlBlock *acb) 1243 { 1244 u_int32_t flag_srb; 1245 1246 /* 1247 ***************************************************************************** 1248 ** areca cdb command done 1249 ***************************************************************************** 1250 */ 1251 bus_dmamap_sync(acb->srb_dmat, acb->srb_dmamap, 1252 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 1253 while((flag_srb=CHIP_REG_READ32(HBA_MessageUnit, 1254 0, outbound_queueport)) != 0xFFFFFFFF) { 1255 /* check if command done with no error*/ 1256 arcmsr_drain_donequeue(acb, flag_srb); 1257 } /*drain reply FIFO*/ 1258 return; 1259 } 1260 /* 1261 ************************************************************************** 1262 ************************************************************************** 1263 */ 1264 static void arcmsr_hbb_postqueue_isr(struct AdapterControlBlock *acb) 1265 { 1266 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 1267 u_int32_t flag_srb; 1268 int index; 1269 1270 /* 1271 ***************************************************************************** 1272 ** areca cdb command done 1273 ***************************************************************************** 1274 */ 1275 bus_dmamap_sync(acb->srb_dmat, acb->srb_dmamap, 1276 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 1277 index=phbbmu->doneq_index; 1278 while((flag_srb=phbbmu->done_qbuffer[index]) != 0) { 1279 phbbmu->done_qbuffer[index]=0; 1280 index++; 1281 index %= ARCMSR_MAX_HBB_POSTQUEUE; /*if last index number set it to 0 */ 1282 phbbmu->doneq_index=index; 1283 /* check if command done with no error*/ 1284 arcmsr_drain_donequeue(acb, flag_srb); 1285 } /*drain reply FIFO*/ 1286 return; 1287 } 1288 /* 1289 ********************************************************************** 1290 ********************************************************************** 1291 */ 1292 static void arcmsr_handle_hba_isr( struct AdapterControlBlock *acb) 1293 { 1294 u_int32_t outbound_intstatus; 1295 /* 1296 ********************************************* 1297 ** check outbound intstatus 1298 ********************************************* 1299 */ 1300 outbound_intstatus=CHIP_REG_READ32(HBA_MessageUnit, 1301 0, outbound_intstatus) & acb->outbound_int_enable; 1302 if(!outbound_intstatus) { 1303 /*it must be share irq*/ 1304 return; 1305 } 1306 CHIP_REG_WRITE32(HBA_MessageUnit, 1307 0, outbound_intstatus, outbound_intstatus);/*clear interrupt*/ 1308 /* MU doorbell interrupts*/ 1309 if(outbound_intstatus & ARCMSR_MU_OUTBOUND_DOORBELL_INT) { 1310 arcmsr_hba_doorbell_isr(acb); 1311 } 1312 /* MU post queue interrupts*/ 1313 if(outbound_intstatus & ARCMSR_MU_OUTBOUND_POSTQUEUE_INT) { 1314 arcmsr_hba_postqueue_isr(acb); 1315 } 1316 return; 1317 } 1318 /* 1319 ********************************************************************** 1320 ********************************************************************** 1321 */ 1322 static void arcmsr_handle_hbb_isr( struct AdapterControlBlock *acb) 1323 { 1324 u_int32_t outbound_doorbell; 1325 /* 1326 ********************************************* 1327 ** check outbound intstatus 1328 ********************************************* 1329 */ 1330 outbound_doorbell=CHIP_REG_READ32(HBB_DOORBELL, 0, iop2drv_doorbell) & acb->outbound_int_enable; 1331 if(!outbound_doorbell) { 1332 /*it must be share irq*/ 1333 return; 1334 } 1335 CHIP_REG_WRITE32(HBB_DOORBELL, 0, iop2drv_doorbell, ~outbound_doorbell); /* clear doorbell interrupt */ 1336 CHIP_REG_READ32(HBB_DOORBELL, 0, iop2drv_doorbell); 1337 CHIP_REG_WRITE32(HBB_DOORBELL, 0, drv2iop_doorbell, ARCMSR_DRV2IOP_END_OF_INTERRUPT); 1338 /* MU ioctl transfer doorbell interrupts*/ 1339 if(outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK) { 1340 arcmsr_iop2drv_data_wrote_handle(acb); 1341 } 1342 if(outbound_doorbell & ARCMSR_IOP2DRV_DATA_READ_OK) { 1343 arcmsr_iop2drv_data_read_handle(acb); 1344 } 1345 /* MU post queue interrupts*/ 1346 if(outbound_doorbell & ARCMSR_IOP2DRV_CDB_DONE) { 1347 arcmsr_hbb_postqueue_isr(acb); 1348 } 1349 return; 1350 } 1351 /* 1352 ****************************************************************************** 1353 ****************************************************************************** 1354 */ 1355 static void arcmsr_interrupt(struct AdapterControlBlock *acb) 1356 { 1357 switch (acb->adapter_type) { 1358 case ACB_ADAPTER_TYPE_A: 1359 arcmsr_handle_hba_isr(acb); 1360 break; 1361 case ACB_ADAPTER_TYPE_B: 1362 arcmsr_handle_hbb_isr(acb); 1363 break; 1364 default: 1365 printf("arcmsr%d: interrupt service," 1366 " unknow adapter type =%d\n", acb->pci_unit, acb->adapter_type); 1367 break; 1368 } 1369 return; 1370 } 1371 /* 1372 ******************************************************************************* 1373 ** 1374 ******************************************************************************* 1375 */ 1376 static void arcmsr_iop_parking(struct AdapterControlBlock *acb) 1377 { 1378 if(acb!=NULL) { 1379 /* stop adapter background rebuild */ 1380 if(acb->acb_flags & ACB_F_MSG_START_BGRB) { 1381 arcmsr_stop_adapter_bgrb(acb); 1382 arcmsr_flush_adapter_cache(acb); 1383 } 1384 } 1385 } 1386 /* 1387 *********************************************************************** 1388 ** 1389 ************************************************************************ 1390 */ 1391 u_int32_t arcmsr_iop_ioctlcmd(struct AdapterControlBlock *acb, u_int32_t ioctl_cmd, caddr_t arg) 1392 { 1393 struct CMD_MESSAGE_FIELD * pcmdmessagefld; 1394 u_int32_t retvalue=EINVAL; 1395 1396 pcmdmessagefld=(struct CMD_MESSAGE_FIELD *) arg; 1397 if(memcmp(pcmdmessagefld->cmdmessage.Signature, "ARCMSR", 6)!=0) { 1398 return retvalue; 1399 } 1400 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 1401 switch(ioctl_cmd) { 1402 case ARCMSR_MESSAGE_READ_RQBUFFER: { 1403 u_int8_t * pQbuffer; 1404 u_int8_t * ptmpQbuffer=pcmdmessagefld->messagedatabuffer; 1405 u_int32_t allxfer_len=0; 1406 1407 while((acb->rqbuf_firstindex!=acb->rqbuf_lastindex) 1408 && (allxfer_len<1031)) { 1409 /*copy READ QBUFFER to srb*/ 1410 pQbuffer= &acb->rqbuffer[acb->rqbuf_firstindex]; 1411 memcpy(ptmpQbuffer, pQbuffer, 1); 1412 acb->rqbuf_firstindex++; 1413 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 1414 /*if last index number set it to 0 */ 1415 ptmpQbuffer++; 1416 allxfer_len++; 1417 } 1418 if(acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1419 struct QBUFFER * prbuffer; 1420 u_int8_t * iop_data; 1421 u_int32_t iop_len; 1422 1423 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1424 prbuffer=arcmsr_get_iop_rqbuffer(acb); 1425 iop_data=(u_int8_t *)prbuffer->data; 1426 iop_len=(u_int32_t)prbuffer->data_len; 1427 /*this iop data does no chance to make me overflow again here, so just do it*/ 1428 while(iop_len>0) { 1429 pQbuffer= &acb->rqbuffer[acb->rqbuf_lastindex]; 1430 memcpy(pQbuffer, iop_data, 1); 1431 acb->rqbuf_lastindex++; 1432 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1433 /*if last index number set it to 0 */ 1434 iop_data++; 1435 iop_len--; 1436 } 1437 arcmsr_iop_message_read(acb); 1438 /*signature, let IOP know data has been readed */ 1439 } 1440 pcmdmessagefld->cmdmessage.Length=allxfer_len; 1441 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1442 retvalue=ARCMSR_MESSAGE_SUCCESS; 1443 } 1444 break; 1445 case ARCMSR_MESSAGE_WRITE_WQBUFFER: { 1446 u_int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; 1447 u_int8_t * pQbuffer; 1448 u_int8_t * ptmpuserbuffer=pcmdmessagefld->messagedatabuffer; 1449 1450 user_len=pcmdmessagefld->cmdmessage.Length; 1451 /*check if data xfer length of this request will overflow my array qbuffer */ 1452 wqbuf_lastindex=acb->wqbuf_lastindex; 1453 wqbuf_firstindex=acb->wqbuf_firstindex; 1454 if(wqbuf_lastindex!=wqbuf_firstindex) { 1455 arcmsr_post_ioctldata2iop(acb); 1456 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_ERROR; 1457 } else { 1458 my_empty_len=(wqbuf_firstindex-wqbuf_lastindex-1)&(ARCMSR_MAX_QBUFFER-1); 1459 if(my_empty_len>=user_len) { 1460 while(user_len>0) { 1461 /*copy srb data to wqbuffer*/ 1462 pQbuffer= &acb->wqbuffer[acb->wqbuf_lastindex]; 1463 memcpy(pQbuffer, ptmpuserbuffer, 1); 1464 acb->wqbuf_lastindex++; 1465 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1466 /*if last index number set it to 0 */ 1467 ptmpuserbuffer++; 1468 user_len--; 1469 } 1470 /*post fist Qbuffer*/ 1471 if(acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) { 1472 acb->acb_flags &=~ACB_F_MESSAGE_WQBUFFER_CLEARED; 1473 arcmsr_post_ioctldata2iop(acb); 1474 } 1475 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1476 } else { 1477 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_ERROR; 1478 } 1479 } 1480 retvalue=ARCMSR_MESSAGE_SUCCESS; 1481 } 1482 break; 1483 case ARCMSR_MESSAGE_CLEAR_RQBUFFER: { 1484 u_int8_t * pQbuffer=acb->rqbuffer; 1485 1486 if(acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1487 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1488 arcmsr_iop_message_read(acb); 1489 /*signature, let IOP know data has been readed */ 1490 } 1491 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; 1492 acb->rqbuf_firstindex=0; 1493 acb->rqbuf_lastindex=0; 1494 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1495 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1496 retvalue=ARCMSR_MESSAGE_SUCCESS; 1497 } 1498 break; 1499 case ARCMSR_MESSAGE_CLEAR_WQBUFFER: 1500 { 1501 u_int8_t * pQbuffer=acb->wqbuffer; 1502 1503 if(acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1504 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1505 arcmsr_iop_message_read(acb); 1506 /*signature, let IOP know data has been readed */ 1507 } 1508 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED|ACB_F_MESSAGE_WQBUFFER_READ); 1509 acb->wqbuf_firstindex=0; 1510 acb->wqbuf_lastindex=0; 1511 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1512 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1513 retvalue=ARCMSR_MESSAGE_SUCCESS; 1514 } 1515 break; 1516 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER: { 1517 u_int8_t * pQbuffer; 1518 1519 if(acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1520 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1521 arcmsr_iop_message_read(acb); 1522 /*signature, let IOP know data has been readed */ 1523 } 1524 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED 1525 |ACB_F_MESSAGE_RQBUFFER_CLEARED 1526 |ACB_F_MESSAGE_WQBUFFER_READ); 1527 acb->rqbuf_firstindex=0; 1528 acb->rqbuf_lastindex=0; 1529 acb->wqbuf_firstindex=0; 1530 acb->wqbuf_lastindex=0; 1531 pQbuffer=acb->rqbuffer; 1532 memset(pQbuffer, 0, sizeof(struct QBUFFER)); 1533 pQbuffer=acb->wqbuffer; 1534 memset(pQbuffer, 0, sizeof(struct QBUFFER)); 1535 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1536 retvalue=ARCMSR_MESSAGE_SUCCESS; 1537 } 1538 break; 1539 case ARCMSR_MESSAGE_REQUEST_RETURNCODE_3F: { 1540 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_3F; 1541 retvalue=ARCMSR_MESSAGE_SUCCESS; 1542 } 1543 break; 1544 case ARCMSR_MESSAGE_SAY_HELLO: { 1545 u_int8_t * hello_string="Hello! I am ARCMSR"; 1546 u_int8_t * puserbuffer=(u_int8_t *)pcmdmessagefld->messagedatabuffer; 1547 1548 if(memcpy(puserbuffer, hello_string, (int16_t)strlen(hello_string))) { 1549 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_ERROR; 1550 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 1551 return ENOIOCTL; 1552 } 1553 pcmdmessagefld->cmdmessage.ReturnCode=ARCMSR_MESSAGE_RETURNCODE_OK; 1554 retvalue=ARCMSR_MESSAGE_SUCCESS; 1555 } 1556 break; 1557 case ARCMSR_MESSAGE_SAY_GOODBYE: { 1558 arcmsr_iop_parking(acb); 1559 retvalue=ARCMSR_MESSAGE_SUCCESS; 1560 } 1561 break; 1562 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE: { 1563 arcmsr_flush_adapter_cache(acb); 1564 retvalue=ARCMSR_MESSAGE_SUCCESS; 1565 } 1566 break; 1567 } 1568 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 1569 return retvalue; 1570 } 1571 /* 1572 ************************************************************************** 1573 ************************************************************************** 1574 */ 1575 struct CommandControlBlock * arcmsr_get_freesrb(struct AdapterControlBlock *acb) 1576 { 1577 struct CommandControlBlock *srb=NULL; 1578 u_int32_t workingsrb_startindex, workingsrb_doneindex; 1579 1580 #if __FreeBSD_version < 700025 1581 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 1582 #endif 1583 workingsrb_doneindex=acb->workingsrb_doneindex; 1584 workingsrb_startindex=acb->workingsrb_startindex; 1585 srb=acb->srbworkingQ[workingsrb_startindex]; 1586 workingsrb_startindex++; 1587 workingsrb_startindex %= ARCMSR_MAX_FREESRB_NUM; 1588 if(workingsrb_doneindex!=workingsrb_startindex) { 1589 acb->workingsrb_startindex=workingsrb_startindex; 1590 } else { 1591 srb=NULL; 1592 } 1593 #if __FreeBSD_version < 700025 1594 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 1595 #endif 1596 return(srb); 1597 } 1598 /* 1599 ************************************************************************** 1600 ************************************************************************** 1601 */ 1602 static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, union ccb * pccb) 1603 { 1604 struct CMD_MESSAGE_FIELD * pcmdmessagefld; 1605 int retvalue = 0, transfer_len = 0; 1606 char *buffer; 1607 u_int32_t controlcode = (u_int32_t ) pccb->csio.cdb_io.cdb_bytes[5] << 24 | 1608 (u_int32_t ) pccb->csio.cdb_io.cdb_bytes[6] << 16 | 1609 (u_int32_t ) pccb->csio.cdb_io.cdb_bytes[7] << 8 | 1610 (u_int32_t ) pccb->csio.cdb_io.cdb_bytes[8]; 1611 /* 4 bytes: Areca io control code */ 1612 if((pccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) { 1613 buffer = pccb->csio.data_ptr; 1614 transfer_len = pccb->csio.dxfer_len; 1615 } else { 1616 retvalue = ARCMSR_MESSAGE_FAIL; 1617 goto message_out; 1618 } 1619 if (transfer_len > sizeof(struct CMD_MESSAGE_FIELD)) { 1620 retvalue = ARCMSR_MESSAGE_FAIL; 1621 goto message_out; 1622 } 1623 pcmdmessagefld = (struct CMD_MESSAGE_FIELD *) buffer; 1624 switch(controlcode) { 1625 case ARCMSR_MESSAGE_READ_RQBUFFER: { 1626 u_int8_t *pQbuffer; 1627 u_int8_t *ptmpQbuffer=pcmdmessagefld->messagedatabuffer; 1628 int32_t allxfer_len = 0; 1629 1630 while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex) 1631 && (allxfer_len < 1031)) { 1632 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; 1633 memcpy(ptmpQbuffer, pQbuffer, 1); 1634 acb->rqbuf_firstindex++; 1635 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; 1636 ptmpQbuffer++; 1637 allxfer_len++; 1638 } 1639 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1640 struct QBUFFER *prbuffer; 1641 u_int8_t *iop_data; 1642 int32_t iop_len; 1643 1644 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1645 prbuffer=arcmsr_get_iop_rqbuffer(acb); 1646 iop_data = (u_int8_t *)prbuffer->data; 1647 iop_len =(u_int32_t)prbuffer->data_len; 1648 while (iop_len > 0) { 1649 pQbuffer= &acb->rqbuffer[acb->rqbuf_lastindex]; 1650 memcpy(pQbuffer, iop_data, 1); 1651 acb->rqbuf_lastindex++; 1652 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1653 iop_data++; 1654 iop_len--; 1655 } 1656 arcmsr_iop_message_read(acb); 1657 } 1658 pcmdmessagefld->cmdmessage.Length = allxfer_len; 1659 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1660 retvalue=ARCMSR_MESSAGE_SUCCESS; 1661 } 1662 break; 1663 case ARCMSR_MESSAGE_WRITE_WQBUFFER: { 1664 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; 1665 u_int8_t *pQbuffer; 1666 u_int8_t *ptmpuserbuffer=pcmdmessagefld->messagedatabuffer; 1667 1668 user_len = pcmdmessagefld->cmdmessage.Length; 1669 wqbuf_lastindex = acb->wqbuf_lastindex; 1670 wqbuf_firstindex = acb->wqbuf_firstindex; 1671 if (wqbuf_lastindex != wqbuf_firstindex) { 1672 arcmsr_post_ioctldata2iop(acb); 1673 /* has error report sensedata */ 1674 if(&pccb->csio.sense_data) { 1675 ((u_int8_t *)&pccb->csio.sense_data)[0] = (0x1 << 7 | 0x70); 1676 /* Valid,ErrorCode */ 1677 ((u_int8_t *)&pccb->csio.sense_data)[2] = 0x05; 1678 /* FileMark,EndOfMedia,IncorrectLength,Reserved,SenseKey */ 1679 ((u_int8_t *)&pccb->csio.sense_data)[7] = 0x0A; 1680 /* AdditionalSenseLength */ 1681 ((u_int8_t *)&pccb->csio.sense_data)[12] = 0x20; 1682 /* AdditionalSenseCode */ 1683 } 1684 retvalue = ARCMSR_MESSAGE_FAIL; 1685 } else { 1686 my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1) 1687 &(ARCMSR_MAX_QBUFFER - 1); 1688 if (my_empty_len >= user_len) { 1689 while (user_len > 0) { 1690 pQbuffer = &acb->wqbuffer[acb->wqbuf_lastindex]; 1691 memcpy(pQbuffer, ptmpuserbuffer, 1); 1692 acb->wqbuf_lastindex++; 1693 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; 1694 ptmpuserbuffer++; 1695 user_len--; 1696 } 1697 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) { 1698 acb->acb_flags &= 1699 ~ACB_F_MESSAGE_WQBUFFER_CLEARED; 1700 arcmsr_post_ioctldata2iop(acb); 1701 } 1702 } else { 1703 /* has error report sensedata */ 1704 if(&pccb->csio.sense_data) { 1705 ((u_int8_t *)&pccb->csio.sense_data)[0] = (0x1 << 7 | 0x70); 1706 /* Valid,ErrorCode */ 1707 ((u_int8_t *)&pccb->csio.sense_data)[2] = 0x05; 1708 /* FileMark,EndOfMedia,IncorrectLength,Reserved,SenseKey */ 1709 ((u_int8_t *)&pccb->csio.sense_data)[7] = 0x0A; 1710 /* AdditionalSenseLength */ 1711 ((u_int8_t *)&pccb->csio.sense_data)[12] = 0x20; 1712 /* AdditionalSenseCode */ 1713 } 1714 retvalue = ARCMSR_MESSAGE_FAIL; 1715 } 1716 } 1717 } 1718 break; 1719 case ARCMSR_MESSAGE_CLEAR_RQBUFFER: { 1720 u_int8_t *pQbuffer = acb->rqbuffer; 1721 1722 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1723 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1724 arcmsr_iop_message_read(acb); 1725 } 1726 acb->acb_flags |= ACB_F_MESSAGE_RQBUFFER_CLEARED; 1727 acb->rqbuf_firstindex = 0; 1728 acb->rqbuf_lastindex = 0; 1729 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1730 pcmdmessagefld->cmdmessage.ReturnCode = 1731 ARCMSR_MESSAGE_RETURNCODE_OK; 1732 } 1733 break; 1734 case ARCMSR_MESSAGE_CLEAR_WQBUFFER: { 1735 u_int8_t *pQbuffer = acb->wqbuffer; 1736 1737 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1738 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1739 arcmsr_iop_message_read(acb); 1740 } 1741 acb->acb_flags |= 1742 (ACB_F_MESSAGE_WQBUFFER_CLEARED | 1743 ACB_F_MESSAGE_WQBUFFER_READ); 1744 acb->wqbuf_firstindex = 0; 1745 acb->wqbuf_lastindex = 0; 1746 memset(pQbuffer, 0, ARCMSR_MAX_QBUFFER); 1747 pcmdmessagefld->cmdmessage.ReturnCode = 1748 ARCMSR_MESSAGE_RETURNCODE_OK; 1749 } 1750 break; 1751 case ARCMSR_MESSAGE_CLEAR_ALLQBUFFER: { 1752 u_int8_t *pQbuffer; 1753 1754 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { 1755 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; 1756 arcmsr_iop_message_read(acb); 1757 } 1758 acb->acb_flags |= 1759 (ACB_F_MESSAGE_WQBUFFER_CLEARED 1760 | ACB_F_MESSAGE_RQBUFFER_CLEARED 1761 | ACB_F_MESSAGE_WQBUFFER_READ); 1762 acb->rqbuf_firstindex = 0; 1763 acb->rqbuf_lastindex = 0; 1764 acb->wqbuf_firstindex = 0; 1765 acb->wqbuf_lastindex = 0; 1766 pQbuffer = acb->rqbuffer; 1767 memset(pQbuffer, 0, sizeof (struct QBUFFER)); 1768 pQbuffer = acb->wqbuffer; 1769 memset(pQbuffer, 0, sizeof (struct QBUFFER)); 1770 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1771 } 1772 break; 1773 case ARCMSR_MESSAGE_REQUEST_RETURNCODE_3F: { 1774 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_3F; 1775 } 1776 break; 1777 case ARCMSR_MESSAGE_SAY_HELLO: { 1778 int8_t * hello_string = "Hello! I am ARCMSR"; 1779 1780 memcpy(pcmdmessagefld->messagedatabuffer, hello_string 1781 , (int16_t)strlen(hello_string)); 1782 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1783 } 1784 break; 1785 case ARCMSR_MESSAGE_SAY_GOODBYE: 1786 arcmsr_iop_parking(acb); 1787 break; 1788 case ARCMSR_MESSAGE_FLUSH_ADAPTER_CACHE: 1789 arcmsr_flush_adapter_cache(acb); 1790 break; 1791 default: 1792 retvalue = ARCMSR_MESSAGE_FAIL; 1793 } 1794 message_out: 1795 return retvalue; 1796 } 1797 /* 1798 ********************************************************************* 1799 ********************************************************************* 1800 */ 1801 static void arcmsr_executesrb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) 1802 { 1803 struct CommandControlBlock *srb=(struct CommandControlBlock *)arg; 1804 struct AdapterControlBlock *acb=(struct AdapterControlBlock *)srb->acb; 1805 union ccb * pccb; 1806 int target, lun; 1807 1808 pccb=srb->pccb; 1809 target=pccb->ccb_h.target_id; 1810 lun=pccb->ccb_h.target_lun; 1811 if(error != 0) { 1812 if(error != EFBIG) { 1813 printf("arcmsr%d: unexpected error %x" 1814 " returned from 'bus_dmamap_load' \n" 1815 , acb->pci_unit, error); 1816 } 1817 if((pccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) { 1818 pccb->ccb_h.status |= CAM_REQ_TOO_BIG; 1819 } 1820 arcmsr_srb_complete(srb, 0); 1821 return; 1822 } 1823 if(nseg > ARCMSR_MAX_SG_ENTRIES) { 1824 pccb->ccb_h.status |= CAM_REQ_TOO_BIG; 1825 arcmsr_srb_complete(srb, 0); 1826 return; 1827 } 1828 if(acb->acb_flags & ACB_F_BUS_RESET) { 1829 printf("arcmsr%d: bus reset and return busy \n", acb->pci_unit); 1830 pccb->ccb_h.status |= CAM_SCSI_BUS_RESET; 1831 arcmsr_srb_complete(srb, 0); 1832 return; 1833 } 1834 if(acb->devstate[target][lun]==ARECA_RAID_GONE) { 1835 u_int8_t block_cmd; 1836 1837 block_cmd=pccb->csio.cdb_io.cdb_bytes[0] & 0x0f; 1838 if(block_cmd==0x08 || block_cmd==0x0a) { 1839 printf("arcmsr%d:block 'read/write' command" 1840 "with gone raid volume Cmd=%2x, TargetId=%d, Lun=%d \n" 1841 , acb->pci_unit, block_cmd, target, lun); 1842 pccb->ccb_h.status |= CAM_DEV_NOT_THERE; 1843 arcmsr_srb_complete(srb, 0); 1844 return; 1845 } 1846 } 1847 if((pccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) { 1848 if(nseg != 0) { 1849 bus_dmamap_unload(acb->dm_segs_dmat, srb->dm_segs_dmamap); 1850 } 1851 arcmsr_srb_complete(srb, 0); 1852 return; 1853 } 1854 if(acb->srboutstandingcount >= ARCMSR_MAX_OUTSTANDING_CMD) { 1855 xpt_freeze_simq(acb->psim, 1); 1856 pccb->ccb_h.status = CAM_REQUEUE_REQ; 1857 acb->acb_flags |= ACB_F_CAM_DEV_QFRZN; 1858 arcmsr_srb_complete(srb, 0); 1859 return; 1860 } 1861 pccb->ccb_h.status |= CAM_SIM_QUEUED; 1862 arcmsr_build_srb(srb, dm_segs, nseg); 1863 arcmsr_post_srb(acb, srb); 1864 return; 1865 } 1866 /* 1867 ***************************************************************************************** 1868 ***************************************************************************************** 1869 */ 1870 static u_int8_t arcmsr_seek_cmd2abort(union ccb * abortccb) 1871 { 1872 struct CommandControlBlock *srb; 1873 struct AdapterControlBlock *acb=(struct AdapterControlBlock *) abortccb->ccb_h.arcmsr_ccbacb_ptr; 1874 u_int32_t intmask_org; 1875 int i=0; 1876 1877 acb->num_aborts++; 1878 /* 1879 *************************************************************************** 1880 ** It is the upper layer do abort command this lock just prior to calling us. 1881 ** First determine if we currently own this command. 1882 ** Start by searching the device queue. If not found 1883 ** at all, and the system wanted us to just abort the 1884 ** command return success. 1885 *************************************************************************** 1886 */ 1887 if(acb->srboutstandingcount!=0) { 1888 for(i=0;i<ARCMSR_MAX_FREESRB_NUM;i++) { 1889 srb=acb->psrb_pool[i]; 1890 if(srb->startdone==ARCMSR_SRB_START) { 1891 if(srb->pccb==abortccb) { 1892 srb->startdone=ARCMSR_SRB_ABORTED; 1893 printf("arcmsr%d:scsi id=%d lun=%d abort srb '%p'" 1894 "outstanding command \n" 1895 , acb->pci_unit, abortccb->ccb_h.target_id 1896 , abortccb->ccb_h.target_lun, srb); 1897 goto abort_outstanding_cmd; 1898 } 1899 } 1900 } 1901 } 1902 return(FALSE); 1903 abort_outstanding_cmd: 1904 /* disable all outbound interrupt */ 1905 intmask_org=arcmsr_disable_allintr(acb); 1906 arcmsr_polling_srbdone(acb, srb); 1907 /* enable outbound Post Queue, outbound doorbell Interrupt */ 1908 arcmsr_enable_allintr(acb, intmask_org); 1909 return (TRUE); 1910 } 1911 /* 1912 **************************************************************************** 1913 **************************************************************************** 1914 */ 1915 static void arcmsr_bus_reset(struct AdapterControlBlock *acb) 1916 { 1917 int retry=0; 1918 1919 acb->num_resets++; 1920 acb->acb_flags |=ACB_F_BUS_RESET; 1921 while(acb->srboutstandingcount!=0 && retry < 400) { 1922 arcmsr_interrupt(acb); 1923 UDELAY(25000); 1924 retry++; 1925 } 1926 arcmsr_iop_reset(acb); 1927 acb->acb_flags &= ~ACB_F_BUS_RESET; 1928 return; 1929 } 1930 /* 1931 ************************************************************************** 1932 ************************************************************************** 1933 */ 1934 static void arcmsr_handle_virtual_command(struct AdapterControlBlock *acb, 1935 union ccb * pccb) 1936 { 1937 pccb->ccb_h.status |= CAM_REQ_CMP; 1938 switch (pccb->csio.cdb_io.cdb_bytes[0]) { 1939 case INQUIRY: { 1940 unsigned char inqdata[36]; 1941 char *buffer=pccb->csio.data_ptr;; 1942 1943 if (pccb->ccb_h.target_lun) { 1944 pccb->ccb_h.status |= CAM_SEL_TIMEOUT; 1945 xpt_done(pccb); 1946 return; 1947 } 1948 inqdata[0] = T_PROCESSOR; 1949 /* Periph Qualifier & Periph Dev Type */ 1950 inqdata[1] = 0; 1951 /* rem media bit & Dev Type Modifier */ 1952 inqdata[2] = 0; 1953 /* ISO, ECMA, & ANSI versions */ 1954 inqdata[4] = 31; 1955 /* length of additional data */ 1956 strncpy(&inqdata[8], "Areca ", 8); 1957 /* Vendor Identification */ 1958 strncpy(&inqdata[16], "RAID controller ", 16); 1959 /* Product Identification */ 1960 strncpy(&inqdata[32], "R001", 4); /* Product Revision */ 1961 memcpy(buffer, inqdata, sizeof(inqdata)); 1962 xpt_done(pccb); 1963 } 1964 break; 1965 case WRITE_BUFFER: 1966 case READ_BUFFER: { 1967 if (arcmsr_iop_message_xfer(acb, pccb)) { 1968 pccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR; 1969 pccb->csio.scsi_status = SCSI_STATUS_CHECK_COND; 1970 } 1971 xpt_done(pccb); 1972 } 1973 break; 1974 default: 1975 xpt_done(pccb); 1976 } 1977 } 1978 /* 1979 ********************************************************************* 1980 ********************************************************************* 1981 */ 1982 static void arcmsr_action(struct cam_sim * psim, union ccb * pccb) 1983 { 1984 struct AdapterControlBlock * acb; 1985 1986 acb=(struct AdapterControlBlock *) cam_sim_softc(psim); 1987 if(acb==NULL) { 1988 pccb->ccb_h.status |= CAM_REQ_INVALID; 1989 xpt_done(pccb); 1990 return; 1991 } 1992 switch (pccb->ccb_h.func_code) { 1993 case XPT_SCSI_IO: { 1994 struct CommandControlBlock *srb; 1995 int target=pccb->ccb_h.target_id; 1996 1997 if(target == 16) { 1998 /* virtual device for iop message transfer */ 1999 arcmsr_handle_virtual_command(acb, pccb); 2000 return; 2001 } 2002 if((srb=arcmsr_get_freesrb(acb)) == NULL) { 2003 pccb->ccb_h.status |= CAM_RESRC_UNAVAIL; 2004 xpt_done(pccb); 2005 return; 2006 } 2007 pccb->ccb_h.arcmsr_ccbsrb_ptr=srb; 2008 pccb->ccb_h.arcmsr_ccbacb_ptr=acb; 2009 srb->pccb=pccb; 2010 if((pccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 2011 if(!(pccb->ccb_h.flags & CAM_SCATTER_VALID)) { 2012 /* Single buffer */ 2013 if(!(pccb->ccb_h.flags & CAM_DATA_PHYS)) { 2014 /* Buffer is virtual */ 2015 u_int32_t error, s; 2016 2017 s=splsoftvm(); 2018 error = bus_dmamap_load(acb->dm_segs_dmat 2019 , srb->dm_segs_dmamap 2020 , pccb->csio.data_ptr 2021 , pccb->csio.dxfer_len 2022 , arcmsr_executesrb, srb, /*flags*/0); 2023 if(error == EINPROGRESS) { 2024 xpt_freeze_simq(acb->psim, 1); 2025 pccb->ccb_h.status |= CAM_RELEASE_SIMQ; 2026 } 2027 splx(s); 2028 } else { 2029 /* Buffer is physical */ 2030 panic("arcmsr: CAM_DATA_PHYS not supported"); 2031 } 2032 } else { 2033 /* Scatter/gather list */ 2034 struct bus_dma_segment *segs; 2035 2036 if((pccb->ccb_h.flags & CAM_SG_LIST_PHYS) == 0 2037 || (pccb->ccb_h.flags & CAM_DATA_PHYS) != 0) { 2038 pccb->ccb_h.status |= CAM_PROVIDE_FAIL; 2039 xpt_done(pccb); 2040 free(srb, M_DEVBUF); 2041 return; 2042 } 2043 segs=(struct bus_dma_segment *)pccb->csio.data_ptr; 2044 arcmsr_executesrb(srb, segs, pccb->csio.sglist_cnt, 0); 2045 } 2046 } else { 2047 arcmsr_executesrb(srb, NULL, 0, 0); 2048 } 2049 break; 2050 } 2051 case XPT_TARGET_IO: { 2052 /* target mode not yet support vendor specific commands. */ 2053 pccb->ccb_h.status |= CAM_REQ_CMP; 2054 xpt_done(pccb); 2055 break; 2056 } 2057 case XPT_PATH_INQ: { 2058 struct ccb_pathinq *cpi= &pccb->cpi; 2059 2060 cpi->version_num=1; 2061 cpi->hba_inquiry=PI_SDTR_ABLE | PI_TAG_ABLE; 2062 cpi->target_sprt=0; 2063 cpi->hba_misc=0; 2064 cpi->hba_eng_cnt=0; 2065 cpi->max_target=ARCMSR_MAX_TARGETID; /* 0-16 */ 2066 cpi->max_lun=ARCMSR_MAX_TARGETLUN; /* 0-7 */ 2067 cpi->initiator_id=ARCMSR_SCSI_INITIATOR_ID; /* 255 */ 2068 cpi->bus_id=cam_sim_bus(psim); 2069 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 2070 strncpy(cpi->hba_vid, "ARCMSR", HBA_IDLEN); 2071 strncpy(cpi->dev_name, cam_sim_name(psim), DEV_IDLEN); 2072 cpi->unit_number=cam_sim_unit(psim); 2073 #ifdef CAM_NEW_TRAN_CODE 2074 cpi->transport = XPORT_SPI; 2075 cpi->transport_version = 2; 2076 cpi->protocol = PROTO_SCSI; 2077 cpi->protocol_version = SCSI_REV_2; 2078 #endif 2079 cpi->ccb_h.status |= CAM_REQ_CMP; 2080 xpt_done(pccb); 2081 break; 2082 } 2083 case XPT_ABORT: { 2084 union ccb *pabort_ccb; 2085 2086 pabort_ccb=pccb->cab.abort_ccb; 2087 switch (pabort_ccb->ccb_h.func_code) { 2088 case XPT_ACCEPT_TARGET_IO: 2089 case XPT_IMMED_NOTIFY: 2090 case XPT_CONT_TARGET_IO: 2091 if(arcmsr_seek_cmd2abort(pabort_ccb)==TRUE) { 2092 pabort_ccb->ccb_h.status |= CAM_REQ_ABORTED; 2093 xpt_done(pabort_ccb); 2094 pccb->ccb_h.status |= CAM_REQ_CMP; 2095 } else { 2096 xpt_print_path(pabort_ccb->ccb_h.path); 2097 printf("Not found\n"); 2098 pccb->ccb_h.status |= CAM_PATH_INVALID; 2099 } 2100 break; 2101 case XPT_SCSI_IO: 2102 pccb->ccb_h.status |= CAM_UA_ABORT; 2103 break; 2104 default: 2105 pccb->ccb_h.status |= CAM_REQ_INVALID; 2106 break; 2107 } 2108 xpt_done(pccb); 2109 break; 2110 } 2111 case XPT_RESET_BUS: 2112 case XPT_RESET_DEV: { 2113 u_int32_t i; 2114 2115 arcmsr_bus_reset(acb); 2116 for (i=0; i < 500; i++) { 2117 DELAY(1000); 2118 } 2119 pccb->ccb_h.status |= CAM_REQ_CMP; 2120 xpt_done(pccb); 2121 break; 2122 } 2123 case XPT_TERM_IO: { 2124 pccb->ccb_h.status |= CAM_REQ_INVALID; 2125 xpt_done(pccb); 2126 break; 2127 } 2128 case XPT_GET_TRAN_SETTINGS: { 2129 struct ccb_trans_settings *cts; 2130 2131 if(pccb->ccb_h.target_id == 16) { 2132 pccb->ccb_h.status |= CAM_FUNC_NOTAVAIL; 2133 xpt_done(pccb); 2134 break; 2135 } 2136 cts= &pccb->cts; 2137 #ifdef CAM_NEW_TRAN_CODE 2138 { 2139 struct ccb_trans_settings_scsi *scsi; 2140 struct ccb_trans_settings_spi *spi; 2141 2142 scsi = &cts->proto_specific.scsi; 2143 spi = &cts->xport_specific.spi; 2144 cts->protocol = PROTO_SCSI; 2145 cts->protocol_version = SCSI_REV_2; 2146 cts->transport = XPORT_SPI; 2147 cts->transport_version = 2; 2148 spi->flags = CTS_SPI_FLAGS_DISC_ENB; 2149 spi->sync_period=3; 2150 spi->sync_offset=32; 2151 spi->bus_width=MSG_EXT_WDTR_BUS_16_BIT; 2152 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; 2153 spi->valid = CTS_SPI_VALID_DISC 2154 | CTS_SPI_VALID_SYNC_RATE 2155 | CTS_SPI_VALID_SYNC_OFFSET 2156 | CTS_SPI_VALID_BUS_WIDTH; 2157 scsi->valid = CTS_SCSI_VALID_TQ; 2158 } 2159 #else 2160 { 2161 cts->flags=(CCB_TRANS_DISC_ENB | CCB_TRANS_TAG_ENB); 2162 cts->sync_period=3; 2163 cts->sync_offset=32; 2164 cts->bus_width=MSG_EXT_WDTR_BUS_16_BIT; 2165 cts->valid=CCB_TRANS_SYNC_RATE_VALID | 2166 CCB_TRANS_SYNC_OFFSET_VALID | 2167 CCB_TRANS_BUS_WIDTH_VALID | 2168 CCB_TRANS_DISC_VALID | 2169 CCB_TRANS_TQ_VALID; 2170 } 2171 #endif 2172 pccb->ccb_h.status |= CAM_REQ_CMP; 2173 xpt_done(pccb); 2174 break; 2175 } 2176 case XPT_SET_TRAN_SETTINGS: { 2177 pccb->ccb_h.status |= CAM_FUNC_NOTAVAIL; 2178 xpt_done(pccb); 2179 break; 2180 } 2181 case XPT_CALC_GEOMETRY: { 2182 struct ccb_calc_geometry *ccg; 2183 u_int32_t size_mb; 2184 u_int32_t secs_per_cylinder; 2185 2186 if(pccb->ccb_h.target_id == 16) { 2187 pccb->ccb_h.status |= CAM_FUNC_NOTAVAIL; 2188 xpt_done(pccb); 2189 break; 2190 } 2191 ccg= &pccb->ccg; 2192 if (ccg->block_size == 0) { 2193 pccb->ccb_h.status = CAM_REQ_INVALID; 2194 xpt_done(pccb); 2195 break; 2196 } 2197 if(((1024L * 1024L)/ccg->block_size) < 0) { 2198 pccb->ccb_h.status = CAM_REQ_INVALID; 2199 xpt_done(pccb); 2200 break; 2201 } 2202 size_mb=ccg->volume_size/((1024L * 1024L)/ccg->block_size); 2203 if(size_mb > 1024 ) { 2204 ccg->heads=255; 2205 ccg->secs_per_track=63; 2206 } else { 2207 ccg->heads=64; 2208 ccg->secs_per_track=32; 2209 } 2210 secs_per_cylinder=ccg->heads * ccg->secs_per_track; 2211 ccg->cylinders=ccg->volume_size / secs_per_cylinder; 2212 pccb->ccb_h.status |= CAM_REQ_CMP; 2213 xpt_done(pccb); 2214 break; 2215 } 2216 default: 2217 pccb->ccb_h.status |= CAM_REQ_INVALID; 2218 xpt_done(pccb); 2219 break; 2220 } 2221 return; 2222 } 2223 /* 2224 ********************************************************************** 2225 ********************************************************************** 2226 */ 2227 static void arcmsr_start_hba_bgrb(struct AdapterControlBlock *acb) 2228 { 2229 acb->acb_flags |= ACB_F_MSG_START_BGRB; 2230 CHIP_REG_WRITE32(HBA_MessageUnit, 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_START_BGRB); 2231 if(!arcmsr_hba_wait_msgint_ready(acb)) { 2232 printf("arcmsr%d: wait 'start adapter background rebulid' timeout \n", acb->pci_unit); 2233 } 2234 return; 2235 } 2236 /* 2237 ********************************************************************** 2238 ********************************************************************** 2239 */ 2240 static void arcmsr_start_hbb_bgrb(struct AdapterControlBlock *acb) 2241 { 2242 acb->acb_flags |= ACB_F_MSG_START_BGRB; 2243 CHIP_REG_WRITE32(HBB_DOORBELL, 2244 0, drv2iop_doorbell, ARCMSR_MESSAGE_START_BGRB); 2245 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2246 printf( "arcmsr%d: wait 'start adapter background rebulid' timeout \n", acb->pci_unit); 2247 } 2248 return; 2249 } 2250 /* 2251 ********************************************************************** 2252 ********************************************************************** 2253 */ 2254 static void arcmsr_start_adapter_bgrb(struct AdapterControlBlock *acb) 2255 { 2256 switch (acb->adapter_type) { 2257 case ACB_ADAPTER_TYPE_A: 2258 arcmsr_start_hba_bgrb(acb); 2259 break; 2260 case ACB_ADAPTER_TYPE_B: 2261 arcmsr_start_hbb_bgrb(acb); 2262 break; 2263 } 2264 return; 2265 } 2266 /* 2267 ********************************************************************** 2268 ** 2269 ********************************************************************** 2270 */ 2271 static void arcmsr_polling_hba_srbdone(struct AdapterControlBlock *acb, struct CommandControlBlock *poll_srb) 2272 { 2273 struct CommandControlBlock *srb; 2274 u_int32_t flag_srb, outbound_intstatus, poll_srb_done=0, poll_count=0; 2275 2276 polling_ccb_retry: 2277 poll_count++; 2278 outbound_intstatus=CHIP_REG_READ32(HBA_MessageUnit, 2279 0, outbound_intstatus) & acb->outbound_int_enable; 2280 CHIP_REG_WRITE32(HBA_MessageUnit, 2281 0, outbound_intstatus, outbound_intstatus);/*clear interrupt*/ 2282 bus_dmamap_sync(acb->srb_dmat, acb->srb_dmamap, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 2283 while(1) { 2284 if((flag_srb=CHIP_REG_READ32(HBA_MessageUnit, 2285 0, outbound_queueport))==0xFFFFFFFF) { 2286 if(poll_srb_done) { 2287 break;/*chip FIFO no ccb for completion already*/ 2288 } else { 2289 UDELAY(25000); 2290 if(poll_count > 100) { 2291 break; 2292 } 2293 goto polling_ccb_retry; 2294 } 2295 } 2296 /* check ifcommand done with no error*/ 2297 srb=(struct CommandControlBlock *) 2298 (acb->vir2phy_offset+(flag_srb << 5));/*frame must be 32 bytes aligned*/ 2299 poll_srb_done = (srb==poll_srb) ? 1:0; 2300 if((srb->acb!=acb) || (srb->startdone!=ARCMSR_SRB_START)) { 2301 if(srb->startdone==ARCMSR_SRB_ABORTED) { 2302 printf("arcmsr%d: scsi id=%d lun=%d srb='%p'" 2303 "poll command abort successfully \n" 2304 , acb->pci_unit 2305 , srb->pccb->ccb_h.target_id 2306 , srb->pccb->ccb_h.target_lun, srb); 2307 srb->pccb->ccb_h.status |= CAM_REQ_ABORTED; 2308 arcmsr_srb_complete(srb, 1); 2309 continue; 2310 } 2311 printf("arcmsr%d: polling get an illegal srb command done srb='%p'" 2312 "srboutstandingcount=%d \n" 2313 , acb->pci_unit 2314 , srb, acb->srboutstandingcount); 2315 continue; 2316 } 2317 arcmsr_report_srb_state(acb, srb, flag_srb); 2318 } /*drain reply FIFO*/ 2319 return; 2320 } 2321 /* 2322 ********************************************************************** 2323 ** 2324 ********************************************************************** 2325 */ 2326 static void arcmsr_polling_hbb_srbdone(struct AdapterControlBlock *acb, struct CommandControlBlock *poll_srb) 2327 { 2328 struct HBB_MessageUnit *phbbmu=(struct HBB_MessageUnit *)acb->pmu; 2329 struct CommandControlBlock *srb; 2330 u_int32_t flag_srb, poll_srb_done=0, poll_count=0; 2331 int index; 2332 2333 polling_ccb_retry: 2334 poll_count++; 2335 CHIP_REG_WRITE32(HBB_DOORBELL, 2336 0, iop2drv_doorbell, ARCMSR_DOORBELL_INT_CLEAR_PATTERN); /* clear doorbell interrupt */ 2337 bus_dmamap_sync(acb->srb_dmat, acb->srb_dmamap, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 2338 while(1) { 2339 index=phbbmu->doneq_index; 2340 if((flag_srb=phbbmu->done_qbuffer[index]) == 0) { 2341 if(poll_srb_done) { 2342 break;/*chip FIFO no ccb for completion already*/ 2343 } else { 2344 UDELAY(25000); 2345 if(poll_count > 100) { 2346 break; 2347 } 2348 goto polling_ccb_retry; 2349 } 2350 } 2351 phbbmu->done_qbuffer[index]=0; 2352 index++; 2353 index %= ARCMSR_MAX_HBB_POSTQUEUE; /*if last index number set it to 0 */ 2354 phbbmu->doneq_index=index; 2355 /* check if command done with no error*/ 2356 srb=(struct CommandControlBlock *) 2357 (acb->vir2phy_offset+(flag_srb << 5));/*frame must be 32 bytes aligned*/ 2358 poll_srb_done = (srb==poll_srb) ? 1:0; 2359 if((srb->acb!=acb) || (srb->startdone!=ARCMSR_SRB_START)) { 2360 if(srb->startdone==ARCMSR_SRB_ABORTED) { 2361 printf("arcmsr%d: scsi id=%d lun=%d srb='%p'" 2362 "poll command abort successfully \n" 2363 , acb->pci_unit 2364 , srb->pccb->ccb_h.target_id 2365 , srb->pccb->ccb_h.target_lun, srb); 2366 srb->pccb->ccb_h.status |= CAM_REQ_ABORTED; 2367 arcmsr_srb_complete(srb, 1); 2368 continue; 2369 } 2370 printf("arcmsr%d: polling get an illegal srb command done srb='%p'" 2371 "srboutstandingcount=%d \n" 2372 , acb->pci_unit 2373 , srb, acb->srboutstandingcount); 2374 continue; 2375 } 2376 arcmsr_report_srb_state(acb, srb, flag_srb); 2377 } /*drain reply FIFO*/ 2378 return; 2379 } 2380 /* 2381 ********************************************************************** 2382 ********************************************************************** 2383 */ 2384 static void arcmsr_polling_srbdone(struct AdapterControlBlock *acb, struct CommandControlBlock *poll_srb) 2385 { 2386 switch (acb->adapter_type) { 2387 case ACB_ADAPTER_TYPE_A: { 2388 arcmsr_polling_hba_srbdone(acb, poll_srb); 2389 } 2390 break; 2391 case ACB_ADAPTER_TYPE_B: { 2392 arcmsr_polling_hbb_srbdone(acb, poll_srb); 2393 } 2394 break; 2395 } 2396 } 2397 /* 2398 ********************************************************************** 2399 ********************************************************************** 2400 */ 2401 static void arcmsr_get_hba_config(struct AdapterControlBlock *acb) 2402 { 2403 char *acb_firm_model=acb->firm_model; 2404 char *acb_firm_version=acb->firm_version; 2405 size_t iop_firm_model=offsetof(struct HBA_MessageUnit,msgcode_rwbuffer[15]); /*firm_model,15,60-67*/ 2406 size_t iop_firm_version=offsetof(struct HBA_MessageUnit,msgcode_rwbuffer[17]); /*firm_version,17,68-83*/ 2407 int i; 2408 2409 CHIP_REG_WRITE32(HBA_MessageUnit, 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_GET_CONFIG); 2410 if(!arcmsr_hba_wait_msgint_ready(acb)) { 2411 printf("arcmsr%d: wait 'get adapter firmware miscellaneous data' timeout \n" 2412 , acb->pci_unit); 2413 } 2414 i=0; 2415 while(i<8) { 2416 *acb_firm_model=bus_space_read_1(acb->btag[0], acb->bhandle[0], iop_firm_model+i); 2417 /* 8 bytes firm_model, 15, 60-67*/ 2418 acb_firm_model++; 2419 i++; 2420 } 2421 i=0; 2422 while(i<16) { 2423 *acb_firm_version=bus_space_read_1(acb->btag[0], acb->bhandle[0], iop_firm_version+i); 2424 /* 16 bytes firm_version, 17, 68-83*/ 2425 acb_firm_version++; 2426 i++; 2427 } 2428 printf("ARECA RAID ADAPTER%d: %s \n", acb->pci_unit, ARCMSR_DRIVER_VERSION); 2429 printf("ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n", acb->pci_unit, acb->firm_version); 2430 acb->firm_request_len=CHIP_REG_READ32(HBA_MessageUnit, 2431 0, msgcode_rwbuffer[1]); /*firm_request_len, 1, 04-07*/ 2432 acb->firm_numbers_queue=CHIP_REG_READ32(HBA_MessageUnit, 2433 0, msgcode_rwbuffer[2]); /*firm_numbers_queue, 2, 08-11*/ 2434 acb->firm_sdram_size=CHIP_REG_READ32(HBA_MessageUnit, 2435 0, msgcode_rwbuffer[3]); /*firm_sdram_size, 3, 12-15*/ 2436 acb->firm_ide_channels=CHIP_REG_READ32(HBA_MessageUnit, 2437 0, msgcode_rwbuffer[4]); /*firm_ide_channels, 4, 16-19*/ 2438 return; 2439 } 2440 /* 2441 ********************************************************************** 2442 ********************************************************************** 2443 */ 2444 static void arcmsr_get_hbb_config(struct AdapterControlBlock *acb) 2445 { 2446 char *acb_firm_model=acb->firm_model; 2447 char *acb_firm_version=acb->firm_version; 2448 size_t iop_firm_model=offsetof(struct HBB_RWBUFFER, 2449 msgcode_rwbuffer[15]); /*firm_model,15,60-67*/ 2450 size_t iop_firm_version=offsetof(struct HBB_RWBUFFER, 2451 msgcode_rwbuffer[17]); /*firm_version,17,68-83*/ 2452 int i; 2453 2454 CHIP_REG_WRITE32(HBB_DOORBELL, 2455 0, drv2iop_doorbell, ARCMSR_MESSAGE_GET_CONFIG); 2456 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2457 printf( "arcmsr%d: wait" 2458 "'get adapter firmware miscellaneous data' timeout \n", acb->pci_unit); 2459 } 2460 i=0; 2461 while(i<8) { 2462 *acb_firm_model=bus_space_read_1(acb->btag[1], acb->bhandle[1], iop_firm_model+i); 2463 /* 8 bytes firm_model, 15, 60-67*/ 2464 acb_firm_model++; 2465 i++; 2466 } 2467 i=0; 2468 while(i<16) { 2469 *acb_firm_version=bus_space_read_1(acb->btag[1], acb->bhandle[1], iop_firm_version+i); 2470 /* 16 bytes firm_version, 17, 68-83*/ 2471 acb_firm_version++; 2472 i++; 2473 } 2474 printf("ARECA RAID ADAPTER%d: %s \n", acb->pci_unit, ARCMSR_DRIVER_VERSION); 2475 printf("ARECA RAID ADAPTER%d: FIRMWARE VERSION %s \n", acb->pci_unit, acb->firm_version); 2476 acb->firm_request_len=CHIP_REG_READ32(HBB_RWBUFFER, 2477 1, msgcode_rwbuffer[1]); /*firm_request_len, 1, 04-07*/ 2478 acb->firm_numbers_queue=CHIP_REG_READ32(HBB_RWBUFFER, 2479 1, msgcode_rwbuffer[2]); /*firm_numbers_queue, 2, 08-11*/ 2480 acb->firm_sdram_size=CHIP_REG_READ32(HBB_RWBUFFER, 2481 1, msgcode_rwbuffer[3]); /*firm_sdram_size, 3, 12-15*/ 2482 acb->firm_ide_channels=CHIP_REG_READ32(HBB_RWBUFFER, 2483 1, msgcode_rwbuffer[4]); /*firm_ide_channels, 4, 16-19*/ 2484 return; 2485 } 2486 /* 2487 ********************************************************************** 2488 ********************************************************************** 2489 */ 2490 static void arcmsr_get_firmware_spec(struct AdapterControlBlock *acb) 2491 { 2492 switch (acb->adapter_type) { 2493 case ACB_ADAPTER_TYPE_A: { 2494 arcmsr_get_hba_config(acb); 2495 } 2496 break; 2497 case ACB_ADAPTER_TYPE_B: { 2498 arcmsr_get_hbb_config(acb); 2499 } 2500 break; 2501 } 2502 return; 2503 } 2504 /* 2505 ********************************************************************** 2506 ********************************************************************** 2507 */ 2508 static void arcmsr_wait_firmware_ready( struct AdapterControlBlock *acb) 2509 { 2510 int timeout=0; 2511 2512 switch (acb->adapter_type) { 2513 case ACB_ADAPTER_TYPE_A: { 2514 while ((CHIP_REG_READ32(HBA_MessageUnit, 2515 0, outbound_msgaddr1) & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0) 2516 { 2517 if (timeout++ > 2000) /* (2000*15)/1000 = 30 sec */ 2518 { 2519 printf( "arcmsr%d:" 2520 "timed out waiting for firmware \n", acb->pci_unit); 2521 return; 2522 } 2523 UDELAY(15000); /* wait 15 milli-seconds */ 2524 } 2525 } 2526 break; 2527 case ACB_ADAPTER_TYPE_B: { 2528 while ((CHIP_REG_READ32(HBB_DOORBELL, 2529 0, iop2drv_doorbell) & ARCMSR_MESSAGE_FIRMWARE_OK) == 0) 2530 { 2531 if (timeout++ > 2000) /* (2000*15)/1000 = 30 sec */ 2532 { 2533 printf( "arcmsr%d:" 2534 " timed out waiting for firmware \n", acb->pci_unit); 2535 return; 2536 } 2537 UDELAY(15000); /* wait 15 milli-seconds */ 2538 } 2539 CHIP_REG_WRITE32(HBB_DOORBELL, 2540 0, drv2iop_doorbell, ARCMSR_DRV2IOP_END_OF_INTERRUPT); 2541 } 2542 break; 2543 } 2544 return; 2545 } 2546 /* 2547 ********************************************************************** 2548 ********************************************************************** 2549 */ 2550 static void arcmsr_clear_doorbell_queue_buffer( struct AdapterControlBlock *acb) 2551 { 2552 switch (acb->adapter_type) { 2553 case ACB_ADAPTER_TYPE_A: { 2554 /* empty doorbell Qbuffer if door bell ringed */ 2555 CHIP_REG_WRITE32(HBA_MessageUnit, 2556 0, outbound_doorbell, 2557 CHIP_REG_READ32(HBA_MessageUnit, 2558 0, outbound_doorbell));/*clear doorbell interrupt */ 2559 CHIP_REG_WRITE32(HBA_MessageUnit, 2560 0, inbound_doorbell, ARCMSR_INBOUND_DRIVER_DATA_READ_OK); 2561 } 2562 break; 2563 case ACB_ADAPTER_TYPE_B: { 2564 CHIP_REG_WRITE32(HBB_DOORBELL, 2565 0, iop2drv_doorbell, ARCMSR_MESSAGE_INT_CLEAR_PATTERN);/*clear interrupt and message state*/ 2566 CHIP_REG_WRITE32(HBB_DOORBELL, 2567 0, drv2iop_doorbell, ARCMSR_DRV2IOP_DATA_READ_OK); 2568 /* let IOP know data has been read */ 2569 } 2570 break; 2571 } 2572 return; 2573 } 2574 /* 2575 ************************************************************************ 2576 ************************************************************************ 2577 */ 2578 static u_int32_t arcmsr_iop_confirm(struct AdapterControlBlock *acb) 2579 { 2580 unsigned long srb_phyaddr; 2581 u_int32_t srb_phyaddr_hi32; 2582 2583 /* 2584 ******************************************************************** 2585 ** here we need to tell iop 331 our freesrb.HighPart 2586 ** if freesrb.HighPart is not zero 2587 ******************************************************************** 2588 */ 2589 srb_phyaddr= (unsigned long) acb->srb_phyaddr; 2590 srb_phyaddr_hi32=(u_int32_t) ((srb_phyaddr>>16)>>16); 2591 switch (acb->adapter_type) { 2592 case ACB_ADAPTER_TYPE_A: { 2593 if(srb_phyaddr_hi32!=0) { 2594 CHIP_REG_WRITE32(HBA_MessageUnit, 2595 0, msgcode_rwbuffer[0], ARCMSR_SIGNATURE_SET_CONFIG); 2596 CHIP_REG_WRITE32(HBA_MessageUnit, 2597 0, msgcode_rwbuffer[1], srb_phyaddr_hi32); 2598 CHIP_REG_WRITE32(HBA_MessageUnit, 2599 0, inbound_msgaddr0, ARCMSR_INBOUND_MESG0_SET_CONFIG); 2600 if(!arcmsr_hba_wait_msgint_ready(acb)) { 2601 printf( "arcmsr%d:" 2602 " 'set srb high part physical address' timeout \n", acb->pci_unit); 2603 return FALSE; 2604 } 2605 } 2606 } 2607 break; 2608 /* 2609 *********************************************************************** 2610 ** if adapter type B, set window of "post command Q" 2611 *********************************************************************** 2612 */ 2613 case ACB_ADAPTER_TYPE_B: { 2614 u_int32_t post_queue_phyaddr; 2615 struct HBB_MessageUnit *phbbmu; 2616 2617 phbbmu=(struct HBB_MessageUnit *)acb->pmu; 2618 phbbmu->postq_index=0; 2619 phbbmu->doneq_index=0; 2620 CHIP_REG_WRITE32(HBB_DOORBELL, 2621 0, drv2iop_doorbell, ARCMSR_MESSAGE_SET_POST_WINDOW); 2622 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2623 printf( "arcmsr%d:" 2624 " 'set window of post command Q' timeout\n", acb->pci_unit); 2625 return FALSE; 2626 } 2627 post_queue_phyaddr = srb_phyaddr 2628 + ARCMSR_MAX_FREESRB_NUM*sizeof(struct CommandControlBlock) 2629 + offsetof(struct HBB_MessageUnit, post_qbuffer); 2630 CHIP_REG_WRITE32(HBB_RWBUFFER, 2631 1, msgcode_rwbuffer[0], ARCMSR_SIGNATURE_SET_CONFIG); /* driver "set config" signature */ 2632 CHIP_REG_WRITE32(HBB_RWBUFFER, 2633 1, msgcode_rwbuffer[1], srb_phyaddr_hi32); /* normal should be zero */ 2634 CHIP_REG_WRITE32(HBB_RWBUFFER, 2635 1, msgcode_rwbuffer[2], post_queue_phyaddr); /* postQ size (256+8)*4 */ 2636 CHIP_REG_WRITE32(HBB_RWBUFFER, 2637 1, msgcode_rwbuffer[3], post_queue_phyaddr+1056); /* doneQ size (256+8)*4 */ 2638 CHIP_REG_WRITE32(HBB_RWBUFFER, 2639 1, msgcode_rwbuffer[4], 1056); /* srb maxQ size must be --> [(256+8)*4] */ 2640 CHIP_REG_WRITE32(HBB_DOORBELL, 2641 0, drv2iop_doorbell, ARCMSR_MESSAGE_SET_CONFIG); 2642 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2643 printf( "arcmsr%d: 'set command Q window' timeout \n", acb->pci_unit); 2644 return FALSE; 2645 } 2646 CHIP_REG_WRITE32(HBB_DOORBELL, 2647 0, drv2iop_doorbell, ARCMSR_MESSAGE_START_DRIVER_MODE); 2648 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2649 printf( "arcmsr%d: 'start diver mode' timeout \n", acb->pci_unit); 2650 return FALSE; 2651 } 2652 } 2653 break; 2654 } 2655 return TRUE; 2656 } 2657 /* 2658 ************************************************************************ 2659 ************************************************************************ 2660 */ 2661 static void arcmsr_enable_eoi_mode(struct AdapterControlBlock *acb) 2662 { 2663 switch (acb->adapter_type) 2664 { 2665 case ACB_ADAPTER_TYPE_A: 2666 return; 2667 case ACB_ADAPTER_TYPE_B: { 2668 CHIP_REG_WRITE32(HBB_DOORBELL, 2669 0, drv2iop_doorbell,ARCMSR_MESSAGE_ACTIVE_EOI_MODE); 2670 if(!arcmsr_hbb_wait_msgint_ready(acb)) { 2671 printf( "arcmsr%d:" 2672 " 'iop enable eoi mode' timeout \n", acb->pci_unit); 2673 return; 2674 } 2675 } 2676 break; 2677 } 2678 return; 2679 } 2680 /* 2681 ********************************************************************** 2682 ********************************************************************** 2683 */ 2684 static void arcmsr_iop_init(struct AdapterControlBlock *acb) 2685 { 2686 u_int32_t intmask_org; 2687 2688 /* disable all outbound interrupt */ 2689 intmask_org=arcmsr_disable_allintr(acb); 2690 arcmsr_wait_firmware_ready(acb); 2691 arcmsr_iop_confirm(acb); 2692 arcmsr_get_firmware_spec(acb); 2693 /*start background rebuild*/ 2694 arcmsr_start_adapter_bgrb(acb); 2695 /* empty doorbell Qbuffer if door bell ringed */ 2696 arcmsr_clear_doorbell_queue_buffer(acb); 2697 arcmsr_enable_eoi_mode(acb); 2698 /* enable outbound Post Queue, outbound doorbell Interrupt */ 2699 arcmsr_enable_allintr(acb, intmask_org); 2700 acb->acb_flags |=ACB_F_IOP_INITED; 2701 return; 2702 } 2703 /* 2704 ********************************************************************** 2705 ********************************************************************** 2706 */ 2707 static void arcmsr_map_freesrb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 2708 { 2709 struct AdapterControlBlock *acb=arg; 2710 struct CommandControlBlock *srb_tmp; 2711 u_int8_t * dma_memptr; 2712 u_int32_t i; 2713 unsigned long srb_phyaddr=(unsigned long)segs->ds_addr; 2714 2715 dma_memptr=acb->uncacheptr; 2716 acb->srb_phyaddr=srb_phyaddr; 2717 srb_tmp=(struct CommandControlBlock *)dma_memptr; 2718 for(i=0;i<ARCMSR_MAX_FREESRB_NUM;i++) { 2719 if(bus_dmamap_create(acb->dm_segs_dmat, 2720 /*flags*/0, &srb_tmp->dm_segs_dmamap)!=0) { 2721 acb->acb_flags |= ACB_F_MAPFREESRB_FAILD; 2722 printf("arcmsr%d:" 2723 " srb dmamap bus_dmamap_create error\n", acb->pci_unit); 2724 return; 2725 } 2726 srb_tmp->cdb_shifted_phyaddr=srb_phyaddr >> 5; 2727 srb_tmp->acb=acb; 2728 acb->srbworkingQ[i]=acb->psrb_pool[i]=srb_tmp; 2729 srb_phyaddr=srb_phyaddr+sizeof(struct CommandControlBlock); 2730 srb_tmp++; 2731 } 2732 acb->vir2phy_offset=(unsigned long)srb_tmp-(unsigned long)srb_phyaddr; 2733 return; 2734 } 2735 /* 2736 ************************************************************************ 2737 ** 2738 ** 2739 ************************************************************************ 2740 */ 2741 static void arcmsr_free_resource(struct AdapterControlBlock *acb) 2742 { 2743 /* remove the control device */ 2744 if(acb->ioctl_dev != NULL) { 2745 destroy_dev(acb->ioctl_dev); 2746 } 2747 bus_dmamap_unload(acb->srb_dmat, acb->srb_dmamap); 2748 bus_dmamap_destroy(acb->srb_dmat, acb->srb_dmamap); 2749 bus_dma_tag_destroy(acb->srb_dmat); 2750 bus_dma_tag_destroy(acb->dm_segs_dmat); 2751 bus_dma_tag_destroy(acb->parent_dmat); 2752 return; 2753 } 2754 /* 2755 ************************************************************************ 2756 ************************************************************************ 2757 */ 2758 static u_int32_t arcmsr_initialize(device_t dev) 2759 { 2760 struct AdapterControlBlock *acb=device_get_softc(dev); 2761 u_int16_t pci_command; 2762 int i, j,max_coherent_size; 2763 2764 switch (pci_get_devid(dev)) { 2765 case PCIDevVenIDARC1201: { 2766 acb->adapter_type=ACB_ADAPTER_TYPE_B; 2767 max_coherent_size=ARCMSR_SRBS_POOL_SIZE 2768 +(sizeof(struct HBB_MessageUnit)); 2769 } 2770 break; 2771 case PCIDevVenIDARC1110: 2772 case PCIDevVenIDARC1120: 2773 case PCIDevVenIDARC1130: 2774 case PCIDevVenIDARC1160: 2775 case PCIDevVenIDARC1170: 2776 case PCIDevVenIDARC1210: 2777 case PCIDevVenIDARC1220: 2778 case PCIDevVenIDARC1230: 2779 case PCIDevVenIDARC1260: 2780 case PCIDevVenIDARC1270: 2781 case PCIDevVenIDARC1280: 2782 case PCIDevVenIDARC1380: 2783 case PCIDevVenIDARC1381: 2784 case PCIDevVenIDARC1680: 2785 case PCIDevVenIDARC1681: { 2786 acb->adapter_type=ACB_ADAPTER_TYPE_A; 2787 max_coherent_size=ARCMSR_SRBS_POOL_SIZE; 2788 } 2789 break; 2790 default: { 2791 printf("arcmsr%d:" 2792 " unknown RAID adapter type \n", device_get_unit(dev)); 2793 return ENOMEM; 2794 } 2795 } 2796 #if __FreeBSD_version >= 502010 2797 if(bus_dma_tag_create( /*parent*/ NULL, 2798 /*alignemnt*/ 1, 2799 /*boundary*/ 0, 2800 /*lowaddr*/ BUS_SPACE_MAXADDR, 2801 /*highaddr*/ BUS_SPACE_MAXADDR, 2802 /*filter*/ NULL, 2803 /*filterarg*/ NULL, 2804 /*maxsize*/ BUS_SPACE_MAXSIZE_32BIT, 2805 /*nsegments*/ BUS_SPACE_UNRESTRICTED, 2806 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2807 /*flags*/ 0, 2808 /*lockfunc*/ NULL, 2809 /*lockarg*/ NULL, 2810 &acb->parent_dmat) != 0) 2811 #else 2812 if(bus_dma_tag_create( /*parent*/ NULL, 2813 /*alignemnt*/ 1, 2814 /*boundary*/ 0, 2815 /*lowaddr*/ BUS_SPACE_MAXADDR, 2816 /*highaddr*/ BUS_SPACE_MAXADDR, 2817 /*filter*/ NULL, 2818 /*filterarg*/ NULL, 2819 /*maxsize*/ BUS_SPACE_MAXSIZE_32BIT, 2820 /*nsegments*/ BUS_SPACE_UNRESTRICTED, 2821 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2822 /*flags*/ 0, 2823 &acb->parent_dmat) != 0) 2824 #endif 2825 { 2826 printf("arcmsr%d: parent_dmat bus_dma_tag_create failure!\n", device_get_unit(dev)); 2827 return ENOMEM; 2828 } 2829 /* Create a single tag describing a region large enough to hold all of the s/g lists we will need. */ 2830 #if __FreeBSD_version >= 502010 2831 if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, 2832 /*alignment*/ 1, 2833 /*boundary*/ 0, 2834 /*lowaddr*/ BUS_SPACE_MAXADDR, 2835 /*highaddr*/ BUS_SPACE_MAXADDR, 2836 /*filter*/ NULL, 2837 /*filterarg*/ NULL, 2838 /*maxsize*/ MAXBSIZE, 2839 /*nsegments*/ ARCMSR_MAX_SG_ENTRIES, 2840 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2841 /*flags*/ 0, 2842 /*lockfunc*/ busdma_lock_mutex, 2843 #if __FreeBSD_version >= 700025 2844 /*lockarg*/ &acb->qbuffer_lock, 2845 #else 2846 /*lockarg*/ &Giant, 2847 #endif 2848 &acb->dm_segs_dmat) != 0) 2849 #else 2850 if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, 2851 /*alignment*/ 1, 2852 /*boundary*/ 0, 2853 /*lowaddr*/ BUS_SPACE_MAXADDR, 2854 /*highaddr*/ BUS_SPACE_MAXADDR, 2855 /*filter*/ NULL, 2856 /*filterarg*/ NULL, 2857 /*maxsize*/ MAXBSIZE, 2858 /*nsegments*/ ARCMSR_MAX_SG_ENTRIES, 2859 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2860 /*flags*/ 0, 2861 &acb->dm_segs_dmat) != 0) 2862 #endif 2863 { 2864 bus_dma_tag_destroy(acb->parent_dmat); 2865 printf("arcmsr%d: dm_segs_dmat bus_dma_tag_create failure!\n", device_get_unit(dev)); 2866 return ENOMEM; 2867 } 2868 /* DMA tag for our srb structures.... Allocate the freesrb memory */ 2869 #if __FreeBSD_version >= 502010 2870 if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, 2871 /*alignment*/ 0x20, 2872 /*boundary*/ 0, 2873 /*lowaddr*/ BUS_SPACE_MAXADDR_32BIT, 2874 /*highaddr*/ BUS_SPACE_MAXADDR, 2875 /*filter*/ NULL, 2876 /*filterarg*/ NULL, 2877 /*maxsize*/ max_coherent_size, 2878 /*nsegments*/ 1, 2879 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2880 /*flags*/ 0, 2881 /*lockfunc*/ NULL, 2882 /*lockarg*/ NULL, 2883 &acb->srb_dmat) != 0) 2884 #else 2885 if(bus_dma_tag_create( /*parent_dmat*/ acb->parent_dmat, 2886 /*alignment*/ 0x20, 2887 /*boundary*/ 0, 2888 /*lowaddr*/ BUS_SPACE_MAXADDR_32BIT, 2889 /*highaddr*/ BUS_SPACE_MAXADDR, 2890 /*filter*/ NULL, 2891 /*filterarg*/ NULL, 2892 /*maxsize*/ max_coherent_size, 2893 /*nsegments*/ 1, 2894 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT, 2895 /*flags*/ 0, 2896 &acb->srb_dmat) != 0) 2897 #endif 2898 { 2899 bus_dma_tag_destroy(acb->dm_segs_dmat); 2900 bus_dma_tag_destroy(acb->parent_dmat); 2901 printf("arcmsr%d: srb_dmat bus_dma_tag_create failure!\n", device_get_unit(dev)); 2902 return ENXIO; 2903 } 2904 /* Allocation for our srbs */ 2905 if(bus_dmamem_alloc(acb->srb_dmat, (void **)&acb->uncacheptr 2906 , BUS_DMA_WAITOK | BUS_DMA_COHERENT, &acb->srb_dmamap) != 0) { 2907 bus_dma_tag_destroy(acb->srb_dmat); 2908 bus_dma_tag_destroy(acb->dm_segs_dmat); 2909 bus_dma_tag_destroy(acb->parent_dmat); 2910 printf("arcmsr%d: srb_dmat bus_dmamem_alloc failure!\n", device_get_unit(dev)); 2911 return ENXIO; 2912 } 2913 /* And permanently map them */ 2914 if(bus_dmamap_load(acb->srb_dmat, acb->srb_dmamap, acb->uncacheptr 2915 , max_coherent_size, arcmsr_map_freesrb, acb, /*flags*/0)) { 2916 bus_dma_tag_destroy(acb->srb_dmat); 2917 bus_dma_tag_destroy(acb->dm_segs_dmat); 2918 bus_dma_tag_destroy(acb->parent_dmat); 2919 printf("arcmsr%d: srb_dmat bus_dmamap_load failure!\n", device_get_unit(dev)); 2920 return ENXIO; 2921 } 2922 pci_command=pci_read_config(dev, PCIR_COMMAND, 2); 2923 pci_command |= PCIM_CMD_BUSMASTEREN; 2924 pci_command |= PCIM_CMD_PERRESPEN; 2925 pci_command |= PCIM_CMD_MWRICEN; 2926 /* Enable Busmaster/Mem */ 2927 pci_command |= PCIM_CMD_MEMEN; 2928 pci_write_config(dev, PCIR_COMMAND, pci_command, 2); 2929 switch(acb->adapter_type) { 2930 case ACB_ADAPTER_TYPE_A: { 2931 u_int32_t rid0=PCIR_BAR(0); 2932 vm_offset_t mem_base0; 2933 2934 acb->sys_res_arcmsr[0]=bus_alloc_resource(dev, 2935 SYS_RES_MEMORY, &rid0, 0ul, ~0ul, 0x1000, RF_ACTIVE); 2936 if(acb->sys_res_arcmsr[0] == NULL) { 2937 arcmsr_free_resource(acb); 2938 printf("arcmsr%d:" 2939 " bus_alloc_resource failure!\n", device_get_unit(dev)); 2940 return ENOMEM; 2941 } 2942 if(rman_get_start(acb->sys_res_arcmsr[0]) <= 0) { 2943 arcmsr_free_resource(acb); 2944 printf("arcmsr%d:" 2945 " rman_get_start failure!\n", device_get_unit(dev)); 2946 return ENXIO; 2947 } 2948 mem_base0=(vm_offset_t) rman_get_virtual(acb->sys_res_arcmsr[0]); 2949 if(mem_base0==0) { 2950 arcmsr_free_resource(acb); 2951 printf("arcmsr%d:" 2952 " rman_get_virtual failure!\n", device_get_unit(dev)); 2953 return ENXIO; 2954 } 2955 acb->btag[0]=rman_get_bustag(acb->sys_res_arcmsr[0]); 2956 acb->bhandle[0]=rman_get_bushandle(acb->sys_res_arcmsr[0]); 2957 acb->pmu=(struct MessageUnit_UNION *)mem_base0; 2958 } 2959 break; 2960 case ACB_ADAPTER_TYPE_B: { 2961 struct HBB_MessageUnit *phbbmu; 2962 struct CommandControlBlock *freesrb; 2963 u_int32_t rid[]={ PCIR_BAR(0), PCIR_BAR(2) }; 2964 vm_offset_t mem_base[]={0,0}; 2965 for(i=0; i<2; i++) { 2966 if(i==0) { 2967 acb->sys_res_arcmsr[i]=bus_alloc_resource(dev, 2968 SYS_RES_MEMORY, &rid[i], 2969 0x20400, 0x20400+sizeof(struct HBB_DOORBELL), 2970 sizeof(struct HBB_DOORBELL), RF_ACTIVE); 2971 } else { 2972 acb->sys_res_arcmsr[i]=bus_alloc_resource(dev, 2973 SYS_RES_MEMORY, &rid[i], 2974 0x0fa00, 0x0fa00+sizeof(struct HBB_RWBUFFER), 2975 sizeof(struct HBB_RWBUFFER), RF_ACTIVE); 2976 } 2977 if(acb->sys_res_arcmsr[i] == NULL) { 2978 arcmsr_free_resource(acb); 2979 printf("arcmsr%d:" 2980 " bus_alloc_resource %d failure!\n", device_get_unit(dev), i); 2981 return ENOMEM; 2982 } 2983 if(rman_get_start(acb->sys_res_arcmsr[i]) <= 0) { 2984 arcmsr_free_resource(acb); 2985 printf("arcmsr%d:" 2986 " rman_get_start %d failure!\n", device_get_unit(dev), i); 2987 return ENXIO; 2988 } 2989 mem_base[i]=(vm_offset_t) rman_get_virtual(acb->sys_res_arcmsr[i]); 2990 if(mem_base[i]==0) { 2991 arcmsr_free_resource(acb); 2992 printf("arcmsr%d:" 2993 " rman_get_virtual %d failure!\n", device_get_unit(dev), i); 2994 return ENXIO; 2995 } 2996 acb->btag[i]=rman_get_bustag(acb->sys_res_arcmsr[i]); 2997 acb->bhandle[i]=rman_get_bushandle(acb->sys_res_arcmsr[i]); 2998 } 2999 freesrb=(struct CommandControlBlock *)acb->uncacheptr; 3000 acb->pmu=(struct MessageUnit_UNION *)&freesrb[ARCMSR_MAX_FREESRB_NUM]; 3001 phbbmu=(struct HBB_MessageUnit *)acb->pmu; 3002 phbbmu->hbb_doorbell=(struct HBB_DOORBELL *)mem_base[0]; 3003 phbbmu->hbb_rwbuffer=(struct HBB_RWBUFFER *)mem_base[1]; 3004 } 3005 break; 3006 } 3007 if(acb->acb_flags & ACB_F_MAPFREESRB_FAILD) { 3008 arcmsr_free_resource(acb); 3009 printf("arcmsr%d: map free srb failure!\n", device_get_unit(dev)); 3010 return ENXIO; 3011 } 3012 acb->acb_flags |= (ACB_F_MESSAGE_WQBUFFER_CLEARED 3013 |ACB_F_MESSAGE_RQBUFFER_CLEARED 3014 |ACB_F_MESSAGE_WQBUFFER_READ); 3015 acb->acb_flags &= ~ACB_F_SCSISTOPADAPTER; 3016 /* 3017 ******************************************************************** 3018 ** init raid volume state 3019 ******************************************************************** 3020 */ 3021 for(i=0;i<ARCMSR_MAX_TARGETID;i++) { 3022 for(j=0;j<ARCMSR_MAX_TARGETLUN;j++) { 3023 acb->devstate[i][j]=ARECA_RAID_GONE; 3024 } 3025 } 3026 arcmsr_iop_init(acb); 3027 return(0); 3028 } 3029 /* 3030 ************************************************************************ 3031 ************************************************************************ 3032 */ 3033 static int arcmsr_attach(device_t dev) 3034 { 3035 struct AdapterControlBlock *acb=(struct AdapterControlBlock *)device_get_softc(dev); 3036 u_int32_t unit=device_get_unit(dev); 3037 struct ccb_setasync csa; 3038 struct cam_devq *devq; /* Device Queue to use for this SIM */ 3039 struct resource *irqres; 3040 int rid; 3041 3042 if(acb == NULL) { 3043 printf("arcmsr%d: cannot allocate softc\n", unit); 3044 return (ENOMEM); 3045 } 3046 ARCMSR_LOCK_INIT(&acb->qbuffer_lock, "arcmsr Q buffer lock"); 3047 if(arcmsr_initialize(dev)) { 3048 printf("arcmsr%d: initialize failure!\n", unit); 3049 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3050 return ENXIO; 3051 } 3052 /* After setting up the adapter, map our interrupt */ 3053 rid=0; 3054 irqres=bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0ul, ~0ul, 1, RF_SHAREABLE | RF_ACTIVE); 3055 if(irqres == NULL || 3056 #if __FreeBSD_version >= 700025 3057 bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY|INTR_MPSAFE 3058 , NULL, arcmsr_intr_handler, acb, &acb->ih)) { 3059 #else 3060 bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY|INTR_MPSAFE 3061 , arcmsr_intr_handler, acb, &acb->ih)) { 3062 #endif 3063 arcmsr_free_resource(acb); 3064 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3065 printf("arcmsr%d: unable to register interrupt handler!\n", unit); 3066 return ENXIO; 3067 } 3068 acb->irqres=irqres; 3069 acb->pci_dev=dev; 3070 acb->pci_unit=unit; 3071 /* 3072 * Now let the CAM generic SCSI layer find the SCSI devices on 3073 * the bus * start queue to reset to the idle loop. * 3074 * Create device queue of SIM(s) * (MAX_START_JOB - 1) : 3075 * max_sim_transactions 3076 */ 3077 devq=cam_simq_alloc(ARCMSR_MAX_START_JOB); 3078 if(devq == NULL) { 3079 arcmsr_free_resource(acb); 3080 bus_release_resource(dev, SYS_RES_IRQ, 0, acb->irqres); 3081 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3082 printf("arcmsr%d: cam_simq_alloc failure!\n", unit); 3083 return ENXIO; 3084 } 3085 #if __FreeBSD_version >= 700025 3086 acb->psim=cam_sim_alloc(arcmsr_action, arcmsr_poll, 3087 "arcmsr", acb, unit, &acb->qbuffer_lock, 1, 3088 ARCMSR_MAX_OUTSTANDING_CMD, devq); 3089 #else 3090 acb->psim=cam_sim_alloc(arcmsr_action, arcmsr_poll, 3091 "arcmsr", acb, unit, 1, 3092 ARCMSR_MAX_OUTSTANDING_CMD, devq); 3093 #endif 3094 if(acb->psim == NULL) { 3095 arcmsr_free_resource(acb); 3096 bus_release_resource(dev, SYS_RES_IRQ, 0, acb->irqres); 3097 cam_simq_free(devq); 3098 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3099 printf("arcmsr%d: cam_sim_alloc failure!\n", unit); 3100 return ENXIO; 3101 } 3102 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 3103 #if __FreeBSD_version >= 700044 3104 if(xpt_bus_register(acb->psim, dev, 0) != CAM_SUCCESS) { 3105 #else 3106 if(xpt_bus_register(acb->psim, 0) != CAM_SUCCESS) { 3107 #endif 3108 arcmsr_free_resource(acb); 3109 bus_release_resource(dev, SYS_RES_IRQ, 0, acb->irqres); 3110 cam_sim_free(acb->psim, /*free_devq*/TRUE); 3111 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3112 printf("arcmsr%d: xpt_bus_register failure!\n", unit); 3113 return ENXIO; 3114 } 3115 if(xpt_create_path(&acb->ppath, /* periph */ NULL 3116 , cam_sim_path(acb->psim) 3117 , CAM_TARGET_WILDCARD 3118 , CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 3119 arcmsr_free_resource(acb); 3120 bus_release_resource(dev, SYS_RES_IRQ, 0, acb->irqres); 3121 xpt_bus_deregister(cam_sim_path(acb->psim)); 3122 cam_sim_free(acb->psim, /* free_simq */ TRUE); 3123 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3124 printf("arcmsr%d: xpt_create_path failure!\n", unit); 3125 return ENXIO; 3126 } 3127 /* 3128 **************************************************** 3129 */ 3130 xpt_setup_ccb(&csa.ccb_h, acb->ppath, /*priority*/5); 3131 csa.ccb_h.func_code=XPT_SASYNC_CB; 3132 csa.event_enable=AC_FOUND_DEVICE|AC_LOST_DEVICE; 3133 csa.callback=arcmsr_async; 3134 csa.callback_arg=acb->psim; 3135 xpt_action((union ccb *)&csa); 3136 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 3137 /* Create the control device. */ 3138 acb->ioctl_dev=make_dev(&arcmsr_cdevsw 3139 , unit 3140 , UID_ROOT 3141 , GID_WHEEL /* GID_OPERATOR */ 3142 , S_IRUSR | S_IWUSR 3143 , "arcmsr%d", unit); 3144 #if __FreeBSD_version < 503000 3145 acb->ioctl_dev->si_drv1=acb; 3146 #endif 3147 #if __FreeBSD_version > 500005 3148 (void)make_dev_alias(acb->ioctl_dev, "arc%d", unit); 3149 #endif 3150 return 0; 3151 } 3152 /* 3153 ************************************************************************ 3154 ************************************************************************ 3155 */ 3156 static int arcmsr_probe(device_t dev) 3157 { 3158 u_int32_t id; 3159 static char buf[256]; 3160 char *type; 3161 int raid6 = 1; 3162 3163 if (pci_get_vendor(dev) != PCI_VENDOR_ID_ARECA) { 3164 return (ENXIO); 3165 } 3166 switch(id=pci_get_devid(dev)) { 3167 case PCIDevVenIDARC1110: 3168 case PCIDevVenIDARC1210: 3169 case PCIDevVenIDARC1201: 3170 raid6 = 0; 3171 /*FALLTHRU*/ 3172 case PCIDevVenIDARC1120: 3173 case PCIDevVenIDARC1130: 3174 case PCIDevVenIDARC1160: 3175 case PCIDevVenIDARC1170: 3176 case PCIDevVenIDARC1220: 3177 case PCIDevVenIDARC1230: 3178 case PCIDevVenIDARC1260: 3179 case PCIDevVenIDARC1270: 3180 case PCIDevVenIDARC1280: 3181 type = "SATA"; 3182 break; 3183 case PCIDevVenIDARC1380: 3184 case PCIDevVenIDARC1381: 3185 case PCIDevVenIDARC1680: 3186 case PCIDevVenIDARC1681: 3187 type = "SAS"; 3188 break; 3189 default: 3190 type = "X-TYPE"; 3191 break; 3192 } 3193 sprintf(buf, "Areca %s Host Adapter RAID Controller %s\n", type, raid6 ? "(RAID6 capable)" : ""); 3194 device_set_desc_copy(dev, buf); 3195 return 0; 3196 } 3197 /* 3198 ************************************************************************ 3199 ************************************************************************ 3200 */ 3201 static int arcmsr_shutdown(device_t dev) 3202 { 3203 u_int32_t i; 3204 u_int32_t intmask_org; 3205 struct CommandControlBlock *srb; 3206 struct AdapterControlBlock *acb=(struct AdapterControlBlock *)device_get_softc(dev); 3207 3208 /* stop adapter background rebuild */ 3209 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 3210 /* disable all outbound interrupt */ 3211 intmask_org=arcmsr_disable_allintr(acb); 3212 arcmsr_stop_adapter_bgrb(acb); 3213 arcmsr_flush_adapter_cache(acb); 3214 /* abort all outstanding command */ 3215 acb->acb_flags |= ACB_F_SCSISTOPADAPTER; 3216 acb->acb_flags &= ~ACB_F_IOP_INITED; 3217 if(acb->srboutstandingcount!=0) { 3218 /*clear and abort all outbound posted Q*/ 3219 arcmsr_done4abort_postqueue(acb); 3220 /* talk to iop 331 outstanding command aborted*/ 3221 arcmsr_abort_allcmd(acb); 3222 for(i=0;i<ARCMSR_MAX_FREESRB_NUM;i++) { 3223 srb=acb->psrb_pool[i]; 3224 if(srb->startdone==ARCMSR_SRB_START) { 3225 srb->startdone=ARCMSR_SRB_ABORTED; 3226 srb->pccb->ccb_h.status |= CAM_REQ_ABORTED; 3227 arcmsr_srb_complete(srb, 1); 3228 } 3229 } 3230 } 3231 atomic_set_int(&acb->srboutstandingcount, 0); 3232 acb->workingsrb_doneindex=0; 3233 acb->workingsrb_startindex=0; 3234 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 3235 return (0); 3236 } 3237 /* 3238 ************************************************************************ 3239 ************************************************************************ 3240 */ 3241 static int arcmsr_detach(device_t dev) 3242 { 3243 struct AdapterControlBlock *acb=(struct AdapterControlBlock *)device_get_softc(dev); 3244 int i; 3245 3246 bus_teardown_intr(dev, acb->irqres, acb->ih); 3247 arcmsr_shutdown(dev); 3248 arcmsr_free_resource(acb); 3249 for(i=0; (acb->sys_res_arcmsr[i]!=NULL) && (i<2); i++) { 3250 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(i), acb->sys_res_arcmsr[i]); 3251 } 3252 bus_release_resource(dev, SYS_RES_IRQ, 0, acb->irqres); 3253 ARCMSR_LOCK_ACQUIRE(&acb->qbuffer_lock); 3254 xpt_async(AC_LOST_DEVICE, acb->ppath, NULL); 3255 xpt_free_path(acb->ppath); 3256 xpt_bus_deregister(cam_sim_path(acb->psim)); 3257 cam_sim_free(acb->psim, TRUE); 3258 ARCMSR_LOCK_RELEASE(&acb->qbuffer_lock); 3259 ARCMSR_LOCK_DESTROY(&acb->qbuffer_lock); 3260 return (0); 3261 } 3262 3263 3264