xref: /freebsd/sys/dev/mps/mps_sas.h (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2011-2015 LSI Corp.
5  * Copyright (c) 2013-2015 Avago Technologies
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
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
21  * FOR 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
27  * SUCH DAMAGE.
28  *
29  * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
30  */
31 
32 struct mps_fw_event_work;
33 
34 struct mpssas_lun {
35 	SLIST_ENTRY(mpssas_lun) lun_link;
36 	lun_id_t	lun_id;
37 	uint8_t		eedp_formatted;
38 	uint32_t	eedp_block_size;
39 };
40 
41 struct mpssas_target {
42 	uint16_t	handle;
43 	uint8_t		linkrate;
44 	uint64_t	devname;
45 	uint32_t	devinfo;
46 	uint16_t	encl_handle;
47 	uint16_t	encl_slot;
48 	uint8_t		flags;
49 #define MPSSAS_TARGET_INABORT	(1 << 0)
50 #define MPSSAS_TARGET_INRESET	(1 << 1)
51 #define MPSSAS_TARGET_INDIAGRESET (1 << 2)
52 #define MPSSAS_TARGET_INREMOVAL	(1 << 3)
53 #define MPS_TARGET_FLAGS_RAID_COMPONENT (1 << 4)
54 #define MPS_TARGET_FLAGS_VOLUME         (1 << 5)
55 #define MPS_TARGET_IS_SATA_SSD	(1 << 6)
56 #define MPSSAS_TARGET_INRECOVERY (MPSSAS_TARGET_INABORT | \
57     MPSSAS_TARGET_INRESET | MPSSAS_TARGET_INCHIPRESET)
58 
59 	uint16_t	tid;
60 	SLIST_HEAD(, mpssas_lun) luns;
61 	TAILQ_HEAD(, mps_command) commands;
62 	struct mps_command *tm;
63 	struct mps_command *pending_remove_tm;
64 	TAILQ_HEAD(, mps_command) timedout_commands;
65 	uint16_t        exp_dev_handle;
66 	uint16_t        phy_num;
67 	uint64_t	sasaddr;
68 	uint16_t	parent_handle;
69 	uint64_t	parent_sasaddr;
70 	uint32_t	parent_devinfo;
71 	uint64_t        issued;
72 	uint64_t        completed;
73 	unsigned int    outstanding;
74 	unsigned int    timeouts;
75 	unsigned int    aborts;
76 	unsigned int    logical_unit_resets;
77 	unsigned int    target_resets;
78 	uint8_t		stop_at_shutdown;
79 	uint8_t		supports_SSU;
80 };
81 
82 struct mpssas_softc {
83 	struct mps_softc	*sc;
84 	u_int			flags;
85 #define MPSSAS_IN_DISCOVERY	(1 << 0)
86 #define MPSSAS_IN_STARTUP	(1 << 1)
87 #define MPSSAS_QUEUE_FROZEN	(1 << 3)
88 	u_int			maxtargets;
89 	struct mpssas_target	*targets;
90 	struct cam_devq		*devq;
91 	struct cam_sim		*sim;
92 	struct cam_path		*path;
93 	struct intr_config_hook	sas_ich;
94 	struct mps_event_handle	*mpssas_eh;
95 
96 	u_int                   startup_refcount;
97 	struct proc             *sysctl_proc;
98 
99 	struct taskqueue	*ev_tq;
100 	struct task		ev_task;
101 	TAILQ_HEAD(, mps_fw_event_work)	ev_queue;
102 };
103 
104 MALLOC_DECLARE(M_MPSSAS);
105 
106 /*
107  * Abstracted so that the driver can be backwards and forwards compatible
108  * with future versions of CAM that will provide this functionality.
109  */
110 #define MPS_SET_LUN(lun, ccblun)	\
111 	mpssas_set_lun(lun, ccblun)
112 
113 static __inline int
114 mpssas_set_lun(uint8_t *lun, u_int ccblun)
115 {
116 	uint64_t *newlun;
117 
118 	newlun = (uint64_t *)lun;
119 	*newlun = 0;
120 	if (ccblun <= 0xff) {
121 		/* Peripheral device address method, LUN is 0 to 255 */
122 		lun[1] = ccblun;
123 	} else if (ccblun <= 0x3fff) {
124 		/* Flat space address method, LUN is <= 16383 */
125 		scsi_ulto2b(ccblun, lun);
126 		lun[0] |= 0x40;
127 	} else if (ccblun <= 0xffffff) {
128 		/* Extended flat space address method, LUN is <= 16777215 */
129 		scsi_ulto3b(ccblun, &lun[1]);
130 		/* Extended Flat space address method */
131 		lun[0] = 0xc0;
132 		/* Length = 1, i.e. LUN is 3 bytes long */
133 		lun[0] |= 0x10;
134 		/* Extended Address Method */
135 		lun[0] |= 0x02;
136 	} else {
137 		return (EINVAL);
138 	}
139 
140 	return (0);
141 }
142 
143 static __inline void
144 mpssas_set_ccbstatus(union ccb *ccb, int status)
145 {
146 	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
147 	ccb->ccb_h.status |= status;
148 }
149 
150 static __inline int
151 mpssas_get_ccbstatus(union ccb *ccb)
152 {
153 	return (ccb->ccb_h.status & CAM_STATUS_MASK);
154 }
155 
156 #define MPS_SET_SINGLE_LUN(req, lun)	\
157 do {					\
158 	bzero((req)->LUN, 8);		\
159 	(req)->LUN[1] = lun;		\
160 } while(0)
161 
162 void mpssas_rescan_target(struct mps_softc *sc, struct mpssas_target *targ);
163 void mpssas_discovery_end(struct mpssas_softc *sassc);
164 void mpssas_prepare_for_tm(struct mps_softc *sc, struct mps_command *tm,
165     struct mpssas_target *target, lun_id_t lun_id);
166 void mpssas_startup_increment(struct mpssas_softc *sassc);
167 void mpssas_startup_decrement(struct mpssas_softc *sassc);
168 
169 void mpssas_firmware_event_work(void *arg, int pending);
170 int mpssas_check_id(struct mpssas_softc *sassc, int id);
171