2 * Copyright (c) 2009 Yahoo! Inc.
3 * Copyright (c) 2011-2015 LSI Corp.
4 * Copyright (c) 2013-2016 Avago Technologies
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
28 * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
36 #define MPR_DRIVER_VERSION "15.03.00.00-fbsd"
38 #define MPR_DB_MAX_WAIT 2500
40 #define MPR_REQ_FRAMES 2048
41 #define MPR_PRI_REQ_FRAMES 128
42 #define MPR_EVT_REPLY_FRAMES 32
43 #define MPR_REPLY_FRAMES MPR_REQ_FRAMES
44 #define MPR_CHAIN_FRAMES 2048
45 #define MPR_MAXIO_PAGES (-1)
46 #define MPR_SENSE_LEN SSD_FULL_SIZE
48 #define MPR_MSIX_MAX 96
49 #define MPR_SGE64_SIZE 12
50 #define MPR_SGE32_SIZE 8
51 #define MPR_SGC_SIZE 8
52 #define MPR_DEFAULT_CHAIN_SEG_SIZE 8
53 #define MPR_MAX_CHAIN_ELEMENT_SIZE 16
56 * PCIe NVMe Specific defines
58 //SLM-for now just use the same value as a SAS disk
59 #define NVME_QDEPTH MPR_REQ_FRAMES
60 #define PRP_ENTRY_SIZE 8
61 #define NVME_CMD_PRP1_OFFSET 24 /* PRP1 offset in NVMe cmd */
62 #define NVME_CMD_PRP2_OFFSET 32 /* PRP2 offset in NVMe cmd */
63 #define NVME_ERROR_RESPONSE_SIZE 16 /* Max NVME Error Response */
64 #define HOST_PAGE_SIZE_4K 12
66 #define MPR_FUNCTRACE(sc) \
67 mpr_dprint((sc), MPR_TRACE, "%s\n", __func__)
72 #define MPR_PERIODIC_DELAY 1 /* 1 second heartbeat/watchdog check */
73 #define MPR_ATA_ID_TIMEOUT 5 /* 5 second timeout for SATA ID cmd */
74 #define MPR_MISSING_CHECK_DELAY 10 /* 10 seconds between missing check */
76 #define IFAULT_IOP_OVER_TEMP_THRESHOLD_EXCEEDED 0x2810
78 #define MPR_SCSI_RI_INVALID_FRAME (0x00000002)
80 #define DEFAULT_SPINUP_WAIT 3 /* seconds to wait for spinup */
82 #include <sys/endian.h>
85 * host mapping related macro definitions
87 #define MPR_MAPTABLE_BAD_IDX 0xFFFFFFFF
88 #define MPR_DPM_BAD_IDX 0xFFFF
89 #define MPR_ENCTABLE_BAD_IDX 0xFF
90 #define MPR_MAX_MISSING_COUNT 0x0F
91 #define MPR_DEV_RESERVED 0x20000000
92 #define MPR_MAP_IN_USE 0x10000000
93 #define MPR_MAP_BAD_ID 0xFFFFFFFF
101 * struct dev_mapping_table - device mapping information
102 * @physical_id: SAS address for drives or WWID for RAID volumes
103 * @device_info: bitfield provides detailed info about the device
104 * @phy_bits: bitfields indicating controller phys
105 * @dpm_entry_num: index of this device in device persistent map table
106 * @dev_handle: device handle for the device pointed by this entry
108 * @missing_count: number of times the device not detected by driver
109 * @hide_flag: Hide this physical disk/not (foreign configuration)
110 * @init_complete: Whether the start of the day checks completed or not
111 * @TLR_bits: Turn TLR support on or off
113 struct dev_mapping_table {
128 * struct enc_mapping_table - mapping information about an enclosure
129 * @enclosure_id: Logical ID of this enclosure
130 * @start_index: index to the entry in dev_mapping_table
131 * @phy_bits: bitfields indicating controller phys
132 * @dpm_entry_num: index of this enclosure in device persistent map table
133 * @enc_handle: device handle for the enclosure pointed by this entry
134 * @num_slots: number of slots in the enclosure
135 * @start_slot: Starting slot id
136 * @missing_count: number of times the device not detected by driver
137 * @removal_flag: used to mark the device for removal
138 * @skip_search: used as a flag to include/exclude enclosure for search
139 * @init_complete: Whether the start of the day checks completed or not
141 struct enc_mapping_table {
156 * struct map_removal_table - entries to be removed from mapping table
157 * @dpm_entry_num: index of this device in device persistent map table
158 * @dev_handle: device handle for the device pointed by this entry
160 struct map_removal_table{
165 typedef struct mpr_fw_diagnostic_buffer {
167 uint8_t extended_type;
169 uint8_t force_release;
170 uint32_t product_specific[23];
174 uint8_t owned_by_firmware;
176 } mpr_fw_diagnostic_buffer_t;
182 struct mprsas_target;
183 struct mpr_column_map;
185 MALLOC_DECLARE(M_MPR);
187 typedef void mpr_evt_callback_t(struct mpr_softc *, uintptr_t,
188 MPI2_EVENT_NOTIFICATION_REPLY *reply);
189 typedef void mpr_command_callback_t(struct mpr_softc *, struct mpr_command *cm);
192 TAILQ_ENTRY(mpr_chain) chain_link;
194 uint64_t chain_busaddr;
197 struct mpr_prp_page {
198 TAILQ_ENTRY(mpr_prp_page) prp_page_link;
200 uint64_t prp_page_busaddr;
204 * This needs to be at least 2 to support SMP passthrough.
206 #define MPR_IOVEC_COUNT 2
209 TAILQ_ENTRY(mpr_command) cm_link;
210 TAILQ_ENTRY(mpr_command) cm_recovery;
211 struct mpr_softc *cm_sc;
217 struct iovec cm_iovec[MPR_IOVEC_COUNT];
223 uint32_t cm_reply_data;
224 mpr_command_callback_t *cm_complete;
225 void *cm_complete_data;
226 struct mprsas_target *cm_targ;
227 MPI2_REQUEST_DESCRIPTOR_UNION cm_desc;
230 #define MPR_CM_FLAGS_POLLED (1 << 0)
231 #define MPR_CM_FLAGS_COMPLETE (1 << 1)
232 #define MPR_CM_FLAGS_SGE_SIMPLE (1 << 2)
233 #define MPR_CM_FLAGS_DATAOUT (1 << 3)
234 #define MPR_CM_FLAGS_DATAIN (1 << 4)
235 #define MPR_CM_FLAGS_WAKEUP (1 << 5)
236 #define MPR_CM_FLAGS_USE_UIO (1 << 6)
237 #define MPR_CM_FLAGS_SMP_PASS (1 << 7)
238 #define MPR_CM_FLAGS_CHAIN_FAILED (1 << 8)
239 #define MPR_CM_FLAGS_ERROR_MASK MPR_CM_FLAGS_CHAIN_FAILED
240 #define MPR_CM_FLAGS_USE_CCB (1 << 9)
241 #define MPR_CM_FLAGS_SATA_ID_TIMEOUT (1 << 10)
243 #define MPR_CM_STATE_FREE 0
244 #define MPR_CM_STATE_BUSY 1
245 #define MPR_CM_STATE_TIMEDOUT 2
246 bus_dmamap_t cm_dmamap;
247 struct scsi_sense_data *cm_sense;
248 uint64_t *nvme_error_response;
249 TAILQ_HEAD(, mpr_chain) cm_chain_list;
250 TAILQ_HEAD(, mpr_prp_page) cm_prp_page_list;
251 uint32_t cm_req_busaddr;
252 bus_addr_t cm_sense_busaddr;
253 struct callout cm_callout;
256 struct mpr_column_map {
258 uint8_t phys_disk_num;
261 struct mpr_event_handle {
262 TAILQ_ENTRY(mpr_event_handle) eh_list;
263 mpr_evt_callback_t *callback;
268 struct mpr_busdma_context {
273 struct mpr_softc *softc;
274 bus_dmamap_t buffer_dmamap;
275 bus_dma_tag_t buffer_dmat;
279 struct mpr_softc *sc;
281 MPI2_REPLY_DESCRIPTORS_UNION *post_queue;
284 ck_ring_buffer_t *ringmem;
285 ck_ring_buffer_t *chainmem;
287 ck_ring_t chain_ring;
289 bus_dma_tag_t buffer_dmat;
290 int io_cmds_highwater;
291 int chain_free_lowwater;
292 int chain_alloc_fail;
293 struct resource *irq;
300 struct cdev *mpr_cdev;
302 #define MPR_FLAGS_INTX (1 << 0)
303 #define MPR_FLAGS_MSI (1 << 1)
304 #define MPR_FLAGS_BUSY (1 << 2)
305 #define MPR_FLAGS_SHUTDOWN (1 << 3)
306 #define MPR_FLAGS_DIAGRESET (1 << 4)
307 #define MPR_FLAGS_ATTACH_DONE (1 << 5)
308 #define MPR_FLAGS_GEN35_IOC (1 << 6)
309 #define MPR_FLAGS_REALLOCATED (1 << 7)
312 u_int atomic_desc_capable;
315 int io_cmds_highwater;
320 int chain_free_lowwater;
321 uint32_t chain_frame_size;
322 uint16_t chain_seg_size;
325 int prp_pages_free_lowwater;
327 int spinup_wait_time;
329 uint64_t chain_alloc_fail;
330 uint64_t prp_page_alloc_fail;
331 struct sysctl_ctx_list sysctl_ctx;
332 struct sysctl_oid *sysctl_tree;
334 struct mpr_command *commands;
335 struct mpr_chain *chains;
336 struct mpr_prp_page *prps;
337 struct callout periodic;
338 struct callout device_check_callout;
339 struct mpr_queue *queues;
341 struct mprsas_softc *sassc;
342 TAILQ_HEAD(, mpr_command) req_list;
343 TAILQ_HEAD(, mpr_command) high_priority_req_list;
344 TAILQ_HEAD(, mpr_chain) chain_list;
345 TAILQ_HEAD(, mpr_prp_page) prp_page_list;
346 TAILQ_HEAD(, mpr_command) tm_list;
350 struct resource *mpr_regs_resource;
351 bus_space_handle_t mpr_bhandle;
352 bus_space_tag_t mpr_btag;
355 bus_dma_tag_t mpr_parent_dmat;
356 bus_dma_tag_t buffer_dmat;
358 MPI2_IOC_FACTS_REPLY *facts;
361 int fqdepth; /* Free queue */
362 int pqdepth; /* Post queue */
364 uint8_t event_mask[16];
365 TAILQ_HEAD(, mpr_event_handle) event_list;
366 struct mpr_event_handle *mpr_log_eh;
369 struct intr_config_hook mpr_ich;
372 bus_addr_t req_busaddr;
373 bus_dma_tag_t req_dmat;
374 bus_dmamap_t req_map;
376 uint8_t *reply_frames;
377 bus_addr_t reply_busaddr;
378 bus_dma_tag_t reply_dmat;
379 bus_dmamap_t reply_map;
381 struct scsi_sense_data *sense_frames;
382 bus_addr_t sense_busaddr;
383 bus_dma_tag_t sense_dmat;
384 bus_dmamap_t sense_map;
386 uint8_t *chain_frames;
387 bus_addr_t chain_busaddr;
388 bus_dma_tag_t chain_dmat;
389 bus_dmamap_t chain_map;
392 bus_addr_t prp_page_busaddr;
393 bus_dma_tag_t prp_page_dmat;
394 bus_dmamap_t prp_page_map;
396 MPI2_REPLY_DESCRIPTORS_UNION *post_queue;
397 bus_addr_t post_busaddr;
398 uint32_t *free_queue;
399 bus_addr_t free_busaddr;
400 bus_dma_tag_t queues_dmat;
401 bus_dmamap_t queues_map;
403 uint8_t *fw_diag_buffer;
404 bus_addr_t fw_diag_busaddr;
405 bus_dma_tag_t fw_diag_dmat;
406 bus_dmamap_t fw_diag_map;
410 /* static config pages */
411 Mpi2IOCPage8_t ioc_pg8;
412 Mpi2IOUnitPage8_t iounit_pg8;
414 /* host mapping support */
415 struct dev_mapping_table *mapping_table;
416 struct enc_mapping_table *enclosure_table;
417 struct map_removal_table *removal_table;
418 uint8_t *dpm_entry_used;
419 uint8_t *dpm_flush_entry;
420 Mpi2DriverMappingPage0_t *dpm_pg0;
421 uint16_t max_devices;
422 uint16_t max_enclosures;
423 uint16_t max_expanders;
425 uint8_t num_enc_table_entries;
426 uint8_t num_rsvd_entries;
427 uint16_t max_dpm_entries;
428 uint8_t is_dpm_enable;
429 uint8_t track_mapping_events;
430 uint32_t pending_map_events;
432 /* FW diag Buffer List */
433 mpr_fw_diagnostic_buffer_t
434 fw_diag_buffer_list[MPI2_DIAG_BUF_TYPE_COUNT];
436 /* Event Recording IOCTL support */
437 uint32_t events_to_record[4];
438 mpr_event_entry_t recorded_events[MPR_EVENT_QUEUE_SIZE];
440 uint32_t event_number;
442 /* EEDP and TLR support */
443 uint8_t eedp_enabled;
446 /* Shutdown Event Handler */
447 eventhandler_tag shutdown_eh;
449 /* To track topo events during reset */
450 #define MPR_DIAG_RESET_TIMEOUT 300000
451 uint8_t wait_for_port_enable;
452 uint8_t port_enable_complete;
453 uint8_t msleep_fake_chan;
455 /* StartStopUnit command handling at shutdown */
456 uint32_t SSU_refcount;
459 /* Configuration tunables */
464 u_int max_prireqframes;
465 u_int max_replyframes;
467 char exclude_ids[80];
469 struct timeval lastfail;
472 struct mpr_config_params {
473 MPI2_CONFIG_EXT_PAGE_HEADER_UNION hdr;
475 u_int page_address; /* Attributes, not a phys address */
480 void (*callback)(struct mpr_softc *, struct mpr_config_params *);
484 struct scsi_read_capacity_eedp
491 static __inline uint32_t
492 mpr_regread(struct mpr_softc *sc, uint32_t offset)
494 return (bus_space_read_4(sc->mpr_btag, sc->mpr_bhandle, offset));
498 mpr_regwrite(struct mpr_softc *sc, uint32_t offset, uint32_t val)
500 bus_space_write_4(sc->mpr_btag, sc->mpr_bhandle, offset, val);
503 /* free_queue must have Little Endian address
504 * TODO- cm_reply_data is unwanted. We can remove it.
507 mpr_free_reply(struct mpr_softc *sc, uint32_t busaddr)
509 if (++sc->replyfreeindex >= sc->fqdepth)
510 sc->replyfreeindex = 0;
511 sc->free_queue[sc->replyfreeindex] = htole32(busaddr);
512 mpr_regwrite(sc, MPI2_REPLY_FREE_HOST_INDEX_OFFSET, sc->replyfreeindex);
515 static __inline struct mpr_chain *
516 mpr_alloc_chain(struct mpr_softc *sc)
518 struct mpr_chain *chain;
520 if ((chain = TAILQ_FIRST(&sc->chain_list)) != NULL) {
521 TAILQ_REMOVE(&sc->chain_list, chain, chain_link);
523 if (sc->chain_free < sc->chain_free_lowwater)
524 sc->chain_free_lowwater = sc->chain_free;
526 sc->chain_alloc_fail++;
531 mpr_free_chain(struct mpr_softc *sc, struct mpr_chain *chain)
534 bzero(chain->chain, 128);
537 TAILQ_INSERT_TAIL(&sc->chain_list, chain, chain_link);
540 static __inline struct mpr_prp_page *
541 mpr_alloc_prp_page(struct mpr_softc *sc)
543 struct mpr_prp_page *prp_page;
545 if ((prp_page = TAILQ_FIRST(&sc->prp_page_list)) != NULL) {
546 TAILQ_REMOVE(&sc->prp_page_list, prp_page, prp_page_link);
547 sc->prp_pages_free--;
548 if (sc->prp_pages_free < sc->prp_pages_free_lowwater)
549 sc->prp_pages_free_lowwater = sc->prp_pages_free;
551 sc->prp_page_alloc_fail++;
556 mpr_free_prp_page(struct mpr_softc *sc, struct mpr_prp_page *prp_page)
558 sc->prp_pages_free++;
559 TAILQ_INSERT_TAIL(&sc->prp_page_list, prp_page, prp_page_link);
563 mpr_free_command(struct mpr_softc *sc, struct mpr_command *cm)
565 struct mpr_chain *chain, *chain_temp;
566 struct mpr_prp_page *prp_page, *prp_page_temp;
568 if (cm->cm_reply != NULL)
569 mpr_free_reply(sc, cm->cm_reply_data);
572 cm->cm_complete = NULL;
573 cm->cm_complete_data = NULL;
578 cm->cm_state = MPR_CM_STATE_FREE;
585 TAILQ_FOREACH_SAFE(chain, &cm->cm_chain_list, chain_link, chain_temp) {
586 TAILQ_REMOVE(&cm->cm_chain_list, chain, chain_link);
587 mpr_free_chain(sc, chain);
589 TAILQ_FOREACH_SAFE(prp_page, &cm->cm_prp_page_list, prp_page_link,
591 TAILQ_REMOVE(&cm->cm_prp_page_list, prp_page, prp_page_link);
592 mpr_free_prp_page(sc, prp_page);
594 TAILQ_INSERT_TAIL(&sc->req_list, cm, cm_link);
597 static __inline struct mpr_command *
598 mpr_alloc_command(struct mpr_softc *sc)
600 struct mpr_command *cm;
602 cm = TAILQ_FIRST(&sc->req_list);
606 TAILQ_REMOVE(&sc->req_list, cm, cm_link);
607 KASSERT(cm->cm_state == MPR_CM_STATE_FREE, ("mpr: Allocating busy "
609 cm->cm_state = MPR_CM_STATE_BUSY;
614 mpr_free_high_priority_command(struct mpr_softc *sc, struct mpr_command *cm)
616 struct mpr_chain *chain, *chain_temp;
618 if (cm->cm_reply != NULL)
619 mpr_free_reply(sc, cm->cm_reply_data);
622 cm->cm_complete = NULL;
623 cm->cm_complete_data = NULL;
627 cm->cm_state = MPR_CM_STATE_FREE;
628 TAILQ_FOREACH_SAFE(chain, &cm->cm_chain_list, chain_link, chain_temp) {
629 TAILQ_REMOVE(&cm->cm_chain_list, chain, chain_link);
630 mpr_free_chain(sc, chain);
632 TAILQ_INSERT_TAIL(&sc->high_priority_req_list, cm, cm_link);
635 static __inline struct mpr_command *
636 mpr_alloc_high_priority_command(struct mpr_softc *sc)
638 struct mpr_command *cm;
640 cm = TAILQ_FIRST(&sc->high_priority_req_list);
644 TAILQ_REMOVE(&sc->high_priority_req_list, cm, cm_link);
645 KASSERT(cm->cm_state == MPR_CM_STATE_FREE, ("mpr: Allocating busy "
647 cm->cm_state = MPR_CM_STATE_BUSY;
652 mpr_lock(struct mpr_softc *sc)
654 mtx_lock(&sc->mpr_mtx);
658 mpr_unlock(struct mpr_softc *sc)
660 mtx_unlock(&sc->mpr_mtx);
663 #define MPR_INFO (1 << 0) /* Basic info */
664 #define MPR_FAULT (1 << 1) /* Hardware faults */
665 #define MPR_EVENT (1 << 2) /* Event data from the controller */
666 #define MPR_LOG (1 << 3) /* Log data from the controller */
667 #define MPR_RECOVERY (1 << 4) /* Command error recovery tracing */
668 #define MPR_ERROR (1 << 5) /* Parameter errors, programming bugs */
669 #define MPR_INIT (1 << 6) /* Things related to system init */
670 #define MPR_XINFO (1 << 7) /* More detailed/noisy info */
671 #define MPR_USER (1 << 8) /* Trace user-generated commands */
672 #define MPR_MAPPING (1 << 9) /* Trace device mappings */
673 #define MPR_TRACE (1 << 10) /* Function-by-function trace */
675 #define MPR_SSU_DISABLE_SSD_DISABLE_HDD 0
676 #define MPR_SSU_ENABLE_SSD_DISABLE_HDD 1
677 #define MPR_SSU_DISABLE_SSD_ENABLE_HDD 2
678 #define MPR_SSU_ENABLE_SSD_ENABLE_HDD 3
680 #define mpr_printf(sc, args...) \
681 device_printf((sc)->mpr_dev, ##args)
683 #define mpr_print_field(sc, msg, args...) \
684 printf("\t" msg, ##args)
686 #define mpr_vprintf(sc, args...) \
689 mpr_printf(sc, ##args); \
692 #define mpr_dprint(sc, level, msg, args...) \
694 if ((sc)->mpr_debug & (level)) \
695 device_printf((sc)->mpr_dev, msg, ##args); \
698 #define MPR_PRINTFIELD_START(sc, tag...) \
699 mpr_printf((sc), ##tag); \
700 mpr_print_field((sc), ":\n")
701 #define MPR_PRINTFIELD_END(sc, tag) \
702 mpr_printf((sc), tag "\n")
703 #define MPR_PRINTFIELD(sc, facts, attr, fmt) \
704 mpr_print_field((sc), #attr ": " #fmt "\n", (facts)->attr)
707 mpr_from_u64(uint64_t data, U64 *mpr)
709 (mpr)->High = htole32((uint32_t)((data) >> 32));
710 (mpr)->Low = htole32((uint32_t)((data) & 0xffffffff));
713 static __inline uint64_t
714 mpr_to_u64(U64 *data)
716 return (((uint64_t)le32toh(data->High) << 32) | le32toh(data->Low));
720 mpr_mask_intr(struct mpr_softc *sc)
724 mask = mpr_regread(sc, MPI2_HOST_INTERRUPT_MASK_OFFSET);
725 mask |= MPI2_HIM_REPLY_INT_MASK;
726 mpr_regwrite(sc, MPI2_HOST_INTERRUPT_MASK_OFFSET, mask);
730 mpr_unmask_intr(struct mpr_softc *sc)
734 mask = mpr_regread(sc, MPI2_HOST_INTERRUPT_MASK_OFFSET);
735 mask &= ~MPI2_HIM_REPLY_INT_MASK;
736 mpr_regwrite(sc, MPI2_HOST_INTERRUPT_MASK_OFFSET, mask);
739 int mpr_pci_setup_interrupts(struct mpr_softc *sc);
740 void mpr_pci_free_interrupts(struct mpr_softc *sc);
741 int mpr_pci_restore(struct mpr_softc *sc);
743 void mpr_get_tunables(struct mpr_softc *sc);
744 int mpr_attach(struct mpr_softc *sc);
745 int mpr_free(struct mpr_softc *sc);
746 void mpr_intr(void *);
747 void mpr_intr_msi(void *);
748 void mpr_intr_locked(void *);
749 int mpr_register_events(struct mpr_softc *, uint8_t *, mpr_evt_callback_t *,
750 void *, struct mpr_event_handle **);
751 int mpr_restart(struct mpr_softc *);
752 int mpr_update_events(struct mpr_softc *, struct mpr_event_handle *, uint8_t *);
753 int mpr_deregister_events(struct mpr_softc *, struct mpr_event_handle *);
754 void mpr_build_nvme_prp(struct mpr_softc *sc, struct mpr_command *cm,
755 Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request, void *data,
756 uint32_t data_in_sz, uint32_t data_out_sz);
757 int mpr_push_sge(struct mpr_command *, MPI2_SGE_SIMPLE64 *, size_t, int);
758 int mpr_push_ieee_sge(struct mpr_command *, void *, int);
759 int mpr_add_dmaseg(struct mpr_command *, vm_paddr_t, size_t, u_int, int);
760 int mpr_attach_sas(struct mpr_softc *sc);
761 int mpr_detach_sas(struct mpr_softc *sc);
762 int mpr_read_config_page(struct mpr_softc *, struct mpr_config_params *);
763 int mpr_write_config_page(struct mpr_softc *, struct mpr_config_params *);
764 void mpr_memaddr_cb(void *, bus_dma_segment_t *, int , int );
765 void mpr_memaddr_wait_cb(void *, bus_dma_segment_t *, int , int );
766 void mpr_init_sge(struct mpr_command *cm, void *req, void *sge);
767 int mpr_attach_user(struct mpr_softc *);
768 void mpr_detach_user(struct mpr_softc *);
769 void mprsas_record_event(struct mpr_softc *sc,
770 MPI2_EVENT_NOTIFICATION_REPLY *event_reply);
772 int mpr_map_command(struct mpr_softc *sc, struct mpr_command *cm);
773 int mpr_wait_command(struct mpr_softc *sc, struct mpr_command **cm, int timeout,
775 int mpr_request_polled(struct mpr_softc *sc, struct mpr_command **cm);
777 int mpr_config_get_bios_pg3(struct mpr_softc *sc, Mpi2ConfigReply_t
778 *mpi_reply, Mpi2BiosPage3_t *config_page);
779 int mpr_config_get_raid_volume_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t
780 *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 page_address);
781 int mpr_config_get_ioc_pg8(struct mpr_softc *sc, Mpi2ConfigReply_t *,
783 int mpr_config_get_iounit_pg8(struct mpr_softc *sc,
784 Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage8_t *config_page);
785 int mpr_config_get_sas_device_pg0(struct mpr_softc *, Mpi2ConfigReply_t *,
786 Mpi2SasDevicePage0_t *, u32 , u16 );
787 int mpr_config_get_pcie_device_pg0(struct mpr_softc *sc, Mpi2ConfigReply_t
788 *mpi_reply, Mpi26PCIeDevicePage0_t *config_page, u32 form, u16 handle);
789 int mpr_config_get_pcie_device_pg2(struct mpr_softc *sc, Mpi2ConfigReply_t
790 *mpi_reply, Mpi26PCIeDevicePage2_t *config_page, u32 form, u16 handle);
791 int mpr_config_get_dpm_pg0(struct mpr_softc *, Mpi2ConfigReply_t *,
792 Mpi2DriverMappingPage0_t *, u16 );
793 int mpr_config_get_raid_volume_pg1(struct mpr_softc *sc,
794 Mpi2ConfigReply_t *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form,
796 int mpr_config_get_volume_wwid(struct mpr_softc *sc, u16 volume_handle,
798 int mpr_config_get_raid_pd_pg0(struct mpr_softc *sc,
799 Mpi2ConfigReply_t *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page,
801 void mprsas_ir_shutdown(struct mpr_softc *sc);
803 int mpr_reinit(struct mpr_softc *sc);
804 void mprsas_handle_reinit(struct mpr_softc *sc);
806 void mpr_base_static_config_pages(struct mpr_softc *sc);
808 int mpr_mapping_initialize(struct mpr_softc *);
809 void mpr_mapping_topology_change_event(struct mpr_softc *,
810 Mpi2EventDataSasTopologyChangeList_t *);
811 void mpr_mapping_pcie_topology_change_event(struct mpr_softc *sc,
812 Mpi26EventDataPCIeTopologyChangeList_t *event_data);
813 void mpr_mapping_free_memory(struct mpr_softc *sc);
814 int mpr_config_set_dpm_pg0(struct mpr_softc *, Mpi2ConfigReply_t *,
815 Mpi2DriverMappingPage0_t *, u16 );
816 void mpr_mapping_exit(struct mpr_softc *);
817 void mpr_mapping_check_devices(void *);
818 int mpr_mapping_allocate_memory(struct mpr_softc *sc);
819 unsigned int mpr_mapping_get_tid(struct mpr_softc *, uint64_t , u16);
820 unsigned int mpr_mapping_get_tid_from_handle(struct mpr_softc *sc,
822 unsigned int mpr_mapping_get_raid_tid(struct mpr_softc *sc, u64 wwid,
824 unsigned int mpr_mapping_get_raid_tid_from_handle(struct mpr_softc *sc,
826 void mpr_mapping_enclosure_dev_status_change_event(struct mpr_softc *,
827 Mpi2EventDataSasEnclDevStatusChange_t *event_data);
828 void mpr_mapping_ir_config_change_event(struct mpr_softc *sc,
829 Mpi2EventDataIrConfigChangeList_t *event_data);
831 void mprsas_evt_handler(struct mpr_softc *sc, uintptr_t data,
832 MPI2_EVENT_NOTIFICATION_REPLY *event);
833 void mprsas_prepare_remove(struct mprsas_softc *sassc, uint16_t handle);
834 void mprsas_prepare_volume_remove(struct mprsas_softc *sassc, uint16_t handle);
835 int mprsas_startup(struct mpr_softc *sc);
836 struct mprsas_target * mprsas_find_target_by_handle(struct mprsas_softc *, int,
838 void mprsas_realloc_targets(struct mpr_softc *sc, int maxtargets);
839 struct mpr_command * mprsas_alloc_tm(struct mpr_softc *sc);
840 void mprsas_free_tm(struct mpr_softc *sc, struct mpr_command *tm);
841 void mprsas_release_simq_reinit(struct mprsas_softc *sassc);
842 int mprsas_send_reset(struct mpr_softc *sc, struct mpr_command *tm,
845 SYSCTL_DECL(_hw_mpr);
847 /* Compatibility shims for different OS versions */
848 #if __FreeBSD_version >= 800001
849 #define mpr_kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
850 kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg)
851 #define mpr_kproc_exit(arg) kproc_exit(arg)
853 #define mpr_kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
854 kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg)
855 #define mpr_kproc_exit(arg) kthread_exit(arg)
858 #if defined(CAM_PRIORITY_XPT)
859 #define MPR_PRIORITY_XPT CAM_PRIORITY_XPT
861 #define MPR_PRIORITY_XPT 5
864 #if __FreeBSD_version < 800107
865 // Prior to FreeBSD-8.0 scp3_flags was not defined.
866 #define spc3_flags reserved
868 #define SPC3_SID_PROTECT 0x01
869 #define SPC3_SID_3PC 0x08
870 #define SPC3_SID_TPGS_MASK 0x30
871 #define SPC3_SID_TPGS_IMPLICIT 0x10
872 #define SPC3_SID_TPGS_EXPLICIT 0x20
873 #define SPC3_SID_ACC 0x40
874 #define SPC3_SID_SCCS 0x80
876 #define CAM_PRIORITY_NORMAL CAM_PRIORITY_NONE
879 /* Definitions for SCSI unmap translation to NVMe DSM command */
881 /* UNMAP block descriptor structure */
882 struct unmap_blk_desc {
888 /* UNMAP command's data */
889 struct unmap_parm_list {
890 uint16_t unmap_data_len;
891 uint16_t unmap_blk_desc_data_len;
893 struct unmap_blk_desc desc[0];
896 /* SCSI ADDITIONAL SENSE Codes */
897 #define FIXED_SENSE_DATA 0x70
898 #define SCSI_ASC_NO_SENSE 0x00
899 #define SCSI_ASC_PERIPHERAL_DEV_WRITE_FAULT 0x03
900 #define SCSI_ASC_LUN_NOT_READY 0x04
901 #define SCSI_ASC_WARNING 0x0B
902 #define SCSI_ASC_LOG_BLOCK_GUARD_CHECK_FAILED 0x10
903 #define SCSI_ASC_LOG_BLOCK_APPTAG_CHECK_FAILED 0x10
904 #define SCSI_ASC_LOG_BLOCK_REFTAG_CHECK_FAILED 0x10
905 #define SCSI_ASC_UNRECOVERED_READ_ERROR 0x11
906 #define SCSI_ASC_MISCOMPARE_DURING_VERIFY 0x1D
907 #define SCSI_ASC_ACCESS_DENIED_INVALID_LUN_ID 0x20
908 #define SCSI_ASC_ILLEGAL_COMMAND 0x20
909 #define SCSI_ASC_ILLEGAL_BLOCK 0x21
910 #define SCSI_ASC_INVALID_CDB 0x24
911 #define SCSI_ASC_INVALID_LUN 0x25
912 #define SCSI_ASC_INVALID_PARAMETER 0x26
913 #define SCSI_ASC_FORMAT_COMMAND_FAILED 0x31
914 #define SCSI_ASC_INTERNAL_TARGET_FAILURE 0x44
916 /* SCSI ADDITIONAL SENSE Code Qualifiers */
917 #define SCSI_ASCQ_CAUSE_NOT_REPORTABLE 0x00
918 #define SCSI_ASCQ_FORMAT_COMMAND_FAILED 0x01
919 #define SCSI_ASCQ_LOG_BLOCK_GUARD_CHECK_FAILED 0x01
920 #define SCSI_ASCQ_LOG_BLOCK_APPTAG_CHECK_FAILED 0x02
921 #define SCSI_ASCQ_LOG_BLOCK_REFTAG_CHECK_FAILED 0x03
922 #define SCSI_ASCQ_FORMAT_IN_PROGRESS 0x04
923 #define SCSI_ASCQ_POWER_LOSS_EXPECTED 0x08
924 #define SCSI_ASCQ_INVALID_LUN_ID 0x09