xref: /dragonfly/sys/dev/raid/mpr/mpr_sas.h (revision d06bda808418afb8abbe5572edcc463c6fce3a86)
1 /*-
2  * Copyright (c) 2011-2015 LSI Corp.
3  * Copyright (c) 2013-2016 Avago Technologies
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
28  *
29  * $FreeBSD: head/sys/dev/mpr/mpr_sas.h 323946 2017-09-23 08:26:42Z scottl $
30  */
31 
32 struct mpr_fw_event_work;
33 
34 struct mprsas_lun {
35           SLIST_ENTRY(mprsas_lun) lun_link;
36           lun_id_t  lun_id;
37           uint8_t             eedp_formatted;
38           uint32_t  eedp_block_size;
39 };
40 
41 struct mprsas_target {
42           uint16_t  handle;
43           uint8_t             linkrate;
44           uint8_t             encl_level_valid;
45           uint8_t             encl_level;
46           char                connector_name[4];
47           uint64_t  devname;
48           uint32_t  devinfo;
49           uint16_t  encl_handle;
50           uint16_t  encl_slot;
51           uint8_t             flags;
52 #define MPRSAS_TARGET_INABORT (1 << 0)
53 #define MPRSAS_TARGET_INRESET (1 << 1)
54 #define MPRSAS_TARGET_INDIAGRESET (1 << 2)
55 #define MPRSAS_TARGET_INREMOVAL         (1 << 3)
56 #define MPR_TARGET_FLAGS_RAID_COMPONENT (1 << 4)
57 #define MPR_TARGET_FLAGS_VOLUME         (1 << 5)
58 #define MPR_TARGET_IS_SATA_SSD          (1 << 6)
59 #define MPRSAS_TARGET_INRECOVERY (MPRSAS_TARGET_INABORT | \
60     MPRSAS_TARGET_INRESET | MPRSAS_TARGET_INCHIPRESET)
61 
62           uint16_t  tid;
63           SLIST_HEAD(, mprsas_lun) luns;
64           TAILQ_HEAD(, mpr_command) commands;
65           struct mpr_command *tm;
66           TAILQ_HEAD(, mpr_command) timedout_commands;
67           uint16_t        exp_dev_handle;
68           uint16_t        phy_num;
69           uint64_t  sasaddr;
70           uint16_t  parent_handle;
71           uint64_t  parent_sasaddr;
72           uint32_t  parent_devinfo;
73           uint64_t        issued;
74           uint64_t        completed;
75           unsigned int    outstanding;
76           unsigned int    timeouts;
77           unsigned int    aborts;
78           unsigned int    logical_unit_resets;
79           unsigned int    target_resets;
80           uint8_t             scsi_req_desc_type;
81           uint8_t             stop_at_shutdown;
82           uint8_t             supports_SSU;
83           uint8_t             is_nvme;
84           uint32_t  MDTS;
85 };
86 
87 struct mprsas_softc {
88           struct mpr_softc    *sc;
89           u_int                         flags;
90 #define MPRSAS_IN_DISCOVERY   (1 << 0)
91 #define MPRSAS_IN_STARTUP     (1 << 1)
92 #define MPRSAS_DISCOVERY_TIMEOUT_PENDING          (1 << 2)
93 #define MPRSAS_QUEUE_FROZEN   (1 << 3)
94 #define   MPRSAS_SHUTDOWN               (1 << 4)
95           u_int                         maxtargets;
96           struct mprsas_target          *targets;
97           struct cam_devq               *devq;
98           struct cam_sim                *sim;
99           struct cam_path               *path;
100           struct intr_config_hook       sas_ich;
101           struct callout                discovery_callout;
102           struct mpr_event_handle       *mprsas_eh;
103 
104           u_int                   startup_refcount;
105           struct proc             *sysctl_proc;
106 
107           struct taskqueue    *ev_tq;
108           struct task                   ev_task;
109           TAILQ_HEAD(, mpr_fw_event_work)         ev_queue;
110 };
111 
112 /*
113  * Abstracted so that the driver can be backwards and forwards compatible
114  * with future versions of CAM that will provide this functionality.
115  */
116 #define MPR_SET_LUN(lun, ccblun)        \
117           mprsas_set_lun(lun, ccblun)
118 
119 static __inline int
mprsas_set_lun(uint8_t * lun,u_int ccblun)120 mprsas_set_lun(uint8_t *lun, u_int ccblun)
121 {
122           uint64_t *newlun;
123 
124           newlun = (uint64_t *)lun;
125           *newlun = 0;
126           if (ccblun <= 0xff) {
127                     /* Peripheral device address method, LUN is 0 to 255 */
128                     lun[1] = ccblun;
129           } else if (ccblun <= 0x3fff) {
130                     /* Flat space address method, LUN is <= 16383 */
131                     scsi_ulto2b(ccblun, lun);
132                     lun[0] |= 0x40;
133           } else if (ccblun <= 0xffffff) {
134                     /* Extended flat space address method, LUN is <= 16777215 */
135                     scsi_ulto3b(ccblun, &lun[1]);
136                     /* Extended Flat space address method */
137                     lun[0] = 0xc0;
138                     /* Length = 1, i.e. LUN is 3 bytes long */
139                     lun[0] |= 0x10;
140                     /* Extended Address Method */
141                     lun[0] |= 0x02;
142           } else {
143                     return (EINVAL);
144           }
145 
146           return (0);
147 }
148 
149 static __inline void
mprsas_set_ccbstatus(union ccb * ccb,int status)150 mprsas_set_ccbstatus(union ccb *ccb, int status)
151 {
152           ccb->ccb_h.status &= ~CAM_STATUS_MASK;
153           ccb->ccb_h.status |= status;
154 }
155 
156 static __inline int
mprsas_get_ccbstatus(union ccb * ccb)157 mprsas_get_ccbstatus(union ccb *ccb)
158 {
159           return (ccb->ccb_h.status & CAM_STATUS_MASK);
160 }
161 
162 #define MPR_SET_SINGLE_LUN(req, lun)    \
163 do {                                              \
164           bzero((req)->LUN, 8);                   \
165           (req)->LUN[1] = lun;                    \
166 } while(0)
167 
168 void mprsas_rescan_target(struct mpr_softc *sc, struct mprsas_target *targ);
169 void mprsas_discovery_end(struct mprsas_softc *sassc);
170 void mprsas_prepare_for_tm(struct mpr_softc *sc, struct mpr_command *tm,
171     struct mprsas_target *target, lun_id_t lun_id);
172 void mprsas_startup_increment(struct mprsas_softc *sassc);
173 void mprsas_startup_decrement(struct mprsas_softc *sassc);
174 
175 void mprsas_firmware_event_work(void *arg, int pending);
176 int mprsas_check_id(struct mprsas_softc *sassc, int id);
177