mirror of
https://github.com/opnsense/src.git
synced 2026-03-22 02:40:09 -04:00
Some of the major changes include: - The SCSI error handling portion of cam_periph_error() has been broken out into a number of subfunctions to better modularize the code that handles the hierarchy of SCSI errors. As a result, the code is now much easier to read. - String handling and error printing has been significantly revamped. We now use sbufs to do string formatting instead of using printfs (for the kernel) and snprintf/strncat (for userland) as before. There is a new catchall error printing routine, cam_error_print() and its string-based counterpart, cam_error_string() that allow the kernel and userland applications to pass in a CCB and have errors printed out properly, whether or not they're SCSI errors. Among other things, this helped eliminate a fair amount of duplicate code in camcontrol. We now print out more information than before, including the CAM status and SCSI status and the error recovery action taken to remedy the problem. - sbufs are now available in userland, via libsbuf. This change was necessary since most of the error printing code is shared between libcam and the kernel. - A new transfer settings interface is included in this checkin. This code is #ifdef'ed out, and is primarily intended to aid discussion with HBA driver authors on the final form the interface should take. There is example code in the ahc(4) driver that implements the HBA driver side of the new interface. The new transfer settings code won't be enabled until we're ready to switch all HBA drivers over to the new interface. src/Makefile.inc1, lib/Makefile: Add libsbuf. It must be built before libcam, since libcam uses sbuf routines. libcam/Makefile: libcam now depends on libsbuf. libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the sbuf sources from sys/kern. bsd.libnames.mk: Add LIBSBUF. camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically linked, we can't depend on the dynamic linker to pull in libsbuf. camcontrol.c: Use cam_error_print() instead of checking for CAM_SCSI_STATUS_ERROR on every failed CCB. sbuf.9: Change the prototypes for sbuf_cat() and sbuf_cpy() so that the source string is now a const char *. This is more in line wth the standard system string functions, and helps eliminate warnings when dealing with a const source buffer. Fix a typo. cam.c: Add description strings for the various CAM error status values, as well as routines to look up those strings. Add new cam_error_string() and cam_error_print() routines for userland and the kernel. cam.h: Add a new CAM flag, CAM_RETRY_SELTO. Add enumerated types for the various options available with cam_error_print() and cam_error_string(). cam_ccb.h: Add new transfer negotiation structures/types. Change inq_len in the ccb_getdev structure to be "reserved". This field has never been filled in, and will be removed when we next bump the CAM version. cam_debug.h: Fix typo. cam_periph.c: Modularize cam_periph_error(). The SCSI error handling part of cam_periph_error() is now in camperiphscsistatuserror() and camperiphscsisenseerror(). In cam_periph_lock(), increase the reference count on the periph while we wait for our lock attempt to succeed so that the periph won't go away while we're sleeping. cam_xpt.c: Add new transfer negotiation code. (ifdefed out) Add a new function, xpt_path_string(). This is a string/sbuf analog to xpt_print_path(). scsi_all.c: Revamp string handing and error printing code. We now use sbufs for much of the string formatting code. More of that code is shared between userland the kernel. scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly useful in the first place. Add a new error action, SS_REQSENSE. (Send a request sense and then retry the command.) This is useful when the controller hasn't performed autosense for some reason. Change the default actions around a bit. scsi_cd.c, scsi_da.c, scsi_pt.c, scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection timeouts shouldn't be covered by a sense flag. scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Get rid of the last vestiges of a read/write interface. libkern/bsearch.c, sys/libkern.h, conf/files: Add bsearch.c, which is needed for some of the new table lookup routines. aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if CAM_NEW_TRAN_CODE is defined. sbuf.h, subr_sbuf.c: Add the appropriate #ifdefs so sbufs can compile and run in userland. Change sbuf_printf() to use vsnprintf() instead of kvprintf(), which is only available in the kernel. Change the source string for sbuf_cpy() and sbuf_cat() to be a const char *. Add __BEGIN_DECLS and __END_DECLS around function prototypes since they're now exported to userland. kdump/mkioctls: Include stdio.h before cam.h since cam.h now includes a function with a FILE * argument. Submitted by: gibbs (mostly) Reviewed by: jdp, marcel (libsbuf makefile changes) Reviewed by: des (sbuf changes) Reviewed by: ken
113 lines
4.2 KiB
C
113 lines
4.2 KiB
C
/*-
|
|
* Copyright (c) 1992, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
* must display the following acknowledgement:
|
|
* This product includes software developed by the University of
|
|
* California, Berkeley and its contributors.
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* @(#)libkern.h 8.1 (Berkeley) 6/10/93
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#ifndef _SYS_LIBKERN_H_
|
|
#define _SYS_LIBKERN_H_
|
|
|
|
#include <sys/cdefs.h>
|
|
#include <sys/types.h>
|
|
#ifdef _KERNEL
|
|
#include <sys/systm.h>
|
|
#endif
|
|
|
|
/* BCD conversions. */
|
|
extern u_char const bcd2bin_data[];
|
|
extern u_char const bin2bcd_data[];
|
|
extern char const hex2ascii_data[];
|
|
|
|
#define bcd2bin(bcd) (bcd2bin_data[bcd])
|
|
#define bin2bcd(bin) (bin2bcd_data[bin])
|
|
#define hex2ascii(hex) (hex2ascii_data[hex])
|
|
|
|
static __inline int imax(int a, int b) { return (a > b ? a : b); }
|
|
static __inline int imin(int a, int b) { return (a < b ? a : b); }
|
|
static __inline long lmax(long a, long b) { return (a > b ? a : b); }
|
|
static __inline long lmin(long a, long b) { return (a < b ? a : b); }
|
|
static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
|
|
static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
|
|
static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
|
|
static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
|
|
static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
|
|
static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
|
|
|
|
/* Prototypes for non-quad routines. */
|
|
u_int32_t arc4random __P((void));
|
|
int bcmp __P((const void *, const void *, size_t));
|
|
void *bsearch __P((const void *, const void *, size_t,
|
|
size_t, int (*)(const void *, const void *)));
|
|
#ifndef HAVE_INLINE_FFS
|
|
int ffs __P((int));
|
|
#endif
|
|
#ifndef HAVE_INLINE_FLS
|
|
int fls __P((int));
|
|
#endif
|
|
int locc __P((int, char *, u_int));
|
|
void qsort __P((void *base, size_t nmemb, size_t size,
|
|
int (*compar)(const void *, const void *)));
|
|
u_long random __P((void));
|
|
char *index __P((const char *, int));
|
|
char *rindex __P((const char *, int));
|
|
int scanc __P((u_int, const u_char *, const u_char *, int));
|
|
int skpc __P((int, int, char *));
|
|
void srandom __P((u_long));
|
|
char *strcat __P((char *, const char *));
|
|
int strcmp __P((const char *, const char *));
|
|
char *strcpy __P((char *, const char *));
|
|
size_t strlen __P((const char *));
|
|
int strncmp __P((const char *, const char *, size_t));
|
|
char *strncpy __P((char *, const char *, size_t));
|
|
|
|
|
|
static __inline int
|
|
memcmp(const void *b1, const void *b2, size_t len)
|
|
{
|
|
return (bcmp(b1, b2, len));
|
|
}
|
|
|
|
static __inline void *
|
|
memset(void *b, int c, size_t len)
|
|
{
|
|
char *bb;
|
|
|
|
if (c == 0)
|
|
bzero(b, len);
|
|
else
|
|
for (bb = b; len--; )
|
|
*bb++ = c;
|
|
return (b);
|
|
}
|
|
|
|
#endif /* !_SYS_LIBKERN_H_ */
|