1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4b063a422SScott Long * Copyright (c) HighPoint Technologies, Inc.
5b063a422SScott Long * All rights reserved.
6b063a422SScott Long *
7b063a422SScott Long * Redistribution and use in source and binary forms, with or without
8b063a422SScott Long * modification, are permitted provided that the following conditions
9b063a422SScott Long * are met:
10b063a422SScott Long * 1. Redistributions of source code must retain the above copyright
11b063a422SScott Long * notice, this list of conditions and the following disclaimer.
12b063a422SScott Long * 2. Redistributions in binary form must reproduce the above copyright
13b063a422SScott Long * notice, this list of conditions and the following disclaimer in the
14b063a422SScott Long * documentation and/or other materials provided with the distribution.
15b063a422SScott Long *
16b063a422SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17b063a422SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b063a422SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b063a422SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20b063a422SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b063a422SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b063a422SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b063a422SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b063a422SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b063a422SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b063a422SScott Long * SUCH DAMAGE.
27b063a422SScott Long */
28b063a422SScott Long #include <dev/hptrr/hptrr_config.h>
29b063a422SScott Long /* $Id: os_bsd.h,v 1.18 2006/04/11 08:19:02 gmm Exp $
30b063a422SScott Long *
31b063a422SScott Long * HighPoint RAID Driver for FreeBSD
32b063a422SScott Long * Copyright (C) 2005 HighPoint Technologies, Inc. All Rights Reserved.
33b063a422SScott Long */
34b063a422SScott Long
35b063a422SScott Long #ifndef _OS_BSD_H
36b063a422SScott Long #define _OS_BSD_H
37b063a422SScott Long
384fdb276aSScott Long #ifndef DBG
394fdb276aSScott Long #define DBG 0
404fdb276aSScott Long #endif
414fdb276aSScott Long
42b063a422SScott Long #include <sys/param.h>
43b063a422SScott Long #include <sys/types.h>
44b063a422SScott Long #include <sys/cons.h>
45b063a422SScott Long #include <sys/time.h>
46b063a422SScott Long #include <sys/systm.h>
47b063a422SScott Long
48b063a422SScott Long #include <sys/stat.h>
49b063a422SScott Long #include <sys/malloc.h>
50b063a422SScott Long #include <sys/conf.h>
51b063a422SScott Long #include <sys/libkern.h>
52b063a422SScott Long #include <sys/kernel.h>
53b063a422SScott Long
54b063a422SScott Long #include <sys/kthread.h>
55b063a422SScott Long #include <sys/mutex.h>
56b063a422SScott Long #include <sys/module.h>
57b063a422SScott Long
58b063a422SScott Long #include <sys/eventhandler.h>
59b063a422SScott Long #include <sys/bus.h>
60b063a422SScott Long #include <sys/taskqueue.h>
61b063a422SScott Long #include <sys/ioccom.h>
62b063a422SScott Long
63b063a422SScott Long #include <machine/resource.h>
64b063a422SScott Long #include <machine/bus.h>
65b063a422SScott Long #include <machine/stdarg.h>
66b063a422SScott Long #include <sys/rman.h>
67b063a422SScott Long
68b063a422SScott Long #include <vm/vm.h>
69b063a422SScott Long #include <vm/pmap.h>
70b063a422SScott Long
71b063a422SScott Long #include <dev/pci/pcireg.h>
72b063a422SScott Long #include <dev/pci/pcivar.h>
73b063a422SScott Long
74b063a422SScott Long #include <cam/cam.h>
75b063a422SScott Long #include <cam/cam_ccb.h>
76b063a422SScott Long #include <cam/cam_sim.h>
77b063a422SScott Long #include <cam/cam_xpt_sim.h>
78b063a422SScott Long #include <cam/cam_debug.h>
79b063a422SScott Long #include <cam/cam_periph.h>
80b063a422SScott Long #include <cam/scsi/scsi_all.h>
81b063a422SScott Long #include <cam/scsi/scsi_message.h>
82b063a422SScott Long
83b063a422SScott Long
84b063a422SScott Long
85b063a422SScott Long typedef struct _INQUIRYDATA {
86b063a422SScott Long u_char DeviceType : 5;
87b063a422SScott Long u_char DeviceTypeQualifier : 3;
88b063a422SScott Long u_char DeviceTypeModifier : 7;
89b063a422SScott Long u_char RemovableMedia : 1;
90b063a422SScott Long u_char Versions;
91b063a422SScott Long u_char ResponseDataFormat;
92b063a422SScott Long u_char AdditionalLength;
93b063a422SScott Long u_char Reserved[2];
94b063a422SScott Long u_char SoftReset : 1;
95b063a422SScott Long u_char CommandQueue : 1;
96b063a422SScott Long u_char Reserved2 : 1;
97b063a422SScott Long u_char LinkedCommands : 1;
98b063a422SScott Long u_char Synchronous : 1;
99b063a422SScott Long u_char Wide16Bit : 1;
100b063a422SScott Long u_char Wide32Bit : 1;
101b063a422SScott Long u_char RelativeAddressing : 1;
102b063a422SScott Long u_char VendorId[8];
103b063a422SScott Long u_char ProductId[16];
104b063a422SScott Long u_char ProductRevisionLevel[4];
105b063a422SScott Long u_char VendorSpecific[20];
106b063a422SScott Long u_char Reserved3[40];
107b063a422SScott Long }
108b063a422SScott Long __attribute__((packed))
109b063a422SScott Long INQUIRYDATA, *PINQUIRYDATA;
110b063a422SScott Long
111b063a422SScott Long #endif
112b063a422SScott Long
113b063a422SScott Long /* private headers */
114b063a422SScott Long
115b063a422SScott Long #include <dev/hptrr/osm.h>
116b063a422SScott Long #include <dev/hptrr/him.h>
117b063a422SScott Long #include <dev/hptrr/ldm.h>
118b063a422SScott Long
119b063a422SScott Long /* driver parameters */
120b063a422SScott Long extern char driver_name[];
121b063a422SScott Long extern char driver_name_long[];
122b063a422SScott Long extern char driver_ver[];
123b063a422SScott Long extern int osm_max_targets;
124b063a422SScott Long
125b063a422SScott Long /*
126b063a422SScott Long * adapter/vbus extensions:
127b063a422SScott Long * each physical controller has an adapter_ext, passed to him.create_adapter()
128b063a422SScott Long * each vbus has a vbus_ext passed to ldm_create_vbus().
129b063a422SScott Long */
130b063a422SScott Long #define EXT_TYPE_HBA 1
131b063a422SScott Long #define EXT_TYPE_VBUS 2
132b063a422SScott Long
133b063a422SScott Long typedef struct _hba {
134b063a422SScott Long int ext_type;
135b063a422SScott Long LDM_ADAPTER ldm_adapter;
136b063a422SScott Long device_t pcidev;
137b063a422SScott Long PCI_ADDRESS pciaddr;
138b063a422SScott Long struct _vbus_ext *vbus_ext;
139b063a422SScott Long struct _hba *next;
140b063a422SScott Long
141b063a422SScott Long struct {
142b063a422SScott Long struct resource *res;
143b063a422SScott Long int type;
144b063a422SScott Long int rid;
145b063a422SScott Long void *base;
146b063a422SScott Long }
147b063a422SScott Long pcibar[6];
148b063a422SScott Long
149b063a422SScott Long struct resource *irq_res;
150b063a422SScott Long void *irq_handle;
151b063a422SScott Long }
152b063a422SScott Long HBA, *PHBA;
153b063a422SScott Long
154b063a422SScott Long typedef struct _os_cmdext {
155b063a422SScott Long struct _vbus_ext *vbus_ext;
156b063a422SScott Long struct _os_cmdext *next;
157b063a422SScott Long union ccb *ccb;
158b063a422SScott Long bus_dmamap_t dma_map;
15904584935SJohn Baldwin struct callout timeout;
160b063a422SScott Long SG psg[os_max_sg_descriptors];
161b063a422SScott Long }
162b063a422SScott Long OS_CMDEXT, *POS_CMDEXT;
163b063a422SScott Long
164b063a422SScott Long typedef struct _vbus_ext {
165b063a422SScott Long int ext_type;
166b063a422SScott Long struct _vbus_ext *next;
167b063a422SScott Long PHBA hba_list;
168b063a422SScott Long struct freelist *freelist_head;
169b063a422SScott Long struct freelist *freelist_dma_head;
170b063a422SScott Long
171b063a422SScott Long struct cam_sim *sim; /* sim for this vbus */
172b063a422SScott Long struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */
173b063a422SScott Long struct mtx lock; /* general purpose lock */
174b063a422SScott Long bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */
175b063a422SScott Long
176b063a422SScott Long POS_CMDEXT cmdext_list;
177b063a422SScott Long
178b063a422SScott Long OSM_TASK *tasks;
179b063a422SScott Long struct task worker;
180b063a422SScott Long
18104584935SJohn Baldwin struct callout timer;
182b063a422SScott Long
183b063a422SScott Long eventhandler_tag shutdown_eh;
184b063a422SScott Long
185b063a422SScott Long /* the LDM vbus instance continues */
186b063a422SScott Long unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long))));
187b063a422SScott Long }
188b063a422SScott Long VBUS_EXT, *PVBUS_EXT;
189b063a422SScott Long
190b063a422SScott Long #define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock)
191b063a422SScott Long #define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock)
19204584935SJohn Baldwin #define hpt_assert_vbus_locked(vbus_ext) mtx_assert(&(vbus_ext)->lock, MA_OWNED)
193b063a422SScott Long
194b063a422SScott Long
195b063a422SScott Long #define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */
196b063a422SScott Long
197b063a422SScott Long #define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM)
198b063a422SScott Long
199b063a422SScott Long #define HPT_SCAN_BUS _IO('H', 1)
200b063a422SScott Long
201b063a422SScott Long #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task));
202b063a422SScott Long
hpt_sleep(PVBUS_EXT vbus_ext,void * ident,int priority,const char * wmesg,int timo)203b063a422SScott Long static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo)
204b063a422SScott Long {
205b063a422SScott Long return msleep(ident, &vbus_ext->lock, priority, wmesg, timo);
206b063a422SScott Long }
207