1 /* $NetBSD: ld_mlx.c,v 1.18 2008/09/09 12:45:40 tron Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Mylex DAC960 front-end for ld(4) driver.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: ld_mlx.c,v 1.18 2008/09/09 12:45:40 tron Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/device.h>
47 #include <sys/endian.h>
54 #include <machine/vmparam.h>
57 #include <dev/ldvar.h>
59 #include <dev/ic/mlxreg.h>
60 #include <dev/ic/mlxio.h>
61 #include <dev/ic/mlxvar.h>
64 struct ld_softc sc_ld
;
68 static void ld_mlx_attach(device_t
, device_t
, void *);
69 static int ld_mlx_detach(device_t
, int);
70 static int ld_mlx_dobio(struct ld_mlx_softc
*, void *, int, int, int,
72 static int ld_mlx_dump(struct ld_softc
*, void *, int, int);
73 static void ld_mlx_handler(struct mlx_ccb
*);
74 static int ld_mlx_match(device_t
, cfdata_t
, void *);
75 static int ld_mlx_start(struct ld_softc
*, struct buf
*);
77 CFATTACH_DECL_NEW(ld_mlx
, sizeof(struct ld_mlx_softc
),
78 ld_mlx_match
, ld_mlx_attach
, ld_mlx_detach
, NULL
);
81 ld_mlx_match(device_t parent
, cfdata_t match
, void *aux
)
88 ld_mlx_attach(device_t parent
, device_t self
, void *aux
)
90 struct mlx_attach_args
*mlxa
= aux
;
91 struct ld_mlx_softc
*sc
= device_private(self
);
92 struct ld_softc
*ld
= &sc
->sc_ld
;
93 struct mlx_softc
*mlx
= device_private(parent
);
94 struct mlx_sysdrive
*ms
= &mlx
->mlx_sysdrive
[mlxa
->mlxa_unit
];
99 sc
->sc_hwunit
= mlxa
->mlxa_unit
;
100 ld
->sc_maxxfer
= MLX_MAX_XFER
;
101 ld
->sc_secsize
= MLX_SECTOR_SIZE
;
102 ld
->sc_maxqueuecnt
= 1;
103 ld
->sc_start
= ld_mlx_start
;
104 ld
->sc_dump
= ld_mlx_dump
;
105 ld
->sc_secperunit
= ms
->ms_size
;
108 * Report on current status, and attach to the ld driver proper.
110 switch (ms
->ms_state
) {
111 case MLX_SYSD_ONLINE
:
113 ld
->sc_flags
= LDF_ENABLED
;
116 case MLX_SYSD_CRITICAL
:
117 statestr
= "critical";
118 ld
->sc_flags
= LDF_ENABLED
;
121 case MLX_SYSD_OFFLINE
:
122 statestr
= "offline";
126 statestr
= "state unknown";
130 if (ms
->ms_raidlevel
== MLX_SYS_DRV_JBOD
)
131 aprint_normal(": JBOD, %s\n", statestr
);
133 aprint_normal(": RAID%d, %s\n", ms
->ms_raidlevel
, statestr
);
139 ld_mlx_detach(device_t dv
, int flags
)
141 struct ld_mlx_softc
*sc
= device_private(dv
);
142 struct ld_softc
*ld
= &sc
->sc_ld
;
143 struct mlx_softc
*mlx
= device_private(device_parent(dv
));
146 if ((rv
= ldbegindetach(ld
, flags
)) != 0)
155 ld_mlx_dobio(struct ld_mlx_softc
*sc
, void *data
, int datasize
, int blkno
,
156 int dowrite
, struct buf
*bp
)
159 struct mlx_softc
*mlx
;
163 mlx
= device_private(device_parent(sc
->sc_ld
.sc_dv
));
165 if ((rv
= mlx_ccb_alloc(mlx
, &mc
, bp
== NULL
)) != 0)
168 /* Map the data transfer. */
169 rv
= mlx_ccb_map(mlx
, mc
, data
, datasize
,
170 dowrite
? MC_XFER_OUT
: MC_XFER_IN
);
172 mlx_ccb_free(mlx
, mc
);
176 /* Build the command. */
177 sgphys
= mlx
->mlx_sgls_paddr
+ (MLX_SGL_SIZE
* mc
->mc_ident
);
178 datasize
/= MLX_SECTOR_SIZE
;
180 if (mlx
->mlx_ci
.ci_iftype
<= 2)
182 dowrite
? MLX_CMD_WRITESG_OLD
: MLX_CMD_READSG_OLD
,
183 datasize
& 0xff, blkno
, sc
->sc_hwunit
, sgphys
,
187 dowrite
? MLX_CMD_WRITESG
: MLX_CMD_READSG
,
189 (sc
->sc_hwunit
<< 3) | ((datasize
>> 8) & 0x07),
190 blkno
, sgphys
, mc
->mc_nsgent
);
194 rv
= mlx_ccb_poll(mlx
, mc
, 10000);
195 mlx_ccb_unmap(mlx
, mc
);
196 mlx_ccb_free(mlx
, mc
);
199 mc
->mc_mx
.mx_handler
= ld_mlx_handler
;
200 mc
->mc_mx
.mx_context
= bp
;
201 mc
->mc_mx
.mx_dv
= sc
->sc_ld
.sc_dv
;
202 mlx_ccb_enqueue(mlx
, mc
);
210 ld_mlx_start(struct ld_softc
*ld
, struct buf
*bp
)
213 return (ld_mlx_dobio((struct ld_mlx_softc
*)ld
, bp
->b_data
,
214 bp
->b_bcount
, bp
->b_rawblkno
, (bp
->b_flags
& B_READ
) == 0, bp
));
218 ld_mlx_handler(struct mlx_ccb
*mc
)
221 struct mlx_context
*mx
;
222 struct ld_mlx_softc
*sc
;
223 struct mlx_softc
*mlx
;
227 sc
= device_private(mx
->mx_dv
);
228 mlx
= device_private(device_parent(sc
->sc_ld
.sc_dv
));
230 if (mc
->mc_status
!= MLX_STATUS_OK
) {
232 bp
->b_resid
= bp
->b_bcount
;
234 if (mc
->mc_status
== MLX_STATUS_RDWROFFLINE
)
235 printf("%s: drive offline\n",
236 device_xname(sc
->sc_ld
.sc_dv
));
238 printf("%s: I/O error - %s\n",
239 device_xname(sc
->sc_ld
.sc_dv
),
240 mlx_ccb_diagnose(mc
));
244 mlx_ccb_unmap(mlx
, mc
);
245 mlx_ccb_free(mlx
, mc
);
246 lddone(&sc
->sc_ld
, bp
);
250 ld_mlx_dump(struct ld_softc
*ld
, void *data
, int blkno
, int blkcnt
)
253 return (ld_mlx_dobio((struct ld_mlx_softc
*)ld
, data
,
254 blkcnt
* ld
->sc_secsize
, blkno
, 1, NULL
));