181966bceSXin LI /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4f29c86f1SXin LI * Copyright (c) 2005-2011 HighPoint Technologies, Inc. 581966bceSXin LI * All rights reserved. 681966bceSXin LI * 781966bceSXin LI * Redistribution and use in source and binary forms, with or without 881966bceSXin LI * modification, are permitted provided that the following conditions 981966bceSXin LI * are met: 1081966bceSXin LI * 1. Redistributions of source code must retain the above copyright 1181966bceSXin LI * notice, this list of conditions and the following disclaimer. 1281966bceSXin LI * 2. Redistributions in binary form must reproduce the above copyright 1381966bceSXin LI * notice, this list of conditions and the following disclaimer in the 1481966bceSXin LI * documentation and/or other materials provided with the distribution. 1581966bceSXin LI * 1681966bceSXin LI * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1781966bceSXin LI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1881966bceSXin LI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1981966bceSXin LI * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2081966bceSXin LI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2181966bceSXin LI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2281966bceSXin LI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2381966bceSXin LI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2481966bceSXin LI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2581966bceSXin LI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2681966bceSXin LI * SUCH DAMAGE. 2781966bceSXin LI */ 2881966bceSXin LI 2981966bceSXin LI #include <dev/hpt27xx/hpt27xx_config.h> 3081966bceSXin LI 3181966bceSXin LI #ifndef _HPT_LDM_H_ 3281966bceSXin LI #define _HPT_LDM_H_ 3381966bceSXin LI 3481966bceSXin LI #define VERMAGIC_LDM 75 3581966bceSXin LI 3681966bceSXin LI #if defined(__cplusplus) 3781966bceSXin LI extern "C" { 3881966bceSXin LI #endif 3981966bceSXin LI 4081966bceSXin LI 4181966bceSXin LI #define __hpt_set_ver(x, v1, v2, v3, v4, v5) x ## _R_ ## v1 ## _ ## v2 ## _ ## v3 ## _ ## v4 ## _ ## v5 4281966bceSXin LI #define _hpt_set_ver(x, v1, v2, v3, v4, v5) __hpt_set_ver(x, v1, v2, v3, v4, v5) 4381966bceSXin LI #define hpt_set_ver(x) _hpt_set_ver(x, VERMAGIC_OSM, VERMAGIC_HIM, VERMAGIC_LDM, VERMAGIC_ARRAY, MAX_MEMBERS) 4481966bceSXin LI 4581966bceSXin LI #define ldm_register_him hpt_set_ver(ldm_register_him) 4681966bceSXin LI #define ldm_register_vdev_class hpt_set_ver(ldm_register_vdev_class) 4781966bceSXin LI #define ldm_alloc_cmds hpt_set_ver(ldm_alloc_cmds) 4881966bceSXin LI 4981966bceSXin LI 5081966bceSXin LI #ifndef HPT_INTERFACE_VERSION 5181966bceSXin LI #define HPT_INTERFACE_VERSION 0x02010000 5281966bceSXin LI #endif 5381966bceSXin LI 5481966bceSXin LI #ifndef MAX_PARTITIONS_PER_DISK 5581966bceSXin LI #define MAX_PARTITIONS_PER_DISK 4 5681966bceSXin LI #endif 5781966bceSXin LI 5881966bceSXin LI #if defined(__MAX_PARTITIONS_PER_DISK) && MAX_PARTITIONS_PER_DISK > __MAX_PARTITIONS_PER_DISK 5981966bceSXin LI #error "Please redefine MAX_PARTITIONS_PER_DISK!!!" 6081966bceSXin LI #endif 6181966bceSXin LI 6281966bceSXin LI typedef char check_HPT_TIME_is_unsigned[ (HPT_TIME)(-1) > 0 ? 1 : -1 ]; 6381966bceSXin LI 6481966bceSXin LI #define hpt_time_after_eq(a, b) ((int)(a) - (int)(b) >= 0) 6581966bceSXin LI #define hpt_time_after(a, b) ((int)(a) - (int)(b) > 0) 6681966bceSXin LI 6781966bceSXin LI 6881966bceSXin LI 6981966bceSXin LI struct freelist { 7081966bceSXin LI int dma; 7181966bceSXin LI HPT_UINT alignment; 7281966bceSXin LI HPT_UINT count; 7381966bceSXin LI HPT_UINT size; 7481966bceSXin LI void * head; 7581966bceSXin LI struct freelist *next; 7681966bceSXin LI #if DBG 7781966bceSXin LI char *tag; 7881966bceSXin LI HPT_UINT reserved_count; 7981966bceSXin LI #define freelist_debug_tag(list, _tag) (list)->tag = _tag 8081966bceSXin LI #else 8181966bceSXin LI #define freelist_debug_tag(list, _tag) 8281966bceSXin LI #endif 8381966bceSXin LI }; 8481966bceSXin LI 8581966bceSXin LI 8681966bceSXin LI void freelist_reserve(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT count); 8781966bceSXin LI 8881966bceSXin LI void *freelist_get(struct freelist *); 8981966bceSXin LI void freelist_put(struct freelist *, void *p); 9081966bceSXin LI 9181966bceSXin LI void freelist_reserve_dma(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT alignment, HPT_UINT count); 9281966bceSXin LI void *freelist_get_dma(struct freelist *, BUS_ADDRESS *busaddr); 9381966bceSXin LI void freelist_put_dma(struct freelist *, void *p, BUS_ADDRESS busaddr); 9481966bceSXin LI 9581966bceSXin LI 9681966bceSXin LI #define freelist_reserve_with_tag(list, osext, size, count) \ 9781966bceSXin LI do {\ 9881966bceSXin LI freelist_debug_tag(list, #list " at " __FILE__);\ 9981966bceSXin LI freelist_reserve(list, osext, (HPT_UINT)(size), (HPT_UINT)(count));\ 10081966bceSXin LI }while(0) 10181966bceSXin LI 10281966bceSXin LI #define freelist_reserve_dma_with_tag(list, osext, size, alignment, count) \ 10381966bceSXin LI do {\ 10481966bceSXin LI freelist_debug_tag(list, #list " at " __FILE__);\ 10581966bceSXin LI freelist_reserve_dma(list, osext, (HPT_UINT)(size), (HPT_UINT)(alignment), (HPT_UINT)(count));\ 10681966bceSXin LI }while(0) 10781966bceSXin LI 10881966bceSXin LI struct lock_request { 10981966bceSXin LI HPT_U64 start, end; 11081966bceSXin LI struct lock_request *next; 11181966bceSXin LI struct list_head waiters; /* blocked commands */ 11281966bceSXin LI struct tq_item callback; 11381966bceSXin LI int lock_cc; 11481966bceSXin LI }; 11581966bceSXin LI 11681966bceSXin LI #define INIT_LOCK_REQUEST(req, _start, _end, _cb, _arg, _cc) \ 11781966bceSXin LI do {\ 11881966bceSXin LI (req)->next = 0;\ 11981966bceSXin LI (req)->start = _start;\ 12081966bceSXin LI (req)->end = _end;\ 12181966bceSXin LI INIT_TQ_ITEM(&(req)->callback, _cb, _arg);\ 12281966bceSXin LI INIT_LIST_HEAD(&(req)->waiters);\ 12381966bceSXin LI (req)->lock_cc = _cc;\ 12481966bceSXin LI } while (0) 12581966bceSXin LI 12681966bceSXin LI struct task_queue { 12781966bceSXin LI struct tq_item *head, *tail; 12881966bceSXin LI }; 12981966bceSXin LI 13081966bceSXin LI #define TQ_EMPTY(tq) ((tq)->head==0) 13181966bceSXin LI 13281966bceSXin LI struct dmapool_order { 13381966bceSXin LI HPT_UINT npages; 13481966bceSXin LI struct tq_item wakeup_fn; 13581966bceSXin LI struct dmapool_order *next; 13681966bceSXin LI }; 13781966bceSXin LI 13881966bceSXin LI struct dmapool_client { 13981966bceSXin LI void * handle; 14081966bceSXin LI HPT_UINT (*shrink)(void *handle, HPT_UINT npages); 14181966bceSXin LI int (*resume)(void *handle); 14281966bceSXin LI struct dmapool_client *next; 14381966bceSXin LI }; 14481966bceSXin LI 14581966bceSXin LI typedef struct _VBUS * PVBUS; 14681966bceSXin LI typedef struct _VDEV * PVDEV; 14781966bceSXin LI 14881966bceSXin LI 14981966bceSXin LI void dmapool_register_client(PVBUS vbus, struct dmapool_client *client); 15081966bceSXin LI 15181966bceSXin LI 15281966bceSXin LI void dmapool_active(PVBUS vbus); 15381966bceSXin LI 15481966bceSXin LI /* return 0 if the request is immediately satisfied, non-zero otherwise. */ 15581966bceSXin LI int dmapool_make_order(PVBUS vbus, struct dmapool_order *order); 15681966bceSXin LI 15781966bceSXin LI 15881966bceSXin LI void *dmapool_get_page(PVBUS vbus, BUS_ADDRESS *busaddr); 15981966bceSXin LI void *dmapool_get_page_at(PVBUS vbus, void *p, BUS_ADDRESS *busaddr); 16081966bceSXin LI void dmapool_put_page(PVBUS vbus, void *p, BUS_ADDRESS busaddr); 16181966bceSXin LI void dmapool_init(PVBUS vbus); 16281966bceSXin LI HPT_UINT dmapool_max_class_pages(PVBUS vbus); 16381966bceSXin LI 16481966bceSXin LI 16581966bceSXin LI struct timer_call { 16681966bceSXin LI HPT_U32 interval; /*microseconds*/ 16781966bceSXin LI HPT_TIME expire_time; /*microseconds*/ 16881966bceSXin LI void (*proc)(void * arg); 16981966bceSXin LI void * arg; 17081966bceSXin LI struct timer_call ** pprev; 17181966bceSXin LI struct timer_call * next; 17281966bceSXin LI }; 17381966bceSXin LI 17481966bceSXin LI #define ldm_init_timer(timer) do { (timer)->next=0; (timer)->pprev=0; } while (0) 17581966bceSXin LI 17681966bceSXin LI #define INIT_TIMER_CALL(timer, _interval, _proc, _arg) \ 17781966bceSXin LI do { \ 17881966bceSXin LI HPT_ASSERT((timer)->next==0 && (timer)->pprev==0);\ 17981966bceSXin LI (timer)->interval = _interval;\ 18081966bceSXin LI (timer)->proc = _proc;\ 18181966bceSXin LI (timer)->arg = _arg;\ 18281966bceSXin LI } while(0) 18381966bceSXin LI 18481966bceSXin LI void ldm_request_timer(PVBUS vbus, struct timer_call * tc); 18581966bceSXin LI void ldm_remove_timer(PVBUS vbus, struct timer_call * tc); 18681966bceSXin LI void ldm_on_timer(PVBUS vbus); 18781966bceSXin LI 18881966bceSXin LI 18981966bceSXin LI typedef struct _LDM_ADAPTER 19081966bceSXin LI { 19181966bceSXin LI struct _LDM_ADAPTER *next; 19281966bceSXin LI HIM *him; 19381966bceSXin LI void *him_handle; 19481966bceSXin LI PVBUS vbus; 19581966bceSXin LI struct freelist freelist_dev; 19681966bceSXin LI int devid_start; 19781966bceSXin LI struct freelist freelist_plugged_dpc; 19881966bceSXin LI HPT_BOOL master; 19981966bceSXin LI } 20081966bceSXin LI LDM_ADAPTER, *PLDM_ADAPTER; 20181966bceSXin LI 20281966bceSXin LI typedef struct _IOCTL_ARG 20381966bceSXin LI { 20481966bceSXin LI struct list_head link; 20581966bceSXin LI PVBUS vbus; 20681966bceSXin LI HPT_U32 dwIoControlCode; 20781966bceSXin LI HPT_U32 nInBufferSize; 20881966bceSXin LI HPT_U32 nOutBufferSize; 20981966bceSXin LI void * lpInBuffer; 21081966bceSXin LI void * lpOutBuffer; 21181966bceSXin LI HPT_U32 *lpBytesReturned; 21281966bceSXin LI void * ioctl_cmnd; 21381966bceSXin LI void (* done)(struct _IOCTL_ARG *); 21481966bceSXin LI int result; /* HPT_IOCTL_RESULT_ */ 21581966bceSXin LI struct tq_item dpc; 21681966bceSXin LI } IOCTL_ARG; 21781966bceSXin LI 21881966bceSXin LI #define HPT_IOCTL_RESULT_OK 0 21981966bceSXin LI #define HPT_IOCTL_RESULT_FAILED (-1) 22081966bceSXin LI #define HPT_IOCTL_RESULT_INVALID (-2) 22181966bceSXin LI #define HPT_IOCTL_RESULT_RETRY (-3) 22281966bceSXin LI #define HPT_IOCTL_RESULT_WRONG_VBUS (-4) 22381966bceSXin LI 22481966bceSXin LI void ldm_ioctl( PVBUS vbus, IOCTL_ARG *IAPnt); 22581966bceSXin LI void ldm_set_autorebuild(PVBUS vbus, int enable); 22681966bceSXin LI HPT_U32 ldm_get_device_id(PVDEV vd); /* for ioctl */ 22781966bceSXin LI 22881966bceSXin LI #ifndef __HPT_RAW_LBA 22981966bceSXin LI #define __HPT_RAW_LBA HPT_RAW_LBA 23081966bceSXin LI #endif 23181966bceSXin LI 23281966bceSXin LI #include <dev/hpt27xx/array.h> 23381966bceSXin LI 23481966bceSXin LI typedef struct hpt_raw_disk 23581966bceSXin LI { 23681966bceSXin LI #ifdef SUPPORT_ARRAY 23781966bceSXin LI PRAW_PARTITION raw_part_list; 23881966bceSXin LI __HPT_RAW_LBA max_available_capacity; 23981966bceSXin LI __HPT_RAW_LBA total_available_capacity; 24081966bceSXin LI #endif 24181966bceSXin LI __HPT_RAW_LBA real_capacity; 24281966bceSXin LI __HPT_RAW_LBA head_position; 243f29c86f1SXin LI HPT_U32 logical_sector_size; 24481966bceSXin LI 24581966bceSXin LI HPT_U16 max_sectors_per_cmd; 24681966bceSXin LI HPT_U8 max_queue_depth; 24781966bceSXin LI HPT_U8 user_select_mode; 24881966bceSXin LI 24981966bceSXin LI HPT_UINT uninitialized : 1; 25081966bceSXin LI HPT_UINT legacy_disk : 1; 25181966bceSXin LI HPT_UINT is_spare : 1; 25281966bceSXin LI HPT_UINT v3_format : 1; 25381966bceSXin LI HPT_UINT need_sync : 1; 25481966bceSXin LI HPT_UINT temp_spare : 1; 25581966bceSXin LI HPT_UINT need_check_array : 1; 25681966bceSXin LI HPT_UINT df_user_mode_set: 1; 25781966bceSXin LI 25881966bceSXin LI HPT_UINT df_read_ahead_set: 1; 25981966bceSXin LI HPT_UINT enable_read_ahead : 1; 26081966bceSXin LI HPT_UINT df_write_cache_set: 1; 26181966bceSXin LI HPT_UINT enable_write_cache : 1; 26281966bceSXin LI HPT_UINT df_tcq_set: 1; 26381966bceSXin LI HPT_UINT enable_tcq : 1; 26481966bceSXin LI HPT_UINT df_ncq_set: 1; 26581966bceSXin LI HPT_UINT enable_ncq : 1; 26681966bceSXin LI 267f29c86f1SXin LI HPT_UINT bad_sector : 1; 268f29c86f1SXin LI HPT_UINT df_sas : 1; 269f29c86f1SXin LI HPT_UINT df_tape : 1; 270f29c86f1SXin LI HPT_UINT df_changer : 1; 271f29c86f1SXin LI 27281966bceSXin LI HIM * him; 27381966bceSXin LI int index; 27481966bceSXin LI PLDM_ADAPTER adapter; 27581966bceSXin LI void * phy_dev; 27681966bceSXin LI 27781966bceSXin LI char model[40]; 27881966bceSXin LI 27981966bceSXin LI struct tq_item reset_dpc; 28081966bceSXin LI int reset_pending; 28181966bceSXin LI 28281966bceSXin LI struct tq_item fail_dpc; 28381966bceSXin LI int fail_pending; 28481966bceSXin LI } 28581966bceSXin LI HPT_RAW_DISK, *PHPT_RAW_DISK; 28681966bceSXin LI 28781966bceSXin LI struct vdev_class 28881966bceSXin LI { 28981966bceSXin LI struct vdev_class *next; 29081966bceSXin LI 29181966bceSXin LI HPT_U8 __type; 29281966bceSXin LI HPT_U8 stripped; /* RAID0,3,5,6 */ 29381966bceSXin LI HPT_U8 redundancy; /* RAID1-1, RAID3/5-1, RAID6-2 */ 29481966bceSXin LI HPT_U8 must_init; /* RAID3,5,6 */ 29581966bceSXin LI HPT_U8 docache; 29681966bceSXin LI 29781966bceSXin LI HPT_UINT vbus_ext_size; 29881966bceSXin LI HPT_UINT vbus_ext_offset; /* used by LDM */ 29981966bceSXin LI HPT_UINT dev_ext_size; 30081966bceSXin LI HPT_UINT cmd_ext_size; 30181966bceSXin LI 30281966bceSXin LI 30381966bceSXin LI void (*get_mem_info)(PVBUS vbus, void *osext, int phydev_count); 30481966bceSXin LI void (*queue_cmd)(PCOMMAND cmd); 30581966bceSXin LI void (*member_failed)(struct _VDEV * vd); 30681966bceSXin LI 30781966bceSXin LI 30881966bceSXin LI void (*initialize)(PVBUS vbus); 30981966bceSXin LI void (*release)(PVBUS vbus); 31081966bceSXin LI int (*add)(PVDEV vd); 31181966bceSXin LI void (*remove)(PVDEV vd); 31281966bceSXin LI void (*reset)(PVDEV vd); 31381966bceSXin LI void (*sync_stamp)(PVDEV vd); 31481966bceSXin LI int (*support_type)(int type); 31581966bceSXin LI }; 31681966bceSXin LI 31781966bceSXin LI 31881966bceSXin LI #define VDEV_CLASS_CONSTRUCTOR(type, prefix) { \ 31981966bceSXin LI 0, \ 32081966bceSXin LI type, \ 32181966bceSXin LI prefix ## _stripped, \ 32281966bceSXin LI prefix ## _redundancy, \ 32381966bceSXin LI prefix ## _must_init, \ 32481966bceSXin LI 0, \ 32581966bceSXin LI (HPT_UINT)(prefix ## _vbus_ext_size), \ 32681966bceSXin LI 0, \ 32781966bceSXin LI (HPT_UINT)(prefix ## _dev_ext_size), \ 32881966bceSXin LI (HPT_UINT)(prefix ## _cmd_ext_size), \ 32981966bceSXin LI prefix ## _get_mem_info, \ 33081966bceSXin LI prefix ## _queue_cmd, \ 33181966bceSXin LI prefix ## _member_failed, \ 33281966bceSXin LI prefix ## _initialize, \ 33381966bceSXin LI prefix ## _release, \ 33481966bceSXin LI prefix ## _add, \ 33581966bceSXin LI prefix ## _remove, \ 33681966bceSXin LI prefix ## _reset, \ 33781966bceSXin LI prefix ## _sync_stamp, \ 33881966bceSXin LI 0 \ 33981966bceSXin LI } 34081966bceSXin LI 34181966bceSXin LI #define VD_RAW 1 34281966bceSXin LI #define VD_PARTITION 4 34381966bceSXin LI 34481966bceSXin LI #define mIsArray(vdev_type) ((vdev_type)>VD_PARTITION) 34581966bceSXin LI 34681966bceSXin LI #define VD_RAID0 5 34781966bceSXin LI #define VD_RAID1 6 34881966bceSXin LI #define VD_JBOD 7 34981966bceSXin LI #define VD_RAID5 8 35081966bceSXin LI #define VD_RAID6 9 35181966bceSXin LI #define VD_RAID3 10 35281966bceSXin LI #define VD_RAID4 11 35381966bceSXin LI #define VD_RAID1E 12 35481966bceSXin LI 35581966bceSXin LI #define MAX_VD_TYPE_ID 12 35681966bceSXin LI 35781966bceSXin LI struct vdev_class *ldm_find_vdev_class(HPT_U8 type); 35881966bceSXin LI 35981966bceSXin LI typedef struct _VDEV { 36081966bceSXin LI PVBUS vbus; 36181966bceSXin LI struct vdev_class *Class; 36281966bceSXin LI HPT_U8 type; 36381966bceSXin LI PVDEV parent; 36481966bceSXin LI void * ext; 36581966bceSXin LI HPT_U64 capacity; 36681966bceSXin LI int target_id; 36781966bceSXin LI HPT_UINT cmds_per_request; 36881966bceSXin LI 36981966bceSXin LI union { 37081966bceSXin LI #ifdef SUPPORT_ARRAY 37181966bceSXin LI HPT_ARRAY array; 37281966bceSXin LI HPT_PARTITION partition; 37381966bceSXin LI #endif 37481966bceSXin LI HPT_RAW_DISK raw; 37581966bceSXin LI } u; 37681966bceSXin LI 37781966bceSXin LI HPT_U8 vf_online : 1; 37881966bceSXin LI HPT_U8 vf_bootmark : 1; 37981966bceSXin LI HPT_U8 vf_bootable : 1; 38081966bceSXin LI HPT_U8 vf_resetting: 1; 38181966bceSXin LI HPT_U8 vf_quiesced: 1; 38281966bceSXin LI HPT_U8 vf_clslock: 1; 38381966bceSXin LI 38481966bceSXin LI HPT_U8 cache_policy; /* see CACHE_POLICY_* */ 38581966bceSXin LI 38681966bceSXin LI HPT_UINT cq_len; 38781966bceSXin LI HPT_UINT cmds_sent; 38881966bceSXin LI 38981966bceSXin LI struct list_head link; 39081966bceSXin LI struct list_head cq_wait_send; 39181966bceSXin LI struct list_head cq_sent; 39281966bceSXin LI 39381966bceSXin LI HPT_U32 last_active; 39481966bceSXin LI int cq_priority; 39581966bceSXin LI struct list_head cq_wait_lock; 39681966bceSXin LI struct lock_request *locks_granted; 39781966bceSXin LI struct lock_request *locks_wait; 39881966bceSXin LI HPT_U32 ioctl_id; 39981966bceSXin LI void * cc_ext; 40081966bceSXin LI } 40181966bceSXin LI VDEV; 40281966bceSXin LI 40381966bceSXin LI #define CACHE_POLICY_NONE 0 40481966bceSXin LI #define CACHE_POLICY_WRITE_THROUGH 1 40581966bceSXin LI #define CACHE_POLICY_WRITE_BACK 2 40681966bceSXin LI 40781966bceSXin LI 40881966bceSXin LI extern HIM *him_list; 40981966bceSXin LI 41081966bceSXin LI 41181966bceSXin LI void ldm_register_him(PHIM him); 41281966bceSXin LI 41381966bceSXin LI 41481966bceSXin LI void ldm_register_vdev_class(struct vdev_class *Class); 41581966bceSXin LI 41681966bceSXin LI 41781966bceSXin LI HPT_BOOL ldm_register_adapter(PLDM_ADAPTER adapter); 41881966bceSXin LI 41981966bceSXin LI 42081966bceSXin LI int init_config(void); 42181966bceSXin LI 42281966bceSXin LI HPT_UINT ldm_get_vbus_size(void); 42381966bceSXin LI 42481966bceSXin LI 42581966bceSXin LI void ldm_create_vbus(PVBUS vbus, void *osext); 42681966bceSXin LI 42781966bceSXin LI 42881966bceSXin LI void ldm_get_mem_info(PVBUS vbus, void *osext); 42981966bceSXin LI 43081966bceSXin LI 43181966bceSXin LI void *ldm_get_vbus_ext(PVBUS vbus, struct vdev_class *Class); 43281966bceSXin LI 43381966bceSXin LI 43481966bceSXin LI PVBUS ldm_get_next_vbus(PVBUS vbus, void **posext); 43581966bceSXin LI 43681966bceSXin LI #define ldm_for_each_vbus(vbus, vbus_ext) \ 43781966bceSXin LI for (vbus = ldm_get_next_vbus(0, (void **)(void *)&vbus_ext); vbus; \ 43881966bceSXin LI vbus = ldm_get_next_vbus(vbus, (void **)(void *)&vbus_ext)) 43981966bceSXin LI 44081966bceSXin LI 44181966bceSXin LI void ldm_initialize_vbus_async(PVBUS vbus, PLDM_ADAPTER master_adapter, void (*done)(void *osext)); 44281966bceSXin LI 44381966bceSXin LI /* ldm_initialize_vbus is deprecated since it will hold the CPU too long. */ 44481966bceSXin LI #define ldm_initialize_vbus(vbus, adapter) ldm_initialize_vbus_async(vbus, adapter, 0) 44581966bceSXin LI 44681966bceSXin LI 44781966bceSXin LI void ldm_release_vbus(PVBUS vbus); 44881966bceSXin LI 44981966bceSXin LI PVDEV ldm_create_vdev(PVBUS vbus, HPT_U8 type); 45081966bceSXin LI void ldm_release_vdev(PVDEV vd); 45181966bceSXin LI 45281966bceSXin LI PVDEV ldm_find_target(PVBUS vbus, int id); 45381966bceSXin LI PVDEV ldm_find_stamp(PVBUS vbus, HPT_U32 stamp, int seq); 45481966bceSXin LI 45581966bceSXin LI 45681966bceSXin LI PCOMMAND ldm_alloc_cmds(PVBUS vbus, HPT_UINT cnt); 45781966bceSXin LI void ldm_free_cmds(PCOMMAND cmd); 45881966bceSXin LI 45981966bceSXin LI HPT_UINT ldm_get_cmd_size(void); 46081966bceSXin LI PCOMMAND ldm_alloc_cmds_from_list(PVBUS vbus, struct freelist *list, HPT_UINT cnt); 46181966bceSXin LI void ldm_free_cmds_to_list(struct freelist *list, PCOMMAND cmd); 46281966bceSXin LI 46381966bceSXin LI 46481966bceSXin LI PCOMMAND __ldm_alloc_cmd(struct freelist *list); 46581966bceSXin LI 46681966bceSXin LI #ifdef OS_SUPPORT_TASK 46781966bceSXin LI #define CMD_SET_PRIORITY(cmd, pri) cmd->priority = (pri) 46881966bceSXin LI #else 46981966bceSXin LI #define CMD_SET_PRIORITY(cmd, pri) 47081966bceSXin LI #endif 47181966bceSXin LI 47281966bceSXin LI 47381966bceSXin LI #define CMD_GROUP_GET(grp, cmd) \ 47481966bceSXin LI do {\ 47581966bceSXin LI grp->grplist->count++;\ 47681966bceSXin LI cmd = __ldm_alloc_cmd(grp->grplist);\ 47781966bceSXin LI cmd->vbus = grp->vbus;\ 47881966bceSXin LI cmd->grplist = grp->grplist;\ 47981966bceSXin LI CMD_SET_PRIORITY(cmd, grp->priority);\ 48081966bceSXin LI } while(0) 48181966bceSXin LI 48281966bceSXin LI #define CMD_GROUP_PUT(grp, cmd) \ 48381966bceSXin LI do {\ 48481966bceSXin LI freelist_put(grp->grplist, cmd);\ 48581966bceSXin LI grp->grplist->count--;\ 48681966bceSXin LI } while (0) 48781966bceSXin LI 48881966bceSXin LI 48981966bceSXin LI 49081966bceSXin LI 49181966bceSXin LI void ldm_queue_cmd(PCOMMAND cmd); 49281966bceSXin LI void vdev_queue_cmd(PCOMMAND cmd); 49381966bceSXin LI void ldm_finish_cmd(PCOMMAND cmd); 49481966bceSXin LI 49581966bceSXin LI 49681966bceSXin LI int ldm_acquire_lock(PVDEV vd, struct lock_request *req); 49781966bceSXin LI void ldm_release_lock(PVDEV vd, struct lock_request *req); 49881966bceSXin LI 49981966bceSXin LI void ldm_queue_vbus_dpc(PVBUS vbus, struct tq_item *t); 500f29c86f1SXin LI void ldm_queue_vbus_idle(PVBUS vbus, struct tq_item *t); 50181966bceSXin LI 50281966bceSXin LI HPT_BOOL ldm_intr(PVBUS vbus); 50381966bceSXin LI void ldm_run(PVBUS vbus); 50481966bceSXin LI int ldm_idle(PVBUS vbus); 50581966bceSXin LI 50681966bceSXin LI 50781966bceSXin LI int ldm_reset_vbus(PVBUS vbus); 50881966bceSXin LI 50981966bceSXin LI 51081966bceSXin LI void ldm_suspend(PVBUS vbus); 51181966bceSXin LI void ldm_resume(PVBUS vbus); 512f29c86f1SXin LI LDM_ADAPTER *ldm_resume_adapter(PVBUS vbus, PLDM_ADAPTER ldm_adapter); 51381966bceSXin LI void ldm_shutdown(PVBUS vbus);/*shutdown all the controllers*/ 51481966bceSXin LI 51581966bceSXin LI 51681966bceSXin LI #define HIM_EVENT_DEVICE_REMOVED 1 51781966bceSXin LI #define HIM_EVENT_DEVICE_PLUGGED 2 51881966bceSXin LI #define HIM_EVENT_DEVICE_ERROR 3 51981966bceSXin LI #define HIM_EVENT_RESET_REQUIRED 4 52081966bceSXin LI #define HIM_EVENT_QUIESCE_DEVICE 5 52181966bceSXin LI #define HIM_EVENT_UNQUIESCE_DEVICE 6 52281966bceSXin LI #define HIM_EVENT_CONFIG_CHANGED 7 52381966bceSXin LI 52481966bceSXin LI void ldm_event_notify(HPT_U32 event, void *arg1, void *arg2); 52581966bceSXin LI 52681966bceSXin LI void log_sector_repair(PVDEV vd, int success, HPT_LBA lba, HPT_U16 nsectors); 52781966bceSXin LI 52881966bceSXin LI void ldm_register_device(PVDEV vd); 52981966bceSXin LI void ldm_unregister_device(PVDEV vd); 53081966bceSXin LI 53181966bceSXin LI PVBUS him_handle_to_vbus(void * him_handle); 53281966bceSXin LI void ldm_ide_fixstring (HPT_U8 *s, const int bytecount); 53381966bceSXin LI #if defined(__cplusplus) 53481966bceSXin LI } 53581966bceSXin LI #endif 53681966bceSXin LI #endif 537