3 * Generic defines for LSI '909 FC adapters.
6 * Copyright (c) 2000, 2001 by Greg Ansley
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Copyright (c) 2002, 2006 by Matthew Jacob
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions are
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
39 * substantially similar to the "NO WARRANTY" disclaimer below
40 * ("Disclaimer") and any redistribution must be conditioned upon including
41 * a substantially similar Disclaimer requirement for further binary
43 * 3. Neither the names of the above listed copyright holders nor the names
44 * of any contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
57 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 * Support from Chris Ellsworth in order to make SAS adapters work
60 * is gratefully acknowledged.
63 * Support from LSI-Logic has also gone a great deal toward making this a
64 * workable subsystem and is gratefully acknowledged.
67 * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
68 * Copyright (c) 2004, 2005 Justin T. Gibbs
69 * Copyright (c) 2005, WHEEL Sp. z o.o.
70 * All rights reserved.
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions are
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
78 * substantially similar to the "NO WARRANTY" disclaimer below
79 * ("Disclaimer") and any redistribution must be conditioned upon including
80 * a substantially similar Disclaimer requirement for further binary
82 * 3. Neither the names of the above listed copyright holders nor the names
83 * of any contributors may be used to endorse or promote products derived
84 * from this software without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
90 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
91 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
92 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
93 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
94 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
95 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
96 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 /********************************* OS Includes ********************************/
103 #include <sys/param.h>
104 #include <sys/systm.h>
106 #include <sys/condvar.h>
107 #include <sys/endian.h>
108 #include <sys/eventhandler.h>
109 #include <sys/kernel.h>
110 #include <sys/lock.h>
111 #include <sys/malloc.h>
112 #include <sys/module.h>
113 #include <sys/mutex.h>
114 #include <sys/proc.h>
115 #include <sys/queue.h>
116 #include <sys/rman.h>
117 #include <sys/types.h>
119 #include <machine/bus.h>
120 #include <machine/cpu.h>
121 #include <machine/resource.h>
124 #include <dev/ofw/openfirm.h>
125 #include <machine/ofw_machdep.h>
128 #include <dev/pci/pcireg.h>
129 #include <dev/pci/pcivar.h>
133 /**************************** Register Definitions ****************************/
134 #include <dev/mpt/mpt_reg.h>
136 /******************************* MPI Definitions ******************************/
137 #include <dev/mpt/mpilib/mpi_type.h>
138 #include <dev/mpt/mpilib/mpi.h>
139 #include <dev/mpt/mpilib/mpi_cnfg.h>
140 #include <dev/mpt/mpilib/mpi_ioc.h>
141 #include <dev/mpt/mpilib/mpi_raid.h>
143 /* XXX For mpt_debug.c */
144 #include <dev/mpt/mpilib/mpi_init.h>
146 #define MPT_S64_2_SCALAR(y) ((((int64_t)y.High) << 32) | (y.Low))
147 #define MPT_U64_2_SCALAR(y) ((((uint64_t)y.High) << 32) | (y.Low))
149 /****************************** Misc Definitions ******************************/
150 /* #define MPT_TEST_MULTIPATH 1 */
152 #define MPT_FAIL (0x10000)
154 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
156 #define MPT_ROLE_NONE 0
157 #define MPT_ROLE_INITIATOR 1
158 #define MPT_ROLE_TARGET 2
159 #define MPT_ROLE_BOTH 3
160 #define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR
162 #define MPT_INI_ID_NONE -1
164 /**************************** Forward Declarations ****************************/
166 struct mpt_personality;
167 typedef struct req_entry request_t;
169 /************************* Personality Module Support *************************/
170 typedef int mpt_load_handler_t(struct mpt_personality *);
171 typedef int mpt_probe_handler_t(struct mpt_softc *);
172 typedef int mpt_attach_handler_t(struct mpt_softc *);
173 typedef int mpt_enable_handler_t(struct mpt_softc *);
174 typedef void mpt_ready_handler_t(struct mpt_softc *);
175 typedef int mpt_event_handler_t(struct mpt_softc *, request_t *,
176 MSG_EVENT_NOTIFY_REPLY *);
177 typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/);
178 /* XXX Add return value and use for veto? */
179 typedef void mpt_shutdown_handler_t(struct mpt_softc *);
180 typedef void mpt_detach_handler_t(struct mpt_softc *);
181 typedef int mpt_unload_handler_t(struct mpt_personality *);
183 struct mpt_personality
186 uint32_t id; /* Assigned identifier. */
187 u_int use_count; /* Instances using personality*/
188 mpt_load_handler_t *load; /* configure personailty */
189 #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load)
190 mpt_probe_handler_t *probe; /* configure personailty */
191 mpt_attach_handler_t *attach; /* initialize device instance */
192 mpt_enable_handler_t *enable; /* enable device */
193 mpt_ready_handler_t *ready; /* final open for business */
194 mpt_event_handler_t *event; /* Handle MPI event. */
195 mpt_reset_handler_t *reset; /* Re-init after reset. */
196 mpt_shutdown_handler_t *shutdown; /* Shutdown instance. */
197 mpt_detach_handler_t *detach; /* release device instance */
198 mpt_unload_handler_t *unload; /* Shutdown personality */
199 #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload)
202 int mpt_modevent(module_t, int, void *);
204 /* Maximum supported number of personalities. */
205 #define MPT_MAX_PERSONALITIES (15)
207 #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \
208 MODULE_DEPEND(name, dep, vmin, vpref, vmax)
210 #define DECLARE_MPT_PERSONALITY(name, order) \
211 static moduledata_t name##_mod = { \
212 #name, mpt_modevent, &name##_personality \
214 DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order); \
215 MODULE_VERSION(name, 1); \
216 MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1)
218 /******************************* Bus DMA Support ******************************/
219 /* XXX Need to update bus_dmamap_sync to take a range argument. */
220 #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \
221 bus_dmamap_sync(dma_tag, dmamap, op)
223 #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \
224 lowaddr, highaddr, filter, filterarg, \
225 maxsize, nsegments, maxsegsz, flags, \
227 bus_dma_tag_create(parent_tag, alignment, boundary, \
228 lowaddr, highaddr, filter, filterarg, \
229 maxsize, nsegments, maxsegsz, flags, \
230 busdma_lock_mutex, &(mpt)->mpt_lock, \
232 struct mpt_map_info {
233 struct mpt_softc *mpt;
238 void mpt_map_rquest(void *, bus_dma_segment_t *, int, int);
240 /********************************* Endianness *********************************/
241 #define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag)
242 #define MPT_2_HOST32(ptr, tag) ptr->tag = le32toh(ptr->tag)
243 #define MPT_2_HOST16(ptr, tag) ptr->tag = le16toh(ptr->tag)
245 #define HOST_2_MPT64(ptr, tag) ptr->tag = htole64(ptr->tag)
246 #define HOST_2_MPT32(ptr, tag) ptr->tag = htole32(ptr->tag)
247 #define HOST_2_MPT16(ptr, tag) ptr->tag = htole16(ptr->tag)
249 #if _BYTE_ORDER == _BIG_ENDIAN
250 void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *);
251 void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *);
252 void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *);
253 void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *);
254 void mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *);
255 void mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *);
256 void mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
257 void host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
258 void mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *);
259 void mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *);
260 void mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
261 void host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
262 void mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *);
263 void mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
264 void host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
265 void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *);
266 void mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *);
267 void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *);
269 #define mpt2host_sge_simple_union(x) do { ; } while (0)
270 #define mpt2host_iocfacts_reply(x) do { ; } while (0)
271 #define mpt2host_portfacts_reply(x) do { ; } while (0)
272 #define mpt2host_config_page_ioc2(x) do { ; } while (0)
273 #define mpt2host_config_page_ioc3(x) do { ; } while (0)
274 #define mpt2host_config_page_scsi_port_0(x) do { ; } while (0)
275 #define mpt2host_config_page_scsi_port_1(x) do { ; } while (0)
276 #define host2mpt_config_page_scsi_port_1(x) do { ; } while (0)
277 #define mpt2host_config_page_scsi_port_2(x) do { ; } while (0)
278 #define mpt2host_config_page_scsi_device_0(x) do { ; } while (0)
279 #define mpt2host_config_page_scsi_device_1(x) do { ; } while (0)
280 #define host2mpt_config_page_scsi_device_1(x) do { ; } while (0)
281 #define mpt2host_config_page_fc_port_0(x) do { ; } while (0)
282 #define mpt2host_config_page_fc_port_1(x) do { ; } while (0)
283 #define host2mpt_config_page_fc_port_1(x) do { ; } while (0)
284 #define mpt2host_config_page_raid_vol_0(x) do { ; } while (0)
285 #define mpt2host_config_page_raid_phys_disk_0(x) \
287 #define mpt2host_mpi_raid_vol_indicator(x) do { ; } while (0)
290 /**************************** MPI Transaction State ***************************/
292 REQ_STATE_NIL = 0x00,
293 REQ_STATE_FREE = 0x01,
294 REQ_STATE_ALLOCATED = 0x02,
295 REQ_STATE_QUEUED = 0x04,
296 REQ_STATE_DONE = 0x08,
297 REQ_STATE_TIMEDOUT = 0x10,
298 REQ_STATE_NEED_WAKEUP = 0x20,
299 REQ_STATE_LOCKED = 0x80, /* can't be freed */
300 REQ_STATE_MASK = 0xFF
304 TAILQ_ENTRY(req_entry) links; /* Pointer to next in list */
305 mpt_req_state_t state; /* Request State Information */
306 uint16_t index; /* Index of this entry */
307 uint16_t IOCStatus; /* Completion status */
308 uint16_t ResponseCode; /* TMF Response Code */
309 uint16_t serno; /* serial number */
310 union ccb *ccb; /* CAM request */
311 void *req_vbuf; /* Virtual Address of Entry */
312 void *sense_vbuf; /* Virtual Address of sense data */
313 bus_addr_t req_pbuf; /* Physical Address of Entry */
314 bus_addr_t sense_pbuf; /* Physical Address of sense data */
315 bus_dmamap_t dmap; /* DMA map for data buffers */
316 struct req_entry *chain; /* for SGE overallocations */
317 struct callout callout; /* Timeout for the request */
320 typedef struct mpt_config_params {
331 /**************************** MPI Target State Info ***************************/
333 uint32_t reply_desc; /* current reply descriptor */
334 uint32_t resid; /* current data residual */
335 uint32_t bytes_xfered; /* current relative offset */
336 union ccb *ccb; /* pointer to currently active ccb */
337 request_t *req; /* pointer to currently active assist request */
347 TGT_STATE_SETTING_UP_FOR_DATA,
348 TGT_STATE_MOVING_DATA,
349 TGT_STATE_MOVING_DATA_AND_STATUS,
350 TGT_STATE_SENDING_STATUS
355 * When we get an incoming command it has its own tag which is called the
356 * IoIndex. This is the value we gave that particular command buffer when
357 * we originally assigned it. It's just a number, really. The FC card uses
358 * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which
359 * contains pointers the request_t structures related to that IoIndex.
361 * What *we* do is construct a tag out of the index for the target command
362 * which owns the incoming ATIO plus a rolling sequence number.
364 #define MPT_MAKE_TAGID(mpt, req, ioindex) \
365 ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff))
368 #define MPT_TAG_2_REQ(a, b) mpt_tag_2_req(a, (uint32_t) b)
370 #define MPT_TAG_2_REQ(mpt, tag) mpt->tgt_cmd_ptrs[tag >> 18]
373 #define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \
374 (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)]))
376 STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr);
377 #define MPT_MAX_LUNS 256
379 struct mpt_hdr_stailq atios;
380 struct mpt_hdr_stailq inots;
383 #define MPT_MAX_ELS 64
385 /**************************** Handler Registration ****************************/
387 * Global table of registered reply handlers. The
388 * handler is indicated by byte 3 of the request
389 * index submitted to the IOC. This allows the
390 * driver core to perform generic processing without
391 * any knowledge of per-personality behavior.
393 * MPT_NUM_REPLY_HANDLERS must be a power of 2
394 * to allow the easy generation of a mask.
396 * The handler offsets used by the core are hard coded
397 * allowing faster code generation when assigning a handler
398 * to a request. All "personalities" must use the
399 * the handler registration mechanism.
401 * The IOC handlers that are rarely executed are placed
402 * at the tail of the table to make it more likely that
403 * all commonly executed handlers fit in a single cache
406 #define MPT_NUM_REPLY_HANDLERS (32)
407 #define MPT_REPLY_HANDLER_EVENTS MPT_CBI_TO_HID(0)
408 #define MPT_REPLY_HANDLER_CONFIG MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1)
409 #define MPT_REPLY_HANDLER_HANDSHAKE MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2)
410 typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request,
411 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame);
413 mpt_reply_handler_t *reply_handler;
423 struct mpt_handler_record
425 LIST_ENTRY(mpt_handler_record) links;
426 mpt_handler_t handler;
429 LIST_HEAD(mpt_handler_list, mpt_handler_record);
432 * The handler_id is currently unused but would contain the
433 * handler ID used in the MsgContext field to allow direction
434 * of replies to the handler. Registrations that don't require
435 * a handler id can pass in NULL for the handler_id.
437 * Deregistrations for handlers without a handler id should
438 * pass in MPT_HANDLER_ID_NONE.
440 #define MPT_HANDLER_ID_NONE (0xFFFFFFFF)
441 int mpt_register_handler(struct mpt_softc *, mpt_handler_type,
442 mpt_handler_t, uint32_t *);
443 int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type,
444 mpt_handler_t, uint32_t);
446 /******************* Per-Controller Instance Data Structures ******************/
447 TAILQ_HEAD(req_queue, req_entry);
449 /* Structure for saving proper values for modifyable PCI config registers */
452 uint16_t LatencyTimer_LineSize;
454 uint32_t Mem0_BAR[2];
455 uint32_t Mem1_BAR[2];
463 MPT_RVF_ACTIVE = 0x1,
464 MPT_RVF_ANNOUNCED = 0x2,
465 MPT_RVF_UP2DATE = 0x4,
466 MPT_RVF_REFERENCED = 0x8,
467 MPT_RVF_WCE_CHANGED = 0x10
468 } mpt_raid_volume_flags;
470 struct mpt_raid_volume {
471 CONFIG_PAGE_RAID_VOL_0 *config_page;
472 MPI_RAID_VOL_INDICATOR sync_progress;
473 mpt_raid_volume_flags flags;
474 u_int quiesced_disks;
479 MPT_RDF_ACTIVE = 0x01,
480 MPT_RDF_ANNOUNCED = 0x02,
481 MPT_RDF_UP2DATE = 0x04,
482 MPT_RDF_REFERENCED = 0x08,
483 MPT_RDF_QUIESCING = 0x10,
484 MPT_RDF_QUIESCED = 0x20
485 } mpt_raid_disk_flags;
487 struct mpt_raid_disk {
488 CONFIG_PAGE_RAID_PHYS_DISK_0 config_page;
489 struct mpt_raid_volume *volume;
491 u_int pass_thru_active;
492 mpt_raid_disk_flags flags;
495 struct mpt_evtf_record {
496 MSG_EVENT_NOTIFY_REPLY reply;
498 LIST_ENTRY(mpt_evtf_record) links;
501 LIST_HEAD(mpt_evtf_list, mpt_evtf_record);
503 struct mptsas_devinfo {
505 uint16_t parent_dev_handle;
506 uint16_t enclosure_handle;
509 uint8_t physical_port;
512 uint64_t sas_address;
513 uint32_t device_info;
516 struct mptsas_phyinfo {
520 uint8_t negotiated_link_rate;
521 uint8_t hw_link_rate;
522 uint8_t programmed_link_rate;
523 uint8_t sas_port_add_phy;
524 struct mptsas_devinfo identify;
525 struct mptsas_devinfo attached;
528 struct mptsas_portinfo {
530 struct mptsas_phyinfo *phy_info;
537 uint32_t mpt_pers_mask;
560 u_int role; /* role: none, ini, target, both */
563 #ifdef MPT_TEST_MULTIPATH
570 MSG_IOC_FACTS_REPLY ioc_facts;
575 MSG_PORT_FACTS_REPLY * port_facts;
576 #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers
579 * Device Configuration Information
583 CONFIG_PAGE_SCSI_PORT_0 _port_page0;
584 CONFIG_PAGE_SCSI_PORT_1 _port_page1;
585 CONFIG_PAGE_SCSI_PORT_2 _port_page2;
586 CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16];
587 CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16];
589 uint16_t _tag_enable;
590 uint16_t _disc_enable;
592 #define mpt_port_page0 cfg.spi._port_page0
593 #define mpt_port_page1 cfg.spi._port_page1
594 #define mpt_port_page2 cfg.spi._port_page2
595 #define mpt_dev_page0 cfg.spi._dev_page0
596 #define mpt_dev_page1 cfg.spi._dev_page1
597 #define mpt_ini_id cfg.spi._ini_id
598 #define mpt_tag_enable cfg.spi._tag_enable
599 #define mpt_disc_enable cfg.spi._disc_enable
601 CONFIG_PAGE_FC_PORT_0 _port_page0;
602 uint32_t _port_speed;
603 #define mpt_fcport_page0 cfg.fc._port_page0
604 #define mpt_fcport_speed cfg.fc._port_speed
608 * Device config information stored up for sysctl to access
612 unsigned int initiator_id;
620 /* Controller Info for RAID information */
621 CONFIG_PAGE_IOC_2 * ioc_page2;
622 CONFIG_PAGE_IOC_3 * ioc_page3;
625 struct mpt_raid_volume* raid_volumes;
626 struct mpt_raid_disk* raid_disks;
627 u_int raid_max_volumes;
628 u_int raid_max_disks;
629 u_int raid_page0_len;
632 u_int raid_resync_rate;
633 u_int raid_mwce_setting;
634 u_int raid_queue_depth;
635 u_int raid_nonopt_volumes;
636 struct proc *raid_thread;
637 struct callout raid_timer;
642 struct resource * pci_irq; /* Interrupt map for chip */
643 void * ih; /* Interrupt handle */
645 struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */
651 struct resource * pci_reg; /* Register map for chip */
652 bus_space_tag_t pci_st; /* Bus tag for registers */
653 bus_space_handle_t pci_sh; /* Bus handle for registers */
654 /* PIO versions of above. */
655 struct resource * pci_pio_reg;
656 bus_space_tag_t pci_pio_st;
657 bus_space_handle_t pci_pio_sh;
659 bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */
660 bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */
661 bus_dmamap_t reply_dmap; /* DMA map for reply memory */
662 uint8_t *reply; /* KVA of reply memory */
663 bus_addr_t reply_phys; /* BusAddr of reply memory */
665 bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */
666 bus_dma_tag_t request_dmat; /* DMA tag for request memory */
667 bus_dmamap_t request_dmap; /* DMA map for request memory */
668 uint8_t *request; /* KVA of Request memory */
669 bus_addr_t request_phys; /* BusAddr of request memory */
671 uint32_t max_seg_cnt; /* calculated after IOC facts */
672 uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/
675 * Hardware management
680 * CAM && Software Management
682 request_t *request_pool;
683 struct req_queue request_free_list;
684 struct req_queue request_pending_list;
685 struct req_queue request_timeout_list;
689 struct cam_path *path;
691 struct cam_sim *phydisk_sim;
692 struct cam_path *phydisk_path;
694 struct proc *recovery_thread;
698 * Deferred frame acks due to resource shortage.
700 struct mpt_evtf_list ack_frames;
703 * Target Mode Support
705 uint32_t scsi_tgt_handler_id;
706 request_t ** tgt_cmd_ptrs;
707 request_t ** els_cmd_ptrs; /* FC only */
710 * *snork*- this is chosen to be here *just in case* somebody
711 * forgets to point to it exactly and we index off of trt with
714 tgt_resource_t trt_wildcard; /* wildcard luns */
715 tgt_resource_t trt[MPT_MAX_LUNS];
716 uint16_t tgt_cmds_allocated;
717 uint16_t els_cmds_allocated; /* FC only */
719 uint16_t timeouts; /* timeout count */
720 uint16_t success; /* successes afer timeout */
721 uint16_t sequence; /* Sequence Number */
725 /* Paired port in some dual adapters configurations */
726 struct mpt_softc * mpt2;
729 /* FW Image management */
730 uint32_t fw_image_size;
732 bus_dma_tag_t fw_dmat; /* DMA tag for firmware image */
733 bus_dmamap_t fw_dmap; /* DMA map for firmware image */
734 bus_addr_t fw_phys; /* BusAddr of firmware image */
737 struct mptsas_portinfo *sas_portinfo;
739 /* Shutdown Event Handler. */
742 /* Userland management interface. */
745 TAILQ_ENTRY(mpt_softc) links;
748 static __inline void mpt_assign_serno(struct mpt_softc *, request_t *);
751 mpt_assign_serno(struct mpt_softc *mpt, request_t *req)
753 if ((req->serno = mpt->sequence++) == 0) {
754 req->serno = mpt->sequence++;
758 /***************************** Locking Primitives *****************************/
759 #define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
760 #define MPT_LOCK_SETUP(mpt) \
761 mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \
762 mpt->mpt_locksetup = 1
763 #define MPT_LOCK_DESTROY(mpt) \
764 if (mpt->mpt_locksetup) { \
765 mtx_destroy(&mpt->mpt_lock); \
766 mpt->mpt_locksetup = 0; \
769 #define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock)
770 #define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock)
771 #define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock)
772 #define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED)
773 #define mpt_sleep(mpt, ident, priority, wmesg, sbt) \
774 msleep_sbt(ident, &(mpt)->mpt_lock, priority, wmesg, sbt, 0, 0)
775 #define mpt_req_timeout(req, sbt, func, arg) \
776 callout_reset_sbt(&(req)->callout, (sbt), 0, (func), (arg), 0)
777 #define mpt_req_untimeout(req, func, arg) \
778 callout_stop(&(req)->callout)
779 #define mpt_callout_init(mpt, c) \
780 callout_init_mtx(c, &(mpt)->mpt_lock, 0)
781 #define mpt_callout_drain(mpt, c) \
784 /******************************* Register Access ******************************/
785 static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t);
786 static __inline void mpt_write_stream(struct mpt_softc *, size_t, uint32_t);
787 static __inline uint32_t mpt_read(struct mpt_softc *, int);
788 static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t);
789 static __inline uint32_t mpt_pio_read(struct mpt_softc *, int);
792 mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
794 bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val);
798 mpt_write_stream(struct mpt_softc *mpt, size_t offset, uint32_t val)
800 bus_space_write_stream_4(mpt->pci_st, mpt->pci_sh, offset, val);
803 static __inline uint32_t
804 mpt_read(struct mpt_softc *mpt, int offset)
806 return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset));
810 * Some operations (e.g. diagnostic register writes while the ARM proccessor
811 * is disabled), must be performed using "PCI pio" operations. On non-PCI
812 * busses, these operations likely map to normal register accesses.
815 mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
817 KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource"));
818 bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val);
821 static __inline uint32_t
822 mpt_pio_read(struct mpt_softc *mpt, int offset)
824 KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource"));
825 return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset));
828 /*********************** Reply Frame/Request Management ***********************/
829 /* Max MPT Reply we are willing to accept (must be power of 2) */
830 #define MPT_REPLY_SIZE 256
833 * Must be less than 16384 in order for target mode to work
835 #define MPT_MAX_REQUESTS(mpt) 512
836 #define MPT_REQUEST_AREA 512
837 #define MPT_SENSE_SIZE 32 /* included in MPT_REQUEST_AREA */
838 #define MPT_REQ_MEM_SIZE(mpt) (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
840 #define MPT_CONTEXT_CB_SHIFT (16)
841 #define MPT_CBI(handle) (handle >> MPT_CONTEXT_CB_SHIFT)
842 #define MPT_CBI_TO_HID(cbi) ((cbi) << MPT_CONTEXT_CB_SHIFT)
843 #define MPT_CONTEXT_TO_CBI(x) \
844 (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1))
845 #define MPT_CONTEXT_REQI_MASK 0xFFFF
846 #define MPT_CONTEXT_TO_REQI(x) ((x) & MPT_CONTEXT_REQI_MASK)
849 * Convert a 32bit physical address returned from IOC to an
850 * offset into our reply frame memory or the kvm address needed
851 * to access the data. The returned address is only the low
852 * 32 bits, so mask our base physical address accordingly.
854 #define MPT_REPLY_BADDR(x) \
856 #define MPT_REPLY_OTOV(m, i) \
857 ((void *)(&m->reply[i]))
859 #define MPT_DUMP_REPLY_FRAME(mpt, reply_frame) \
861 if (mpt->verbose > MPT_PRT_DEBUG) \
862 mpt_dump_reply_frame(mpt, reply_frame); \
865 static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt);
866 static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr);
869 * Give the reply buffer back to the IOC after we have
870 * finished processing it.
873 mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr)
875 mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr);
878 /* Get a reply from the IOC */
879 static __inline uint32_t
880 mpt_pop_reply_queue(struct mpt_softc *mpt)
882 return mpt_read(mpt, MPT_OFFSET_REPLY_Q);
886 mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int);
888 /************************** Scatter Gather Management **************************/
889 /* MPT_RQSL- size of request frame, in bytes */
890 #define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2)
892 /* MPT_NSGL- how many SG entries can fit in a request frame size */
893 #define MPT_NSGL(mpt) (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION))
895 /* MPT_NRFM- how many request frames can fit in each request alloc we make */
896 #define MPT_NRFM(mpt) (MPT_REQUEST_AREA / MPT_RQSL(mpt))
899 * MPT_NSGL_FIRST- # of SG elements that can fit after
900 * an I/O request but still within the request frame.
901 * Do this safely based upon SGE_IO_UNION.
903 * Note that the first element is *within* the SCSI request.
905 #define MPT_NSGL_FIRST(mpt) \
906 ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \
907 sizeof (SGE_IO_UNION))
909 /***************************** IOC Initialization *****************************/
910 int mpt_reset(struct mpt_softc *, int /*reinit*/);
912 /****************************** Debugging ************************************/
913 void mpt_dump_data(struct mpt_softc *, const char *, void *, int);
914 void mpt_dump_request(struct mpt_softc *, request_t *);
931 #define mpt_lprt(mpt, level, ...) \
933 if (level <= (mpt)->verbose) \
934 mpt_prt(mpt, __VA_ARGS__); \
938 #define mpt_lprtc(mpt, level, ...) \
940 if (level <= (mpt)->verbose) \
941 mpt_prtc(mpt, __VA_ARGS__); \
945 void mpt_prt(struct mpt_softc *, const char *, ...)
947 void mpt_prtc(struct mpt_softc *, const char *, ...)
950 /**************************** Target Mode Related ***************************/
951 static __inline int mpt_cdblen(uint8_t, int);
953 mpt_cdblen(uint8_t cdb0, int maxlen)
955 int group = cdb0 >> 5;
970 static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t);
971 static __inline request_t *
972 mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag)
974 uint16_t rtg = (tag >> 18);
975 KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d", tag));
976 KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array"));
977 KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer"));
978 return (mpt->tgt_cmd_ptrs[rtg]);
983 mpt_req_on_free_list(struct mpt_softc *, request_t *);
985 mpt_req_on_pending_list(struct mpt_softc *, request_t *);
988 * Is request on freelist?
991 mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req)
995 TAILQ_FOREACH(lrq, &mpt->request_free_list, links) {
1004 * Is request on pending list?
1007 mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req)
1011 TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) {
1020 static __inline void
1021 mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int);
1022 static __inline void
1023 mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int);
1026 * Make sure that req *is* part of one of the special lists
1028 static __inline void
1029 mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
1032 for (i = 0; i < mpt->els_cmds_allocated; i++) {
1033 if (req == mpt->els_cmd_ptrs[i]) {
1037 for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
1038 if (req == mpt->tgt_cmd_ptrs[i]) {
1042 panic("%s(%d): req %p:%u function %x not in els or tgt ptrs",
1043 s, line, req, req->serno,
1044 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function);
1048 * Make sure that req is *not* part of one of the special lists.
1050 static __inline void
1051 mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
1054 for (i = 0; i < mpt->els_cmds_allocated; i++) {
1055 KASSERT(req != mpt->els_cmd_ptrs[i],
1056 ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d",
1057 s, line, req, req->serno,
1058 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
1060 for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
1061 KASSERT(req != mpt->tgt_cmd_ptrs[i],
1062 ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d",
1063 s, line, req, req->serno,
1064 ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
1070 * Task Management Types, purely for internal consumption
1073 MPT_ABORT_TASK_SET=1234,
1078 MPT_NIL_TMT_VALUE=5678
1081 /**************************** Unclassified Routines ***************************/
1082 void mpt_send_cmd(struct mpt_softc *mpt, request_t *req);
1083 int mpt_recv_handshake_reply(struct mpt_softc *mpt,
1084 size_t reply_len, void *reply);
1085 int mpt_wait_req(struct mpt_softc *mpt, request_t *req,
1086 mpt_req_state_t state, mpt_req_state_t mask,
1087 int sleep_ok, int time_ms);
1088 void mpt_enable_ints(struct mpt_softc *mpt);
1089 void mpt_disable_ints(struct mpt_softc *mpt);
1090 int mpt_attach(struct mpt_softc *mpt);
1091 int mpt_shutdown(struct mpt_softc *mpt);
1092 int mpt_detach(struct mpt_softc *mpt);
1093 int mpt_send_handshake_cmd(struct mpt_softc *mpt,
1094 size_t len, void *cmd);
1095 request_t * mpt_get_request(struct mpt_softc *mpt, int sleep_ok);
1096 void mpt_free_request(struct mpt_softc *mpt, request_t *req);
1097 void mpt_intr(void *arg);
1098 void mpt_check_doorbell(struct mpt_softc *mpt);
1099 void mpt_dump_reply_frame(struct mpt_softc *mpt,
1100 MSG_DEFAULT_REPLY *reply_frame);
1102 int mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/,
1104 bus_addr_t /*addr*/, bus_size_t/*len*/,
1105 int /*sleep_ok*/, int /*timeout_ms*/);
1106 int mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion,
1107 int PageNumber, uint32_t PageAddress,
1109 CONFIG_EXTENDED_PAGE_HEADER *rslt,
1110 int sleep_ok, int timeout_ms);
1111 int mpt_read_extcfg_page(struct mpt_softc *mpt, int Action,
1112 uint32_t PageAddress,
1113 CONFIG_EXTENDED_PAGE_HEADER *hdr,
1114 void *buf, size_t len, int sleep_ok,
1116 int mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/,
1118 uint32_t /*PageAddress*/,
1119 CONFIG_PAGE_HEADER *,
1120 int /*sleep_ok*/, int /*timeout_ms*/);
1121 int mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/,
1122 uint32_t /*PageAddress*/,
1123 CONFIG_PAGE_HEADER *, size_t /*len*/,
1124 int /*sleep_ok*/, int /*timeout_ms*/);
1125 int mpt_write_cfg_page(struct mpt_softc *, int /*Action*/,
1126 uint32_t /*PageAddress*/,
1127 CONFIG_PAGE_HEADER *, size_t /*len*/,
1128 int /*sleep_ok*/, int /*timeout_ms*/);
1130 mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1131 CONFIG_PAGE_HEADER *hdr, size_t len,
1132 int sleep_ok, int timeout_ms)
1134 return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
1135 PageAddress, hdr, len, sleep_ok, timeout_ms));
1139 mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1140 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1143 return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT,
1144 PageAddress, hdr, len, sleep_ok,
1148 /* mpt_debug.c functions */
1149 void mpt_print_reply(void *vmsg);
1150 void mpt_print_db(uint32_t mb);
1151 void mpt_print_config_reply(void *vmsg);
1152 char *mpt_ioc_diag(uint32_t diag);
1153 void mpt_req_state(mpt_req_state_t state);
1154 void mpt_print_config_request(void *vmsg);
1155 void mpt_print_request(void *vmsg);
1156 void mpt_dump_sgl(SGE_IO_UNION *se, int offset);
1158 #endif /* _MPT_H_ */