1229997Sken/*- 2229997Sken * Copyright (c) 2004 Silicon Graphics International Corp. 3229997Sken * All rights reserved. 4229997Sken * 5229997Sken * Redistribution and use in source and binary forms, with or without 6229997Sken * modification, are permitted provided that the following conditions 7229997Sken * are met: 8229997Sken * 1. Redistributions of source code must retain the above copyright 9229997Sken * notice, this list of conditions, and the following disclaimer, 10229997Sken * without modification. 11229997Sken * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12229997Sken * substantially similar to the "NO WARRANTY" disclaimer below 13229997Sken * ("Disclaimer") and any redistribution must be conditioned upon 14229997Sken * including a substantially similar Disclaimer requirement for further 15229997Sken * binary redistribution. 16229997Sken * 17229997Sken * NO WARRANTY 18229997Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19229997Sken * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20229997Sken * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21229997Sken * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22229997Sken * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23229997Sken * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24229997Sken * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25229997Sken * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26229997Sken * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27229997Sken * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28229997Sken * POSSIBILITY OF SUCH DAMAGES. 29229997Sken * 30229997Sken * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend_internal.h#1 $ 31229997Sken * $FreeBSD$ 32229997Sken */ 33229997Sken/* 34229997Sken * CTL kernel internal frontend target driver. This allows kernel-level 35229997Sken * clients to send commands into CTL. 36229997Sken * 37229997Sken * Author: Ken Merry <ken@FreeBSD.org> 38229997Sken */ 39229997Sken 40229997Sken#ifndef _CTL_FRONTEND_INTERNAL_H_ 41229997Sken#define _CTL_FRONTEND_INTERNAL_H_ 42229997Sken 43229997Sken/* 44229997Sken * These are general metatask error codes. If the error code is CFI_MT_ERROR, 45229997Sken * check any metatask-specific status codes for more detail on the problem. 46229997Sken */ 47229997Skentypedef enum { 48229997Sken CFI_MT_NONE, 49229997Sken CFI_MT_PORT_OFFLINE, 50229997Sken CFI_MT_ERROR, 51229997Sken CFI_MT_SUCCESS 52229997Sken} cfi_mt_status; 53229997Sken 54229997Skentypedef enum { 55229997Sken CFI_TASK_NONE, 56229997Sken CFI_TASK_SHUTDOWN, 57229997Sken CFI_TASK_STARTUP, 58229997Sken CFI_TASK_BBRREAD 59229997Sken} cfi_tasktype; 60229997Sken 61229997Skenstruct cfi_task_startstop { 62229997Sken int total_luns; 63229997Sken int luns_complete; 64229997Sken int luns_failed; 65229997Sken}; 66229997Sken 67229997Sken/* 68229997Sken * Error code description: 69229997Sken * CFI_BBR_SUCCESS - the read was successful 70229997Sken * CFI_BBR_LUN_UNCONFIG - CFI probe for this lun hasn't completed 71229997Sken * CFI_BBR_NO_LUN - this lun doesn't exist, as far as CFI knows 72229997Sken * CFI_BBR_NO_MEM - memory allocation error 73229997Sken * CFI_BBR_BAD_LEN - data length isn't a multiple of the blocksize 74229997Sken * CFI_BBR_RESERV_CONFLICT - another initiator has this lun reserved, so 75229997Sken * we can't issue I/O at all. 76229997Sken * CFI_BBR_LUN_STOPPED - the lun is powered off. 77229997Sken * CFI_BBR_LUN_OFFLINE_CTL - the lun is offline from a CTL standpoint 78229997Sken * CFI_BBR_LUN_OFFLINE_RC - the lun is offline from a RAIDCore standpoint. 79229997Sken * This is bad, because it basically means we've 80229997Sken * had a double failure on the LUN. 81229997Sken * CFI_BBR_SCSI_ERROR - generic SCSI error, see status byte and sense 82229997Sken * data for more resolution if you want it. 83229997Sken * CFI_BBR_ERROR - the catch-all error code. 84229997Sken */ 85229997Skentypedef enum { 86229997Sken CFI_BBR_SUCCESS, 87229997Sken CFI_BBR_LUN_UNCONFIG, 88229997Sken CFI_BBR_NO_LUN, 89229997Sken CFI_BBR_NO_MEM, 90229997Sken CFI_BBR_BAD_LEN, 91229997Sken CFI_BBR_RESERV_CONFLICT, 92229997Sken CFI_BBR_LUN_STOPPED, 93229997Sken CFI_BBR_LUN_OFFLINE_CTL, 94229997Sken CFI_BBR_LUN_OFFLINE_RC, 95229997Sken CFI_BBR_SCSI_ERROR, 96229997Sken CFI_BBR_ERROR, 97229997Sken} cfi_bbrread_status; 98229997Sken 99229997Skenstruct cfi_task_bbrread { 100229997Sken int lun_num; /* lun number */ 101229997Sken uint64_t lba; /* logical block address */ 102229997Sken int len; /* length in bytes */ 103229997Sken cfi_bbrread_status status; /* BBR status */ 104229997Sken uint8_t scsi_status; /* SCSI status */ 105229997Sken struct scsi_sense_data sense_data; /* SCSI sense data */ 106229997Sken}; 107229997Sken 108229997Skenunion cfi_taskinfo { 109229997Sken struct cfi_task_startstop startstop; 110229997Sken struct cfi_task_bbrread bbrread; 111229997Sken}; 112229997Sken 113229997Skenstruct cfi_metatask; 114229997Sken 115229997Skentypedef void (*cfi_cb_t)(void *arg, struct cfi_metatask *metatask); 116229997Sken 117229997Skenstruct cfi_metatask { 118229997Sken cfi_tasktype tasktype; /* passed to CFI */ 119229997Sken cfi_mt_status status; /* returned from CFI */ 120229997Sken union cfi_taskinfo taskinfo; /* returned from CFI */ 121229997Sken struct ctl_mem_element *element; /* used by CFI, don't touch*/ 122229997Sken cfi_cb_t callback; /* passed to CFI */ 123229997Sken void *callback_arg; /* passed to CFI */ 124229997Sken STAILQ_ENTRY(cfi_metatask) links; /* used by CFI, don't touch*/ 125229997Sken}; 126229997Sken 127229997Sken#ifdef _KERNEL 128229997Sken 129229997SkenMALLOC_DECLARE(M_CTL_CFI); 130229997Sken 131229997Sken/* 132229997Sken * This is the API for sending meta commands (commands that are sent to more 133229997Sken * than one LUN) to the internal frontend: 134229997Sken * - Allocate a metatask using cfi_alloc_metatask(). can_wait == 0 means 135229997Sken * that you're calling from an interrupt context. can_wait == 1 means 136229997Sken * that you're calling from a thread context and don't mind waiting to 137229997Sken * allocate memory. 138229997Sken * - Setup the task type, callback and callback argument. 139229997Sken * - Call cfi_action(). 140229997Sken * - When the callback comes, note the status and any per-command status 141229997Sken * (see the taskinfo union) and then free the metatask with 142229997Sken * cfi_free_metatask(). 143229997Sken */ 144229997Skenstruct cfi_metatask *cfi_alloc_metatask(int can_wait); 145229997Skenvoid cfi_free_metatask(struct cfi_metatask *metatask); 146229997Skenvoid cfi_action(struct cfi_metatask *metatask); 147229997Sken 148229997Sken#endif /* _KERNEL */ 149229997Sken 150229997Sken#endif /* _CTL_FRONTEND_INTERNAL_H_ */ 151229997Sken 152229997Sken/* 153229997Sken * vim: ts=8 154229997Sken */ 155