127da7e6fSSøren Schmidt /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 49a14aa01SUlrich Spörlein * Copyright (c) 2001,2002,2003 Søren Schmidt <sos@FreeBSD.org> 527da7e6fSSøren Schmidt * All rights reserved. 627da7e6fSSøren Schmidt * 727da7e6fSSøren Schmidt * Redistribution and use in source and binary forms, with or without 827da7e6fSSøren Schmidt * modification, are permitted provided that the following conditions 927da7e6fSSøren Schmidt * are met: 1027da7e6fSSøren Schmidt * 1. Redistributions of source code must retain the above copyright 1127da7e6fSSøren Schmidt * notice, this list of conditions and the following disclaimer, 1227da7e6fSSøren Schmidt * without modification, immediately at the beginning of the file. 1327da7e6fSSøren Schmidt * 2. Redistributions in binary form must reproduce the above copyright 1427da7e6fSSøren Schmidt * notice, this list of conditions and the following disclaimer in the 1527da7e6fSSøren Schmidt * documentation and/or other materials provided with the distribution. 1627da7e6fSSøren Schmidt * 3. The name of the author may not be used to endorse or promote products 1727da7e6fSSøren Schmidt * derived from this software without specific prior written permission. 1827da7e6fSSøren Schmidt * 1927da7e6fSSøren Schmidt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2027da7e6fSSøren Schmidt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2127da7e6fSSøren Schmidt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2227da7e6fSSøren Schmidt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2327da7e6fSSøren Schmidt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2427da7e6fSSøren Schmidt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2527da7e6fSSøren Schmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2627da7e6fSSøren Schmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2727da7e6fSSøren Schmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2827da7e6fSSøren Schmidt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2927da7e6fSSøren Schmidt */ 3027da7e6fSSøren Schmidt 3127da7e6fSSøren Schmidt #include <sys/param.h> 3227da7e6fSSøren Schmidt #include <sys/systm.h> 3327da7e6fSSøren Schmidt #include <sys/module.h> 3427da7e6fSSøren Schmidt #include <sys/bio.h> 3566d9c2f3SMitchell Horne #include <sys/bus.h> 3627da7e6fSSøren Schmidt #include <sys/conf.h> 3727da7e6fSSøren Schmidt #include <sys/eventhandler.h> 3866d9c2f3SMitchell Horne #include <sys/kernel.h> 3927da7e6fSSøren Schmidt #include <sys/lock.h> 4066d9c2f3SMitchell Horne #include <sys/malloc.h> 4127da7e6fSSøren Schmidt #include <sys/mutex.h> 42f97aab79SWarner Losh #include <sys/proc.h> 4366d9c2f3SMitchell Horne #include <sys/rman.h> 4466d9c2f3SMitchell Horne 4527da7e6fSSøren Schmidt #include <vm/vm.h> 4627da7e6fSSøren Schmidt #include <vm/pmap.h> 4766d9c2f3SMitchell Horne 4827da7e6fSSøren Schmidt #include <machine/stdarg.h> 4927da7e6fSSøren Schmidt #include <machine/resource.h> 5027da7e6fSSøren Schmidt #include <machine/bus.h> 5166d9c2f3SMitchell Horne 5238d8c994SWarner Losh #include <dev/pci/pcivar.h> 5338d8c994SWarner Losh #include <dev/pci/pcireg.h> 5427da7e6fSSøren Schmidt #include "dev/pst/pst-iop.h" 5527da7e6fSSøren Schmidt 5666d9c2f3SMitchell Horne #include <geom/geom_disk.h> 5766d9c2f3SMitchell Horne 5827da7e6fSSøren Schmidt struct pst_softc { 5927da7e6fSSøren Schmidt struct iop_softc *iop; 6027da7e6fSSøren Schmidt struct i2o_lct_entry *lct; 6127da7e6fSSøren Schmidt struct i2o_bsa_device *info; 620b7ed341SPoul-Henning Kamp struct disk *disk; 6327da7e6fSSøren Schmidt struct bio_queue_head queue; 6427da7e6fSSøren Schmidt }; 6527da7e6fSSøren Schmidt 6627da7e6fSSøren Schmidt struct pst_request { 6727da7e6fSSøren Schmidt struct pst_softc *psc; /* pointer to softc */ 6827da7e6fSSøren Schmidt u_int32_t mfa; /* frame addreess */ 69369934d6SJohn Baldwin struct callout timeout; /* timeout timer */ 7027da7e6fSSøren Schmidt struct bio *bp; /* associated bio ptr */ 7127da7e6fSSøren Schmidt }; 7227da7e6fSSøren Schmidt 7327da7e6fSSøren Schmidt /* prototypes */ 745cd0cc88SPoul-Henning Kamp static disk_strategy_t pststrategy; 7527da7e6fSSøren Schmidt static int pst_probe(device_t); 7627da7e6fSSøren Schmidt static int pst_attach(device_t); 77c4dacfa7SMitchell Horne static void pst_shutdown_post_sync(device_t, int); 7827da7e6fSSøren Schmidt static void pst_start(struct pst_softc *); 7927da7e6fSSøren Schmidt static void pst_done(struct iop_softc *, u_int32_t, struct i2o_single_reply *); 8027da7e6fSSøren Schmidt static int pst_rw(struct pst_request *); 81369934d6SJohn Baldwin static void pst_timeout(void *); 8227da7e6fSSøren Schmidt static void bpack(int8_t *, int8_t *, int); 8327da7e6fSSøren Schmidt 8427da7e6fSSøren Schmidt /* local vars */ 8527da7e6fSSøren Schmidt static MALLOC_DEFINE(M_PSTRAID, "pst", "Promise SuperTrak RAID driver"); 8627da7e6fSSøren Schmidt 8727da7e6fSSøren Schmidt int 8827da7e6fSSøren Schmidt pst_add_raid(struct iop_softc *sc, struct i2o_lct_entry *lct) 8927da7e6fSSøren Schmidt { 9027da7e6fSSøren Schmidt struct pst_softc *psc; 915b56413dSWarner Losh device_t child = device_add_child(sc->dev, "pst", DEVICE_UNIT_ANY); 9227da7e6fSSøren Schmidt 9327da7e6fSSøren Schmidt if (!child) 9427da7e6fSSøren Schmidt return ENOMEM; 955cd0cc88SPoul-Henning Kamp if (!(psc = malloc(sizeof(struct pst_softc), 965cd0cc88SPoul-Henning Kamp M_PSTRAID, M_NOWAIT | M_ZERO))) { 975cd0cc88SPoul-Henning Kamp device_delete_child(sc->dev, child); 985cd0cc88SPoul-Henning Kamp return ENOMEM; 995cd0cc88SPoul-Henning Kamp } 10027da7e6fSSøren Schmidt psc->iop = sc; 10127da7e6fSSøren Schmidt psc->lct = lct; 10227da7e6fSSøren Schmidt device_set_softc(child, psc); 103369934d6SJohn Baldwin return device_probe_and_attach(child); 10427da7e6fSSøren Schmidt } 10527da7e6fSSøren Schmidt 10627da7e6fSSøren Schmidt static int 10727da7e6fSSøren Schmidt pst_probe(device_t dev) 10827da7e6fSSøren Schmidt { 10927da7e6fSSøren Schmidt device_set_desc(dev, "Promise SuperTrak RAID"); 11027da7e6fSSøren Schmidt return 0; 11127da7e6fSSøren Schmidt } 11227da7e6fSSøren Schmidt 11327da7e6fSSøren Schmidt static int 11427da7e6fSSøren Schmidt pst_attach(device_t dev) 11527da7e6fSSøren Schmidt { 11627da7e6fSSøren Schmidt struct pst_softc *psc = device_get_softc(dev); 11727da7e6fSSøren Schmidt struct i2o_get_param_reply *reply; 11827da7e6fSSøren Schmidt struct i2o_device_identity *ident; 11927da7e6fSSøren Schmidt int lun = device_get_unit(dev); 12027da7e6fSSøren Schmidt int8_t name [32]; 12127da7e6fSSøren Schmidt 12227da7e6fSSøren Schmidt if (!(reply = iop_get_util_params(psc->iop, psc->lct->local_tid, 12327da7e6fSSøren Schmidt I2O_PARAMS_OPERATION_FIELD_GET, 12427da7e6fSSøren Schmidt I2O_BSA_DEVICE_INFO_GROUP_NO))) 12527da7e6fSSøren Schmidt return ENODEV; 12627da7e6fSSøren Schmidt 12727da7e6fSSøren Schmidt if (!(psc->info = (struct i2o_bsa_device *) 12827da7e6fSSøren Schmidt malloc(sizeof(struct i2o_bsa_device), M_PSTRAID, M_NOWAIT))) { 129*d1bdc282SBjoern A. Zeeb free(reply, M_PSTIOP); 13027da7e6fSSøren Schmidt return ENOMEM; 13127da7e6fSSøren Schmidt } 13227da7e6fSSøren Schmidt bcopy(reply->result, psc->info, sizeof(struct i2o_bsa_device)); 133*d1bdc282SBjoern A. Zeeb free(reply, M_PSTIOP); 13427da7e6fSSøren Schmidt 13527da7e6fSSøren Schmidt if (!(reply = iop_get_util_params(psc->iop, psc->lct->local_tid, 13627da7e6fSSøren Schmidt I2O_PARAMS_OPERATION_FIELD_GET, 13727da7e6fSSøren Schmidt I2O_UTIL_DEVICE_IDENTITY_GROUP_NO))) 13827da7e6fSSøren Schmidt return ENODEV; 13927da7e6fSSøren Schmidt ident = (struct i2o_device_identity *)reply->result; 14027da7e6fSSøren Schmidt #ifdef PSTDEBUG 14127da7e6fSSøren Schmidt printf("pst: vendor=<%.16s> product=<%.16s>\n", 14227da7e6fSSøren Schmidt ident->vendor, ident->product); 14327da7e6fSSøren Schmidt printf("pst: description=<%.16s> revision=<%.8s>\n", 14427da7e6fSSøren Schmidt ident->description, ident->revision); 14527da7e6fSSøren Schmidt printf("pst: capacity=%lld blocksize=%d\n", 14627da7e6fSSøren Schmidt psc->info->capacity, psc->info->block_size); 14727da7e6fSSøren Schmidt #endif 14827da7e6fSSøren Schmidt bpack(ident->vendor, ident->vendor, 16); 14927da7e6fSSøren Schmidt bpack(ident->product, ident->product, 16); 15027da7e6fSSøren Schmidt sprintf(name, "%s %s", ident->vendor, ident->product); 151*d1bdc282SBjoern A. Zeeb free(reply, M_PSTIOP); 15227da7e6fSSøren Schmidt 15327da7e6fSSøren Schmidt bioq_init(&psc->queue); 15427da7e6fSSøren Schmidt 1550b7ed341SPoul-Henning Kamp psc->disk = disk_alloc(); 1560b7ed341SPoul-Henning Kamp psc->disk->d_name = "pst"; 1570b7ed341SPoul-Henning Kamp psc->disk->d_strategy = pststrategy; 1580b7ed341SPoul-Henning Kamp psc->disk->d_maxsize = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/ 1590b7ed341SPoul-Henning Kamp psc->disk->d_drv1 = psc; 1600b7ed341SPoul-Henning Kamp psc->disk->d_unit = lun; 16127da7e6fSSøren Schmidt 1620b7ed341SPoul-Henning Kamp psc->disk->d_sectorsize = psc->info->block_size; 1630b7ed341SPoul-Henning Kamp psc->disk->d_mediasize = psc->info->capacity; 1640b7ed341SPoul-Henning Kamp psc->disk->d_fwsectors = 63; 1650b7ed341SPoul-Henning Kamp psc->disk->d_fwheads = 255; 1660b7ed341SPoul-Henning Kamp 1670b7ed341SPoul-Henning Kamp disk_create(psc->disk, DISK_VERSION); 16827da7e6fSSøren Schmidt 169595ecc67SSøren Schmidt printf("pst%d: %lluMB <%.40s> [%lld/%d/%d] on %.16s\n", lun, 170595ecc67SSøren Schmidt (unsigned long long)psc->info->capacity / (1024 * 1024), 171595ecc67SSøren Schmidt name, psc->info->capacity/(512*255*63), 255, 63, 17227da7e6fSSøren Schmidt device_get_nameunit(psc->iop->dev)); 17327da7e6fSSøren Schmidt 174c4dacfa7SMitchell Horne EVENTHANDLER_REGISTER(shutdown_post_sync, pst_shutdown_post_sync, 17527da7e6fSSøren Schmidt dev, SHUTDOWN_PRI_FIRST); 17627da7e6fSSøren Schmidt return 0; 17727da7e6fSSøren Schmidt } 17827da7e6fSSøren Schmidt 179c4dacfa7SMitchell Horne static void 180c4dacfa7SMitchell Horne pst_shutdown_post_sync(device_t dev, int howto __unused) 18127da7e6fSSøren Schmidt { 18227da7e6fSSøren Schmidt struct pst_softc *psc = device_get_softc(dev); 18327da7e6fSSøren Schmidt struct i2o_bsa_cache_flush_message *msg; 18427da7e6fSSøren Schmidt int mfa; 18527da7e6fSSøren Schmidt 186c4dacfa7SMitchell Horne if (SCHEDULER_STOPPED()) { 187c4dacfa7SMitchell Horne /* Request polled shutdown. */ 188c4dacfa7SMitchell Horne psc->iop->reg->oqueue_intr_mask = 0xffffffff; 189c4dacfa7SMitchell Horne } 190c4dacfa7SMitchell Horne 19127da7e6fSSøren Schmidt mfa = iop_get_mfa(psc->iop); 19227da7e6fSSøren Schmidt msg = (struct i2o_bsa_cache_flush_message *)(psc->iop->ibase + mfa); 19327da7e6fSSøren Schmidt bzero(msg, sizeof(struct i2o_bsa_cache_flush_message)); 19427da7e6fSSøren Schmidt msg->version_offset = 0x01; 19527da7e6fSSøren Schmidt msg->message_flags = 0x0; 19627da7e6fSSøren Schmidt msg->message_size = sizeof(struct i2o_bsa_cache_flush_message) >> 2; 19727da7e6fSSøren Schmidt msg->target_address = psc->lct->local_tid; 19827da7e6fSSøren Schmidt msg->initiator_address = I2O_TID_HOST; 19927da7e6fSSøren Schmidt msg->function = I2O_BSA_CACHE_FLUSH; 20027da7e6fSSøren Schmidt msg->control_flags = 0x0; /* 0x80 = post progress reports */ 20127da7e6fSSøren Schmidt if (iop_queue_wait_msg(psc->iop, mfa, (struct i2o_basic_message *)msg)) 20227da7e6fSSøren Schmidt printf("pst: shutdown failed!\n"); 20327da7e6fSSøren Schmidt } 20427da7e6fSSøren Schmidt 20527da7e6fSSøren Schmidt static void 20627da7e6fSSøren Schmidt pststrategy(struct bio *bp) 20727da7e6fSSøren Schmidt { 2085cd0cc88SPoul-Henning Kamp struct pst_softc *psc = bp->bio_disk->d_drv1; 20927da7e6fSSøren Schmidt 210ac9953bfSSøren Schmidt mtx_lock(&psc->iop->mtx); 211891619a6SPoul-Henning Kamp bioq_disksort(&psc->queue, bp); 21227da7e6fSSøren Schmidt pst_start(psc); 213ac9953bfSSøren Schmidt mtx_unlock(&psc->iop->mtx); 21427da7e6fSSøren Schmidt } 21527da7e6fSSøren Schmidt 21627da7e6fSSøren Schmidt static void 21727da7e6fSSøren Schmidt pst_start(struct pst_softc *psc) 21827da7e6fSSøren Schmidt { 21927da7e6fSSøren Schmidt struct pst_request *request; 22027da7e6fSSøren Schmidt struct bio *bp; 22127da7e6fSSøren Schmidt u_int32_t mfa; 222d176b803SScott Long int error; 22327da7e6fSSøren Schmidt 224ac9953bfSSøren Schmidt if (psc->iop->outstanding < (I2O_IOP_OUTBOUND_FRAME_COUNT - 1) && 22527da7e6fSSøren Schmidt (bp = bioq_first(&psc->queue))) { 22627da7e6fSSøren Schmidt if ((mfa = iop_get_mfa(psc->iop)) != 0xffffffff) { 227b539f9d5SSøren Schmidt bioq_remove(&psc->queue, bp); 22827da7e6fSSøren Schmidt if (!(request = malloc(sizeof(struct pst_request), 22927da7e6fSSøren Schmidt M_PSTRAID, M_NOWAIT | M_ZERO))) { 23027da7e6fSSøren Schmidt printf("pst: out of memory in start\n"); 231b539f9d5SSøren Schmidt biofinish(request->bp, NULL, ENOMEM); 23227da7e6fSSøren Schmidt iop_free_mfa(psc->iop, mfa); 23327da7e6fSSøren Schmidt return; 23427da7e6fSSøren Schmidt } 235369934d6SJohn Baldwin callout_init_mtx(&request->timeout, &psc->iop->mtx, 0); 236ac9953bfSSøren Schmidt psc->iop->outstanding++; 23727da7e6fSSøren Schmidt request->psc = psc; 23827da7e6fSSøren Schmidt request->mfa = mfa; 23927da7e6fSSøren Schmidt request->bp = bp; 240d176b803SScott Long if ((error = pst_rw(request)) != 0) { 241d176b803SScott Long biofinish(request->bp, NULL, error); 24227da7e6fSSøren Schmidt iop_free_mfa(request->psc->iop, request->mfa); 243ac9953bfSSøren Schmidt psc->iop->outstanding--; 24427da7e6fSSøren Schmidt free(request, M_PSTRAID); 24527da7e6fSSøren Schmidt } 24627da7e6fSSøren Schmidt } 24727da7e6fSSøren Schmidt } 24827da7e6fSSøren Schmidt } 24927da7e6fSSøren Schmidt 25027da7e6fSSøren Schmidt static void 25127da7e6fSSøren Schmidt pst_done(struct iop_softc *sc, u_int32_t mfa, struct i2o_single_reply *reply) 25227da7e6fSSøren Schmidt { 25327da7e6fSSøren Schmidt struct pst_request *request = 25427da7e6fSSøren Schmidt (struct pst_request *)reply->transaction_context; 25527da7e6fSSøren Schmidt struct pst_softc *psc = request->psc; 25627da7e6fSSøren Schmidt 257369934d6SJohn Baldwin callout_stop(&request->timeout); 25827da7e6fSSøren Schmidt request->bp->bio_resid = request->bp->bio_bcount - reply->donecount; 25960794e04SPoul-Henning Kamp biofinish(request->bp, NULL, reply->status ? EIO : 0); 26027da7e6fSSøren Schmidt free(request, M_PSTRAID); 26127da7e6fSSøren Schmidt psc->iop->reg->oqueue = mfa; 262ac9953bfSSøren Schmidt psc->iop->outstanding--; 26327da7e6fSSøren Schmidt pst_start(psc); 26427da7e6fSSøren Schmidt } 26527da7e6fSSøren Schmidt 26627da7e6fSSøren Schmidt int 26727da7e6fSSøren Schmidt pst_rw(struct pst_request *request) 26827da7e6fSSøren Schmidt { 26927da7e6fSSøren Schmidt struct i2o_bsa_rw_block_message *msg; 27027da7e6fSSøren Schmidt int sgl_flag; 27127da7e6fSSøren Schmidt 27227da7e6fSSøren Schmidt msg = (struct i2o_bsa_rw_block_message *) 27327da7e6fSSøren Schmidt (request->psc->iop->ibase + request->mfa); 27427da7e6fSSøren Schmidt bzero(msg, sizeof(struct i2o_bsa_rw_block_message)); 27527da7e6fSSøren Schmidt msg->version_offset = 0x81; 27627da7e6fSSøren Schmidt msg->message_flags = 0x0; 27727da7e6fSSøren Schmidt msg->message_size = sizeof(struct i2o_bsa_rw_block_message) >> 2; 27827da7e6fSSøren Schmidt msg->target_address = request->psc->lct->local_tid; 27927da7e6fSSøren Schmidt msg->initiator_address = I2O_TID_HOST; 28027da7e6fSSøren Schmidt switch (request->bp->bio_cmd) { 28127da7e6fSSøren Schmidt case BIO_READ: 28227da7e6fSSøren Schmidt msg->function = I2O_BSA_BLOCK_READ; 28327da7e6fSSøren Schmidt msg->control_flags = 0x0; /* 0x0c = read cache + readahead */ 28427da7e6fSSøren Schmidt msg->fetch_ahead = 0x0; /* 8 Kb */ 28527da7e6fSSøren Schmidt sgl_flag = 0; 28627da7e6fSSøren Schmidt break; 28727da7e6fSSøren Schmidt case BIO_WRITE: 28827da7e6fSSøren Schmidt msg->function = I2O_BSA_BLOCK_WRITE; 28927da7e6fSSøren Schmidt msg->control_flags = 0x0; /* 0x10 = write behind cache */ 29027da7e6fSSøren Schmidt msg->fetch_ahead = 0x0; 29127da7e6fSSøren Schmidt sgl_flag = I2O_SGL_DIR; 29227da7e6fSSøren Schmidt break; 29327da7e6fSSøren Schmidt default: 294ac9953bfSSøren Schmidt printf("pst: unknown command type 0x%02x\n", request->bp->bio_cmd); 295d176b803SScott Long return EOPNOTSUPP; 29627da7e6fSSøren Schmidt } 29727da7e6fSSøren Schmidt msg->initiator_context = (u_int32_t)pst_done; 29827da7e6fSSøren Schmidt msg->transaction_context = (u_int32_t)request; 29927da7e6fSSøren Schmidt msg->time_multiplier = 1; 30027da7e6fSSøren Schmidt msg->bytecount = request->bp->bio_bcount; 30127da7e6fSSøren Schmidt msg->lba = ((u_int64_t)request->bp->bio_pblkno) * (DEV_BSIZE * 1LL); 302ac9953bfSSøren Schmidt 30327da7e6fSSøren Schmidt if (!iop_create_sgl((struct i2o_basic_message *)msg, request->bp->bio_data, 30427da7e6fSSøren Schmidt request->bp->bio_bcount, sgl_flag)) 305d176b803SScott Long return EIO; 306ac9953bfSSøren Schmidt 30727da7e6fSSøren Schmidt request->psc->iop->reg->iqueue = request->mfa; 308ac9953bfSSøren Schmidt 309369934d6SJohn Baldwin if (!dumping) 310369934d6SJohn Baldwin callout_reset(&request->timeout, 10 * hz, pst_timeout, request); 31127da7e6fSSøren Schmidt return 0; 31227da7e6fSSøren Schmidt } 31327da7e6fSSøren Schmidt 31427da7e6fSSøren Schmidt static void 315369934d6SJohn Baldwin pst_timeout(void *arg) 316ac9953bfSSøren Schmidt { 317369934d6SJohn Baldwin struct pst_request *request; 318d176b803SScott Long int error; 319369934d6SJohn Baldwin 320369934d6SJohn Baldwin request = arg; 321ac9953bfSSøren Schmidt printf("pst: timeout mfa=0x%08x cmd=0x%02x\n", 322ac9953bfSSøren Schmidt request->mfa, request->bp->bio_cmd); 323369934d6SJohn Baldwin mtx_assert(&request->psc->iop->mtx, MA_OWNED); 324ac9953bfSSøren Schmidt iop_free_mfa(request->psc->iop, request->mfa); 325ac9953bfSSøren Schmidt if ((request->mfa = iop_get_mfa(request->psc->iop)) == 0xffffffff) { 326ac9953bfSSøren Schmidt printf("pst: timeout no mfa possible\n"); 327ac9953bfSSøren Schmidt biofinish(request->bp, NULL, EIO); 328ac9953bfSSøren Schmidt request->psc->iop->outstanding--; 329ac9953bfSSøren Schmidt return; 330ac9953bfSSøren Schmidt } 331d176b803SScott Long if ((error = pst_rw(request)) != 0) { 332ac9953bfSSøren Schmidt iop_free_mfa(request->psc->iop, request->mfa); 333d176b803SScott Long biofinish(request->bp, NULL, error); 334ac9953bfSSøren Schmidt request->psc->iop->outstanding--; 335ac9953bfSSøren Schmidt } 336ac9953bfSSøren Schmidt } 337ac9953bfSSøren Schmidt 338ac9953bfSSøren Schmidt static void 33927da7e6fSSøren Schmidt bpack(int8_t *src, int8_t *dst, int len) 34027da7e6fSSøren Schmidt { 34127da7e6fSSøren Schmidt int i, j, blank; 34227da7e6fSSøren Schmidt int8_t *ptr, *buf = dst; 34327da7e6fSSøren Schmidt 34427da7e6fSSøren Schmidt for (i = j = blank = 0 ; i < len; i++) { 345ac9953bfSSøren Schmidt if (blank && src[i] == ' ') 346ac9953bfSSøren Schmidt continue; 34727da7e6fSSøren Schmidt if (blank && src[i] != ' ') { 34827da7e6fSSøren Schmidt dst[j++] = src[i]; 34927da7e6fSSøren Schmidt blank = 0; 35027da7e6fSSøren Schmidt continue; 35127da7e6fSSøren Schmidt } 35227da7e6fSSøren Schmidt if (src[i] == ' ') { 35327da7e6fSSøren Schmidt blank = 1; 35427da7e6fSSøren Schmidt if (i == 0) 35527da7e6fSSøren Schmidt continue; 35627da7e6fSSøren Schmidt } 35727da7e6fSSøren Schmidt dst[j++] = src[i]; 35827da7e6fSSøren Schmidt } 35927da7e6fSSøren Schmidt if (j < len) 36027da7e6fSSøren Schmidt dst[j] = 0x00; 36127da7e6fSSøren Schmidt for (ptr = buf; ptr < buf+len; ++ptr) 36227da7e6fSSøren Schmidt if (!*ptr) 36327da7e6fSSøren Schmidt *ptr = ' '; 36427da7e6fSSøren Schmidt for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr) 36527da7e6fSSøren Schmidt *ptr = 0; 36627da7e6fSSøren Schmidt } 36727da7e6fSSøren Schmidt 36827da7e6fSSøren Schmidt static device_method_t pst_methods[] = { 36927da7e6fSSøren Schmidt DEVMETHOD(device_probe, pst_probe), 37027da7e6fSSøren Schmidt DEVMETHOD(device_attach, pst_attach), 37127da7e6fSSøren Schmidt { 0, 0 } 37227da7e6fSSøren Schmidt }; 37327da7e6fSSøren Schmidt 37427da7e6fSSøren Schmidt static driver_t pst_driver = { 37527da7e6fSSøren Schmidt "pst", 37627da7e6fSSøren Schmidt pst_methods, 37727da7e6fSSøren Schmidt sizeof(struct pst_softc), 37827da7e6fSSøren Schmidt }; 37927da7e6fSSøren Schmidt 3809199ef40SJohn Baldwin DRIVER_MODULE(pst, pstpci, pst_driver, 0, 0); 381