]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/mps/mps_sas.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / mps / mps_sas.h
1 /*-
2  * Copyright (c) 2011, 2012 LSI Corp.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * LSI MPT-Fusion Host Adapter FreeBSD
27  *
28  * $FreeBSD$
29  */
30
31 struct mps_fw_event_work;
32
33 struct mpssas_lun {
34         SLIST_ENTRY(mpssas_lun) lun_link;
35         lun_id_t        lun_id;
36         uint8_t         eedp_formatted;
37         uint32_t        eedp_block_size;
38 };
39
40 struct mpssas_target {
41         uint16_t        handle;
42         uint8_t         linkrate;
43         uint64_t        devname;
44         uint32_t        devinfo;
45         uint16_t        encl_handle;
46         uint16_t        encl_slot;
47         uint8_t         flags;
48 #define MPSSAS_TARGET_INABORT   (1 << 0)
49 #define MPSSAS_TARGET_INRESET   (1 << 1)
50 #define MPSSAS_TARGET_INDIAGRESET (1 << 2)
51 #define MPSSAS_TARGET_INREMOVAL (1 << 3)
52 #define MPS_TARGET_FLAGS_RAID_COMPONENT (1 << 4)
53 #define MPS_TARGET_FLAGS_VOLUME         (1 << 5)
54 #define MPSSAS_TARGET_INRECOVERY (MPSSAS_TARGET_INABORT | \
55     MPSSAS_TARGET_INRESET | MPSSAS_TARGET_INCHIPRESET)
56
57 #define MPSSAS_TARGET_ADD       (1 << 29)
58 #define MPSSAS_TARGET_REMOVE    (1 << 30)
59         uint16_t        tid;
60         SLIST_HEAD(, mpssas_lun) luns;
61         TAILQ_HEAD(, mps_command) commands;
62         struct mps_command *tm;
63         TAILQ_HEAD(, mps_command) timedout_commands;
64         uint16_t        exp_dev_handle;
65         uint16_t        phy_num;
66         uint64_t        sasaddr;
67         uint16_t        parent_handle;
68         uint64_t        parent_sasaddr;
69         uint32_t        parent_devinfo;
70         struct sysctl_ctx_list sysctl_ctx;
71         struct sysctl_oid *sysctl_tree;
72         TAILQ_ENTRY(mpssas_target) sysctl_link;
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 };
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_DISCOVERY_TIMEOUT_PENDING        (1 << 2)
88 #define MPSSAS_QUEUE_FROZEN     (1 << 3)
89 #define MPSSAS_SHUTDOWN         (1 << 4)
90 #define MPSSAS_SCANTHREAD       (1 << 5)
91         struct mpssas_target    *targets;
92         struct cam_devq         *devq;
93         struct cam_sim          *sim;
94         struct cam_path         *path;
95         struct intr_config_hook sas_ich;
96         struct callout          discovery_callout;
97         u_int                   discovery_timeouts;
98         struct mps_event_handle *mpssas_eh;
99
100         u_int                   startup_refcount;
101         u_int                   tm_count;
102         struct proc             *sysctl_proc;
103
104         TAILQ_HEAD(, ccb_hdr) ccb_scanq;
105         struct proc             *rescan_thread;
106
107         struct taskqueue        *ev_tq;
108         struct task             ev_task;
109         TAILQ_HEAD(, mps_fw_event_work) ev_queue;
110 };
111
112 MALLOC_DECLARE(M_MPSSAS);
113
114 /*
115  * Abstracted so that the driver can be backwards and forwards compatible
116  * with future versions of CAM that will provide this functionality.
117  */
118 #define MPS_SET_LUN(lun, ccblun)        \
119         mpssas_set_lun(lun, ccblun)
120
121 static __inline int
122 mpssas_set_lun(uint8_t *lun, u_int ccblun)
123 {
124         uint64_t *newlun;
125
126         newlun = (uint64_t *)lun;
127         *newlun = 0;
128         if (ccblun <= 0xff) {
129                 /* Peripheral device address method, LUN is 0 to 255 */
130                 lun[1] = ccblun;
131         } else if (ccblun <= 0x3fff) {
132                 /* Flat space address method, LUN is <= 16383 */
133                 scsi_ulto2b(ccblun, lun);
134                 lun[0] |= 0x40;
135         } else if (ccblun <= 0xffffff) {
136                 /* Extended flat space address method, LUN is <= 16777215 */
137                 scsi_ulto3b(ccblun, &lun[1]);
138                 /* Extended Flat space address method */
139                 lun[0] = 0xc0;
140                 /* Length = 1, i.e. LUN is 3 bytes long */
141                 lun[0] |= 0x10;
142                 /* Extended Address Method */
143                 lun[0] |= 0x02;
144         } else {
145                 return (EINVAL);
146         }
147
148         return (0);
149 }
150
151 #define MPS_SET_SINGLE_LUN(req, lun)    \
152 do {                                    \
153         bzero((req)->LUN, 8);           \
154         (req)->LUN[1] = lun;            \
155 } while(0)
156
157 void mpssas_rescan_target(struct mps_softc *sc, struct mpssas_target *targ);
158 void mpssas_discovery_end(struct mpssas_softc *sassc);
159 void mpssas_startup_increment(struct mpssas_softc *sassc);
160 void mpssas_startup_decrement(struct mpssas_softc *sassc);
161
162 struct mps_command * mpssas_alloc_tm(struct mps_softc *sc);
163 void mpssas_free_tm(struct mps_softc *sc, struct mps_command *tm);
164 void mpssas_firmware_event_work(void *arg, int pending);