Deleted Added
full compact
aac_disk.c (177619) aac_disk.c (177899)
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

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
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

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
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/aac/aac_disk.c 177619 2008-03-25 21:39:06Z emaste $");
31__FBSDID("$FreeBSD: head/sys/dev/aac/aac_disk.c 177899 2008-04-03 23:29:31Z emaste $");
32
33#include "opt_aac.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/sysctl.h>

--- 138 unchanged lines hidden (view full) ---

178 aac_submit_bio(bp);
179 mtx_unlock(&sc->ad_controller->aac_io_lock);
180
181 return;
182}
183
184/*
185 * Map the S/G elements for doing a dump.
32
33#include "opt_aac.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/sysctl.h>

--- 138 unchanged lines hidden (view full) ---

178 aac_submit_bio(bp);
179 mtx_unlock(&sc->ad_controller->aac_io_lock);
180
181 return;
182}
183
184/*
185 * Map the S/G elements for doing a dump.
186 *
187 * XXX This does not handle >4GB of RAM. Fixing it is possible except on
188 * adapters that cannot do 64bit s/g lists.
189 */
190static void
191aac_dump_map_sg(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
192{
193 struct aac_fib *fib;
194 struct aac_blockwrite *bw;
195 struct aac_sg_table *sg;
196 int i;

--- 10 unchanged lines hidden (view full) ---

207 sg->SgEntry[i].SgAddress = segs[i].ds_addr;
208 sg->SgEntry[i].SgByteCount = segs[i].ds_len;
209 }
210 fib->Header.Size = nsegs * sizeof(struct aac_sg_entry);
211 }
212}
213
214/*
186 */
187static void
188aac_dump_map_sg(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
189{
190 struct aac_fib *fib;
191 struct aac_blockwrite *bw;
192 struct aac_sg_table *sg;
193 int i;

--- 10 unchanged lines hidden (view full) ---

204 sg->SgEntry[i].SgAddress = segs[i].ds_addr;
205 sg->SgEntry[i].SgByteCount = segs[i].ds_len;
206 }
207 fib->Header.Size = nsegs * sizeof(struct aac_sg_entry);
208 }
209}
210
211/*
212 * Map the S/G elements for doing a dump on 64-bit capable devices.
213 */
214static void
215aac_dump_map_sg64(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
216{
217 struct aac_fib *fib;
218 struct aac_blockwrite64 *bw;
219 struct aac_sg_table64 *sg;
220 int i;
221
222 fib = (struct aac_fib *)arg;
223 bw = (struct aac_blockwrite64 *)&fib->data[0];
224 sg = &bw->SgMap64;
225
226 if (sg != NULL) {
227 sg->SgCount = nsegs;
228 for (i = 0; i < nsegs; i++) {
229 sg->SgEntry64[i].SgAddress = segs[i].ds_addr;
230 sg->SgEntry64[i].SgByteCount = segs[i].ds_len;
231 }
232 fib->Header.Size = nsegs * sizeof(struct aac_sg_entry64);
233 }
234}
235
236/*
215 * Dump memory out to an array
216 *
217 * Send out one command at a time with up to AAC_MAXIO of data.
218 */
219static int
220aac_disk_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
221{
222 struct aac_disk *ad;
223 struct aac_softc *sc;
224 struct aac_fib *fib;
237 * Dump memory out to an array
238 *
239 * Send out one command at a time with up to AAC_MAXIO of data.
240 */
241static int
242aac_disk_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
243{
244 struct aac_disk *ad;
245 struct aac_softc *sc;
246 struct aac_fib *fib;
225 struct aac_blockwrite *bw;
226 size_t len;
227 int size;
228 static bus_dmamap_t dump_datamap;
229 static int first = 0;
230 struct disk *dp;
247 size_t len;
248 int size;
249 static bus_dmamap_t dump_datamap;
250 static int first = 0;
251 struct disk *dp;
252 bus_dmamap_callback_t *callback;
253 u_int32_t command;
231
232 dp = arg;
233 ad = dp->d_drv1;
234
235 if (ad == NULL)
236 return (EINVAL);
237
238 sc= ad->ad_controller;
239
240 if (!first) {
241 first = 1;
242 if (bus_dmamap_create(sc->aac_buffer_dmat, 0, &dump_datamap)) {
243 printf("bus_dmamap_create failed\n");
244 return (ENOMEM);
245 }
246 }
247
248 /* Skip aac_alloc_sync_fib(). We don't want to mess with sleep locks */
249 fib = &sc->aac_common->ac_sync_fib;
254
255 dp = arg;
256 ad = dp->d_drv1;
257
258 if (ad == NULL)
259 return (EINVAL);
260
261 sc= ad->ad_controller;
262
263 if (!first) {
264 first = 1;
265 if (bus_dmamap_create(sc->aac_buffer_dmat, 0, &dump_datamap)) {
266 printf("bus_dmamap_create failed\n");
267 return (ENOMEM);
268 }
269 }
270
271 /* Skip aac_alloc_sync_fib(). We don't want to mess with sleep locks */
272 fib = &sc->aac_common->ac_sync_fib;
250 bw = (struct aac_blockwrite *)&fib->data[0];
251
252 while (length > 0) {
253 len = (length > AAC_MAXIO) ? AAC_MAXIO : length;
273
274 while (length > 0) {
275 len = (length > AAC_MAXIO) ? AAC_MAXIO : length;
254 bw->Command = VM_CtBlockWrite;
255 bw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
256 bw->BlockNumber = offset / AAC_BLOCK_SIZE;
257 bw->ByteCount = len;
258 bw->Stable = CUNSTABLE;
276 if ((sc->flags & AAC_FLAGS_SG_64BIT) == 0) {
277 struct aac_blockwrite *bw;
278 bw = (struct aac_blockwrite *)&fib->data[0];
279 bw->Command = VM_CtBlockWrite;
280 bw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
281 bw->BlockNumber = offset / AAC_BLOCK_SIZE;
282 bw->ByteCount = len;
283 bw->Stable = CUNSTABLE;
284 command = ContainerCommand;
285 callback = aac_dump_map_sg;
286 size = sizeof(struct aac_blockwrite);
287 } else {
288 struct aac_blockwrite64 *bw;
289 bw = (struct aac_blockwrite64 *)&fib->data[0];
290 bw->Command = VM_CtHostWrite64;
291 bw->ContainerId = ad->ad_container->co_mntobj.ObjectId;
292 bw->BlockNumber = offset / AAC_BLOCK_SIZE;
293 bw->SectorCount = len / AAC_BLOCK_SIZE;
294 bw->Pad = 0;
295 bw->Flags = 0;
296 command = ContainerCommand64;
297 callback = aac_dump_map_sg64;
298 size = sizeof(struct aac_blockwrite64);
299 }
259
260 /*
261 * There really isn't any way to recover from errors or
262 * resource shortages here. Oh well. Because of that, don't
263 * bother trying to send the command from the callback; there
264 * is too much required context.
265 */
266 if (bus_dmamap_load(sc->aac_buffer_dmat, dump_datamap, virtual,
300
301 /*
302 * There really isn't any way to recover from errors or
303 * resource shortages here. Oh well. Because of that, don't
304 * bother trying to send the command from the callback; there
305 * is too much required context.
306 */
307 if (bus_dmamap_load(sc->aac_buffer_dmat, dump_datamap, virtual,
267 len, aac_dump_map_sg, fib, BUS_DMA_NOWAIT) != 0)
308 len, callback, fib, BUS_DMA_NOWAIT) != 0)
268 return (ENOMEM);
269
270 bus_dmamap_sync(sc->aac_buffer_dmat, dump_datamap,
271 BUS_DMASYNC_PREWRITE);
272
273 /* fib->Header.Size is set in aac_dump_map_sg */
309 return (ENOMEM);
310
311 bus_dmamap_sync(sc->aac_buffer_dmat, dump_datamap,
312 BUS_DMASYNC_PREWRITE);
313
314 /* fib->Header.Size is set in aac_dump_map_sg */
274 size = fib->Header.Size + sizeof(struct aac_blockwrite);
315 size += fib->Header.Size;
275
316
276 if (aac_sync_fib(sc, ContainerCommand, 0, fib, size)) {
317 if (aac_sync_fib(sc, command, 0, fib, size)) {
277 printf("Error dumping block 0x%jx\n",
278 (uintmax_t)physical);
279 return (EIO);
280 }
281
282 bus_dmamap_sync(sc->aac_buffer_dmat, dump_datamap,
283 BUS_DMASYNC_POSTWRITE);
284

--- 118 unchanged lines hidden ---
318 printf("Error dumping block 0x%jx\n",
319 (uintmax_t)physical);
320 return (EIO);
321 }
322
323 bus_dmamap_sync(sc->aac_buffer_dmat, dump_datamap,
324 BUS_DMASYNC_POSTWRITE);
325

--- 118 unchanged lines hidden ---