freebsd-dev/sys/dev/hptnr
Alan Somers 4195c7de24 Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)
The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".

This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.

PR:		215474
Reported by:	Coverity
CID:		1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID:		1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID:		1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID:		1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID:		1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID:		1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID:		1010035 1010036 1010042 1010041 1010040 1010039
Reviewed by:	imp, sephe, slm
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D9037
Differential Revision:	https://reviews.freebsd.org/D9038
2017-01-04 20:26:42 +00:00
..
amd64-elf.hptnr_lib.o.uu
array.h
him.h
himfuncs.h
hptintf.h
hptnr_config.c
hptnr_config.h
hptnr_os_bsd.c
hptnr_osm_bsd.c
i386-elf.hptnr_lib.o.uu
ldm.h
list.h
os_bsd.h
osm.h
README
wj.h

Rocket Controller Driver for FreeBSD
Copyright (C) 2015 HighPoint Technologies, Inc. All rights reserved.

#############################################################################
Revision History:

   v1.1.4 2015-06-09
     * Fix a bug that FailLED was not initialized properly.

   v1.1.3 2015-05-19
     * Support Report Luns command.

   v1.1.2 2015-05-05
     * Fix a bug that report wrong physical sector size for 512e HDD.

   v1.1.1 2015-03-26
     * Support 4Kn drive.
     * Change the SCSI target ID of the disk to be the index of physical connetion to the HBA.
     * Support staggered drive spin up.
     * Fix a bug that command would be timeout because of improper interrupt service routine.
     * Error handling to avoid scsi command lost which caused system hang up.
     * Fix a bug that fail to get the devcie's serial number via FreeNAS WebGUI.

   v1.0.1 2014-8-19
     * Do not retry the command and reset the disk when failed to enable or 
       disable spin up feature.
     * Fix up a bug that disk failed to probe if driver failed to access the
       10th LBA.
     * Fix a bug that request timeout but it has been completed in certain 
       cases.
     * Support smartmontool for R750.

   v1.0 2013-7-3
        First source code release

#############################################################################

1. Overview
---------------------
  This package contains FreeBSD driver source code for HighPoint Rocket 
  controller, include:
  SATA Controller: R750, DC7280.

  NO WARRANTY

  THE DRIVER SOURCE CODE HIGHPOINT PROVIDED IS FREE OF CHARGE, AND THERE IS
  NO WARRANTY FOR THE PROGRAM. THERE ARE NO RESTRICTIONS ON THE USE OF THIS
  FREE SOURCE CODE. HIGHPOINT DOES NOT PROVIDE ANY TECHNICAL SUPPORT IF THE
  CODE HAS BEEN CHANGED FROM ORIGINAL SOURCE CODE.

  LIMITATION OF LIABILITY

  IN NO EVENT WILL HIGHPOINT BE LIABLE FOR DIRECT, INDIRECT, SPECIAL,
  INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF OR
  INABILITY TO USE THIS PRODUCT OR DOCUMENTATION, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGES. IN PARTICULAR, HIGHPOINT SHALL NOT HAVE
  LIABILITY FOR ANY HARDWARE, SOFTWARE, OR DATA STORED USED WITH THE
  PRODUCT, INCLUDING THE COSTS OF REPAIRING, REPLACING, OR RECOVERING
  SUCH HARDWARE, OR DATA.


