📄 lun.h
字号:
/*============================================================================
____________________________________________________________________________
______________________________________________
SSSS M M CCCC Standard Microsystems Corporation
S MM MM SSSS C Austin Design Center
SSS M M M S C 11000 N. Mopac Expressway
S M M SSS C Stonelake Bldg. 6, Suite 500
SSSS M M S CCCC Austin, Texas 78759
SSSS ______________________________________________
____________________________________________________________________________
Copyright(C) 1999, Standard Microsystems Corporation
All Rights Reserved.
This program code listing is proprietary to SMSC and may not be copied,
distributed, or used without a license to do so. Such license may have
Limited or Restricted Rights. Please refer to the license for further
clarification.
____________________________________________________________________________
Notice: The program contained in this listing is a proprietary trade
secret of SMSC, Hauppauge, New York, and is copyrighted
under the United States Copyright Act of 1976 as an unpublished work,
pursuant to Section 104 and Section 408 of Title XVII of the United
States code. Unauthorized copying, adaption, distribution, use, or
display is prohibited by this law.
____________________________________________________________________________
Use, duplication, or disclosure by the Government is subject to
restrictions as set forth in subparagraph(c)(1)(ii) of the Rights
in Technical Data and Computer Software clause at DFARS 52.227-7013.
Contractor/Manufacturer is Standard Microsystems Corporation,
80 Arkay Drive, Hauppauge, New York, 1178-8847.
____________________________________________________________________________
____________________________________________________________________________
lun.h - defines the root object for the class hierarchy.
lun
+-ata
| +-cf
| +-atapi (not used)
+-sm
| +-nand
+-ms
+-sd
+-mmc
____________________________________________________________________________
comments tbd
____________________________________________________________________________
Revision History
Date Who Comment
________ ___ _____________________________________________________________
10/19/01 cds initial version
11/27/01 cds - added lun_enable_mux() stub
- converted all methods to reentrant model
11/30/01 tbh added lun media property bitmasks
12/06/01 tbh clean sweep re-organization
02/26/02 tbh added logical to physical lun mapping
04/18/02 tbh added kbm_lun_media_wrprot
06/21/02 cds - added nand lun to the mix
- removed separate "nil" vtable declaration to allow
grandchild luns (lun derived from an existing lun subclass)
to correctly inherit parent methods, even if the parent lun
itself isn't present in the build configuration.
This removes the requirement for lun subclasses to protect
their overrides with a "#if k_log_lun_XXX < k_max_log_lun"
07/01/02 tbh - moved __thread_return_dfa() from lun.c
07/09/02 cds moved declaration of g_sector_buffer here, so that it is common
to all luns, regardless of build configuration.
09/20/02 cds exported new mode sense vfunction which can be used by derived
classes to return a mode format device mode page.
09/21/02 tbh added lun_process_idle()
09/22/02 tbh eliminated unused code on 242 builds
09/23/02 cds moved mode sense dfa for fmt dev page from lun to media so that
luns w/o the mapper will be able to link
09/25/02 cds added support for erase_flash and report_media_geometry to lun vtable
10/01/02 cds converted _lun_is_media_XXX() macros to functions to conserve
code space.
10/01/02 ds Added _dfa_lun_secure_memory_write and _dfa_lun_secure_memory_read tothe lun-table
to support access to a secure area in the nvstore using vendor specific commands.
10/10/02 cds exported lun_is_media_ready()
10/17/02 cds - project-wide lun data & vtbl paging to reduce code space.
- removed g_active_media from _lun_data, _lun_() virtual functions
- added _lun_data_rd() and _lun_data_wr() macros to bypass lun paging
- added lun_set_active(log_lun) function to switch luns
==============================================================================*/
#ifndef __lun_dot_h__
#define __lun_dot_h__
// physical luns, the index into lun tables. these are fixed, and do not vary with build
#define k_lun_cf 0
#define k_lun_ms 1
#define k_lun_sm 2
#define k_lun_sd 3
#define k_lun_mmc 4
#define k_lun_nand 5
#define k_max_phy_lun 6
//------------------------------------------------------------------------------
// this macro is only to be used in the read and write dfa's.
// the purpose is as follows:
// for improved performance on reads and writes it is desireable to avoid
// dfa's where possible to recude cbw/csw overhead.
// therefore in the optimized version the rd/wr dfa's are called directly
// from the dev layer as functions, not as dfa's.
// so the rd/wr dfa's need to use __thread_return_dfa() instead of
// _thread_return_dfa().
#define __thread_return_dfa(__val) { (*(uint8 *)thread_rd_dfa_argp())=(__val); return; }
//------------------------------------------------------------------------------
// these are set by env vars set in the build scripts and passed in via the makefile
// number of logical luns supported
// k_max_log_lun
// logical luns, what comes over the bus
// k_log_lun_cf
// k_log_lun_ms
// k_log_lun_sm
// k_log_lun_sd
// k_log_lun_mmc
#define _vtbl(__class) _vtbl##__class
#define _vtbl_sz(__class) ((sizeof(_vtbl##__class))/ (sizeof(t_thd_entry)))
#define _vtbl_decl(__class) t_thd_entry _vtbl##__class[]
#define _vtbl_defn(__class) _vtbl_decl(__class) = { _v_##__class }
//------------------------------------------------------------------------------
// typedefs
typedef uint8 (code *t_lun_mngr)(t_message *msgp) reentrant;
//------------------------------------------------------------------------------
// lun data
#define k_lun_max_devid_sz 16
typedef struct s_lun_data
{
t_sense code *sensep ; // the sense code to report on next request sense
t_sense code *statusp ; // the current, volatile status of the device
uint8 sense_data[3]; // additional sense data
uint8 device_id[k_lun_max_devid_sz]; // inquiry and device identification data
uint8 media ;
t_capacity capacity ; // capacity (and fmt capacity) of current media
uint32 max_lb_per_split;
uint32 max_lb_per_burst;
uint8 device_type; // set in dfa_initialize
} t_lun_data ;
// active media page size
#define k_lun_data_sz sizeof(t_lun_data)
//------------------------------------------------------------------------------
// active lun 'page'
extern xdata t_sense code *g_lun_data_sensep ; // the sense code to report on next request sense
extern xdata t_sense code *g_lun_data_statusp ; // the current, volatile status of the device
extern xdata uint8 g_lun_data_sense_data[3]; // additional sense data
extern xdata uint8 g_lun_data_device_id[k_lun_max_devid_sz]; // inquiry and device identification data
extern xdata uint8 g_lun_data_media ;
extern xdata t_capacity g_lun_data_capacity ; // capacity (and fmt capacity) of current media
extern xdata uint32 g_lun_data_max_lb_per_split;
extern xdata uint32 g_lun_data_max_lb_per_burst;
extern xdata uint8 g_lun_data_device_type; // set in dfa_initialize
//------------------------------------------------------------------------------
// device type
#define k_device_type_none 0
#define k_device_type_ata 1
#define k_device_type_atapi 2
#define k_device_type_cf 3
#define k_device_type_sm 4
#define k_device_type_ms 5
#define k_device_type_sd 6
#define k_device_type_mmc 7
#define k_device_type_nand 8
//------------------------------------------------------------------------------
// macro to wrap instancing of the lun data
//------------------------------------------------------------------------------
// macro to wrap instancing of the lun data
// #define _media_data(__field) g_media_data[g_active_media].##__field
#define _lun_data(__field) g_lun_data_##__field
// write lun data to arbitrary lun, regardless of current g_active_lun
#define _lun_data_wr(__lun, __field, __val) ((__lun)==g_active_lun?(_lun_data(__field)=__val):(g_lun_data[__lun].##__field=__val))
// read lun data from arbitrary lun, regardless of current g_active_lun
#define _lun_data_rd(__lun, __field) ((__lun)==g_active_lun?_lun_data(__field):g_lun_data[__lun].##__field)
#define _lun_log2phy(__log) g_lun_log2phy_map[(__log)]
#define _lun_map_log2phy(__log, __phy) { g_lun_log2phy_map[(__log)] = (__phy); }
//------------------------------------------------------------------------------
// lun media property bitmasks
#define kbm_lun_media_removable 0x01
#define kbm_lun_media_present 0x02
#define kbm_lun_media_unknown 0x04
#define kbm_lun_media_changed 0x08
#define kbm_lun_media_wrprot 0x10
#define kbm_lun_media_lockable 0x20
#define kbm_lun_media_custom0 0x40 // lun-specific flag 0
#define kbm_lun_media_process_idle 0x80
// some "helpful" macros to retrieve lun status bits
#define __lun_is_media_removable(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_removable) ?k_true :k_false)
#define __lun_is_media_known(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_unknown) ?k_false:k_true)
#define __lun_is_media_changed(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_changed) ?k_true :k_false)
#define __lun_is_media_lockable(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_lockable) ?k_true :k_false)
#define __lun_requests_idle_processing(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_process_idle)?k_true :k_false)
// logic of _lun_is_media_present macro, expanded
#define _media_present(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_present) ?k_true :k_false)
#define _media_lockable(__lun) ((_lun_data_rd((__lun), media)&kbm_lun_media_lockable) ?k_true :k_false)
/*
if( _media_present(__lun) )
{
if( media_lockable(__lun))
{
if(sec_password_validated())
k_true;
else
k_false;
}
else k_true; // present, not lockable
}
else k_false; // not present
*/
#define __lun_is_media_present(__lun) (_media_present(__lun)?(_media_lockable(__lun)?(_sec_is_password_validated()?k_true:k_false):k_true):k_false)
extern t_bool _lun_is_media_removable(uint8 lun) reentrant;
extern t_bool _lun_is_media_present(uint8 lun) reentrant;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -