1 /* $Id: osm_bsd.c,v 1.36 2010/05/11 03:12:11 lcn Exp $ */
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * HighPoint RAID Driver for FreeBSD
6 * Copyright (C) 2005-2011 HighPoint Technologies, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <dev/hptnr/hptnr_config.h>
33 #include <dev/hptnr/os_bsd.h>
34 #include <dev/hptnr/hptintf.h>
37 static HIM *hpt_match(device_t dev, int scan)
43 for (him = him_list; him; him = him->next) {
44 for (i=0; him->get_supported_device_id(i, &pci_id); i++) {
45 if (scan && him->get_controller_count)
46 him->get_controller_count(&pci_id,0,0);
47 if ((pci_get_vendor(dev) == pci_id.vid) &&
48 (pci_get_device(dev) == pci_id.did)){
57 static int hpt_probe(device_t dev)
61 him = hpt_match(dev, 0);
63 KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d",
64 pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev)
66 device_set_desc(dev, him->name);
67 return (BUS_PROBE_DEFAULT);
73 static int hpt_attach(device_t dev)
75 PHBA hba = (PHBA)device_get_softc(dev);
82 KdPrint(("hpt_attach(%d/%d/%d)", pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)));
84 him = hpt_match(dev, 1);
85 hba->ext_type = EXT_TYPE_HBA;
86 hba->ldm_adapter.him = him;
88 pci_enable_busmaster(dev);
90 pci_id.vid = pci_get_vendor(dev);
91 pci_id.did = pci_get_device(dev);
92 pci_id.rev = pci_get_revid(dev);
93 pci_id.subsys = (HPT_U32)(pci_get_subdevice(dev)) << 16 | pci_get_subvendor(dev);
95 size = him->get_adapter_size(&pci_id);
96 hba->ldm_adapter.him_handle = malloc(size, M_DEVBUF, M_WAITOK);
99 hba->pciaddr.tree = 0;
100 hba->pciaddr.bus = pci_get_bus(dev);
101 hba->pciaddr.device = pci_get_slot(dev);
102 hba->pciaddr.function = pci_get_function(dev);
104 if (!him->create_adapter(&pci_id, hba->pciaddr, hba->ldm_adapter.him_handle, hba)) {
105 free(hba->ldm_adapter.him_handle, M_DEVBUF);
109 os_printk("adapter at PCI %d:%d:%d, IRQ %d",
110 hba->pciaddr.bus, hba->pciaddr.device, hba->pciaddr.function, pci_get_irq(dev));
112 if (!ldm_register_adapter(&hba->ldm_adapter)) {
113 size = ldm_get_vbus_size();
114 vbus_ext = malloc(sizeof(VBUS_EXT) + size, M_DEVBUF, M_WAITOK |
116 vbus_ext->ext_type = EXT_TYPE_VBUS;
117 ldm_create_vbus((PVBUS)vbus_ext->vbus, vbus_ext);
118 ldm_register_adapter(&hba->ldm_adapter);
121 ldm_for_each_vbus(vbus, vbus_ext) {
122 if (hba->ldm_adapter.vbus==vbus) {
123 hba->vbus_ext = vbus_ext;
124 hba->next = vbus_ext->hba_list;
125 vbus_ext->hba_list = hba;
133 * Maybe we'd better to use the bus_dmamem_alloc to alloc DMA memory,
134 * but there are some problems currently (alignment, etc).
136 static __inline void *__get_free_pages(int order)
138 /* don't use low memory - other devices may get starved */
139 return contigmalloc(PAGE_SIZE<<order,
140 M_DEVBUF, M_WAITOK, BUS_SPACE_MAXADDR_24BIT, BUS_SPACE_MAXADDR, PAGE_SIZE, 0);
143 static __inline void free_pages(void *p, int order)
145 contigfree(p, PAGE_SIZE<<order, M_DEVBUF);
148 static int hpt_alloc_mem(PVBUS_EXT vbus_ext)
155 for (hba = vbus_ext->hba_list; hba; hba = hba->next)
156 hba->ldm_adapter.him->get_meminfo(hba->ldm_adapter.him_handle);
158 ldm_get_mem_info((PVBUS)vbus_ext->vbus, 0);
160 for (f=vbus_ext->freelist_head; f; f=f->next) {
161 KdPrint(("%s: %d*%d=%d bytes",
162 f->tag, f->count, f->size, f->count*f->size));
163 for (i=0; i<f->count; i++) {
164 p = (void **)malloc(f->size, M_DEVBUF, M_WAITOK);
165 if (!p) return (ENXIO);
171 for (f=vbus_ext->freelist_dma_head; f; f=f->next) {
174 HPT_ASSERT((f->size & (f->alignment-1))==0);
176 for (order=0, size=PAGE_SIZE; size<f->size; order++, size<<=1)
179 KdPrint(("%s: %d*%d=%d bytes, order %d",
180 f->tag, f->count, f->size, f->count*f->size, order));
181 HPT_ASSERT(f->alignment<=PAGE_SIZE);
183 for (i=0; i<f->count;) {
184 p = (void **)__get_free_pages(order);
186 for (j = size/f->size; j && i<f->count; i++,j--) {
188 *(BUS_ADDRESS *)(p+1) = (BUS_ADDRESS)vtophys(p);
190 p = (void **)((unsigned long)p + f->size);
195 HPT_ASSERT(PAGE_SIZE==DMAPOOL_PAGE_SIZE);
197 for (i=0; i<os_max_cache_pages; i++) {
198 p = (void **)__get_free_pages(0);
200 HPT_ASSERT(((HPT_UPTR)p & (DMAPOOL_PAGE_SIZE-1))==0);
201 dmapool_put_page((PVBUS)vbus_ext->vbus, p, (BUS_ADDRESS)vtophys(p));
207 static void hpt_free_mem(PVBUS_EXT vbus_ext)
214 for (f=vbus_ext->freelist_head; f; f=f->next) {
216 if (f->count!=f->reserved_count) {
217 KdPrint(("memory leak for freelist %s (%d/%d)", f->tag, f->count, f->reserved_count));
220 while ((p=freelist_get(f)))
224 for (i=0; i<os_max_cache_pages; i++) {
225 p = dmapool_get_page((PVBUS)vbus_ext->vbus, &bus);
230 for (f=vbus_ext->freelist_dma_head; f; f=f->next) {
233 if (f->count!=f->reserved_count) {
234 KdPrint(("memory leak for dma freelist %s (%d/%d)", f->tag, f->count, f->reserved_count));
237 for (order=0, size=PAGE_SIZE; size<f->size; order++, size<<=1) ;
239 while ((p=freelist_get_dma(f, &bus))) {
241 free_pages(p, order);
243 /* can't free immediately since other blocks in this page may still be in the list */
244 if (((HPT_UPTR)p & (PAGE_SIZE-1))==0)
245 dmapool_put_page((PVBUS)vbus_ext->vbus, p, bus);
250 while ((p = dmapool_get_page((PVBUS)vbus_ext->vbus, &bus)))
254 static int hpt_init_vbus(PVBUS_EXT vbus_ext)
258 for (hba = vbus_ext->hba_list; hba; hba = hba->next)
259 if (!hba->ldm_adapter.him->initialize(hba->ldm_adapter.him_handle)) {
260 KdPrint(("fail to initialize %p", hba));
264 ldm_initialize_vbus((PVBUS)vbus_ext->vbus, &vbus_ext->hba_list->ldm_adapter);
268 static void hpt_flush_done(PCOMMAND pCmd)
270 PVDEV vd = pCmd->target;
272 if (mIsArray(vd->type) && vd->u.array.transform && vd!=vd->u.array.transform->target) {
273 vd = vd->u.array.transform->target;
276 pCmd->Result = RETURN_PENDING;
277 vdev_queue_cmd(pCmd);
281 *(int *)pCmd->priv = 1;
286 * flush a vdev (without retry).
288 static int hpt_flush_vdev(PVBUS_EXT vbus_ext, PVDEV vd)
291 int result = 0, done;
294 KdPrint(("flusing dev %p", vd));
296 hpt_assert_vbus_locked(vbus_ext);
298 if (mIsArray(vd->type) && vd->u.array.transform)
299 count = max(vd->u.array.transform->source->cmds_per_request,
300 vd->u.array.transform->target->cmds_per_request);
302 count = vd->cmds_per_request;
304 pCmd = ldm_alloc_cmds(vd->vbus, count);
310 pCmd->type = CMD_TYPE_FLUSH;
311 pCmd->flags.hard_flush = 1;
313 pCmd->done = hpt_flush_done;
320 while (hpt_sleep(vbus_ext, pCmd, PPAUSE, "hptfls", HPT_OSM_TIMEOUT)) {
321 ldm_reset_vbus(vd->vbus);
325 KdPrint(("flush result %d", pCmd->Result));
327 if (pCmd->Result!=RETURN_SUCCESS)
335 static void hpt_stop_tasks(PVBUS_EXT vbus_ext);
336 static void hpt_shutdown_vbus(PVBUS_EXT vbus_ext, int howto)
338 PVBUS vbus = (PVBUS)vbus_ext->vbus;
342 KdPrint(("hpt_shutdown_vbus"));
344 /* stop all ctl tasks and disable the worker taskqueue */
345 hpt_stop_tasks(vbus_ext);
346 hpt_lock_vbus(vbus_ext);
347 vbus_ext->worker.ta_context = 0;
350 for (i=0; i<osm_max_targets; i++) {
351 PVDEV vd = ldm_find_target(vbus, i);
354 if (hpt_flush_vdev(vbus_ext, vd))
355 hpt_flush_vdev(vbus_ext, vd);
360 hpt_unlock_vbus(vbus_ext);
362 ldm_release_vbus(vbus);
364 for (hba=vbus_ext->hba_list; hba; hba=hba->next)
365 bus_teardown_intr(hba->pcidev, hba->irq_res, hba->irq_handle);
367 hpt_free_mem(vbus_ext);
369 while ((hba=vbus_ext->hba_list)) {
370 vbus_ext->hba_list = hba->next;
371 free(hba->ldm_adapter.him_handle, M_DEVBUF);
374 callout_drain(&vbus_ext->timer);
375 mtx_destroy(&vbus_ext->lock);
376 free(vbus_ext, M_DEVBUF);
377 KdPrint(("hpt_shutdown_vbus done"));
380 static void __hpt_do_tasks(PVBUS_EXT vbus_ext)
384 tasks = vbus_ext->tasks;
391 t->func(vbus_ext->vbus, t->data);
395 static void hpt_do_tasks(PVBUS_EXT vbus_ext, int pending)
398 hpt_lock_vbus(vbus_ext);
399 __hpt_do_tasks(vbus_ext);
400 hpt_unlock_vbus(vbus_ext);
404 static void hpt_action(struct cam_sim *sim, union ccb *ccb);
405 static void hpt_poll(struct cam_sim *sim);
406 static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg);
407 static void hpt_pci_intr(void *arg);
409 static __inline POS_CMDEXT cmdext_get(PVBUS_EXT vbus_ext)
411 POS_CMDEXT p = vbus_ext->cmdext_list;
413 vbus_ext->cmdext_list = p->next;
417 static __inline void cmdext_put(POS_CMDEXT p)
419 p->next = p->vbus_ext->cmdext_list;
420 p->vbus_ext->cmdext_list = p;
423 static void hpt_timeout(void *arg)
425 PCOMMAND pCmd = (PCOMMAND)arg;
426 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
428 KdPrint(("pCmd %p timeout", pCmd));
430 ldm_reset_vbus((PVBUS)ext->vbus_ext->vbus);
433 static void os_cmddone(PCOMMAND pCmd)
435 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
436 union ccb *ccb = ext->ccb;
439 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
440 cdb = ccb->csio.cdb_io.cdb_ptr;
442 cdb = ccb->csio.cdb_io.cdb_bytes;
444 KdPrint(("os_cmddone(%p, %d)", pCmd, pCmd->Result));
446 callout_stop(&ext->timeout);
448 case 0x85: /*ATA_16*/
449 case 0xA1: /*ATA_12*/
451 PassthroughCmd *passthru = &pCmd->uCmd.Passthrough;
452 HPT_U8 *sense_buffer = (HPT_U8 *)&ccb->csio.sense_data;
453 memset(&ccb->csio.sense_data, 0,sizeof(ccb->csio.sense_data));
455 sense_buffer[0] = 0x72; /* Response Code */
456 sense_buffer[7] = 14; /* Additional Sense Length */
458 sense_buffer[8] = 0x9; /* ATA Return Descriptor */
459 sense_buffer[9] = 0xc; /* Additional Descriptor Length */
460 sense_buffer[11] = (HPT_U8)passthru->bFeaturesReg; /* Error */
461 sense_buffer[13] = (HPT_U8)passthru->bSectorCountReg; /* Sector Count (7:0) */
462 sense_buffer[15] = (HPT_U8)passthru->bLbaLowReg; /* LBA Low (7:0) */
463 sense_buffer[17] = (HPT_U8)passthru->bLbaMidReg; /* LBA Mid (7:0) */
464 sense_buffer[19] = (HPT_U8)passthru->bLbaHighReg; /* LBA High (7:0) */
466 if ((cdb[0] == 0x85) && (cdb[1] & 0x1))
468 sense_buffer[10] = 1;
469 sense_buffer[12] = (HPT_U8)(passthru->bSectorCountReg >> 8); /* Sector Count (15:8) */
470 sense_buffer[14] = (HPT_U8)(passthru->bLbaLowReg >> 8); /* LBA Low (15:8) */
471 sense_buffer[16] = (HPT_U8)(passthru->bLbaMidReg >> 8); /* LBA Mid (15:8) */
472 sense_buffer[18] = (HPT_U8)(passthru->bLbaHighReg >> 8); /* LBA High (15:8) */
475 sense_buffer[20] = (HPT_U8)passthru->bDriveHeadReg; /* Device */
476 sense_buffer[21] = (HPT_U8)passthru->bCommandReg; /* Status */
477 KdPrint(("sts 0x%x err 0x%x low 0x%x mid 0x%x hig 0x%x dh 0x%x sc 0x%x",
478 passthru->bCommandReg,
479 passthru->bFeaturesReg,
480 passthru->bLbaLowReg,
481 passthru->bLbaMidReg,
482 passthru->bLbaHighReg,
483 passthru->bDriveHeadReg,
484 passthru->bSectorCountReg));
485 KdPrint(("result:0x%x,bFeaturesReg:0x%04x,bSectorCountReg:0x%04x,LBA:0x%04x%04x%04x ",
486 pCmd->Result,passthru->bFeaturesReg,passthru->bSectorCountReg,
487 passthru->bLbaHighReg,passthru->bLbaMidReg,passthru->bLbaLowReg));
493 switch(pCmd->Result) {
495 ccb->ccb_h.status = CAM_REQ_CMP;
497 case RETURN_BAD_DEVICE:
498 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
500 case RETURN_DEVICE_BUSY:
501 ccb->ccb_h.status = CAM_BUSY;
503 case RETURN_INVALID_REQUEST:
504 ccb->ccb_h.status = CAM_REQ_INVALID;
506 case RETURN_SELECTION_TIMEOUT:
507 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
510 ccb->ccb_h.status = CAM_BUSY;
513 ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR;
517 if (pCmd->flags.data_in) {
518 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map, BUS_DMASYNC_POSTREAD);
520 else if (pCmd->flags.data_out) {
521 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map, BUS_DMASYNC_POSTWRITE);
524 bus_dmamap_unload(ext->vbus_ext->io_dmat, ext->dma_map);
531 static int os_buildsgl(PCOMMAND pCmd, PSG pSg, int logical)
533 /* since we have provided physical sg, nobody will ask us to build physical sg */
538 static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
540 PCOMMAND pCmd = (PCOMMAND)arg;
541 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
545 HPT_ASSERT(pCmd->flags.physical_sg);
548 panic("busdma error");
550 HPT_ASSERT(nsegs<=os_max_sg_descriptors);
553 for (idx = 0; idx < nsegs; idx++, psg++) {
554 psg->addr.bus = segs[idx].ds_addr;
555 psg->size = segs[idx].ds_len;
560 if (pCmd->flags.data_in) {
561 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
562 BUS_DMASYNC_PREREAD);
564 else if (pCmd->flags.data_out) {
565 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
566 BUS_DMASYNC_PREWRITE);
570 callout_reset(&ext->timeout, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
574 static void hpt_scsi_io(PVBUS_EXT vbus_ext, union ccb *ccb)
576 PVBUS vbus = (PVBUS)vbus_ext->vbus;
582 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
583 cdb = ccb->csio.cdb_io.cdb_ptr;
585 cdb = ccb->csio.cdb_io.cdb_bytes;
587 KdPrint(("hpt_scsi_io: ccb %x id %d lun %d cdb %x-%x-%x",
589 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
590 *(HPT_U32 *)&cdb[0], *(HPT_U32 *)&cdb[4], *(HPT_U32 *)&cdb[8]
593 /* ccb->ccb_h.path_id is not our bus id - don't check it */
594 if (ccb->ccb_h.target_lun != 0 ||
595 ccb->ccb_h.target_id >= osm_max_targets ||
596 (ccb->ccb_h.flags & CAM_CDB_PHYS))
598 ccb->ccb_h.status = CAM_TID_INVALID;
603 vd = ldm_find_target(vbus, ccb->ccb_h.target_id);
606 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
612 case TEST_UNIT_READY:
613 case START_STOP_UNIT:
614 case SYNCHRONIZE_CACHE:
615 ccb->ccb_h.status = CAM_REQ_CMP;
618 case 0x85: /*ATA_16*/
619 case 0xA1: /*ATA_12*/
623 PassthroughCmd *passthru;
625 if (mIsArray(vd->type)) {
626 ccb->ccb_h.status = CAM_REQ_INVALID;
630 HPT_ASSERT(vd->type == VD_RAW && vd->u.raw.legacy_disk);
632 prot = (cdb[1] & 0x1e) >> 1;
635 if (prot < 3 || prot > 5)
637 ccb->ccb_h.status = CAM_REQ_INVALID;
641 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
644 ccb->ccb_h.status = CAM_BUSY;
648 passthru = &pCmd->uCmd.Passthrough;
649 if (cdb[0] == 0x85/*ATA_16*/) {
651 passthru->bFeaturesReg =
652 ((HPT_U16)cdb[3] << 8)
654 passthru->bSectorCountReg =
655 ((HPT_U16)cdb[5] << 8) |
657 passthru->bLbaLowReg =
658 ((HPT_U16)cdb[7] << 8) |
660 passthru->bLbaMidReg =
661 ((HPT_U16)cdb[9] << 8) |
663 passthru->bLbaHighReg =
664 ((HPT_U16)cdb[11] << 8) |
667 passthru->bFeaturesReg = cdb[4];
668 passthru->bSectorCountReg = cdb[6];
669 passthru->bLbaLowReg = cdb[8];
670 passthru->bLbaMidReg = cdb[10];
671 passthru->bLbaHighReg = cdb[12];
673 passthru->bDriveHeadReg = cdb[13];
674 passthru->bCommandReg = cdb[14];
678 passthru->bFeaturesReg = cdb[3];
679 passthru->bSectorCountReg = cdb[4];
680 passthru->bLbaLowReg = cdb[5];
681 passthru->bLbaMidReg = cdb[6];
682 passthru->bLbaHighReg = cdb[7];
683 passthru->bDriveHeadReg = cdb[8];
684 passthru->bCommandReg = cdb[9];
690 if (!(passthru->bCommandReg == ATA_CMD_READ_MULTI ||
691 passthru->bCommandReg == ATA_CMD_READ_MULTI_EXT ||
692 passthru->bCommandReg == ATA_CMD_WRITE_MULTI ||
693 passthru->bCommandReg == ATA_CMD_WRITE_MULTI_EXT ||
694 passthru->bCommandReg == ATA_CMD_WRITE_MULTI_FUA_EXT)
701 if (passthru->bFeaturesReg == ATA_SET_FEATURES_XFER &&
702 passthru->bCommandReg == ATA_CMD_SET_FEATURES) {
707 passthru->nSectors = ccb->csio.dxfer_len/ATA_SECTOR_SIZE;
709 default: /*None data*/
711 case 4: /*PIO data in, T_DIR=1 match check*/
715 OsPrint(("PIO data in, T_DIR=1 match check"));
718 pCmd->flags.data_in = 1;
720 case 5: /*PIO data out, T_DIR=0 match check*/
724 OsPrint(("PIO data out, T_DIR=0 match check"));
728 pCmd->flags.data_out = 1;
731 pCmd->type = CMD_TYPE_PASSTHROUGH;
732 pCmd->priv = ext = cmdext_get(vbus_ext);
736 pCmd->done = os_cmddone;
737 pCmd->buildsgl = os_buildsgl;
738 pCmd->psg = ext->psg;
740 if(!ccb->csio.dxfer_len)
745 pCmd->flags.physical_sg = 1;
746 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
748 hpt_io_dmamap_callback, pCmd,
751 KdPrint(("bus_dmamap_load return %d", error));
752 if (error && error!=EINPROGRESS) {
753 os_printk("bus_dmamap_load error %d", error);
756 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
762 ccb->ccb_h.status = CAM_REQ_INVALID;
768 PINQUIRYDATA inquiryData;
769 HIM_DEVICE_CONFIG devconf;
772 memset(ccb->csio.data_ptr, 0, ccb->csio.dxfer_len);
773 inquiryData = (PINQUIRYDATA)ccb->csio.data_ptr;
776 rbuf = (HPT_U8 *)inquiryData;
786 ccb->ccb_h.status = CAM_REQ_CMP;
792 if (vd->type == VD_RAW) {
794 vd->u.raw.him->get_device_config(vd->u.raw.phy_dev,&devconf);
795 memcpy(&rbuf[4], devconf.pIdentifyData->SerialNumber, 20);
796 ldm_ide_fixstring(&rbuf[4], 20);
801 ccb->ccb_h.status = CAM_REQ_CMP;
821 ccb->ccb_h.status = CAM_REQ_CMP;
824 ccb->ccb_h.status = CAM_REQ_INVALID;
831 ccb->ccb_h.status = CAM_REQ_INVALID;
835 inquiryData->DeviceType = 0; /*DIRECT_ACCESS_DEVICE*/
836 inquiryData->Versions = 5; /*SPC-3*/
837 inquiryData->ResponseDataFormat = 2;
838 inquiryData->AdditionalLength = 0x5b;
839 inquiryData->CommandQueue = 1;
841 if (ccb->csio.dxfer_len > 63) {
842 rbuf = (HPT_U8 *)inquiryData;
852 if (vd->type == VD_RAW) {
853 vd->u.raw.him->get_device_config(vd->u.raw.phy_dev,&devconf);
855 if ((devconf.pIdentifyData->GeneralConfiguration & 0x80))
856 inquiryData->RemovableMedia = 1;
859 memcpy(&inquiryData->VendorId, "ATA ", 8);
860 memcpy(&inquiryData->ProductId, devconf.pIdentifyData->ModelNumber, 16);
861 ldm_ide_fixstring((HPT_U8 *)&inquiryData->ProductId, 16);
862 memcpy(&inquiryData->ProductRevisionLevel, devconf.pIdentifyData->FirmwareRevision, 4);
863 ldm_ide_fixstring((HPT_U8 *)&inquiryData->ProductRevisionLevel, 4);
864 if (inquiryData->ProductRevisionLevel[0] == 0 || inquiryData->ProductRevisionLevel[0] == ' ')
865 memcpy(&inquiryData->ProductRevisionLevel, "n/a ", 4);
867 memcpy(&inquiryData->VendorId, "HPT ", 8);
868 snprintf((char *)&inquiryData->ProductId, 16, "DISK_%d_%d ",
869 os_get_vbus_seq(vbus_ext), vd->target_id);
870 inquiryData->ProductId[15] = ' ';
871 memcpy(&inquiryData->ProductRevisionLevel, "4.00", 4);
874 ccb->ccb_h.status = CAM_REQ_CMP;
879 HPT_U8 *rbuf = ccb->csio.data_ptr;
881 HPT_U8 sector_size_shift = 0;
883 HPT_U32 sector_size = 0;
885 if (mIsArray(vd->type))
886 sector_size_shift = vd->u.array.sector_size_shift;
888 if(vd->type == VD_RAW){
889 sector_size = vd->u.raw.logical_sector_size;
892 switch (sector_size) {
894 KdPrint(("set 4k setctor size in READ_CAPACITY"));
895 sector_size_shift = 3;
901 new_cap = vd->capacity >> sector_size_shift;
903 if (new_cap > 0xfffffffful)
908 rbuf[0] = (HPT_U8)(cap>>24);
909 rbuf[1] = (HPT_U8)(cap>>16);
910 rbuf[2] = (HPT_U8)(cap>>8);
911 rbuf[3] = (HPT_U8)cap;
914 rbuf[6] = 2 << sector_size_shift;
917 ccb->ccb_h.status = CAM_REQ_CMP;
923 HPT_U8 *rbuf = ccb->csio.data_ptr;
926 ccb->ccb_h.status = CAM_REQ_CMP;
929 case SERVICE_ACTION_IN:
931 HPT_U8 *rbuf = ccb->csio.data_ptr;
933 HPT_U8 sector_size_shift = 0;
934 HPT_U32 sector_size = 0;
936 if(mIsArray(vd->type))
937 sector_size_shift = vd->u.array.sector_size_shift;
939 if(vd->type == VD_RAW){
940 sector_size = vd->u.raw.logical_sector_size;
943 switch (sector_size) {
945 KdPrint(("set 4k setctor size in SERVICE_ACTION_IN"));
946 sector_size_shift = 3;
952 cap = (vd->capacity >> sector_size_shift) - 1;
954 rbuf[0] = (HPT_U8)(cap>>56);
955 rbuf[1] = (HPT_U8)(cap>>48);
956 rbuf[2] = (HPT_U8)(cap>>40);
957 rbuf[3] = (HPT_U8)(cap>>32);
958 rbuf[4] = (HPT_U8)(cap>>24);
959 rbuf[5] = (HPT_U8)(cap>>16);
960 rbuf[6] = (HPT_U8)(cap>>8);
961 rbuf[7] = (HPT_U8)cap;
964 rbuf[10] = 2 << sector_size_shift;
967 if(!mIsArray(vd->type)){
968 rbuf[13] = vd->u.raw.logicalsectors_per_physicalsector;
969 rbuf[14] = (HPT_U8)((vd->u.raw.lowest_aligned >> 8) & 0x3f);
970 rbuf[15] = (HPT_U8)(vd->u.raw.lowest_aligned);
973 ccb->ccb_h.status = CAM_REQ_CMP;
985 case 0x8f: /* VERIFY_16 */
988 HPT_U8 sector_size_shift = 0;
989 HPT_U32 sector_size = 0;
990 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
992 KdPrint(("Failed to allocate command!"));
993 ccb->ccb_h.status = CAM_BUSY;
1001 pCmd->uCmd.Ide.Lba = ((HPT_U32)cdb[1] << 16) | ((HPT_U32)cdb[2] << 8) | (HPT_U32)cdb[3];
1002 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[4];
1006 case 0x8f: /* VERIFY_16 */
1009 ((HPT_U64)cdb[2]<<56) |
1010 ((HPT_U64)cdb[3]<<48) |
1011 ((HPT_U64)cdb[4]<<40) |
1012 ((HPT_U64)cdb[5]<<32) |
1013 ((HPT_U64)cdb[6]<<24) |
1014 ((HPT_U64)cdb[7]<<16) |
1015 ((HPT_U64)cdb[8]<<8) |
1017 pCmd->uCmd.Ide.Lba = block;
1018 pCmd->uCmd.Ide.nSectors = (HPT_U16)cdb[13] | ((HPT_U16)cdb[12]<<8);
1023 pCmd->uCmd.Ide.Lba = (HPT_U32)cdb[5] | ((HPT_U32)cdb[4] << 8) | ((HPT_U32)cdb[3] << 16) | ((HPT_U32)cdb[2] << 24);
1024 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[8] | ((HPT_U16)cdb[7]<<8);
1028 if(mIsArray(vd->type)) {
1029 sector_size_shift = vd->u.array.sector_size_shift;
1032 if(vd->type == VD_RAW){
1033 sector_size = vd->u.raw.logical_sector_size;
1036 switch (sector_size) {
1038 KdPrint(("<8>resize sector size from 4k to 512"));
1039 sector_size_shift = 3;
1045 pCmd->uCmd.Ide.Lba <<= sector_size_shift;
1046 pCmd->uCmd.Ide.nSectors <<= sector_size_shift;
1053 pCmd->flags.data_in = 1;
1058 pCmd->flags.data_out = 1;
1061 pCmd->priv = ext = cmdext_get(vbus_ext);
1065 pCmd->done = os_cmddone;
1066 pCmd->buildsgl = os_buildsgl;
1067 pCmd->psg = ext->psg;
1068 pCmd->flags.physical_sg = 1;
1069 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
1071 hpt_io_dmamap_callback, pCmd,
1074 KdPrint(("bus_dmamap_load return %d", error));
1075 if (error && error!=EINPROGRESS) {
1076 os_printk("bus_dmamap_load error %d", error);
1078 ldm_free_cmds(pCmd);
1079 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1086 ccb->ccb_h.status = CAM_REQ_INVALID;
1094 static void hpt_action(struct cam_sim *sim, union ccb *ccb)
1096 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
1098 KdPrint(("hpt_action(fn=%d, id=%d)", ccb->ccb_h.func_code, ccb->ccb_h.target_id));
1100 hpt_assert_vbus_locked(vbus_ext);
1101 switch (ccb->ccb_h.func_code) {
1104 hpt_scsi_io(vbus_ext, ccb);
1108 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
1111 case XPT_GET_TRAN_SETTINGS:
1112 case XPT_SET_TRAN_SETTINGS:
1113 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1116 case XPT_CALC_GEOMETRY:
1117 ccb->ccg.heads = 255;
1118 ccb->ccg.secs_per_track = 63;
1119 ccb->ccg.cylinders = ccb->ccg.volume_size / (ccb->ccg.heads * ccb->ccg.secs_per_track);
1120 ccb->ccb_h.status = CAM_REQ_CMP;
1125 struct ccb_pathinq *cpi = &ccb->cpi;
1127 cpi->version_num = 1;
1128 cpi->hba_inquiry = PI_SDTR_ABLE;
1129 cpi->target_sprt = 0;
1130 cpi->hba_misc = PIM_NOBUSRESET;
1131 cpi->hba_eng_cnt = 0;
1132 cpi->max_target = osm_max_targets;
1134 cpi->unit_number = cam_sim_unit(sim);
1135 cpi->bus_id = cam_sim_bus(sim);
1136 cpi->initiator_id = osm_max_targets;
1137 cpi->base_transfer_speed = 3300;
1139 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1140 strlcpy(cpi->hba_vid, "HPT ", HBA_IDLEN);
1141 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1142 cpi->transport = XPORT_SPI;
1143 cpi->transport_version = 2;
1144 cpi->protocol = PROTO_SCSI;
1145 cpi->protocol_version = SCSI_REV_2;
1146 cpi->ccb_h.status = CAM_REQ_CMP;
1151 ccb->ccb_h.status = CAM_REQ_INVALID;
1159 static void hpt_pci_intr(void *arg)
1161 PVBUS_EXT vbus_ext = (PVBUS_EXT)arg;
1162 hpt_lock_vbus(vbus_ext);
1163 ldm_intr((PVBUS)vbus_ext->vbus);
1164 hpt_unlock_vbus(vbus_ext);
1167 static void hpt_poll(struct cam_sim *sim)
1169 PVBUS_EXT vbus_ext = cam_sim_softc(sim);
1170 hpt_assert_vbus_locked(vbus_ext);
1171 ldm_intr((PVBUS)vbus_ext->vbus);
1174 static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg)
1176 KdPrint(("hpt_async"));
1179 static int hpt_shutdown(device_t dev)
1181 KdPrint(("hpt_shutdown(dev=%p)", dev));
1185 static int hpt_detach(device_t dev)
1187 /* we don't allow the driver to be unloaded. */
1191 static void hpt_ioctl_done(struct _IOCTL_ARG *arg)
1193 arg->ioctl_cmnd = 0;
1197 static void __hpt_do_ioctl(PVBUS_EXT vbus_ext, IOCTL_ARG *ioctl_args)
1199 ioctl_args->result = -1;
1200 ioctl_args->done = hpt_ioctl_done;
1201 ioctl_args->ioctl_cmnd = (void *)1;
1203 hpt_lock_vbus(vbus_ext);
1204 ldm_ioctl((PVBUS)vbus_ext->vbus, ioctl_args);
1206 while (ioctl_args->ioctl_cmnd) {
1207 if (hpt_sleep(vbus_ext, ioctl_args, PPAUSE, "hptctl", HPT_OSM_TIMEOUT)==0)
1209 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
1210 __hpt_do_tasks(vbus_ext);
1213 /* KdPrint(("ioctl %x result %d", ioctl_args->dwIoControlCode, ioctl_args->result)); */
1215 hpt_unlock_vbus(vbus_ext);
1218 static void hpt_do_ioctl(IOCTL_ARG *ioctl_args)
1223 ldm_for_each_vbus(vbus, vbus_ext) {
1224 __hpt_do_ioctl(vbus_ext, ioctl_args);
1225 if (ioctl_args->result!=HPT_IOCTL_RESULT_WRONG_VBUS)
1230 #define HPT_DO_IOCTL(code, inbuf, insize, outbuf, outsize) ({\
1232 arg.dwIoControlCode = code;\
1233 arg.lpInBuffer = inbuf;\
1234 arg.lpOutBuffer = outbuf;\
1235 arg.nInBufferSize = insize;\
1236 arg.nOutBufferSize = outsize;\
1237 arg.lpBytesReturned = 0;\
1238 hpt_do_ioctl(&arg);\
1242 #define DEVICEID_VALID(id) ((id) && ((HPT_U32)(id)!=0xffffffff))
1244 static int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount)
1247 HPT_U32 count = nMaxCount-1;
1249 if (HPT_DO_IOCTL(HPT_IOCTL_GET_LOGICAL_DEVICES,
1250 &count, sizeof(HPT_U32), pIds, sizeof(DEVICEID)*nMaxCount))
1253 nMaxCount = (int)pIds[0];
1254 for (i=0; i<nMaxCount; i++) pIds[i] = pIds[i+1];
1258 static int hpt_get_device_info_v3(DEVICEID id, PLOGICAL_DEVICE_INFO_V3 pInfo)
1260 return HPT_DO_IOCTL(HPT_IOCTL_GET_DEVICE_INFO_V3,
1261 &id, sizeof(DEVICEID), pInfo, sizeof(LOGICAL_DEVICE_INFO_V3));
1264 /* not belong to this file logically, but we want to use ioctl interface */
1265 static int __hpt_stop_tasks(PVBUS_EXT vbus_ext, DEVICEID id)
1267 LOGICAL_DEVICE_INFO_V3 devinfo;
1269 DEVICEID param[2] = { id, 0 };
1271 if (hpt_get_device_info_v3(id, &devinfo))
1274 if (devinfo.Type!=LDT_ARRAY)
1277 if (devinfo.u.array.Flags & ARRAY_FLAG_REBUILDING)
1278 param[1] = AS_REBUILD_ABORT;
1279 else if (devinfo.u.array.Flags & ARRAY_FLAG_VERIFYING)
1280 param[1] = AS_VERIFY_ABORT;
1281 else if (devinfo.u.array.Flags & ARRAY_FLAG_INITIALIZING)
1282 param[1] = AS_INITIALIZE_ABORT;
1283 else if (devinfo.u.array.Flags & ARRAY_FLAG_TRANSFORMING)
1284 param[1] = AS_TRANSFORM_ABORT;
1288 KdPrint(("SET_ARRAY_STATE(%x, %d)", param[0], param[1]));
1289 result = HPT_DO_IOCTL(HPT_IOCTL_SET_ARRAY_STATE,
1290 param, sizeof(param), 0, 0);
1292 for (i=0; i<devinfo.u.array.nDisk; i++)
1293 if (DEVICEID_VALID(devinfo.u.array.Members[i]))
1294 __hpt_stop_tasks(vbus_ext, devinfo.u.array.Members[i]);
1299 static void hpt_stop_tasks(PVBUS_EXT vbus_ext)
1304 count = hpt_get_logical_devices((DEVICEID *)&ids, sizeof(ids)/sizeof(ids[0]));
1306 for (i=0; i<count; i++)
1307 __hpt_stop_tasks(vbus_ext, ids[i]);
1310 static d_open_t hpt_open;
1311 static d_close_t hpt_close;
1312 static d_ioctl_t hpt_ioctl;
1313 static int hpt_rescan_bus(void);
1315 static struct cdevsw hpt_cdevsw = {
1317 .d_close = hpt_close,
1318 .d_ioctl = hpt_ioctl,
1319 .d_name = driver_name,
1320 .d_version = D_VERSION,
1323 static struct intr_config_hook hpt_ich;
1326 * hpt_final_init will be called after all hpt_attach.
1328 static void hpt_final_init(void *dummy)
1330 int i,unit_number=0;
1335 /* Clear the config hook */
1336 config_intrhook_disestablish(&hpt_ich);
1338 /* allocate memory */
1340 ldm_for_each_vbus(vbus, vbus_ext) {
1341 if (hpt_alloc_mem(vbus_ext)) {
1342 os_printk("out of memory");
1350 os_printk("no controller detected.");
1354 /* initializing hardware */
1355 ldm_for_each_vbus(vbus, vbus_ext) {
1356 /* make timer available here */
1357 mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF);
1358 callout_init_mtx(&vbus_ext->timer, &vbus_ext->lock, 0);
1359 if (hpt_init_vbus(vbus_ext)) {
1360 os_printk("fail to initialize hardware");
1365 /* register CAM interface */
1366 ldm_for_each_vbus(vbus, vbus_ext) {
1367 struct cam_devq *devq;
1368 struct ccb_setasync ccb;
1370 if (bus_dma_tag_create(NULL,/* parent */
1372 BUS_SPACE_MAXADDR_32BIT+1, /* boundary */
1373 BUS_SPACE_MAXADDR, /* lowaddr */
1374 BUS_SPACE_MAXADDR, /* highaddr */
1375 NULL, NULL, /* filter, filterarg */
1376 PAGE_SIZE * (os_max_sg_descriptors-1), /* maxsize */
1377 os_max_sg_descriptors, /* nsegments */
1378 0x10000, /* maxsegsize */
1379 BUS_DMA_WAITOK, /* flags */
1380 busdma_lock_mutex, /* lockfunc */
1381 &vbus_ext->lock, /* lockfuncarg */
1382 &vbus_ext->io_dmat /* tag */))
1387 for (i=0; i<os_max_queue_comm; i++) {
1388 POS_CMDEXT ext = (POS_CMDEXT)malloc(sizeof(OS_CMDEXT), M_DEVBUF, M_WAITOK);
1390 os_printk("Can't alloc cmdext(%d)", i);
1393 ext->vbus_ext = vbus_ext;
1394 ext->next = vbus_ext->cmdext_list;
1395 vbus_ext->cmdext_list = ext;
1397 if (bus_dmamap_create(vbus_ext->io_dmat, 0, &ext->dma_map)) {
1398 os_printk("Can't create dma map(%d)", i);
1401 callout_init_mtx(&ext->timeout, &vbus_ext->lock, 0);
1404 if ((devq = cam_simq_alloc(os_max_queue_comm)) == NULL) {
1405 os_printk("cam_simq_alloc failed");
1409 hpt_lock_vbus(vbus_ext);
1410 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name,
1411 vbus_ext, unit_number, &vbus_ext->lock,
1412 os_max_queue_comm, /*tagged*/8, devq);
1414 if (!vbus_ext->sim) {
1415 os_printk("cam_sim_alloc failed");
1416 cam_simq_free(devq);
1417 hpt_unlock_vbus(vbus_ext);
1421 if (xpt_bus_register(vbus_ext->sim, NULL, 0) != CAM_SUCCESS) {
1422 os_printk("xpt_bus_register failed");
1423 cam_sim_free(vbus_ext->sim, /*free devq*/ TRUE);
1424 vbus_ext->sim = NULL;
1428 if (xpt_create_path(&vbus_ext->path, /*periph */ NULL,
1429 cam_sim_path(vbus_ext->sim), CAM_TARGET_WILDCARD,
1430 CAM_LUN_WILDCARD) != CAM_REQ_CMP)
1432 os_printk("xpt_create_path failed");
1433 xpt_bus_deregister(cam_sim_path(vbus_ext->sim));
1434 cam_sim_free(vbus_ext->sim, /*free_devq*/TRUE);
1435 hpt_unlock_vbus(vbus_ext);
1436 vbus_ext->sim = NULL;
1439 hpt_unlock_vbus(vbus_ext);
1441 xpt_setup_ccb(&ccb.ccb_h, vbus_ext->path, /*priority*/5);
1442 ccb.ccb_h.func_code = XPT_SASYNC_CB;
1443 ccb.event_enable = AC_LOST_DEVICE;
1444 ccb.callback = hpt_async;
1445 ccb.callback_arg = vbus_ext;
1446 xpt_action((union ccb *)&ccb);
1448 for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
1450 if ((hba->irq_res = bus_alloc_resource_any(hba->pcidev,
1451 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE)) == NULL)
1453 os_printk("can't allocate interrupt");
1457 if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM | INTR_MPSAFE,
1458 NULL, hpt_pci_intr, vbus_ext, &hba->irq_handle))
1460 os_printk("can't set up interrupt");
1463 hba->ldm_adapter.him->intr_control(hba->ldm_adapter.him_handle, HPT_TRUE);
1467 vbus_ext->shutdown_eh = EVENTHANDLER_REGISTER(shutdown_final,
1468 hpt_shutdown_vbus, vbus_ext, SHUTDOWN_PRI_DEFAULT);
1469 if (!vbus_ext->shutdown_eh)
1470 os_printk("Shutdown event registration failed");
1473 ldm_for_each_vbus(vbus, vbus_ext) {
1474 TASK_INIT(&vbus_ext->worker, 0, (task_fn_t *)hpt_do_tasks, vbus_ext);
1475 if (vbus_ext->tasks)
1476 TASK_ENQUEUE(&vbus_ext->worker);
1479 make_dev(&hpt_cdevsw, DRIVER_MINOR, UID_ROOT, GID_OPERATOR,
1480 S_IRUSR | S_IWUSR, "%s", driver_name);
1483 #if defined(KLD_MODULE)
1485 typedef struct driverlink *driverlink_t;
1487 kobj_class_t driver;
1488 TAILQ_ENTRY(driverlink) link; /* list of drivers in devclass */
1491 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
1494 TAILQ_ENTRY(devclass) link;
1495 devclass_t parent; /* parent in devclass hierarchy */
1496 driver_list_t drivers; /* bus devclasses store drivers for bus */
1498 device_t *devices; /* array of devices indexed by unit */
1499 int maxunit; /* size of devices array */
1502 static void override_kernel_driver(void)
1504 driverlink_t dl, dlfirst;
1505 driver_t *tmpdriver;
1506 devclass_t dc = devclass_find("pci");
1509 dlfirst = TAILQ_FIRST(&dc->drivers);
1510 for (dl = dlfirst; dl; dl = TAILQ_NEXT(dl, link)) {
1511 if(strcmp(dl->driver->name, driver_name) == 0) {
1512 tmpdriver=dl->driver;
1513 dl->driver=dlfirst->driver;
1514 dlfirst->driver=tmpdriver;
1522 #define override_kernel_driver()
1525 static void hpt_init(void *dummy)
1528 os_printk("%s %s", driver_name_long, driver_ver);
1530 override_kernel_driver();
1533 hpt_ich.ich_func = hpt_final_init;
1534 hpt_ich.ich_arg = NULL;
1535 if (config_intrhook_establish(&hpt_ich) != 0) {
1536 printf("%s: cannot establish configuration hook\n",
1541 SYSINIT(hptinit, SI_SUB_CONFIGURE, SI_ORDER_FIRST, hpt_init, NULL);
1544 * CAM driver interface
1546 static device_method_t driver_methods[] = {
1547 /* Device interface */
1548 DEVMETHOD(device_probe, hpt_probe),
1549 DEVMETHOD(device_attach, hpt_attach),
1550 DEVMETHOD(device_detach, hpt_detach),
1551 DEVMETHOD(device_shutdown, hpt_shutdown),
1555 static driver_t hpt_pci_driver = {
1561 static devclass_t hpt_devclass;
1564 #error "no TARGETNAME found"
1567 /* use this to make TARGETNAME be expanded */
1568 #define __DRIVER_MODULE(p1, p2, p3, p4, p5, p6) DRIVER_MODULE(p1, p2, p3, p4, p5, p6)
1569 #define __MODULE_VERSION(p1, p2) MODULE_VERSION(p1, p2)
1570 #define __MODULE_DEPEND(p1, p2, p3, p4, p5) MODULE_DEPEND(p1, p2, p3, p4, p5)
1571 __DRIVER_MODULE(TARGETNAME, pci, hpt_pci_driver, hpt_devclass, 0, 0);
1572 __MODULE_VERSION(TARGETNAME, 1);
1573 __MODULE_DEPEND(TARGETNAME, cam, 1, 1, 1);
1575 static int hpt_open(struct cdev *dev, int flags, int devtype, struct thread *td)
1580 static int hpt_close(struct cdev *dev, int flags, int devtype, struct thread *td)
1585 static int hpt_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
1587 PHPT_IOCTL_PARAM piop=(PHPT_IOCTL_PARAM)data;
1588 IOCTL_ARG ioctl_args;
1589 HPT_U32 bytesReturned = 0;
1592 case HPT_DO_IOCONTROL:
1594 if (piop->Magic == HPT_IOCTL_MAGIC || piop->Magic == HPT_IOCTL_MAGIC32) {
1595 KdPrint(("ioctl=%x in=%p len=%d out=%p len=%d\n",
1596 piop->dwIoControlCode,
1598 piop->nInBufferSize,
1600 piop->nOutBufferSize));
1602 memset(&ioctl_args, 0, sizeof(ioctl_args));
1604 ioctl_args.dwIoControlCode = piop->dwIoControlCode;
1605 ioctl_args.nInBufferSize = piop->nInBufferSize;
1606 ioctl_args.nOutBufferSize = piop->nOutBufferSize;
1607 ioctl_args.lpBytesReturned = &bytesReturned;
1609 if (ioctl_args.nInBufferSize) {
1610 ioctl_args.lpInBuffer = malloc(ioctl_args.nInBufferSize, M_DEVBUF, M_WAITOK);
1611 if (!ioctl_args.lpInBuffer)
1613 if (copyin((void*)piop->lpInBuffer,
1614 ioctl_args.lpInBuffer, piop->nInBufferSize))
1618 if (ioctl_args.nOutBufferSize) {
1619 ioctl_args.lpOutBuffer = malloc(ioctl_args.nOutBufferSize, M_DEVBUF, M_WAITOK | M_ZERO);
1620 if (!ioctl_args.lpOutBuffer)
1624 hpt_do_ioctl(&ioctl_args);
1626 if (ioctl_args.result==HPT_IOCTL_RESULT_OK) {
1627 if (piop->nOutBufferSize) {
1628 if (copyout(ioctl_args.lpOutBuffer,
1629 (void*)piop->lpOutBuffer, piop->nOutBufferSize))
1632 if (piop->lpBytesReturned) {
1633 if (copyout(&bytesReturned,
1634 (void*)piop->lpBytesReturned, sizeof(HPT_U32)))
1637 if (ioctl_args.lpInBuffer) free(ioctl_args.lpInBuffer, M_DEVBUF);
1638 if (ioctl_args.lpOutBuffer) free(ioctl_args.lpOutBuffer, M_DEVBUF);
1642 if (ioctl_args.lpInBuffer) free(ioctl_args.lpInBuffer, M_DEVBUF);
1643 if (ioctl_args.lpOutBuffer) free(ioctl_args.lpOutBuffer, M_DEVBUF);
1651 return hpt_rescan_bus();
1654 KdPrint(("invalid command!"));
1660 static int hpt_rescan_bus(void)
1666 ldm_for_each_vbus(vbus, vbus_ext) {
1667 if ((ccb = xpt_alloc_ccb()) == NULL)
1671 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(vbus_ext->sim),
1672 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP)