sd_bio.c revision fcf3ce441efd61da9bb2884968af01cb7c1452cc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern uintptr_t kobj_getsymvalue(char *, int); /* DDI violation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shouldn't really use an extern here but no .h file provides this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so we have no choice (other than not using it)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern struct vnode kvp; /* the vnode for seg_kmem memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define DO_PAGE_LIST sdbc_do_page /* enable pagelist code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Forward declare all statics that are used before defined to enforce
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameter checking. Also forward-declare all functions that have 64-bit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argument types to enforce correct parameter checking.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Some (if not all) of these could be removed if the code were reordered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_sync_ea(struct buf *, iob_hook_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _sd_async_ea(struct buf *, iob_hook_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_pack_pages(struct buf *bp, struct buf *list, sd_addr_t *addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_pack_pages_nopageio(struct buf *bp, struct buf *list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sd_addr_t *addr, nsc_off_t offset, nsc_size_t size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sd_setup_iob(struct buf *bp, dev_t dev, nsc_off_t pos, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _sdbc_ioj_clear_err(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int SD_WRITES_TOT = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_add_vm_to_bp_plist - add the page corresponding to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * virtual address "v" (kernel virtaddr) to the pagelist linked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to buffer "bp".
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The virtual address "v" is "known" to be allocated by segkmem
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and we can look up the page by using the segkmem vnode kvp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This violates the ddi/ddk but is workable for now anyway.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_add_vm_to_bp_plist(struct buf *bp, unsigned char *v)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp = page_find(&kvp, (u_offset_t)((uintptr_t)v & ~page_offset_mask));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_add_vm_to_bp_plist: couldn't find page for 0x%p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cnt = 1, pp1 = pp->p_next; pp != pp1; cnt++, pp1 = pp1->p_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_iobuf_load - load time initialization of io bufs structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine initializes load time buf structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Should be called when the cache is loaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&sdbc_bio_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HACK add a ref to kvp, to prevent VN_RELE on it from panicing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the system
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_iobuf_unload - unload time cleanup of io buf structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine removes load time buf structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Should be called when the cache is unloaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Undo our VN_HOLD hack, by putting ref count back to normal state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_iobuf_configure - configure a list of io bufs for later use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * num_bufs - number of buffers. (from the configuration file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * <0 - failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine configures the buf structures for io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Should be called when the cache is configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_sd_buflist.hooks = (iob_hook_t *)nsc_kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num * sizeof (iob_hook_t), KM_SLEEP, sdbc_iobuf_mem))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hook->iob_drv_iodone = (dcb_t)kobj_getsymvalue(symbol_name, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < MAX_HOOK_LOCKS; i++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_sd_buflist.hook_locks[i], NULL, MUTEX_DRIVER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&_sd_buflist.hook_wait, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* pagelist i/o pages must be done in cache_init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sdbc_iobuf_deconfigure - release all memory allocated for buf list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < _sd_buflist.bl_init_count; i ++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buflist.bl_init_count * sizeof (iob_hook_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < MAX_HOOK_LOCKS; i ++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ioj_clear_err(-1); /* clear any injected i/o errors */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sdbc_ioj_set_dev(-1, 0); /* clear dev entries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_pending_iobuf()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the number of I/O bufs outstanding
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_get_iobuf - allocate a buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL - failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buf ptr otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ASSUMPTIONS - process could block if we run out.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct buf *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get a buffer, ready for page list i/o */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_put_iobuf - put a buf back in the freelist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - buf pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* use for ORing only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_setup_iob(struct buf *bp, dev_t dev, nsc_off_t pos, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if pagelist i/o, _sd_get_iobuf()/pageio_setup() has already
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set b_flags to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * B_KERNBUF | B_PAGEIO | B_NOCACHE | B_BUSY (sol 6,7,8)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * B_PAGEIO | B_NOCACHE | B_BUSY (sol 9)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_get_hook - get an iob hook from the free list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the newly allocated iob_hook.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_buflist.max_hook_waiters < _sd_buflist.hook_waiters)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buflist.max_hook_waiters = _sd_buflist.hook_waiters;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&_sd_buflist.hook_wait, &sdbc_bio_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_sd_buflist.bl_hook_lowmark > --_sd_buflist.bl_hooks_avail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _sd_buflist.bl_hook_lowmark = _sd_buflist.bl_hooks_avail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_put_hook - put an iob hook back on the free list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hook - an iob_hook to be returned to the freelist.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_extend_iob - the i/o block we are handling needs a new struct buf to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * describe the next hunk of i/o. Get a new struct buf initialize it based
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the state in the struct buf we are passed as an arg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * head_bp - a buffer header in the current i/o block we are handling.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (generally the initial header but in fact could be any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the ones [if any] that were chained to the initial
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct buf *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iob_hook_t *hook = (iob_hook_t *)head_bp->b_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp->b_flags |= (head_bp->b_flags & (B_READ | B_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * b_forw/b_back will form a doubly linked list of all the buffers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associated with this block of i/o.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hook->tail points to the last buffer in the chain.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_alloc_iob - start processing a block of i/o. This allocates an initial
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer header for describing the i/o and a iob_hook for collecting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information about all the i/o requests added to this buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dev - the device all the i/o is destined for.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - the initial disk block to read.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * blks - ignored
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - signal whether this is a read or write request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pointer to free struct buf which will be used to describe i/o request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_alloc_iob(dev_t dev, nsc_off_t fba_pos, int blks, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* can't see how this could happen */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pick an arbitrary lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hook->lockp = &_sd_buflist.hook_locks[((long)hook >> 9) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_pack_pages - produce i/o requests that will perform the type of i/o
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * described by bp (READ/WRITE). It attempt to tack the i/o onto the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buf pointer to by list to minimize the number of bufs required.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - is the i/o description i.e. head
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list - is where to start adding this i/o request (null if we should extend)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addr - address describing where the data is.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * offset - offset from addr where data begins
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * size - size of the i/o request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_pack_pages(struct buf *bp, struct buf *list, sd_addr_t *addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page_end_aligned = !(end_addr & page_offset_mask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we're hosed since we have no error return...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * though we could ignore stuff from here on out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return ENOMEM when we get to sd_start_io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will do for now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "_sd_pack_pages: couldn't extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We only want to do pagelist i/o if we end on a page boundary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we don't end on a page boundary we won't combine with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * next request and so we may as well do it as normal as it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will only use one buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handle the partial page
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we're hosed since we have no error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return though we could ignore stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from here on out and return ENOMEM
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when we get to sd_start_io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will do for now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_pack_pages: couldn't extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned char *) start_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now fill with all the full pages remaining.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (unsigned char *) start_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wasn't worth it as pagelist i/o, do as normal
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (list->b_bufsize && !(list = _sd_extend_iob(bp))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we're hosed since we have no error return...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * though we could ignore stuff from here on out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return ENOMEM when we get to sd_start_io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will do for now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "_sd_pack_pages: couldn't extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* kernel virtual */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * perform same function as _sd_pack_pages() when not doing pageio
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_sd_pack_pages_nopageio(struct buf *bp, struct buf *list, sd_addr_t *addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we're hosed since we have no error return...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * though we could ignore stuff from here on out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return ENOMEM when we get to sd_start_io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will do for now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "_sd_pack_pages_nopageio: couldn't "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (start_addr == (uintptr_t)(list->b_un.b_addr + list->b_bufsize))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* contiguous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not contiguous mem (extend) or first buffer (bufsize == 0).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (list->b_bufsize && !(list = _sd_extend_iob(bp))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we're hosed since we have no error return...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * though we could ignore stuff from here on out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return ENOMEM when we get to sd_start_io.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This will do for now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "_sd_pack_pages_nopageio: couldn't "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_add_fba - add an i/o request to the block of i/o described by bp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We try and combine this request with the previous request. In
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Addition we try and do the i/o as PAGELIST_IO if it satisfies
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the restrictions for it. If the i/o request can't be combined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we extend the i/o description with a new buffer header and add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it to the chain headed by bp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - the struct buf describing the block i/o we are collecting.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addr - description of the address where the data will read/written to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A NULL indicates that this i/o request doesn't need to actually
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * happen. Used to mark reads when the fba is already in cache and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_pos - offset from address in addr where the i/o is to start.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fba_len - number of consecutive fbas to transfer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: It is assumed that the memory is physically contiguous but may span
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multiple pages (should a cache block be larger than a page).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_add_fba(struct buf *bp, sd_addr_t *addr, nsc_off_t fba_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if this can be combined with previous request(s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Last buffer was a pagelist. Unless a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * skip was detected the last request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ended on a page boundary. If this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one starts on one we combine the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * best we can.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Last buffer was vanilla i/o or worse
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (sd_add_mem)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be a read of dirty block we want to discard */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_add_mem - add an i/o request to the block of i/o described by bp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The memory target for this i/o may span multiple pages and may
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not be physically contiguous.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * also the len might also not be a multiple of an fba.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - the struct buf describing the block i/o we are collecting.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buf - target of this i/o request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * len - number of bytes to transfer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_add_mem(struct buf *bp, char *buf, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = min((nsc_size_t)len, (nsc_size_t)(page_size - start));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i/o size must be multiple of an FBA since we can't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count on lower level drivers to understand b_offset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (BLK_FBA_OFF(n) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sdbc(sd_add_mem) i/o request not FBA sized (%"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we're hosed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sd_add_mem: couldn't extend iob");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sd_start_io - start all the i/o needed to satisfy the i/o request described
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by bp. If supplied the a non-NULL fn then this is an async request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and we will return NSC_PENDING and call fn when all the i/o complete.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Otherwise this is a synchronous request and we sleep until all the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i/o is complete. If any buffer in the chain gets an error we return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the first error we see (once all the i/o is complete).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - the struct buf describing the block i/o we are collecting.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * strategy - strategy function to call if known by the user, or NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fn - user's callback function. NULL implies synchronous request.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * arg - an argument passed to user's callback function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesd_start_io(struct buf *bp, strategy_fn_t strategy, sdbc_ea_fn_t fn,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int total_pages, total_pages_combined, total_norm,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sizeof (SD_WRITES_LEN)/sizeof (int))]++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It's possible for us to be told to read a dirty block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * where all the i/o can go away (e.g. read one fba, it's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in cache and dirty) so we really have nothing to do but
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * say we're done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* inject i/o error for testing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bp->b_error = _sdbc_ioj_lookup(bp->b_edev)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sdbc(sd_start_io) t_bufs %d pages %d "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "combined %d norm %d norm_size %" NSC_SZFMT " skipped %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sdbc(sd_start_io) (r) max_run %d, total_xp %d total yp %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "sdbc(sd_start_io) (w) max_run %d, total_xp %d total yp %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SD_BIO_STATS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_sync_ea - called when a single i/o operation is complete. If this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is the last outstanding i/o we wakeup the sleeper.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this i/o had an error then we store the error result in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iob_hook if this was the first error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - the struct buf describing the block i/o that just completed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is called at interrupt level when the io is done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We get called for each buf that completes. When they are all done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we wakeup the waiter.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error = (bp->b_flags & B_ERROR) ? bp->b_error : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remember the last buffer so we can free it later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * let sd_start_io free the final buffer so the hook can be returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _sd_async_ea - End action for async read/write.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ARGUMENTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * bp - io buf pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine is called at interrupt level when the io is done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is only called when the operation is asynchronous.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We get called for each buf that completes. When they are all done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we call the requestor's callback function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error = (bp->b_flags & B_ERROR) ? bp->b_error : 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* MAKE SURE b_lblkno, b_count never changes!! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct ioerr_inject_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sdbc_max_devs * sizeof (ioerr_inject_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cd == -1) { /* all -- used for clearing table on shutdown */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; ++i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioerr_inject_table[cd].ioj_dev = crdev; /* assume valid cd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sdbc_max_devs; ++i) {