1 /* $Id: osm_bsd.c,v 1.36 2010/05/11 03:12:11 lcn Exp $ */
3 * HighPoint RAID Driver for FreeBSD
4 * Copyright (C) 2005-2011 HighPoint Technologies, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <dev/hptnr/hptnr_config.h>
31 #include <dev/hptnr/os_bsd.h>
32 #include <dev/hptnr/hptintf.h>
35 static HIM *hpt_match(device_t dev)
41 for (him = him_list; him; him = him->next) {
42 for (i=0; him->get_supported_device_id(i, &pci_id); i++) {
43 if (him->get_controller_count)
44 him->get_controller_count(&pci_id,0,0);
45 if ((pci_get_vendor(dev) == pci_id.vid) &&
46 (pci_get_device(dev) == pci_id.did)){
55 static int hpt_probe(device_t dev)
61 KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d",
62 pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev)
64 device_set_desc(dev, him->name);
65 return (BUS_PROBE_DEFAULT);
71 static int hpt_attach(device_t dev)
73 PHBA hba = (PHBA)device_get_softc(dev);
80 KdPrint(("hpt_attach(%d/%d/%d)", pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)));
83 hba->ext_type = EXT_TYPE_HBA;
84 hba->ldm_adapter.him = him;
86 pci_enable_busmaster(dev);
88 pci_id.vid = pci_get_vendor(dev);
89 pci_id.did = pci_get_device(dev);
90 pci_id.rev = pci_get_revid(dev);
91 pci_id.subsys = (HPT_U32)(pci_get_subdevice(dev)) << 16 | pci_get_subvendor(dev);
93 size = him->get_adapter_size(&pci_id);
94 hba->ldm_adapter.him_handle = malloc(size, M_DEVBUF, M_WAITOK);
97 hba->pciaddr.tree = 0;
98 hba->pciaddr.bus = pci_get_bus(dev);
99 hba->pciaddr.device = pci_get_slot(dev);
100 hba->pciaddr.function = pci_get_function(dev);
102 if (!him->create_adapter(&pci_id, hba->pciaddr, hba->ldm_adapter.him_handle, hba)) {
103 free(hba->ldm_adapter.him_handle, M_DEVBUF);
107 os_printk("adapter at PCI %d:%d:%d, IRQ %d",
108 hba->pciaddr.bus, hba->pciaddr.device, hba->pciaddr.function, pci_get_irq(dev));
110 if (!ldm_register_adapter(&hba->ldm_adapter)) {
111 size = ldm_get_vbus_size();
112 vbus_ext = malloc(sizeof(VBUS_EXT) + size, M_DEVBUF, M_WAITOK |
114 vbus_ext->ext_type = EXT_TYPE_VBUS;
115 ldm_create_vbus((PVBUS)vbus_ext->vbus, vbus_ext);
116 ldm_register_adapter(&hba->ldm_adapter);
119 ldm_for_each_vbus(vbus, vbus_ext) {
120 if (hba->ldm_adapter.vbus==vbus) {
121 hba->vbus_ext = vbus_ext;
122 hba->next = vbus_ext->hba_list;
123 vbus_ext->hba_list = hba;
131 * Maybe we'd better to use the bus_dmamem_alloc to alloc DMA memory,
132 * but there are some problems currently (alignment, etc).
134 static __inline void *__get_free_pages(int order)
136 /* don't use low memory - other devices may get starved */
137 return contigmalloc(PAGE_SIZE<<order,
138 M_DEVBUF, M_WAITOK, BUS_SPACE_MAXADDR_24BIT, BUS_SPACE_MAXADDR, PAGE_SIZE, 0);
141 static __inline void free_pages(void *p, int order)
143 contigfree(p, PAGE_SIZE<<order, M_DEVBUF);
146 static int hpt_alloc_mem(PVBUS_EXT vbus_ext)
153 for (hba = vbus_ext->hba_list; hba; hba = hba->next)
154 hba->ldm_adapter.him->get_meminfo(hba->ldm_adapter.him_handle);
156 ldm_get_mem_info((PVBUS)vbus_ext->vbus, 0);
158 for (f=vbus_ext->freelist_head; f; f=f->next) {
159 KdPrint(("%s: %d*%d=%d bytes",
160 f->tag, f->count, f->size, f->count*f->size));
161 for (i=0; i<f->count; i++) {
162 p = (void **)malloc(f->size, M_DEVBUF, M_WAITOK);
163 if (!p) return (ENXIO);
169 for (f=vbus_ext->freelist_dma_head; f; f=f->next) {
172 HPT_ASSERT((f->size & (f->alignment-1))==0);
174 for (order=0, size=PAGE_SIZE; size<f->size; order++, size<<=1)
177 KdPrint(("%s: %d*%d=%d bytes, order %d",
178 f->tag, f->count, f->size, f->count*f->size, order));
179 HPT_ASSERT(f->alignment<=PAGE_SIZE);
181 for (i=0; i<f->count;) {
182 p = (void **)__get_free_pages(order);
184 for (j = size/f->size; j && i<f->count; i++,j--) {
186 *(BUS_ADDRESS *)(p+1) = (BUS_ADDRESS)vtophys(p);
188 p = (void **)((unsigned long)p + f->size);
193 HPT_ASSERT(PAGE_SIZE==DMAPOOL_PAGE_SIZE);
195 for (i=0; i<os_max_cache_pages; i++) {
196 p = (void **)__get_free_pages(0);
198 HPT_ASSERT(((HPT_UPTR)p & (DMAPOOL_PAGE_SIZE-1))==0);
199 dmapool_put_page((PVBUS)vbus_ext->vbus, p, (BUS_ADDRESS)vtophys(p));
205 static void hpt_free_mem(PVBUS_EXT vbus_ext)
212 for (f=vbus_ext->freelist_head; f; f=f->next) {
214 if (f->count!=f->reserved_count) {
215 KdPrint(("memory leak for freelist %s (%d/%d)", f->tag, f->count, f->reserved_count));
218 while ((p=freelist_get(f)))
222 for (i=0; i<os_max_cache_pages; i++) {
223 p = dmapool_get_page((PVBUS)vbus_ext->vbus, &bus);
228 for (f=vbus_ext->freelist_dma_head; f; f=f->next) {
231 if (f->count!=f->reserved_count) {
232 KdPrint(("memory leak for dma freelist %s (%d/%d)", f->tag, f->count, f->reserved_count));
235 for (order=0, size=PAGE_SIZE; size<f->size; order++, size<<=1) ;
237 while ((p=freelist_get_dma(f, &bus))) {
239 free_pages(p, order);
241 /* can't free immediately since other blocks in this page may still be in the list */
242 if (((HPT_UPTR)p & (PAGE_SIZE-1))==0)
243 dmapool_put_page((PVBUS)vbus_ext->vbus, p, bus);
248 while ((p = dmapool_get_page((PVBUS)vbus_ext->vbus, &bus)))
252 static int hpt_init_vbus(PVBUS_EXT vbus_ext)
256 for (hba = vbus_ext->hba_list; hba; hba = hba->next)
257 if (!hba->ldm_adapter.him->initialize(hba->ldm_adapter.him_handle)) {
258 KdPrint(("fail to initialize %p", hba));
262 ldm_initialize_vbus((PVBUS)vbus_ext->vbus, &vbus_ext->hba_list->ldm_adapter);
266 static void hpt_flush_done(PCOMMAND pCmd)
268 PVDEV vd = pCmd->target;
270 if (mIsArray(vd->type) && vd->u.array.transform && vd!=vd->u.array.transform->target) {
271 vd = vd->u.array.transform->target;
274 pCmd->Result = RETURN_PENDING;
275 vdev_queue_cmd(pCmd);
279 *(int *)pCmd->priv = 1;
284 * flush a vdev (without retry).
286 static int hpt_flush_vdev(PVBUS_EXT vbus_ext, PVDEV vd)
289 int result = 0, done;
292 KdPrint(("flusing dev %p", vd));
294 hpt_assert_vbus_locked(vbus_ext);
296 if (mIsArray(vd->type) && vd->u.array.transform)
297 count = MAX(vd->u.array.transform->source->cmds_per_request,
298 vd->u.array.transform->target->cmds_per_request);
300 count = vd->cmds_per_request;
302 pCmd = ldm_alloc_cmds(vd->vbus, count);
308 pCmd->type = CMD_TYPE_FLUSH;
309 pCmd->flags.hard_flush = 1;
311 pCmd->done = hpt_flush_done;
318 while (hpt_sleep(vbus_ext, pCmd, PPAUSE, "hptfls", HPT_OSM_TIMEOUT)) {
319 ldm_reset_vbus(vd->vbus);
323 KdPrint(("flush result %d", pCmd->Result));
325 if (pCmd->Result!=RETURN_SUCCESS)
333 static void hpt_stop_tasks(PVBUS_EXT vbus_ext);
334 static void hpt_shutdown_vbus(PVBUS_EXT vbus_ext, int howto)
336 PVBUS vbus = (PVBUS)vbus_ext->vbus;
340 KdPrint(("hpt_shutdown_vbus"));
342 /* stop all ctl tasks and disable the worker taskqueue */
343 hpt_stop_tasks(vbus_ext);
344 hpt_lock_vbus(vbus_ext);
345 vbus_ext->worker.ta_context = 0;
348 for (i=0; i<osm_max_targets; i++) {
349 PVDEV vd = ldm_find_target(vbus, i);
352 if (hpt_flush_vdev(vbus_ext, vd))
353 hpt_flush_vdev(vbus_ext, vd);
358 hpt_unlock_vbus(vbus_ext);
360 ldm_release_vbus(vbus);
362 for (hba=vbus_ext->hba_list; hba; hba=hba->next)
363 bus_teardown_intr(hba->pcidev, hba->irq_res, hba->irq_handle);
365 hpt_free_mem(vbus_ext);
367 while ((hba=vbus_ext->hba_list)) {
368 vbus_ext->hba_list = hba->next;
369 free(hba->ldm_adapter.him_handle, M_DEVBUF);
372 callout_drain(&vbus_ext->timer);
373 mtx_destroy(&vbus_ext->lock);
374 free(vbus_ext, M_DEVBUF);
375 KdPrint(("hpt_shutdown_vbus done"));
378 static void __hpt_do_tasks(PVBUS_EXT vbus_ext)
382 tasks = vbus_ext->tasks;
389 t->func(vbus_ext->vbus, t->data);
393 static void hpt_do_tasks(PVBUS_EXT vbus_ext, int pending)
396 hpt_lock_vbus(vbus_ext);
397 __hpt_do_tasks(vbus_ext);
398 hpt_unlock_vbus(vbus_ext);
402 static void hpt_action(struct cam_sim *sim, union ccb *ccb);
403 static void hpt_poll(struct cam_sim *sim);
404 static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg);
405 static void hpt_pci_intr(void *arg);
407 static __inline POS_CMDEXT cmdext_get(PVBUS_EXT vbus_ext)
409 POS_CMDEXT p = vbus_ext->cmdext_list;
411 vbus_ext->cmdext_list = p->next;
415 static __inline void cmdext_put(POS_CMDEXT p)
417 p->next = p->vbus_ext->cmdext_list;
418 p->vbus_ext->cmdext_list = p;
421 static void hpt_timeout(void *arg)
423 PCOMMAND pCmd = (PCOMMAND)arg;
424 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
426 KdPrint(("pCmd %p timeout", pCmd));
428 ldm_reset_vbus((PVBUS)ext->vbus_ext->vbus);
431 static void os_cmddone(PCOMMAND pCmd)
433 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
434 union ccb *ccb = ext->ccb;
437 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
438 cdb = ccb->csio.cdb_io.cdb_ptr;
440 cdb = ccb->csio.cdb_io.cdb_bytes;
442 KdPrint(("os_cmddone(%p, %d)", pCmd, pCmd->Result));
444 callout_stop(&ext->timeout);
446 case 0x85: /*ATA_16*/
447 case 0xA1: /*ATA_12*/
449 PassthroughCmd *passthru = &pCmd->uCmd.Passthrough;
450 HPT_U8 *sense_buffer = (HPT_U8 *)&ccb->csio.sense_data;
451 memset(&ccb->csio.sense_data, 0,sizeof(ccb->csio.sense_data));
453 sense_buffer[0] = 0x72; /* Response Code */
454 sense_buffer[7] = 14; /* Additional Sense Length */
456 sense_buffer[8] = 0x9; /* ATA Return Descriptor */
457 sense_buffer[9] = 0xc; /* Additional Descriptor Length */
458 sense_buffer[11] = (HPT_U8)passthru->bFeaturesReg; /* Error */
459 sense_buffer[13] = (HPT_U8)passthru->bSectorCountReg; /* Sector Count (7:0) */
460 sense_buffer[15] = (HPT_U8)passthru->bLbaLowReg; /* LBA Low (7:0) */
461 sense_buffer[17] = (HPT_U8)passthru->bLbaMidReg; /* LBA Mid (7:0) */
462 sense_buffer[19] = (HPT_U8)passthru->bLbaHighReg; /* LBA High (7:0) */
464 if ((cdb[0] == 0x85) && (cdb[1] & 0x1))
466 sense_buffer[10] = 1;
467 sense_buffer[12] = (HPT_U8)(passthru->bSectorCountReg >> 8); /* Sector Count (15:8) */
468 sense_buffer[14] = (HPT_U8)(passthru->bLbaLowReg >> 8); /* LBA Low (15:8) */
469 sense_buffer[16] = (HPT_U8)(passthru->bLbaMidReg >> 8); /* LBA Mid (15:8) */
470 sense_buffer[18] = (HPT_U8)(passthru->bLbaHighReg >> 8); /* LBA High (15:8) */
473 sense_buffer[20] = (HPT_U8)passthru->bDriveHeadReg; /* Device */
474 sense_buffer[21] = (HPT_U8)passthru->bCommandReg; /* Status */
475 KdPrint(("sts 0x%x err 0x%x low 0x%x mid 0x%x hig 0x%x dh 0x%x sc 0x%x",
476 passthru->bCommandReg,
477 passthru->bFeaturesReg,
478 passthru->bLbaLowReg,
479 passthru->bLbaMidReg,
480 passthru->bLbaHighReg,
481 passthru->bDriveHeadReg,
482 passthru->bSectorCountReg));
483 KdPrint(("result:0x%x,bFeaturesReg:0x%04x,bSectorCountReg:0x%04x,LBA:0x%04x%04x%04x ",
484 pCmd->Result,passthru->bFeaturesReg,passthru->bSectorCountReg,
485 passthru->bLbaHighReg,passthru->bLbaMidReg,passthru->bLbaLowReg));
491 switch(pCmd->Result) {
493 ccb->ccb_h.status = CAM_REQ_CMP;
495 case RETURN_BAD_DEVICE:
496 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
498 case RETURN_DEVICE_BUSY:
499 ccb->ccb_h.status = CAM_BUSY;
501 case RETURN_INVALID_REQUEST:
502 ccb->ccb_h.status = CAM_REQ_INVALID;
504 case RETURN_SELECTION_TIMEOUT:
505 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
508 ccb->ccb_h.status = CAM_BUSY;
511 ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
515 if (pCmd->flags.data_in) {
516 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map, BUS_DMASYNC_POSTREAD);
518 else if (pCmd->flags.data_out) {
519 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map, BUS_DMASYNC_POSTWRITE);
522 bus_dmamap_unload(ext->vbus_ext->io_dmat, ext->dma_map);
529 static int os_buildsgl(PCOMMAND pCmd, PSG pSg, int logical)
531 /* since we have provided physical sg, nobody will ask us to build physical sg */
536 static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
538 PCOMMAND pCmd = (PCOMMAND)arg;
539 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
543 HPT_ASSERT(pCmd->flags.physical_sg);
546 panic("busdma error");
548 HPT_ASSERT(nsegs<=os_max_sg_descriptors);
551 for (idx = 0; idx < nsegs; idx++, psg++) {
552 psg->addr.bus = segs[idx].ds_addr;
553 psg->size = segs[idx].ds_len;
558 if (pCmd->flags.data_in) {
559 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
560 BUS_DMASYNC_PREREAD);
562 else if (pCmd->flags.data_out) {
563 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
564 BUS_DMASYNC_PREWRITE);
568 callout_reset(&ext->timeout, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
572 static void hpt_scsi_io(PVBUS_EXT vbus_ext, union ccb *ccb)
574 PVBUS vbus = (PVBUS)vbus_ext->vbus;
580 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
581 cdb = ccb->csio.cdb_io.cdb_ptr;
583 cdb = ccb->csio.cdb_io.cdb_bytes;
585 KdPrint(("hpt_scsi_io: ccb %x id %d lun %d cdb %x-%x-%x",
587 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
588 *(HPT_U32 *)&cdb[0], *(HPT_U32 *)&cdb[4], *(HPT_U32 *)&cdb[8]
591 /* ccb->ccb_h.path_id is not our bus id - don't check it */
592 if (ccb->ccb_h.target_lun != 0 ||
593 ccb->ccb_h.target_id >= osm_max_targets ||
594 (ccb->ccb_h.flags & CAM_CDB_PHYS))
596 ccb->ccb_h.status = CAM_TID_INVALID;
601 vd = ldm_find_target(vbus, ccb->ccb_h.target_id);
604 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
610 case TEST_UNIT_READY:
611 case START_STOP_UNIT:
612 case SYNCHRONIZE_CACHE:
613 ccb->ccb_h.status = CAM_REQ_CMP;
616 case 0x85: /*ATA_16*/
617 case 0xA1: /*ATA_12*/
621 PassthroughCmd *passthru;
623 if (mIsArray(vd->type)) {
624 ccb->ccb_h.status = CAM_REQ_INVALID;
628 HPT_ASSERT(vd->type == VD_RAW && vd->u.raw.legacy_disk);
630 prot = (cdb[1] & 0x1e) >> 1;
633 if (prot < 3 || prot > 5)
635 ccb->ccb_h.status = CAM_REQ_INVALID;
639 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
642 ccb->ccb_h.status = CAM_BUSY;
646 passthru = &pCmd->uCmd.Passthrough;
647 if (cdb[0] == 0x85/*ATA_16*/) {
649 passthru->bFeaturesReg =
650 ((HPT_U16)cdb[3] << 8)
652 passthru->bSectorCountReg =
653 ((HPT_U16)cdb[5] << 8) |
655 passthru->bLbaLowReg =
656 ((HPT_U16)cdb[7] << 8) |
658 passthru->bLbaMidReg =
659 ((HPT_U16)cdb[9] << 8) |
661 passthru->bLbaHighReg =
662 ((HPT_U16)cdb[11] << 8) |
665 passthru->bFeaturesReg = cdb[4];
666 passthru->bSectorCountReg = cdb[6];
667 passthru->bLbaLowReg = cdb[8];
668 passthru->bLbaMidReg = cdb[10];
669 passthru->bLbaHighReg = cdb[12];
671 passthru->bDriveHeadReg = cdb[13];
672 passthru->bCommandReg = cdb[14];
676 passthru->bFeaturesReg = cdb[3];
677 passthru->bSectorCountReg = cdb[4];
678 passthru->bLbaLowReg = cdb[5];
679 passthru->bLbaMidReg = cdb[6];
680 passthru->bLbaHighReg = cdb[7];
681 passthru->bDriveHeadReg = cdb[8];
682 passthru->bCommandReg = cdb[9];
688 if (!(passthru->bCommandReg == ATA_CMD_READ_MULTI ||
689 passthru->bCommandReg == ATA_CMD_READ_MULTI_EXT ||
690 passthru->bCommandReg == ATA_CMD_WRITE_MULTI ||
691 passthru->bCommandReg == ATA_CMD_WRITE_MULTI_EXT ||
692 passthru->bCommandReg == ATA_CMD_WRITE_MULTI_FUA_EXT)
699 if (passthru->bFeaturesReg == ATA_SET_FEATURES_XFER &&
700 passthru->bCommandReg == ATA_CMD_SET_FEATURES) {
705 passthru->nSectors = ccb->csio.dxfer_len/ATA_SECTOR_SIZE;
707 default: /*None data*/
709 case 4: /*PIO data in, T_DIR=1 match check*/
713 OsPrint(("PIO data in, T_DIR=1 match check"));
716 pCmd->flags.data_in = 1;
718 case 5: /*PIO data out, T_DIR=0 match check*/
722 OsPrint(("PIO data out, T_DIR=0 match check"));
726 pCmd->flags.data_out = 1;
729 pCmd->type = CMD_TYPE_PASSTHROUGH;
730 pCmd->priv = ext = cmdext_get(vbus_ext);
734 pCmd->done = os_cmddone;
735 pCmd->buildsgl = os_buildsgl;
736 pCmd->psg = ext->psg;
738 if(!ccb->csio.dxfer_len)
743 pCmd->flags.physical_sg = 1;
744 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
746 hpt_io_dmamap_callback, pCmd,
749 KdPrint(("bus_dmamap_load return %d", error));
750 if (error && error!=EINPROGRESS) {
751 os_printk("bus_dmamap_load error %d", error);
754 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
760 ccb->ccb_h.status = CAM_REQ_INVALID;
766 PINQUIRYDATA inquiryData;
767 HIM_DEVICE_CONFIG devconf;
770 memset(ccb->csio.data_ptr, 0, ccb->csio.dxfer_len);
771 inquiryData = (PINQUIRYDATA)ccb->csio.data_ptr;
774 rbuf = (HPT_U8 *)inquiryData;
784 ccb->ccb_h.status = CAM_REQ_CMP;
790 if (vd->type == VD_RAW) {
792 vd->u.raw.him->get_device_config(vd->u.raw.phy_dev,&devconf);
793 memcpy(&rbuf[4], devconf.pIdentifyData->SerialNumber, 20);
794 ldm_ide_fixstring(&rbuf[4], 20);
799 ccb->ccb_h.status = CAM_REQ_CMP;
819 ccb->ccb_h.status = CAM_REQ_CMP;
822 ccb->ccb_h.status = CAM_REQ_INVALID;
829 ccb->ccb_h.status = CAM_REQ_INVALID;
833 inquiryData->DeviceType = 0; /*DIRECT_ACCESS_DEVICE*/
834 inquiryData->Versions = 5; /*SPC-3*/
835 inquiryData->ResponseDataFormat = 2;
836 inquiryData->AdditionalLength = 0x5b;
837 inquiryData->CommandQueue = 1;
839 if (ccb->csio.dxfer_len > 63) {
840 rbuf = (HPT_U8 *)inquiryData;
850 if (vd->type == VD_RAW) {
851 vd->u.raw.him->get_device_config(vd->u.raw.phy_dev,&devconf);
853 if ((devconf.pIdentifyData->GeneralConfiguration & 0x80))
854 inquiryData->RemovableMedia = 1;
857 memcpy(&inquiryData->VendorId, "ATA ", 8);
858 memcpy(&inquiryData->ProductId, devconf.pIdentifyData->ModelNumber, 16);
859 ldm_ide_fixstring((HPT_U8 *)&inquiryData->ProductId, 16);
860 memcpy(&inquiryData->ProductRevisionLevel, devconf.pIdentifyData->FirmwareRevision, 4);
861 ldm_ide_fixstring((HPT_U8 *)&inquiryData->ProductRevisionLevel, 4);
862 if (inquiryData->ProductRevisionLevel[0] == 0 || inquiryData->ProductRevisionLevel[0] == ' ')
863 memcpy(&inquiryData->ProductRevisionLevel, "n/a ", 4);
865 memcpy(&inquiryData->VendorId, "HPT ", 8);
866 snprintf((char *)&inquiryData->ProductId, 16, "DISK_%d_%d ",
867 os_get_vbus_seq(vbus_ext), vd->target_id);
868 inquiryData->ProductId[15] = ' ';
869 memcpy(&inquiryData->ProductRevisionLevel, "4.00", 4);
872 ccb->ccb_h.status = CAM_REQ_CMP;
877 HPT_U8 *rbuf = ccb->csio.data_ptr;
879 HPT_U8 sector_size_shift = 0;
881 HPT_U32 sector_size = 0;
883 if (mIsArray(vd->type))
884 sector_size_shift = vd->u.array.sector_size_shift;
886 if(vd->type == VD_RAW){
887 sector_size = vd->u.raw.logical_sector_size;
890 switch (sector_size) {
892 KdPrint(("set 4k setctor size in READ_CAPACITY"));
893 sector_size_shift = 3;
899 new_cap = vd->capacity >> sector_size_shift;
901 if (new_cap > 0xfffffffful)
906 rbuf[0] = (HPT_U8)(cap>>24);
907 rbuf[1] = (HPT_U8)(cap>>16);
908 rbuf[2] = (HPT_U8)(cap>>8);
909 rbuf[3] = (HPT_U8)cap;
912 rbuf[6] = 2 << sector_size_shift;
915 ccb->ccb_h.status = CAM_REQ_CMP;
921 HPT_U8 *rbuf = ccb->csio.data_ptr;
924 ccb->ccb_h.status = CAM_REQ_CMP;
927 case SERVICE_ACTION_IN:
929 HPT_U8 *rbuf = ccb->csio.data_ptr;
931 HPT_U8 sector_size_shift = 0;
932 HPT_U32 sector_size = 0;
934 if(mIsArray(vd->type))
935 sector_size_shift = vd->u.array.sector_size_shift;
937 if(vd->type == VD_RAW){
938 sector_size = vd->u.raw.logical_sector_size;
941 switch (sector_size) {
943 KdPrint(("set 4k setctor size in SERVICE_ACTION_IN"));
944 sector_size_shift = 3;
950 cap = (vd->capacity >> sector_size_shift) - 1;
952 rbuf[0] = (HPT_U8)(cap>>56);
953 rbuf[1] = (HPT_U8)(cap>>48);
954 rbuf[2] = (HPT_U8)(cap>>40);
955 rbuf[3] = (HPT_U8)(cap>>32);
956 rbuf[4] = (HPT_U8)(cap>>24);
957 rbuf[5] = (HPT_U8)(cap>>16);
958 rbuf[6] = (HPT_U8)(cap>>8);
959 rbuf[7] = (HPT_U8)cap;
962 rbuf[10] = 2 << sector_size_shift;
965 if(!mIsArray(vd->type)){
966 rbuf[13] = vd->u.raw.logicalsectors_per_physicalsector;
967 rbuf[14] = (HPT_U8)((vd->u.raw.lowest_aligned >> 8) & 0x3f);
968 rbuf[15] = (HPT_U8)(vd->u.raw.lowest_aligned);
971 ccb->ccb_h.status = CAM_REQ_CMP;
983 case 0x8f: /* VERIFY_16 */
986 HPT_U8 sector_size_shift = 0;
987 HPT_U32 sector_size = 0;
988 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
990 KdPrint(("Failed to allocate command!"));
991 ccb->ccb_h.status = CAM_BUSY;
999 pCmd->uCmd.Ide.Lba = ((HPT_U32)cdb[1] << 16) | ((HPT_U32)cdb[2] << 8) | (HPT_U32)cdb[3];
1000 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[4];
1004 case 0x8f: /* VERIFY_16 */
1007 ((HPT_U64)cdb[2]<<56) |
1008 ((HPT_U64)cdb[3]<<48) |
1009 ((HPT_U64)cdb[4]<<40) |
1010 ((HPT_U64)cdb[5]<<32) |
1011 ((HPT_U64)cdb[6]<<24) |
1012 ((HPT_U64)cdb[7]<<16) |
1013 ((HPT_U64)cdb[8]<<8) |
1015 pCmd->uCmd.Ide.Lba = block;
1016 pCmd->uCmd.Ide.nSectors = (HPT_U16)cdb[13] | ((HPT_U16)cdb[12]<<8);
1021 pCmd->uCmd.Ide.Lba = (HPT_U32)cdb[5] | ((HPT_U32)cdb[4] << 8) | ((HPT_U32)cdb[3] << 16) | ((HPT_U32)cdb[2] << 24);
1022 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[8] | ((HPT_U16)cdb[7]<<8);
1026 if(mIsArray(vd->type)) {
1027 sector_size_shift = vd->u.array.sector_size_shift;
1030 if(vd->type == VD_RAW){
1031 sector_size = vd->u.raw.logical_sector_size;
1034 switch (sector_size) {
1036 KdPrint(("<8>resize sector size from 4k to 512"));
1037 sector_size_shift = 3;
1043 pCmd->uCmd.Ide.Lba <<= sector_size_shift;
1044 pCmd->uCmd.Ide.nSectors <<= sector_size_shift;
1051 pCmd->flags.data_in = 1;
1056 pCmd->flags.data_out = 1;
1059 pCmd->priv = ext = cmdext_get(vbus_ext);
1063 pCmd->done = os_cmddone;
1064 pCmd->buildsgl = os_buildsgl;
1065 pCmd->psg = ext->psg;
1066 pCmd->flags.physical_sg = 1;
1067 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
1069 hpt_io_dmamap_callback, pCmd,
1072 KdPrint(("bus_dmamap_load return %d", error));
1073 if (error && error!=EINPROGRESS) {
1074 os_printk("bus_dmamap_load error %d", error);
1076 ldm_free_cmds(pCmd);
1077 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1084 ccb->ccb_h.status = CAM_REQ_INVALID;
1092 static void hpt_action(struct cam_sim *sim, union ccb *ccb)
1094 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
1096 KdPrint(("hpt_action(fn=%d, id=%d)", ccb->ccb_h.func_code, ccb->ccb_h.target_id));
1098 hpt_assert_vbus_locked(vbus_ext);
1099 switch (ccb->ccb_h.func_code) {
1102 hpt_scsi_io(vbus_ext, ccb);
1106 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
1109 case XPT_GET_TRAN_SETTINGS:
1110 case XPT_SET_TRAN_SETTINGS:
1111 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1114 case XPT_CALC_GEOMETRY:
1115 ccb->ccg.heads = 255;
1116 ccb->ccg.secs_per_track = 63;
1117 ccb->ccg.cylinders = ccb->ccg.volume_size / (ccb->ccg.heads * ccb->ccg.secs_per_track);
1118 ccb->ccb_h.status = CAM_REQ_CMP;
1123 struct ccb_pathinq *cpi = &ccb->cpi;
1125 cpi->version_num = 1;
1126 cpi->hba_inquiry = PI_SDTR_ABLE;
1127 cpi->target_sprt = 0;
1128 cpi->hba_misc = PIM_NOBUSRESET;
1129 cpi->hba_eng_cnt = 0;
1130 cpi->max_target = osm_max_targets;
1132 cpi->unit_number = cam_sim_unit(sim);
1133 cpi->bus_id = cam_sim_bus(sim);
1134 cpi->initiator_id = osm_max_targets;
1135 cpi->base_transfer_speed = 3300;
1137 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1138 strncpy(cpi->hba_vid, "HPT ", HBA_IDLEN);
1139 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1140 cpi->transport = XPORT_SPI;
1141 cpi->transport_version = 2;
1142 cpi->protocol = PROTO_SCSI;
1143 cpi->protocol_version = SCSI_REV_2;
1144 cpi->ccb_h.status = CAM_REQ_CMP;
1149 ccb->ccb_h.status = CAM_REQ_INVALID;
1157 static void hpt_pci_intr(void *arg)
1159 PVBUS_EXT vbus_ext = (PVBUS_EXT)arg;
1160 hpt_lock_vbus(vbus_ext);
1161 ldm_intr((PVBUS)vbus_ext->vbus);
1162 hpt_unlock_vbus(vbus_ext);
1165 static void hpt_poll(struct cam_sim *sim)
1167 PVBUS_EXT vbus_ext = cam_sim_softc(sim);
1168 hpt_assert_vbus_locked(vbus_ext);
1169 ldm_intr((PVBUS)vbus_ext->vbus);
1172 static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg)
1174 KdPrint(("hpt_async"));
1177 static int hpt_shutdown(device_t dev)
1179 KdPrint(("hpt_shutdown(dev=%p)", dev));
1183 static int hpt_detach(device_t dev)
1185 /* we don't allow the driver to be unloaded. */
1189 static void hpt_ioctl_done(struct _IOCTL_ARG *arg)
1191 arg->ioctl_cmnd = 0;
1195 static void __hpt_do_ioctl(PVBUS_EXT vbus_ext, IOCTL_ARG *ioctl_args)
1197 ioctl_args->result = -1;
1198 ioctl_args->done = hpt_ioctl_done;
1199 ioctl_args->ioctl_cmnd = (void *)1;
1201 hpt_lock_vbus(vbus_ext);
1202 ldm_ioctl((PVBUS)vbus_ext->vbus, ioctl_args);
1204 while (ioctl_args->ioctl_cmnd) {
1205 if (hpt_sleep(vbus_ext, ioctl_args, PPAUSE, "hptctl", HPT_OSM_TIMEOUT)==0)
1207 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
1208 __hpt_do_tasks(vbus_ext);
1211 /* KdPrint(("ioctl %x result %d", ioctl_args->dwIoControlCode, ioctl_args->result)); */
1213 hpt_unlock_vbus(vbus_ext);
1216 static void hpt_do_ioctl(IOCTL_ARG *ioctl_args)
1221 ldm_for_each_vbus(vbus, vbus_ext) {
1222 __hpt_do_ioctl(vbus_ext, ioctl_args);
1223 if (ioctl_args->result!=HPT_IOCTL_RESULT_WRONG_VBUS)
1228 #define HPT_DO_IOCTL(code, inbuf, insize, outbuf, outsize) ({\
1230 arg.dwIoControlCode = code;\
1231 arg.lpInBuffer = inbuf;\
1232 arg.lpOutBuffer = outbuf;\
1233 arg.nInBufferSize = insize;\
1234 arg.nOutBufferSize = outsize;\
1235 arg.lpBytesReturned = 0;\
1236 hpt_do_ioctl(&arg);\
1240 #define DEVICEID_VALID(id) ((id) && ((HPT_U32)(id)!=0xffffffff))
1242 static int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount)
1245 HPT_U32 count = nMaxCount-1;
1247 if (HPT_DO_IOCTL(HPT_IOCTL_GET_LOGICAL_DEVICES,
1248 &count, sizeof(HPT_U32), pIds, sizeof(DEVICEID)*nMaxCount))
1251 nMaxCount = (int)pIds[0];
1252 for (i=0; i<nMaxCount; i++) pIds[i] = pIds[i+1];
1256 static int hpt_get_device_info_v3(DEVICEID id, PLOGICAL_DEVICE_INFO_V3 pInfo)
1258 return HPT_DO_IOCTL(HPT_IOCTL_GET_DEVICE_INFO_V3,
1259 &id, sizeof(DEVICEID), pInfo, sizeof(LOGICAL_DEVICE_INFO_V3));
1262 /* not belong to this file logically, but we want to use ioctl interface */
1263 static int __hpt_stop_tasks(PVBUS_EXT vbus_ext, DEVICEID id)
1265 LOGICAL_DEVICE_INFO_V3 devinfo;
1267 DEVICEID param[2] = { id, 0 };
1269 if (hpt_get_device_info_v3(id, &devinfo))
1272 if (devinfo.Type!=LDT_ARRAY)
1275 if (devinfo.u.array.Flags & ARRAY_FLAG_REBUILDING)
1276 param[1] = AS_REBUILD_ABORT;
1277 else if (devinfo.u.array.Flags & ARRAY_FLAG_VERIFYING)
1278 param[1] = AS_VERIFY_ABORT;
1279 else if (devinfo.u.array.Flags & ARRAY_FLAG_INITIALIZING)
1280 param[1] = AS_INITIALIZE_ABORT;
1281 else if (devinfo.u.array.Flags & ARRAY_FLAG_TRANSFORMING)
1282 param[1] = AS_TRANSFORM_ABORT;
1286 KdPrint(("SET_ARRAY_STATE(%x, %d)", param[0], param[1]));
1287 result = HPT_DO_IOCTL(HPT_IOCTL_SET_ARRAY_STATE,
1288 param, sizeof(param), 0, 0);
1290 for (i=0; i<devinfo.u.array.nDisk; i++)
1291 if (DEVICEID_VALID(devinfo.u.array.Members[i]))
1292 __hpt_stop_tasks(vbus_ext, devinfo.u.array.Members[i]);
1297 static void hpt_stop_tasks(PVBUS_EXT vbus_ext)
1302 count = hpt_get_logical_devices((DEVICEID *)&ids, sizeof(ids)/sizeof(ids[0]));
1304 for (i=0; i<count; i++)
1305 __hpt_stop_tasks(vbus_ext, ids[i]);
1308 static d_open_t hpt_open;
1309 static d_close_t hpt_close;
1310 static d_ioctl_t hpt_ioctl;
1311 static int hpt_rescan_bus(void);
1313 static struct cdevsw hpt_cdevsw = {
1315 .d_close = hpt_close,
1316 .d_ioctl = hpt_ioctl,
1317 .d_name = driver_name,
1318 .d_version = D_VERSION,
1321 static struct intr_config_hook hpt_ich;
1324 * hpt_final_init will be called after all hpt_attach.
1326 static void hpt_final_init(void *dummy)
1328 int i,unit_number=0;
1333 /* Clear the config hook */
1334 config_intrhook_disestablish(&hpt_ich);
1336 /* allocate memory */
1338 ldm_for_each_vbus(vbus, vbus_ext) {
1339 if (hpt_alloc_mem(vbus_ext)) {
1340 os_printk("out of memory");
1348 os_printk("no controller detected.");
1352 /* initializing hardware */
1353 ldm_for_each_vbus(vbus, vbus_ext) {
1354 /* make timer available here */
1355 mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF);
1356 callout_init_mtx(&vbus_ext->timer, &vbus_ext->lock, 0);
1357 if (hpt_init_vbus(vbus_ext)) {
1358 os_printk("fail to initialize hardware");
1363 /* register CAM interface */
1364 ldm_for_each_vbus(vbus, vbus_ext) {
1365 struct cam_devq *devq;
1366 struct ccb_setasync ccb;
1368 if (bus_dma_tag_create(NULL,/* parent */
1370 BUS_SPACE_MAXADDR_32BIT+1, /* boundary */
1371 BUS_SPACE_MAXADDR, /* lowaddr */
1372 BUS_SPACE_MAXADDR, /* highaddr */
1373 NULL, NULL, /* filter, filterarg */
1374 PAGE_SIZE * (os_max_sg_descriptors-1), /* maxsize */
1375 os_max_sg_descriptors, /* nsegments */
1376 0x10000, /* maxsegsize */
1377 BUS_DMA_WAITOK, /* flags */
1378 busdma_lock_mutex, /* lockfunc */
1379 &vbus_ext->lock, /* lockfuncarg */
1380 &vbus_ext->io_dmat /* tag */))
1385 for (i=0; i<os_max_queue_comm; i++) {
1386 POS_CMDEXT ext = (POS_CMDEXT)malloc(sizeof(OS_CMDEXT), M_DEVBUF, M_WAITOK);
1388 os_printk("Can't alloc cmdext(%d)", i);
1391 ext->vbus_ext = vbus_ext;
1392 ext->next = vbus_ext->cmdext_list;
1393 vbus_ext->cmdext_list = ext;
1395 if (bus_dmamap_create(vbus_ext->io_dmat, 0, &ext->dma_map)) {
1396 os_printk("Can't create dma map(%d)", i);
1399 callout_init_mtx(&ext->timeout, &vbus_ext->lock, 0);
1402 if ((devq = cam_simq_alloc(os_max_queue_comm)) == NULL) {
1403 os_printk("cam_simq_alloc failed");
1407 hpt_lock_vbus(vbus_ext);
1408 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name,
1409 vbus_ext, unit_number, &vbus_ext->lock,
1410 os_max_queue_comm, /*tagged*/8, devq);
1412 if (!vbus_ext->sim) {
1413 os_printk("cam_sim_alloc failed");
1414 cam_simq_free(devq);
1415 hpt_unlock_vbus(vbus_ext);
1419 if (xpt_bus_register(vbus_ext->sim, NULL, 0) != CAM_SUCCESS) {
1420 os_printk("xpt_bus_register failed");
1421 cam_sim_free(vbus_ext->sim, /*free devq*/ TRUE);
1422 vbus_ext->sim = NULL;
1426 if (xpt_create_path(&vbus_ext->path, /*periph */ NULL,
1427 cam_sim_path(vbus_ext->sim), CAM_TARGET_WILDCARD,
1428 CAM_LUN_WILDCARD) != CAM_REQ_CMP)
1430 os_printk("xpt_create_path failed");
1431 xpt_bus_deregister(cam_sim_path(vbus_ext->sim));
1432 cam_sim_free(vbus_ext->sim, /*free_devq*/TRUE);
1433 hpt_unlock_vbus(vbus_ext);
1434 vbus_ext->sim = NULL;
1437 hpt_unlock_vbus(vbus_ext);
1439 xpt_setup_ccb(&ccb.ccb_h, vbus_ext->path, /*priority*/5);
1440 ccb.ccb_h.func_code = XPT_SASYNC_CB;
1441 ccb.event_enable = AC_LOST_DEVICE;
1442 ccb.callback = hpt_async;
1443 ccb.callback_arg = vbus_ext;
1444 xpt_action((union ccb *)&ccb);
1446 for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
1448 if ((hba->irq_res = bus_alloc_resource(hba->pcidev,
1449 SYS_RES_IRQ, &rid, 0, ~0ul, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL)
1451 os_printk("can't allocate interrupt");
1455 if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM | INTR_MPSAFE,
1456 NULL, hpt_pci_intr, vbus_ext, &hba->irq_handle))
1458 os_printk("can't set up interrupt");
1461 hba->ldm_adapter.him->intr_control(hba->ldm_adapter.him_handle, HPT_TRUE);
1465 vbus_ext->shutdown_eh = EVENTHANDLER_REGISTER(shutdown_final,
1466 hpt_shutdown_vbus, vbus_ext, SHUTDOWN_PRI_DEFAULT);
1467 if (!vbus_ext->shutdown_eh)
1468 os_printk("Shutdown event registration failed");
1471 ldm_for_each_vbus(vbus, vbus_ext) {
1472 TASK_INIT(&vbus_ext->worker, 0, (task_fn_t *)hpt_do_tasks, vbus_ext);
1473 if (vbus_ext->tasks)
1474 TASK_ENQUEUE(&vbus_ext->worker);
1477 make_dev(&hpt_cdevsw, DRIVER_MINOR, UID_ROOT, GID_OPERATOR,
1478 S_IRUSR | S_IWUSR, "%s", driver_name);
1481 #if defined(KLD_MODULE)
1483 typedef struct driverlink *driverlink_t;
1485 kobj_class_t driver;
1486 TAILQ_ENTRY(driverlink) link; /* list of drivers in devclass */
1489 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
1492 TAILQ_ENTRY(devclass) link;
1493 devclass_t parent; /* parent in devclass hierarchy */
1494 driver_list_t drivers; /* bus devclasses store drivers for bus */
1496 device_t *devices; /* array of devices indexed by unit */
1497 int maxunit; /* size of devices array */
1500 static void override_kernel_driver(void)
1502 driverlink_t dl, dlfirst;
1503 driver_t *tmpdriver;
1504 devclass_t dc = devclass_find("pci");
1507 dlfirst = TAILQ_FIRST(&dc->drivers);
1508 for (dl = dlfirst; dl; dl = TAILQ_NEXT(dl, link)) {
1509 if(strcmp(dl->driver->name, driver_name) == 0) {
1510 tmpdriver=dl->driver;
1511 dl->driver=dlfirst->driver;
1512 dlfirst->driver=tmpdriver;
1520 #define override_kernel_driver()
1523 static void hpt_init(void *dummy)
1526 os_printk("%s %s", driver_name_long, driver_ver);
1528 override_kernel_driver();
1531 hpt_ich.ich_func = hpt_final_init;
1532 hpt_ich.ich_arg = NULL;
1533 if (config_intrhook_establish(&hpt_ich) != 0) {
1534 printf("%s: cannot establish configuration hook\n",
1539 SYSINIT(hptinit, SI_SUB_CONFIGURE, SI_ORDER_FIRST, hpt_init, NULL);
1542 * CAM driver interface
1544 static device_method_t driver_methods[] = {
1545 /* Device interface */
1546 DEVMETHOD(device_probe, hpt_probe),
1547 DEVMETHOD(device_attach, hpt_attach),
1548 DEVMETHOD(device_detach, hpt_detach),
1549 DEVMETHOD(device_shutdown, hpt_shutdown),
1553 static driver_t hpt_pci_driver = {
1559 static devclass_t hpt_devclass;
1562 #error "no TARGETNAME found"
1565 /* use this to make TARGETNAME be expanded */
1566 #define __DRIVER_MODULE(p1, p2, p3, p4, p5, p6) DRIVER_MODULE(p1, p2, p3, p4, p5, p6)
1567 #define __MODULE_VERSION(p1, p2) MODULE_VERSION(p1, p2)
1568 #define __MODULE_DEPEND(p1, p2, p3, p4, p5) MODULE_DEPEND(p1, p2, p3, p4, p5)
1569 __DRIVER_MODULE(TARGETNAME, pci, hpt_pci_driver, hpt_devclass, 0, 0);
1570 __MODULE_VERSION(TARGETNAME, 1);
1571 __MODULE_DEPEND(TARGETNAME, cam, 1, 1, 1);
1573 static int hpt_open(struct cdev *dev, int flags, int devtype, struct thread *td)
1578 static int hpt_close(struct cdev *dev, int flags, int devtype, struct thread *td)
1583 static int hpt_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
1585 PHPT_IOCTL_PARAM piop=(PHPT_IOCTL_PARAM)data;
1586 IOCTL_ARG ioctl_args;
1587 HPT_U32 bytesReturned;
1590 case HPT_DO_IOCONTROL:
1592 if (piop->Magic == HPT_IOCTL_MAGIC || piop->Magic == HPT_IOCTL_MAGIC32) {
1593 KdPrint(("ioctl=%x in=%p len=%d out=%p len=%d\n",
1594 piop->dwIoControlCode,
1596 piop->nInBufferSize,
1598 piop->nOutBufferSize));
1600 memset(&ioctl_args, 0, sizeof(ioctl_args));
1602 ioctl_args.dwIoControlCode = piop->dwIoControlCode;
1603 ioctl_args.nInBufferSize = piop->nInBufferSize;
1604 ioctl_args.nOutBufferSize = piop->nOutBufferSize;
1605 ioctl_args.lpBytesReturned = &bytesReturned;
1607 if (ioctl_args.nInBufferSize) {
1608 ioctl_args.lpInBuffer = malloc(ioctl_args.nInBufferSize, M_DEVBUF, M_WAITOK);
1609 if (!ioctl_args.lpInBuffer)
1611 if (copyin((void*)piop->lpInBuffer,
1612 ioctl_args.lpInBuffer, piop->nInBufferSize))
1616 if (ioctl_args.nOutBufferSize) {
1617 ioctl_args.lpOutBuffer = malloc(ioctl_args.nOutBufferSize, M_DEVBUF, M_WAITOK);
1618 if (!ioctl_args.lpOutBuffer)
1622 hpt_do_ioctl(&ioctl_args);
1624 if (ioctl_args.result==HPT_IOCTL_RESULT_OK) {
1625 if (piop->nOutBufferSize) {
1626 if (copyout(ioctl_args.lpOutBuffer,
1627 (void*)piop->lpOutBuffer, piop->nOutBufferSize))
1630 if (piop->lpBytesReturned) {
1631 if (copyout(&bytesReturned,
1632 (void*)piop->lpBytesReturned, sizeof(HPT_U32)))
1635 if (ioctl_args.lpInBuffer) free(ioctl_args.lpInBuffer, M_DEVBUF);
1636 if (ioctl_args.lpOutBuffer) free(ioctl_args.lpOutBuffer, M_DEVBUF);
1640 if (ioctl_args.lpInBuffer) free(ioctl_args.lpInBuffer, M_DEVBUF);
1641 if (ioctl_args.lpOutBuffer) free(ioctl_args.lpOutBuffer, M_DEVBUF);
1649 return hpt_rescan_bus();
1652 KdPrint(("invalid command!"));
1658 static int hpt_rescan_bus(void)
1664 ldm_for_each_vbus(vbus, vbus_ext) {
1665 if ((ccb = xpt_alloc_ccb()) == NULL)
1669 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(vbus_ext->sim),
1670 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP)