1*44704f69SBart Van AsscheIntroduction 2*44704f69SBart Van Assche============ 3*44704f69SBart Van AsscheThe FreeBSD port of sg3_utils contains those utilities that are _not_ 4*44704f69SBart Van Asschespecific to Linux. In some cases the FreeBSD camcontrol command supplies 5*44704f69SBart Van Asschesimilar functionality; for example 'sg_map' is similar to 6*44704f69SBart Van Assche'camcontrol devlist'. 7*44704f69SBart Van Assche 8*44704f69SBart Van AsscheThe dd variants from the sg3_utils package (e.g. sg_dd) rely on too many 9*44704f69SBart Van AsscheLinux idiosyncrasies to be easily ported. A new package called 'ddpt' 10*44704f69SBart Van Asschecontains a utility with similar functionality to sg_dd and ddpt is available 11*44704f69SBart Van Asschefor FreeBSD. 12*44704f69SBart Van Assche 13*44704f69SBart Van AsscheSupported Utilities 14*44704f69SBart Van Assche=================== 15*44704f69SBart Van AsscheHere is a list of utilities that have been ported: 16*44704f69SBart Van Assche sg_bg_ctl 17*44704f69SBart Van Assche sg_compare_and_write 18*44704f69SBart Van Assche sg_decode_sense 19*44704f69SBart Van Assche sg_format 20*44704f69SBart Van Assche sg_get_config 21*44704f69SBart Van Assche sg_get_elem_status 22*44704f69SBart Van Assche sg_get_lba_status 23*44704f69SBart Van Assche sg_ident 24*44704f69SBart Van Assche sg_inq [dropped ATA IDENTIFY DEVICE capability] 25*44704f69SBart Van Assche sg_logs 26*44704f69SBart Van Assche sg_luns 27*44704f69SBart Van Assche sg_modes 28*44704f69SBart Van Assche sg_opcodes 29*44704f69SBart Van Assche sg_persist 30*44704f69SBart Van Assche sg_prevent 31*44704f69SBart Van Assche sg_raw 32*44704f69SBart Van Assche sg_rdac 33*44704f69SBart Van Assche sg_read_block_limits 34*44704f69SBart Van Assche sg_read_buffer 35*44704f69SBart Van Assche sg_read_long 36*44704f69SBart Van Assche sg_readcap 37*44704f69SBart Van Assche sg_reassign 38*44704f69SBart Van Assche sg_referrals 39*44704f69SBart Van Assche sg_rep_pip 40*44704f69SBart Van Assche sg_rep_zones 41*44704f69SBart Van Assche sg_requests 42*44704f69SBart Van Assche sg_rmsn 43*44704f69SBart Van Assche sg_rtpg 44*44704f69SBart Van Assche sg_safte 45*44704f69SBart Van Assche sg_sanitize 46*44704f69SBart Van Assche sg_sat_identify 47*44704f69SBart Van Assche sg_sat_phy_event 48*44704f69SBart Van Assche sg_sat_set_features 49*44704f69SBart Van Assche sg_seek 50*44704f69SBart Van Assche sg_senddiag 51*44704f69SBart Van Assche sg_ses 52*44704f69SBart Van Assche sg_start 53*44704f69SBart Van Assche sg_stpg 54*44704f69SBart Van Assche sg_stream_ctl 55*44704f69SBart Van Assche sg_sync 56*44704f69SBart Van Assche sg_turs 57*44704f69SBart Van Assche sg_verify 58*44704f69SBart Van Assche sg_unmap 59*44704f69SBart Van Assche sg_vpd 60*44704f69SBart Van Assche sg_wr_mode 61*44704f69SBart Van Assche sg_write_buffer 62*44704f69SBart Van Assche sg_write_long 63*44704f69SBart Van Assche sg_write_same 64*44704f69SBart Van Assche sg_write_verify 65*44704f69SBart Van Assche sg_write_x 66*44704f69SBart Van Assche sg_zone 67*44704f69SBart Van Assche 68*44704f69SBart Van AsscheMost utility names are indicative of the main SCSI command 69*44704f69SBart Van Asschethat they execute. Some utilities are slightly higher level, for 70*44704f69SBart Van Asscheexample sg_ses fetches SCSI Enclosure Services (SES) status pages and 71*44704f69SBart Van Asschecan send control pages. Each utility has a man page (placed in 72*44704f69SBart Van Asschesection 8). An overview of sg3_utils can be found at: 73*44704f69SBart Van Asschehttps://sg.danny.cz/sg/sg3_utils.html . 74*44704f69SBart Van AsscheA copy of the "sg3_utils.html" file is in the "doc" subdirectory. 75*44704f69SBart Van Assche 76*44704f69SBart Van Assche 77*44704f69SBart Van AsscheThe executables and library can be built from the source code in 78*44704f69SBart Van Asschethe tarball and installed with the familiar 79*44704f69SBart Van Assche"./configure ; make ; make install" sequence. If this fails try 80*44704f69SBart Van Asscherunning the "./autogen.sh" script prior to that sequence. There 81*44704f69SBart Van Asscheare generic instruction on configure and friend in the INSTALL file. 82*44704f69SBart Van Assche 83*44704f69SBart Van AsscheSome man pages have examples which use Linux device names which 84*44704f69SBart Van Asschehopefully will not confuse the FreeBSD users. 85*44704f69SBart Van Assche 86*44704f69SBart Van AsscheDevice naming 87*44704f69SBart Van Assche============= 88*44704f69SBart Van AsscheIn FreeBSD disks have block names like '/dev/da0' with a corresponding 89*44704f69SBart Van Asschepass-through device name like '/dev/pass0'. Use this command: 90*44704f69SBart Van Assche"camcontrol devlist" to see that SCSI devices available. To list NVMe 91*44704f69SBart Van Asschedevices: "nvmecontrol devlist" can be used. Any many, but not all 92*44704f69SBart Van Asschecontexts, the device name can be used without the '/dev/' prefix. 93*44704f69SBart Van AsscheFreeBSD is relatively unique in this respect and support for this 94*44704f69SBart Van Asscheabbreviated form has been broken in this package and fixed in 95*44704f69SBart Van Asschesg3_utils release 1.46 . 96*44704f69SBart Van Assche 97*44704f69SBart Van AsscheDevice naming for NVMe is a bit more complex. Controllers have names 98*44704f69SBart Van Asschelike /dev/nvme0 and namespaces /dev/nvme0ns1 . Partitions are not 99*44704f69SBart Van Asschesupported on /dev/nvme0ns1 type nodes. Instead there are /dev/nvd0 100*44704f69SBart Van Asscheand /dev/nvd0p<m> where <m> is th partition number starting at 1. 101*44704f69SBart Van AsscheThe nvd driver (written by Intel) is not CAM compatible and has its 102*44704f69SBart Van Asscheown utility nvmecontrol which has similar capabilities as camcontrol 103*44704f69SBart Van Asschehas for CAM devices. In FreeBSD release 12 the nda driver was 104*44704f69SBart Van Asscheintroduced with names like /dev/nda0 and /dev/nda0n<m>. The difference 105*44704f69SBart Van Asscheis that nda is CAM compatible. From the point of view of this package, 106*44704f69SBart Van Asschethe nda driver is preferred as CAM supports NVMe command timeouts and 107*44704f69SBart Van Asschethe error processing is more mature. 108*44704f69SBart Van Assche 109*44704f69SBart Van AsscheFreeBSD installation 110*44704f69SBart Van Assche==================== 111*44704f69SBart Van AsscheThe traditional './configure ; make ; make install' sequence from the 112*44704f69SBart Van Asschetop level of the unpacked tarball will work on FreeBSD. But the man pages 113*44704f69SBart Van Asschewill be placed under the /usr/local/share/man directory which unfortunately 114*44704f69SBart Van Asscheis not on the standard manpath. One solution is to add this path by 115*44704f69SBart Van Asschecreating a file with a name like local_share.conf in the 116*44704f69SBart Van Assche/usr/local/etc/man.d/ directory and placing this line in it: 117*44704f69SBart Van Assche MANPATH /usr/local/share/man 118*44704f69SBart Van Assche 119*44704f69SBart Van AsscheFreeBSD 9.0 has a "ports" entry for sg3_utils under the 120*44704f69SBart Van Assche/usr/ports/sysutils directory. It points to version 1.28 of sg3_utils 121*44704f69SBart Van Asschewhich is now a bit dated. It could be used as a template to point 122*44704f69SBart Van Asscheto more recent versions. 123*44704f69SBart Van Assche 124*44704f69SBart Van AsschekFreeBSD 125*44704f69SBart Van Assche======== 126*44704f69SBart Van Asschesg3_utils can be built into a Debian package for kFreeBSD using the 127*44704f69SBart Van Assche./build_debian.sh script in the top level directory. This has been tested 128*44704f69SBart Van Asschewith Debian 6.0 release. 129*44704f69SBart Van Assche 130*44704f69SBart Van AsscheDetails 131*44704f69SBart Van Assche======= 132*44704f69SBart Van AsscheMost of the ported utilities listed above use SCSI command functions 133*44704f69SBart Van Asschedeclared in sg_cmds_*.h headers . Those SCSI command functions are 134*44704f69SBart Van Asscheimplemented in the corresponding ".c" files. The ".c" files pass SCSI 135*44704f69SBart Van Asschecommands to the host operating system via an interface declared in sg_pt.h . 136*44704f69SBart Van AsscheThere are currently five implementations of that interface depending on 137*44704f69SBart Van Asschethe host operating system: 138*44704f69SBart Van Assche - sg_pt_linux.c 139*44704f69SBart Van Assche - sg_pt_freebsd.c 140*44704f69SBart Van Assche - sg_pt_osf1.c [Tru64] 141*44704f69SBart Van Assche - sg_pt_win32.c 142*44704f69SBart Van Assche - sg_pt_solaris.c 143*44704f69SBart Van Assche 144*44704f69SBart Van AsscheThe sg_pt_freebsd.c file uses the FreeBSD CAM SCSI pass through mechanism. 145*44704f69SBart Van AsscheHence only FreeBSD device nodes that support CAM can be used. These can be 146*44704f69SBart Van Asscheviewed with the "camcontrol devlist" command. To access ATAPI devices (e.g. 147*44704f69SBart Van AsscheATAPI DVD drives) the kernel may need to be configured with the "atapicam" 148*44704f69SBart Van Asschedevice. 149*44704f69SBart Van Assche 150*44704f69SBart Van AsscheAttempts to send SCSI commands with data-in or data-out buffers around 64 KB 151*44704f69SBart Van Asscheand larger failed on a FreeBSD 7.0 with an "argument list too long" error 152*44704f69SBart Van Asschemessage. There is an associated kernel message (viewable with dmesg) that an 153*44704f69SBart Van Asscheattempt has been made to map <n> bytes which is greater than 154*44704f69SBart Van AsscheDFLTPHYS(65536). Still a problem in FreeBSD 8.1 . Due to CAM overhead the 155*44704f69SBart Van Asschelargest power of 2 that can fit through with one command is 32768 bytes (32 156*44704f69SBart Van AsscheKB). 157*44704f69SBart Van Assche 158*44704f69SBart Van AsscheFreeBSD 9.0 is the most recent version of FreeBSD tested with these 159*44704f69SBart Van Asscheutilities. 160*44704f69SBart Van Assche 161*44704f69SBart Van Assche 162*44704f69SBart Van Assche 163*44704f69SBart Van AsscheDouglas Gilbert 164*44704f69SBart Van Assche1st May 2021 165