1 /* $FreeBSD: src/sys/dev/mpt/mpt_freebsd.h,v 1.3.2.3 2002/09/24 21:37:25 mjacob Exp $ */
2 /* $DragonFly: src/sys/dev/disk/mpt/mpt_freebsd.h,v 1.11 2008/01/06 01:29:00 swildner Exp $ */
4 * LSI MPT Host Adapter FreeBSD Wrapper Definitions (CAM version)
6 * Copyright (c) 2000, 2001 by Greg Ansley, Adam Prewett
8 * Partially derived from Matty Jacobs ISP driver.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * Additional Copyright (c) 2002 by Matthew Jacob under same license.
33 #ifndef _MPT_FREEBSD_H_
34 #define _MPT_FREEBSD_H_
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/queue.h>
40 #include <sys/malloc.h>
43 #include <sys/thread2.h>
45 #include <machine/clock.h>
46 #include <machine/cpu.h>
48 #include <bus/cam/cam.h>
49 #include <bus/cam/cam_debug.h>
50 #include <bus/cam/cam_ccb.h>
51 #include <bus/cam/cam_sim.h>
52 #include <bus/cam/cam_xpt.h>
53 #include <bus/cam/cam_xpt_sim.h>
54 #include <bus/cam/cam_debug.h>
55 #include <bus/cam/scsi/scsi_all.h>
56 #include <bus/cam/scsi/scsi_message.h>
60 #include "mpilib/mpi_type.h"
61 #include "mpilib/mpi.h"
62 #include "mpilib/mpi_cnfg.h"
63 #include "mpilib/mpi_fc.h"
64 #include "mpilib/mpi_init.h"
65 #include "mpilib/mpi_ioc.h"
66 #include "mpilib/mpi_lan.h"
67 #include "mpilib/mpi_targ.h"
70 #define INLINE __inline
73 #define MPT_LOCK(mpt) crit_enter()
74 #define MPT_UNLOCK(mpt) crit_exit()
75 #define MPT_LOCK_SETUP(mpt)
76 #define MPT_LOCK_DESTROY(mpt)
78 /* Max MPT Reply we are willing to accept (must be power of 2) */
79 #define MPT_REPLY_SIZE 128
81 #define MPT_MAX_REQUESTS(mpt) ((mpt)->is_fc? 1024 : 256)
82 #define MPT_REQUEST_AREA 512
83 #define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_SIZE */
84 #define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
87 * We cannot tell prior to getting IOC facts how big the IOC's request
88 * area is. Because of this we cannot tell at compile time how many
89 * simple SG elements we can fit within an IOC request prior to having
90 * to put in a chain element.
92 * Experimentally we know that the Ultra4 parts have a 96 byte request
93 * element size and the Fibre Channel units have a 144 byte request
94 * element size. Therefore, if we have 512-32 (== 480) bytes of request
95 * area to play with, we have room for between 3 and 5 request sized
96 * regions- the first of which is the command plus a simple SG list,
97 * the rest of which are chained continuation SG lists. Given that the
98 * normal request we use is 48 bytes w/o the first SG element, we can
99 * assume we have 480-48 == 432 bytes to have simple SG elements and/or
100 * chain elements. If we assume 32 bit addressing, this works out to
101 * 54 SG or chain elements. If we assume 5 chain elements, then we have
102 * a maximum of 49 separate actual SG segments.
105 #define MPT_SGL_MAX 49
107 #define MPT_RQSL(mpt) (mpt->request_frame_size << 2)
108 #define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_SIMPLE32))
110 #define MPT_NSGL_FIRST(mpt) \
111 (((mpt->request_frame_size << 2) - \
112 sizeof (MSG_SCSI_IO_REQUEST) - \
113 sizeof (SGE_IO_UNION)) / sizeof (SGE_SIMPLE32))
116 * Convert a physical address returned from IOC to kvm address
117 * needed to access the data.
119 #define MPT_REPLY_PTOV(m, x) \
120 ((void *)(&m->reply[((x << 1) - m->reply_phys)]))
122 #define ccb_mpt_ptr sim_priv.entries[0].ptr
123 #define ccb_req_ptr sim_priv.entries[1].ptr
126 REQ_FREE, REQ_IN_PROGRESS, REQ_TIMEOUT, REQ_ON_CHIP, REQ_DONE
128 typedef struct req_entry {
129 u_int16_t index; /* Index of this entry */
130 union ccb * ccb; /* CAM request */
131 void * req_vbuf; /* Virtual Address of Entry */
132 void * sense_vbuf; /* Virtual Address of sense data */
133 bus_addr_t req_pbuf; /* Physical Address of Entry */
134 bus_addr_t sense_pbuf; /* Physical Address of sense data */
135 bus_dmamap_t dmap; /* DMA map for data buffer */
136 SLIST_ENTRY(req_entry) link; /* Pointer to next in list */
137 enum mpt_req_state debug; /* Debugging */
138 u_int32_t sequence; /* Sequence Number */
139 struct callout timeout;
143 /* Structure for saving proper values for modifyable PCI configuration registers */
146 u_int16_t LatencyTimer_LineSize;
148 u_int32_t Mem0_BAR[2];
149 u_int32_t Mem1_BAR[2];
155 typedef struct mpt_softc {
165 bus : 1; /* FC929/1030 have two busses */
170 u_int16_t mpt_global_credits;
171 u_int16_t request_frame_size;
172 u_int8_t mpt_max_devices;
173 u_int8_t mpt_max_buses;
178 u_int16_t mpt_ini_id;
182 * Device Configuration Information
186 fCONFIG_PAGE_SCSI_PORT_0 _port_page0;
187 fCONFIG_PAGE_SCSI_PORT_1 _port_page1;
188 fCONFIG_PAGE_SCSI_PORT_2 _port_page2;
189 fCONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16];
190 fCONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16];
191 uint16_t _tag_enable;
192 uint16_t _disc_enable;
193 uint16_t _update_params0;
194 uint16_t _update_params1;
196 #define mpt_port_page0 cfg.spi._port_page0
197 #define mpt_port_page1 cfg.spi._port_page1
198 #define mpt_port_page2 cfg.spi._port_page2
199 #define mpt_dev_page0 cfg.spi._dev_page0
200 #define mpt_dev_page1 cfg.spi._dev_page1
201 #define mpt_tag_enable cfg.spi._tag_enable
202 #define mpt_disc_enable cfg.spi._disc_enable
203 #define mpt_update_params0 cfg.spi._update_params0
204 #define mpt_update_params1 cfg.spi._update_params1
213 struct resource * pci_irq; /* Interrupt map for chip */
214 void * ih; /* Interupt handle */
215 struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */
221 struct resource * pci_reg; /* Register map for chip */
222 int pci_reg_id; /* Resource ID */
223 bus_space_tag_t pci_st; /* Bus tag for registers */
224 bus_space_handle_t pci_sh; /* Bus handle for registers */
225 vm_offset_t pci_pa; /* Physical Address */
227 bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */
228 bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */
229 bus_dmamap_t reply_dmap; /* DMA map for reply memory */
230 char * reply; /* KVA of reply memory */
231 bus_addr_t reply_phys; /* BusAddr of reply memory */
234 bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */
235 bus_dma_tag_t request_dmat; /* DMA tag for request memroy */
236 bus_dmamap_t request_dmap; /* DMA map for request memroy */
237 char * request; /* KVA of Request memory */
238 bus_addr_t request_phys; /* BusADdr of request memory */
241 * CAM && Software Management
244 request_t * request_pool;
245 SLIST_HEAD(req_queue, req_entry) request_free_list;
247 struct cam_sim * sim;
248 struct cam_path * path;
250 u_int32_t sequence; /* Sequence Number */
251 u_int32_t timeouts; /* timeout count */
252 u_int32_t success; /* successes afer timeout */
254 /* Opposing port in a 929 or 1030, or NULL */
255 struct mpt_softc * mpt2;
262 static INLINE void mpt_write(mpt_softc_t *, size_t, u_int32_t);
263 static INLINE u_int32_t mpt_read(mpt_softc_t *, int);
266 mpt_write(mpt_softc_t *mpt, size_t offset, u_int32_t val)
268 bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val);
271 static INLINE u_int32_t
272 mpt_read(mpt_softc_t *mpt, int offset)
274 return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset));
277 void mpt_cam_attach(mpt_softc_t *);
278 void mpt_cam_detach(mpt_softc_t *);
279 void mpt_done(mpt_softc_t *, u_int32_t);
280 void mpt_set_config_regs(mpt_softc_t *);
282 #endif /* _MPT_FREEBSD_H */