2. Rebuild the kernel with HighPoint Rocket support
-----------------------------------------------

  1) Install kernel source package and building tools. 
  
  2) Extract the driver files under the kernel source tree:

     # cd /usr/src/sys/
     # tar xvzf /your/path/to/HPTNR_FreeBSD_Src_1.x.x_xx_xx_xx.tgz

  3) Update the kernel configuration file to include the HighPoint source.
     Assume the configure file is GENERIC, and new kernel configure file is 
     MYKERNEL:

     # cd i386/conf          (or amd64/conf for AMD64)
     # cp GENERIC MYKERNEL

  4) Edit MYKERNEL, and add the following line under "RAID controllers 
     interfaced to the SCSI subsystem":

          device  "hptnr"   #HighPoint Rocket

  5) For i386 system, edit /usr/src/sys/conf/files.i386 and append the lines
     shown below:

          hptnr_lib.o optional    hptnr  \
              dependency  "$S/dev/hptnr/i386-elf.hptnr_lib.o.uu" \
              compile-with    "uudecode < $S/dev/hptnr/i386-elf.hptnr_lib.o.uu" \
              no-implicit-rule

          dev/hptnr/hptnr_os_bsd.c      optional        hptnr
          dev/hptnr/hptnr_osm_bsd.c     optional        hptnr
          dev/hptnr/hptnr_config.c      optional        hptnr

     For amd64 system, edit /usr/src/sys/conf/files.amd64 and append the lines
     shown below:

          hptnr_lib.o optional    hptnr  \
              dependency  "$S/dev/hptnr/amd64-elf.hptnr_lib.o.uu" \
              compile-with    "uudecode < $S/dev/hptnr/amd64-elf.hptnr_lib.o.uu" \
              no-implicit-rule

          dev/hptnr/hptnr_os_bsd.c      optional        hptnr
          dev/hptnr/hptnr_osm_bsd.c     optional        hptnr
          dev/hptnr/hptnr_config.c      optional        hptnr

  6) Rebuild and install the kernel:

     a) for FreeBSD 5.x-i386/6.x-i386/7.x-i386/8.x-i386/9.x-i386/10.x-i386:
     
        # cd /usr/src/sys/i386/conf/
        # /usr/sbin/config MYKERNEL
        # cd ../compile/MYKERNEL/
        # make depend
        # make 
        # make install

     b) for FreeBSD 5.x-amd64/6.x-amd64/7.x-amd64/8.x-amd64/9.x-amd64/10.x-amd64:

        # cd /usr/src/sys/amd64/conf/
        # /usr/sbin/config MYKERNEL
        # cd ../compile/MYKERNEL/
        # make depend
        # make 
        # make install

     c) for FreeBSD 4.x:
     
        # cd /usr/src/sys/i386/conf/
        # /usr/sbin/config MYKERNEL
        # cd ../../compile/MYKERNEL/
        # make depend
        # make 
        # make install

    If the driver was previously configured as an auto-loaded module by
    /boot/defaults/loader.conf, please remove the entry hptnr_load="YES"
    from loader.conf to prevent the driver from being loaded twice.
    
  7) Reboot from the new kernel.


3. Build/Load the driver as a kernel module
------------------------------------------------

  1) Install kernel source package and building tools. 
  
  2) Extract the driver files under the kernel source tree:
    
     # cd /usr/src/sys/
     # tar xvzf /your/path/to/HPTNR_FreeBSD_Src_1.x.x_xx_xx_xx.tgz


  4) Build the driver module:
    
     # cd modules/hptnr
     # make

  5) Copy the driver module to the kernel module directory

     For FreeBSD 4.x:
     
     # cp hptnr.ko /modules/

     For FreeBSD 5.x/6.x/7.x/8.x/9.x/10.x:
    
     # cp hptnr.ko /boot/kernel/

  6) Reboot and load the driver under loader prompt. e.g:

        BTX loader 1.00  BTX version is 1.01
        Console: internal video/keyboard
        BIOS driver A: is disk0
        BIOS driver C: is disk2
        BIOS 636kB/74512kB available memory
        
        FreeBSD/i386 bootstrap loader, Revision 0.8
        (mailto:jkh@narf.osd.bsdi.com, Sat Apr 21 08:46:19 GMT 2001)
        Loading /boot/defaults/loader.conf
        /kernel text=0x24f1db data=0x3007ec+0x2062c -
        
        Hit [Enter] to boot immediagely, or any other key for command prompt.
        Booting [kernel] in 9 seconds
        
         <-- press SPACE key here 
        Type '?' for a list of commands, 'help' for more detailed help.
        ok load hptnr
        /modules/hptnr.ko text=0xf571 data=0x2c8+0x254
        ok boot
        
     For FreeBSD 5.x/6.x/7.x/8.x/9.x/10.x, you can select 6 on the boot menu to get a loader
     prompt.
  
  7) You can add a below line into /boot/defaults/loader.conf to load the
     driver automatically:
    
           hptnr_load="YES"
    
     Please refer to the installation guide in HighPoint FreeBSD driver release 
     package for more information.
     

#############################################################################
Technical support and service

  If you have questions about installing or using your HighPoint product,
  check the user's guide or readme file first, and you will find answers to
  most of your questions here. If you need further assistance, please
  contact us. We offer the following support and information services:

  1)  The HighPoint Web Site provides information on software upgrades,
      answers to common questions, and other topics. The Web Site is
      available from Internet 24 hours a day, 7 days a week, at
      http://www.highpoint-tech.com.

  2)  For technical support, send e-mail to support@highpoint-tech.com

  NOTE: Before you send an e-mail, please visit our Web Site
        (http://www.highpoint-tech.com) to check if there is a new or 
        updated device driver for your system.

$FreeBSD$