1d043c564SKenneth D. Merry /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4ef065d89SStephen McConnell * Copyright (c) 2011-2015 LSI Corp.
5ef065d89SStephen McConnell * Copyright (c) 2013-2015 Avago Technologies
6d043c564SKenneth D. Merry * All rights reserved.
7d043c564SKenneth D. Merry *
8d043c564SKenneth D. Merry * Redistribution and use in source and binary forms, with or without
9d043c564SKenneth D. Merry * modification, are permitted provided that the following conditions
10d043c564SKenneth D. Merry * are met:
11d043c564SKenneth D. Merry * 1. Redistributions of source code must retain the above copyright
12d043c564SKenneth D. Merry * notice, this list of conditions and the following disclaimer.
13d043c564SKenneth D. Merry * 2. Redistributions in binary form must reproduce the above copyright
14d043c564SKenneth D. Merry * notice, this list of conditions and the following disclaimer in the
15d043c564SKenneth D. Merry * documentation and/or other materials provided with the distribution.
16d043c564SKenneth D. Merry *
17d043c564SKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18d043c564SKenneth D. Merry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d043c564SKenneth D. Merry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20d043c564SKenneth D. Merry * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21d043c564SKenneth D. Merry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22d043c564SKenneth D. Merry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23d043c564SKenneth D. Merry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24d043c564SKenneth D. Merry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25d043c564SKenneth D. Merry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26d043c564SKenneth D. Merry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27d043c564SKenneth D. Merry * SUCH DAMAGE.
28d043c564SKenneth D. Merry *
29ef065d89SStephen McConnell * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
30d043c564SKenneth D. Merry */
31d043c564SKenneth D. Merry
32d043c564SKenneth D. Merry struct mps_fw_event_work;
33d043c564SKenneth D. Merry
34d043c564SKenneth D. Merry struct mpssas_lun {
35d043c564SKenneth D. Merry SLIST_ENTRY(mpssas_lun) lun_link;
36d043c564SKenneth D. Merry lun_id_t lun_id;
37d043c564SKenneth D. Merry uint8_t eedp_formatted;
38d043c564SKenneth D. Merry uint32_t eedp_block_size;
39d043c564SKenneth D. Merry };
40d043c564SKenneth D. Merry
41d043c564SKenneth D. Merry struct mpssas_target {
42d043c564SKenneth D. Merry uint16_t handle;
43d043c564SKenneth D. Merry uint8_t linkrate;
44d043c564SKenneth D. Merry uint64_t devname;
45d043c564SKenneth D. Merry uint32_t devinfo;
46d043c564SKenneth D. Merry uint16_t encl_handle;
47d043c564SKenneth D. Merry uint16_t encl_slot;
48d043c564SKenneth D. Merry uint8_t flags;
49d043c564SKenneth D. Merry #define MPSSAS_TARGET_INABORT (1 << 0)
50d043c564SKenneth D. Merry #define MPSSAS_TARGET_INRESET (1 << 1)
51d043c564SKenneth D. Merry #define MPSSAS_TARGET_INDIAGRESET (1 << 2)
52d043c564SKenneth D. Merry #define MPSSAS_TARGET_INREMOVAL (1 << 3)
53653c521fSKenneth D. Merry #define MPS_TARGET_FLAGS_RAID_COMPONENT (1 << 4)
54653c521fSKenneth D. Merry #define MPS_TARGET_FLAGS_VOLUME (1 << 5)
55ef065d89SStephen McConnell #define MPS_TARGET_IS_SATA_SSD (1 << 6)
56d043c564SKenneth D. Merry #define MPSSAS_TARGET_INRECOVERY (MPSSAS_TARGET_INABORT | \
57d043c564SKenneth D. Merry MPSSAS_TARGET_INRESET | MPSSAS_TARGET_INCHIPRESET)
58653c521fSKenneth D. Merry
59d043c564SKenneth D. Merry uint16_t tid;
60d043c564SKenneth D. Merry SLIST_HEAD(, mpssas_lun) luns;
61acb570cfSScott Long TAILQ_HEAD(, mps_command) commands;
62d043c564SKenneth D. Merry struct mps_command *tm;
634c1cdd4aSWarner Losh struct mps_command *pending_remove_tm;
64d043c564SKenneth D. Merry TAILQ_HEAD(, mps_command) timedout_commands;
65d043c564SKenneth D. Merry uint16_t exp_dev_handle;
66d043c564SKenneth D. Merry uint16_t phy_num;
67d043c564SKenneth D. Merry uint64_t sasaddr;
68d043c564SKenneth D. Merry uint16_t parent_handle;
69d043c564SKenneth D. Merry uint64_t parent_sasaddr;
70d043c564SKenneth D. Merry uint32_t parent_devinfo;
71d043c564SKenneth D. Merry uint64_t issued;
72d043c564SKenneth D. Merry uint64_t completed;
73d043c564SKenneth D. Merry unsigned int outstanding;
74d043c564SKenneth D. Merry unsigned int timeouts;
75d043c564SKenneth D. Merry unsigned int aborts;
76d043c564SKenneth D. Merry unsigned int logical_unit_resets;
77d043c564SKenneth D. Merry unsigned int target_resets;
78ef065d89SStephen McConnell uint8_t stop_at_shutdown;
79ef065d89SStephen McConnell uint8_t supports_SSU;
80d043c564SKenneth D. Merry };
81d043c564SKenneth D. Merry
82d043c564SKenneth D. Merry struct mpssas_softc {
83d043c564SKenneth D. Merry struct mps_softc *sc;
84d043c564SKenneth D. Merry u_int flags;
85d043c564SKenneth D. Merry #define MPSSAS_IN_DISCOVERY (1 << 0)
86d043c564SKenneth D. Merry #define MPSSAS_IN_STARTUP (1 << 1)
87d043c564SKenneth D. Merry #define MPSSAS_QUEUE_FROZEN (1 << 3)
8808235773SScott Long u_int maxtargets;
89d043c564SKenneth D. Merry struct mpssas_target *targets;
90d043c564SKenneth D. Merry struct cam_devq *devq;
91d043c564SKenneth D. Merry struct cam_sim *sim;
92d043c564SKenneth D. Merry struct cam_path *path;
93d043c564SKenneth D. Merry struct intr_config_hook sas_ich;
94d043c564SKenneth D. Merry struct mps_event_handle *mpssas_eh;
95d043c564SKenneth D. Merry
96d043c564SKenneth D. Merry u_int startup_refcount;
97d043c564SKenneth D. Merry struct proc *sysctl_proc;
98d043c564SKenneth D. Merry
99d043c564SKenneth D. Merry struct taskqueue *ev_tq;
100d043c564SKenneth D. Merry struct task ev_task;
101d043c564SKenneth D. Merry TAILQ_HEAD(, mps_fw_event_work) ev_queue;
102d043c564SKenneth D. Merry };
103d043c564SKenneth D. Merry
104d043c564SKenneth D. Merry MALLOC_DECLARE(M_MPSSAS);
105d043c564SKenneth D. Merry
106d043c564SKenneth D. Merry /*
107d043c564SKenneth D. Merry * Abstracted so that the driver can be backwards and forwards compatible
108d043c564SKenneth D. Merry * with future versions of CAM that will provide this functionality.
109d043c564SKenneth D. Merry */
110d043c564SKenneth D. Merry #define MPS_SET_LUN(lun, ccblun) \
111d043c564SKenneth D. Merry mpssas_set_lun(lun, ccblun)
112d043c564SKenneth D. Merry
113d043c564SKenneth D. Merry static __inline int
mpssas_set_lun(uint8_t * lun,u_int ccblun)114d043c564SKenneth D. Merry mpssas_set_lun(uint8_t *lun, u_int ccblun)
115d043c564SKenneth D. Merry {
116d043c564SKenneth D. Merry uint64_t *newlun;
117d043c564SKenneth D. Merry
118d043c564SKenneth D. Merry newlun = (uint64_t *)lun;
119d043c564SKenneth D. Merry *newlun = 0;
120d043c564SKenneth D. Merry if (ccblun <= 0xff) {
121d043c564SKenneth D. Merry /* Peripheral device address method, LUN is 0 to 255 */
122d043c564SKenneth D. Merry lun[1] = ccblun;
123d043c564SKenneth D. Merry } else if (ccblun <= 0x3fff) {
124d043c564SKenneth D. Merry /* Flat space address method, LUN is <= 16383 */
125d043c564SKenneth D. Merry scsi_ulto2b(ccblun, lun);
126d043c564SKenneth D. Merry lun[0] |= 0x40;
127d043c564SKenneth D. Merry } else if (ccblun <= 0xffffff) {
128d043c564SKenneth D. Merry /* Extended flat space address method, LUN is <= 16777215 */
129d043c564SKenneth D. Merry scsi_ulto3b(ccblun, &lun[1]);
130d043c564SKenneth D. Merry /* Extended Flat space address method */
131d043c564SKenneth D. Merry lun[0] = 0xc0;
132d043c564SKenneth D. Merry /* Length = 1, i.e. LUN is 3 bytes long */
133d043c564SKenneth D. Merry lun[0] |= 0x10;
134d043c564SKenneth D. Merry /* Extended Address Method */
135d043c564SKenneth D. Merry lun[0] |= 0x02;
136d043c564SKenneth D. Merry } else {
137d043c564SKenneth D. Merry return (EINVAL);
138d043c564SKenneth D. Merry }
139d043c564SKenneth D. Merry
140d043c564SKenneth D. Merry return (0);
141d043c564SKenneth D. Merry }
142d043c564SKenneth D. Merry
143601781ccSScott Long static __inline void
mpssas_set_ccbstatus(union ccb * ccb,int status)144601781ccSScott Long mpssas_set_ccbstatus(union ccb *ccb, int status)
145601781ccSScott Long {
146601781ccSScott Long ccb->ccb_h.status &= ~CAM_STATUS_MASK;
147601781ccSScott Long ccb->ccb_h.status |= status;
148601781ccSScott Long }
149601781ccSScott Long
150601781ccSScott Long static __inline int
mpssas_get_ccbstatus(union ccb * ccb)151601781ccSScott Long mpssas_get_ccbstatus(union ccb *ccb)
152601781ccSScott Long {
153601781ccSScott Long return (ccb->ccb_h.status & CAM_STATUS_MASK);
154601781ccSScott Long }
155601781ccSScott Long
156d043c564SKenneth D. Merry #define MPS_SET_SINGLE_LUN(req, lun) \
157d043c564SKenneth D. Merry do { \
158d043c564SKenneth D. Merry bzero((req)->LUN, 8); \
159d043c564SKenneth D. Merry (req)->LUN[1] = lun; \
160d043c564SKenneth D. Merry } while(0)
161d043c564SKenneth D. Merry
162d043c564SKenneth D. Merry void mpssas_rescan_target(struct mps_softc *sc, struct mpssas_target *targ);
163d043c564SKenneth D. Merry void mpssas_discovery_end(struct mpssas_softc *sassc);
164ef065d89SStephen McConnell void mpssas_prepare_for_tm(struct mps_softc *sc, struct mps_command *tm,
165ef065d89SStephen McConnell struct mpssas_target *target, lun_id_t lun_id);
166d043c564SKenneth D. Merry void mpssas_startup_increment(struct mpssas_softc *sassc);
167d043c564SKenneth D. Merry void mpssas_startup_decrement(struct mpssas_softc *sassc);
168d043c564SKenneth D. Merry
169d043c564SKenneth D. Merry void mpssas_firmware_event_work(void *arg, int pending);
170d9802debSScott Long int mpssas_check_id(struct mpssas_softc *sassc, int id);
171