Locked History Actions

attachment:kamikaze_7.09-for-alix-0xff-02.patch of AlixBoards

Attachment 'kamikaze_7.09-for-alix-0xff-02.patch'

Download

   1 diff -Nur kamikaze_7.09.orig/.config kamikaze_7.09/.config
   2 --- kamikaze_7.09.orig/.config	1970-01-01 01:00:00.000000000 +0100
   3 +++ kamikaze_7.09/.config	2008-06-19 17:34:17.000000000 +0200
   4 @@ -0,0 +1,1012 @@
   5 +#
   6 +# Automatically generated make config: don't edit
   7 +# OpenWrt version: 7.09 (Kamikaze)
   8 +# Thu Jun 19 17:23:33 2008
   9 +#
  10 +CONFIG_HAVE_DOT_CONFIG=y
  11 +# CONFIG_LINUX_2_6_AMCC is not set
  12 +# CONFIG_LINUX_2_6_AU1000 is not set
  13 +# CONFIG_LINUX_2_6_ATHEROS is not set
  14 +# CONFIG_LINUX_2_6_AVR32 is not set
  15 +# CONFIG_LINUX_2_4_BRCM is not set
  16 +# CONFIG_LINUX_2_6_BRCM47XX is not set
  17 +# CONFIG_LINUX_2_6_IXP4XX is not set
  18 +# CONFIG_LINUX_2_6_MAGICBOX is not set
  19 +# CONFIG_LINUX_2_6_RB532 is not set
  20 +CONFIG_LINUX_2_6_X86=y
  21 +# CONFIG_LINUX_2_6_ARM is not set
  22 +# CONFIG_LINUX_2_6_CRIS is not set
  23 +# CONFIG_LINUX_2_6_M68K is not set
  24 +# CONFIG_LINUX_2_6_SH3 is not set
  25 +# CONFIG_LINUX_2_6_SH3EB is not set
  26 +# CONFIG_LINUX_2_6_SH4 is not set
  27 +# CONFIG_LINUX_2_6_SH4EB is not set
  28 +# CONFIG_LINUX_2_6_SPARC is not set
  29 +# CONFIG_LINUX_2_6_AMCC_Default is not set
  30 +# CONFIG_LINUX_2_6_AU1000_Atheros is not set
  31 +# CONFIG_LINUX_2_6_AU1000_Broadcom is not set
  32 +# CONFIG_LINUX_2_6_AU1000_Intel is not set
  33 +# CONFIG_LINUX_2_6_ATHEROS_Default is not set
  34 +# CONFIG_LINUX_2_6_AVR32_Default is not set
  35 +# CONFIG_LINUX_2_4_BRCM_Broadcom is not set
  36 +# CONFIG_LINUX_2_4_BRCM_BroadcomMimo is not set
  37 +# CONFIG_LINUX_2_4_BRCM_Atheros is not set
  38 +# CONFIG_LINUX_2_4_BRCM_None is not set
  39 +# CONFIG_LINUX_2_4_BRCM_WL500G is not set
  40 +# CONFIG_LINUX_2_4_BRCM_WL500GD is not set
  41 +# CONFIG_LINUX_2_4_BRCM_WL500GP is not set
  42 +# CONFIG_LINUX_2_4_BRCM_WL700GE is not set
  43 +# CONFIG_LINUX_2_4_BRCM_WLHDD is not set
  44 +# CONFIG_LINUX_2_4_BRCM_WRT54G3G is not set
  45 +# CONFIG_LINUX_2_6_BRCM47XX_Atheros is not set
  46 +# CONFIG_LINUX_2_6_BRCM47XX_None is not set
  47 +# CONFIG_LINUX_2_6_BRCM47XX_WGT634U is not set
  48 +# CONFIG_LINUX_2_6_BRCM47XX_WRTSL54GS is not set
  49 +# CONFIG_LINUX_2_6_IXP4XX_Default is not set
  50 +# CONFIG_LINUX_2_6_IXP4XX_NSLU2 is not set
  51 +# CONFIG_LINUX_2_6_IXP4XX_NAS100d is not set
  52 +# CONFIG_LINUX_2_6_IXP4XX_DSMG600RevA is not set
  53 +# CONFIG_LINUX_2_6_MAGICBOX_Default is not set
  54 +# CONFIG_LINUX_2_6_RB532_Default is not set
  55 +# CONFIG_LINUX_2_6_X86_Generic is not set
  56 +CONFIG_LINUX_2_6_X86_Alix=y
  57 +# CONFIG_LINUX_2_6_X86_Soekris is not set
  58 +CONFIG_LINUX_2_6=y
  59 +CONFIG_PCI_SUPPORT=y
  60 +CONFIG_PCMCIA_SUPPORT=y
  61 +CONFIG_USB_SUPPORT=y
  62 +CONFIG_ATM_SUPPORT=y
  63 +CONFIG_VIDEO_SUPPORT=y
  64 +CONFIG_USES_SQUASHFS=y
  65 +CONFIG_USES_JFFS2=y
  66 +CONFIG_USES_EXT2=y
  67 +CONFIG_i386=y
  68 +CONFIG_ARCH="i386"
  69 +
  70 +#
  71 +# Target Images
  72 +#
  73 +# CONFIG_TARGET_ROOTFS_INITRAMFS is not set
  74 +CONFIG_TARGET_ROOTFS_JFFS2=y
  75 +CONFIG_TARGET_ROOTFS_SQUASHFS=y
  76 +# CONFIG_TARGET_ROOTFS_TGZ is not set
  77 +CONFIG_TARGET_ROOTFS_EXT2FS=y
  78 +
  79 +#
  80 +# Image Options
  81 +#
  82 +CONFIG_X86_GRUB_IMAGES=y
  83 +# CONFIG_X86_GRUB_IMAGES_PAD is not set
  84 +CONFIG_X86_GRUB_BAUDRATE=38400
  85 +CONFIG_X86_GRUB_KERNELPART=8
  86 +CONFIG_X86_GRUB_ROOTPART="/dev/hda2"
  87 +CONFIG_X86_GRUB_BOOTOPTS=""
  88 +CONFIG_TARGET_ROOTFS_FSPART=55
  89 +CONFIG_TARGET_ROOTFS_MAXINODE=1500
  90 +# CONFIG_ALL is not set
  91 +# CONFIG_DEVEL is not set
  92 +# CONFIG_BROKEN is not set
  93 +CONFIG_AUTOREBUILD=y
  94 +# CONFIG_TAR_VERBOSITY is not set
  95 +CONFIG_JLEVEL=1
  96 +# CONFIG_CCACHE is not set
  97 +CONFIG_SOURCE_FEEDS="https://svn.openwrt.org/openwrt/packages/"
  98 +CONFIG_SOURCE_FEEDS_REV=""
  99 +# CONFIG_NATIVE_TOOLCHAIN is not set
 100 +CONFIG_BINUTILS_VERSION="2.17"
 101 +CONFIG_EXTRA_GCC_CONFIG_OPTIONS=""
 102 +CONFIG_INSTALL_LIBSTDCPP=y
 103 +# CONFIG_GDB is not set
 104 +CONFIG_LARGEFILE=y
 105 +# CONFIG_C99_MATH is not set
 106 +CONFIG_TARGET_OPTIMIZATION="-O2 -pipe -march=i486 -funit-at-a-time"
 107 +CONFIG_GCC_VERSION="4.1.2"
 108 +# CONFIG_IB is not set
 109 +# CONFIG_SDK is not set
 110 +# CONFIG_UCI_PRECONFIG is not set
 111 +CONFIG_UCI_PRECONFIG_network_lan_proto="static"
 112 +CONFIG_UCI_PRECONFIG_network_lan_ipaddr="192.168.1.1"
 113 +CONFIG_UCI_PRECONFIG_network_lan_netmask="255.255.255.0"
 114 +CONFIG_UCI_PRECONFIG_network_lan_gateway=""
 115 +CONFIG_UCI_PRECONFIG_network_lan_dns=""
 116 +
 117 +#
 118 +# Base system
 119 +#
 120 +CONFIG_DEFAULT_base-files=y
 121 +CONFIG_DEFAULT_libgcc=y
 122 +CONFIG_DEFAULT_uclibc=y
 123 +CONFIG_DEFAULT_bridge=y
 124 +CONFIG_DEFAULT_busybox=y
 125 +CONFIG_DEFAULT_dnsmasq=y
 126 +CONFIG_DEFAULT_dropbear=y
 127 +CONFIG_DEFAULT_iptables=y
 128 +CONFIG_DEFAULT_mtd=y
 129 +CONFIG_PACKAGE_base-files=y
 130 +# CONFIG_PACKAGE_br2684ctl is not set
 131 +CONFIG_PACKAGE_bridge=y
 132 +CONFIG_PACKAGE_busybox=y
 133 +# CONFIG_BUSYBOX_CONFIG_FEATURE_DEVFS is not set
 134 +# CONFIG_BUSYBOX_CONFIG_FEATURE_2_4_MODULES is not set
 135 +CONFIG_BUSYBOX_CONFIG_FEATURE_2_6_MODULES=y
 136 +
 137 +#
 138 +# Configuration
 139 +#
 140 +CONFIG_BUSYBOX_CONFIG_HAVE_DOT_CONFIG=y
 141 +
 142 +#
 143 +# Busybox Settings
 144 +#
 145 +
 146 +#
 147 +# General Configuration
 148 +#
 149 +# CONFIG_BUSYBOX_CONFIG_NITPICK is not set
 150 +# CONFIG_BUSYBOX_CONFIG_DESKTOP is not set
 151 +CONFIG_BUSYBOX_CONFIG_SHOW_USAGE=y
 152 +CONFIG_BUSYBOX_CONFIG_FEATURE_VERBOSE_USAGE=y
 153 +CONFIG_BUSYBOX_CONFIG_FEATURE_COMPRESS_USAGE=y
 154 +# CONFIG_BUSYBOX_CONFIG_FEATURE_INSTALLER is not set
 155 +# CONFIG_BUSYBOX_CONFIG_LOCALE_SUPPORT is not set
 156 +CONFIG_BUSYBOX_CONFIG_GETOPT_LONG=y
 157 +CONFIG_BUSYBOX_CONFIG_FEATURE_DEVPTS=y
 158 +CONFIG_BUSYBOX_CONFIG_FEATURE_SUID=y
 159 +CONFIG_BUSYBOX_CONFIG_FEATURE_SYSLOG=y
 160 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SUID_CONFIG is not set
 161 +CONFIG_BUSYBOX_CONFIG_FEATURE_HAVE_RPC=y
 162 +# CONFIG_BUSYBOX_CONFIG_SELINUX is not set
 163 +CONFIG_BUSYBOX_CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
 164 +
 165 +#
 166 +# Build Options
 167 +#
 168 +# CONFIG_BUSYBOX_CONFIG_STATIC is not set
 169 +# CONFIG_BUSYBOX_CONFIG_BUILD_LIBBUSYBOX is not set
 170 +CONFIG_BUSYBOX_CONFIG_LFS=y
 171 +# CONFIG_BUSYBOX_CONFIG_BUILD_AT_ONCE is not set
 172 +
 173 +#
 174 +# Debugging Options
 175 +#
 176 +# CONFIG_BUSYBOX_CONFIG_DEBUG is not set
 177 +CONFIG_BUSYBOX_CONFIG_INCLUDE_SUSv2=y
 178 +
 179 +#
 180 +# Installation Options
 181 +#
 182 +# CONFIG_BUSYBOX_CONFIG_INSTALL_NO_USR is not set
 183 +CONFIG_BUSYBOX_CONFIG_INSTALL_APPLET_SYMLINKS=y
 184 +# CONFIG_BUSYBOX_CONFIG_INSTALL_APPLET_HARDLINKS is not set
 185 +# CONFIG_BUSYBOX_CONFIG_INSTALL_APPLET_DONT is not set
 186 +CONFIG_BUSYBOX_CONFIG_PREFIX="./_install"
 187 +
 188 +#
 189 +# Busybox Library Tuning
 190 +#
 191 +CONFIG_BUSYBOX_CONFIG_PASSWORD_MINLEN=6
 192 +CONFIG_BUSYBOX_CONFIG_MD5_SIZE_VS_SPEED=2
 193 +
 194 +#
 195 +# Applets
 196 +#
 197 +
 198 +#
 199 +# Archival Utilities
 200 +#
 201 +# CONFIG_BUSYBOX_CONFIG_AR is not set
 202 +CONFIG_BUSYBOX_CONFIG_BUNZIP2=y
 203 +# CONFIG_BUSYBOX_CONFIG_CPIO is not set
 204 +# CONFIG_BUSYBOX_CONFIG_DPKG is not set
 205 +# CONFIG_BUSYBOX_CONFIG_DPKG_DEB is not set
 206 +CONFIG_BUSYBOX_CONFIG_GUNZIP=y
 207 +CONFIG_BUSYBOX_CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
 208 +CONFIG_BUSYBOX_CONFIG_GZIP=y
 209 +CONFIG_BUSYBOX_CONFIG_IPKG=y
 210 +# CONFIG_BUSYBOX_CONFIG_RPM2CPIO is not set
 211 +# CONFIG_BUSYBOX_CONFIG_RPM is not set
 212 +CONFIG_BUSYBOX_CONFIG_TAR=y
 213 +CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_CREATE=y
 214 +CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_BZIP2=y
 215 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_LZMA is not set
 216 +CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_FROM=y
 217 +CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_GZIP=y
 218 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_COMPRESS is not set
 219 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
 220 +CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
 221 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TAR_LONG_OPTIONS is not set
 222 +# CONFIG_BUSYBOX_CONFIG_UNCOMPRESS is not set
 223 +# CONFIG_BUSYBOX_CONFIG_UNLZMA is not set
 224 +# CONFIG_BUSYBOX_CONFIG_UNZIP is not set
 225 +
 226 +#
 227 +# Common options for cpio and tar
 228 +#
 229 +# CONFIG_BUSYBOX_CONFIG_FEATURE_UNARCHIVE_TAPE is not set
 230 +
 231 +#
 232 +# Coreutils
 233 +#
 234 +CONFIG_BUSYBOX_CONFIG_BASENAME=y
 235 +# CONFIG_BUSYBOX_CONFIG_CAL is not set
 236 +CONFIG_BUSYBOX_CONFIG_CAT=y
 237 +# CONFIG_BUSYBOX_CONFIG_CATV is not set
 238 +CONFIG_BUSYBOX_CONFIG_CHGRP=y
 239 +CONFIG_BUSYBOX_CONFIG_CHMOD=y
 240 +CONFIG_BUSYBOX_CONFIG_CHOWN=y
 241 +CONFIG_BUSYBOX_CONFIG_CHROOT=y
 242 +# CONFIG_BUSYBOX_CONFIG_CKSUM is not set
 243 +# CONFIG_BUSYBOX_CONFIG_CMP is not set
 244 +# CONFIG_BUSYBOX_CONFIG_COMM is not set
 245 +CONFIG_BUSYBOX_CONFIG_CP=y
 246 +CONFIG_BUSYBOX_CONFIG_CUT=y
 247 +CONFIG_BUSYBOX_CONFIG_DATE=y
 248 +CONFIG_BUSYBOX_CONFIG_FEATURE_DATE_ISOFMT=y
 249 +CONFIG_BUSYBOX_CONFIG_DD=y
 250 +CONFIG_BUSYBOX_CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
 251 +# CONFIG_BUSYBOX_CONFIG_FEATURE_DD_IBS_OBS is not set
 252 +CONFIG_BUSYBOX_CONFIG_DF=y
 253 +# CONFIG_BUSYBOX_CONFIG_DIFF is not set
 254 +CONFIG_BUSYBOX_CONFIG_DIRNAME=y
 255 +# CONFIG_BUSYBOX_CONFIG_DOS2UNIX is not set
 256 +CONFIG_BUSYBOX_CONFIG_DU=y
 257 +CONFIG_BUSYBOX_CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
 258 +CONFIG_BUSYBOX_CONFIG_ECHO=y
 259 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_ECHO=y
 260 +CONFIG_BUSYBOX_CONFIG_ENV=y
 261 +# CONFIG_BUSYBOX_CONFIG_FEATURE_ENV_LONG_OPTIONS is not set
 262 +CONFIG_BUSYBOX_CONFIG_EXPR=y
 263 +# CONFIG_BUSYBOX_CONFIG_EXPR_MATH_SUPPORT_64 is not set
 264 +CONFIG_BUSYBOX_CONFIG_FALSE=y
 265 +# CONFIG_BUSYBOX_CONFIG_FOLD is not set
 266 +CONFIG_BUSYBOX_CONFIG_HEAD=y
 267 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_HEAD=y
 268 +CONFIG_BUSYBOX_CONFIG_HOSTID=y
 269 +CONFIG_BUSYBOX_CONFIG_ID=y
 270 +# CONFIG_BUSYBOX_CONFIG_INSTALL is not set
 271 +CONFIG_BUSYBOX_CONFIG_LENGTH=y
 272 +CONFIG_BUSYBOX_CONFIG_LN=y
 273 +# CONFIG_BUSYBOX_CONFIG_LOGNAME is not set
 274 +CONFIG_BUSYBOX_CONFIG_LS=y
 275 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_FILETYPES=y
 276 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_FOLLOWLINKS=y
 277 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_RECURSIVE=y
 278 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_SORTFILES=y
 279 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_TIMESTAMPS=y
 280 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_USERNAME=y
 281 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_COLOR=y
 282 +CONFIG_BUSYBOX_CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
 283 +CONFIG_BUSYBOX_CONFIG_MD5SUM=y
 284 +CONFIG_BUSYBOX_CONFIG_MKDIR=y
 285 +# CONFIG_BUSYBOX_CONFIG_FEATURE_MKDIR_LONG_OPTIONS is not set
 286 +CONFIG_BUSYBOX_CONFIG_MKFIFO=y
 287 +CONFIG_BUSYBOX_CONFIG_MKNOD=y
 288 +CONFIG_BUSYBOX_CONFIG_MV=y
 289 +# CONFIG_BUSYBOX_CONFIG_FEATURE_MV_LONG_OPTIONS is not set
 290 +# CONFIG_BUSYBOX_CONFIG_NICE is not set
 291 +# CONFIG_BUSYBOX_CONFIG_NOHUP is not set
 292 +# CONFIG_BUSYBOX_CONFIG_OD is not set
 293 +# CONFIG_BUSYBOX_CONFIG_PRINTENV is not set
 294 +CONFIG_BUSYBOX_CONFIG_PRINTF=y
 295 +CONFIG_BUSYBOX_CONFIG_PWD=y
 296 +# CONFIG_BUSYBOX_CONFIG_REALPATH is not set
 297 +CONFIG_BUSYBOX_CONFIG_RM=y
 298 +CONFIG_BUSYBOX_CONFIG_RMDIR=y
 299 +CONFIG_BUSYBOX_CONFIG_SEQ=y
 300 +# CONFIG_BUSYBOX_CONFIG_SHA1SUM is not set
 301 +CONFIG_BUSYBOX_CONFIG_SLEEP=y
 302 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_SLEEP=y
 303 +CONFIG_BUSYBOX_CONFIG_SORT=y
 304 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SORT_BIG is not set
 305 +# CONFIG_BUSYBOX_CONFIG_STAT is not set
 306 +# CONFIG_BUSYBOX_CONFIG_STTY is not set
 307 +# CONFIG_BUSYBOX_CONFIG_SUM is not set
 308 +CONFIG_BUSYBOX_CONFIG_SYNC=y
 309 +CONFIG_BUSYBOX_CONFIG_TAIL=y
 310 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_TAIL=y
 311 +CONFIG_BUSYBOX_CONFIG_TEE=y
 312 +CONFIG_BUSYBOX_CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
 313 +CONFIG_BUSYBOX_CONFIG_TEST=y
 314 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TEST_64 is not set
 315 +CONFIG_BUSYBOX_CONFIG_TOUCH=y
 316 +CONFIG_BUSYBOX_CONFIG_TR=y
 317 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TR_CLASSES is not set
 318 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TR_EQUIV is not set
 319 +CONFIG_BUSYBOX_CONFIG_TRUE=y
 320 +# CONFIG_BUSYBOX_CONFIG_TTY is not set
 321 +CONFIG_BUSYBOX_CONFIG_UNAME=y
 322 +CONFIG_BUSYBOX_CONFIG_UNIQ=y
 323 +# CONFIG_BUSYBOX_CONFIG_USLEEP is not set
 324 +# CONFIG_BUSYBOX_CONFIG_UUDECODE is not set
 325 +# CONFIG_BUSYBOX_CONFIG_UUENCODE is not set
 326 +# CONFIG_BUSYBOX_CONFIG_WATCH is not set
 327 +CONFIG_BUSYBOX_CONFIG_WC=y
 328 +# CONFIG_BUSYBOX_CONFIG_FEATURE_WC_LARGE is not set
 329 +# CONFIG_BUSYBOX_CONFIG_WHO is not set
 330 +# CONFIG_BUSYBOX_CONFIG_WHOAMI is not set
 331 +CONFIG_BUSYBOX_CONFIG_YES=y
 332 +
 333 +#
 334 +# Common options for cp and mv
 335 +#
 336 +CONFIG_BUSYBOX_CONFIG_FEATURE_PRESERVE_HARDLINKS=y
 337 +
 338 +#
 339 +# Common options for ls, more and telnet
 340 +#
 341 +CONFIG_BUSYBOX_CONFIG_FEATURE_AUTOWIDTH=y
 342 +
 343 +#
 344 +# Common options for df, du, ls
 345 +#
 346 +CONFIG_BUSYBOX_CONFIG_FEATURE_HUMAN_READABLE=y
 347 +
 348 +#
 349 +# Common options for md5sum, sha1sum
 350 +#
 351 +CONFIG_BUSYBOX_CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
 352 +
 353 +#
 354 +# Console Utilities
 355 +#
 356 +# CONFIG_BUSYBOX_CONFIG_CHVT is not set
 357 +CONFIG_BUSYBOX_CONFIG_CLEAR=y
 358 +# CONFIG_BUSYBOX_CONFIG_DEALLOCVT is not set
 359 +# CONFIG_BUSYBOX_CONFIG_DUMPKMAP is not set
 360 +# CONFIG_BUSYBOX_CONFIG_LOADFONT is not set
 361 +# CONFIG_BUSYBOX_CONFIG_LOADKMAP is not set
 362 +# CONFIG_BUSYBOX_CONFIG_OPENVT is not set
 363 +CONFIG_BUSYBOX_CONFIG_RESET=y
 364 +# CONFIG_BUSYBOX_CONFIG_RESIZE is not set
 365 +# CONFIG_BUSYBOX_CONFIG_SETCONSOLE is not set
 366 +# CONFIG_BUSYBOX_CONFIG_SETKEYCODES is not set
 367 +# CONFIG_BUSYBOX_CONFIG_SETLOGCONS is not set
 368 +
 369 +#
 370 +# Debian Utilities
 371 +#
 372 +CONFIG_BUSYBOX_CONFIG_MKTEMP=y
 373 +# CONFIG_BUSYBOX_CONFIG_PIPE_PROGRESS is not set
 374 +# CONFIG_BUSYBOX_CONFIG_READLINK is not set
 375 +# CONFIG_BUSYBOX_CONFIG_RUN_PARTS is not set
 376 +# CONFIG_BUSYBOX_CONFIG_START_STOP_DAEMON is not set
 377 +CONFIG_BUSYBOX_CONFIG_WHICH=y
 378 +
 379 +#
 380 +# Editors
 381 +#
 382 +CONFIG_BUSYBOX_CONFIG_AWK=y
 383 +CONFIG_BUSYBOX_CONFIG_AWX=y
 384 +CONFIG_BUSYBOX_CONFIG_FEATURE_AWK_MATH=y
 385 +# CONFIG_BUSYBOX_CONFIG_ED is not set
 386 +# CONFIG_BUSYBOX_CONFIG_PATCH is not set
 387 +CONFIG_BUSYBOX_CONFIG_SED=y
 388 +CONFIG_BUSYBOX_CONFIG_VI=y
 389 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_COLON=y
 390 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_YANKMARK=y
 391 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_SEARCH=y
 392 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_USE_SIGNALS=y
 393 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_DOT_CMD=y
 394 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_READONLY=y
 395 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_SETOPTS=y
 396 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_SET=y
 397 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_WIN_RESIZE=y
 398 +CONFIG_BUSYBOX_CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y
 399 +CONFIG_BUSYBOX_CONFIG_FEATURE_ALLOW_EXEC=y
 400 +
 401 +#
 402 +# Finding Utilities
 403 +#
 404 +CONFIG_BUSYBOX_CONFIG_FIND=y
 405 +CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_PRINT0=y
 406 +# CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_MTIME is not set
 407 +# CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_MMIN is not set
 408 +CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_PERM=y
 409 +CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_TYPE=y
 410 +CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_XDEV=y
 411 +# CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_NEWER is not set
 412 +# CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_INUM is not set
 413 +CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_EXEC=y
 414 +CONFIG_BUSYBOX_CONFIG_GREP=y
 415 +CONFIG_BUSYBOX_CONFIG_FEATURE_GREP_EGREP_ALIAS=y
 416 +CONFIG_BUSYBOX_CONFIG_FEATURE_GREP_FGREP_ALIAS=y
 417 +CONFIG_BUSYBOX_CONFIG_FEATURE_GREP_CONTEXT=y
 418 +CONFIG_BUSYBOX_CONFIG_XARGS=y
 419 +CONFIG_BUSYBOX_CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
 420 +CONFIG_BUSYBOX_CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
 421 +CONFIG_BUSYBOX_CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
 422 +CONFIG_BUSYBOX_CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
 423 +
 424 +#
 425 +# Init Utilities
 426 +#
 427 +CONFIG_BUSYBOX_CONFIG_INIT=y
 428 +# CONFIG_BUSYBOX_CONFIG_DEBUG_INIT is not set
 429 +CONFIG_BUSYBOX_CONFIG_FEATURE_USE_INITTAB=y
 430 +# CONFIG_BUSYBOX_CONFIG_FEATURE_INIT_SCTTY is not set
 431 +# CONFIG_BUSYBOX_CONFIG_FEATURE_EXTRA_QUIET is not set
 432 +# CONFIG_BUSYBOX_CONFIG_FEATURE_INIT_COREDUMPS is not set
 433 +# CONFIG_BUSYBOX_CONFIG_FEATURE_INITRD is not set
 434 +CONFIG_BUSYBOX_CONFIG_HALT=y
 435 +CONFIG_BUSYBOX_CONFIG_MESG=y
 436 +
 437 +#
 438 +# Login/Password Management Utilities
 439 +#
 440 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SHADOWPASSWDS is not set
 441 +# CONFIG_BUSYBOX_CONFIG_USE_BB_PWD_GRP is not set
 442 +# CONFIG_BUSYBOX_CONFIG_ADDGROUP is not set
 443 +# CONFIG_BUSYBOX_CONFIG_DELGROUP is not set
 444 +# CONFIG_BUSYBOX_CONFIG_ADDUSER is not set
 445 +# CONFIG_BUSYBOX_CONFIG_DELUSER is not set
 446 +# CONFIG_BUSYBOX_CONFIG_GETTY is not set
 447 +# CONFIG_BUSYBOX_CONFIG_LOGIN is not set
 448 +CONFIG_BUSYBOX_CONFIG_PASSWD=y
 449 +CONFIG_BUSYBOX_CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
 450 +# CONFIG_BUSYBOX_CONFIG_SU is not set
 451 +# CONFIG_BUSYBOX_CONFIG_SULOGIN is not set
 452 +# CONFIG_BUSYBOX_CONFIG_VLOCK is not set
 453 +
 454 +#
 455 +# Linux Ext2 FS Progs
 456 +#
 457 +# CONFIG_BUSYBOX_CONFIG_CHATTR is not set
 458 +# CONFIG_BUSYBOX_CONFIG_FSCK is not set
 459 +# CONFIG_BUSYBOX_CONFIG_LSATTR is not set
 460 +
 461 +#
 462 +# Linux Module Utilities
 463 +#
 464 +CONFIG_BUSYBOX_CONFIG_INSMOD=y
 465 +# CONFIG_BUSYBOX_CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
 466 +CONFIG_BUSYBOX_CONFIG_RMMOD=y
 467 +CONFIG_BUSYBOX_CONFIG_LSMOD=y
 468 +CONFIG_BUSYBOX_CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
 469 +# CONFIG_BUSYBOX_CONFIG_MODPROBE is not set
 470 +
 471 +#
 472 +# Options common to multiple modutils
 473 +#
 474 +CONFIG_BUSYBOX_CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
 475 +
 476 +#
 477 +# Linux System Utilities
 478 +#
 479 +CONFIG_BUSYBOX_CONFIG_DMESG=y
 480 +CONFIG_BUSYBOX_CONFIG_FEATURE_DMESG_PRETTY=y
 481 +# CONFIG_BUSYBOX_CONFIG_FBSET is not set
 482 +# CONFIG_BUSYBOX_CONFIG_FDFLUSH is not set
 483 +# CONFIG_BUSYBOX_CONFIG_FDFORMAT is not set
 484 +# CONFIG_BUSYBOX_CONFIG_FDISK is not set
 485 +CONFIG_BUSYBOX_CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
 486 +# CONFIG_BUSYBOX_CONFIG_FREERAMDISK is not set
 487 +# CONFIG_BUSYBOX_CONFIG_FSCK_MINIX is not set
 488 +# CONFIG_BUSYBOX_CONFIG_MKFS_MINIX is not set
 489 +# CONFIG_BUSYBOX_CONFIG_GETOPT is not set
 490 +CONFIG_BUSYBOX_CONFIG_HEXDUMP=y
 491 +# CONFIG_BUSYBOX_CONFIG_HWCLOCK is not set
 492 +# CONFIG_BUSYBOX_CONFIG_IPCRM is not set
 493 +# CONFIG_BUSYBOX_CONFIG_IPCS is not set
 494 +# CONFIG_BUSYBOX_CONFIG_LOSETUP is not set
 495 +# CONFIG_BUSYBOX_CONFIG_MDEV is not set
 496 +# CONFIG_BUSYBOX_CONFIG_MKSWAP is not set
 497 +# CONFIG_BUSYBOX_CONFIG_MORE is not set
 498 +CONFIG_BUSYBOX_CONFIG_MOUNT=y
 499 +CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_NFS=y
 500 +CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_CIFS=y
 501 +CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_FLAGS=y
 502 +CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_FSTAB=y
 503 +CONFIG_BUSYBOX_CONFIG_PIVOT_ROOT=y
 504 +CONFIG_BUSYBOX_CONFIG_RDATE=y
 505 +# CONFIG_BUSYBOX_CONFIG_READPROFILE is not set
 506 +# CONFIG_BUSYBOX_CONFIG_SETARCH is not set
 507 +# CONFIG_BUSYBOX_CONFIG_SWAPONOFF is not set
 508 +CONFIG_BUSYBOX_CONFIG_SWITCH_ROOT=y
 509 +CONFIG_BUSYBOX_CONFIG_UMOUNT=y
 510 +CONFIG_BUSYBOX_CONFIG_FEATURE_UMOUNT_ALL=y
 511 +
 512 +#
 513 +# Common options for mount/umount
 514 +#
 515 +CONFIG_BUSYBOX_CONFIG_FEATURE_MOUNT_LOOP=y
 516 +# CONFIG_BUSYBOX_CONFIG_FEATURE_MTAB_SUPPORT is not set
 517 +
 518 +#
 519 +# Miscellaneous Utilities
 520 +#
 521 +# CONFIG_BUSYBOX_CONFIG_ADJTIMEX is not set
 522 +# CONFIG_BUSYBOX_CONFIG_BBCONFIG is not set
 523 +CONFIG_BUSYBOX_CONFIG_CROND=y
 524 +# CONFIG_BUSYBOX_CONFIG_DEBUG_CROND_OPTION is not set
 525 +# CONFIG_BUSYBOX_CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
 526 +CONFIG_BUSYBOX_CONFIG_CRONTAB=y
 527 +# CONFIG_BUSYBOX_CONFIG_DC is not set
 528 +# CONFIG_BUSYBOX_CONFIG_DEVFSD is not set
 529 +# CONFIG_BUSYBOX_CONFIG_EJECT is not set
 530 +# CONFIG_BUSYBOX_CONFIG_LAST is not set
 531 +CONFIG_BUSYBOX_CONFIG_LESS=y
 532 +CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_MAXLINES=9999999
 533 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_BRACKETS is not set
 534 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_FLAGS is not set
 535 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_FLAGCS is not set
 536 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_MARKS is not set
 537 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LESS_REGEXP is not set
 538 +# CONFIG_BUSYBOX_CONFIG_HDPARM is not set
 539 +CONFIG_BUSYBOX_CONFIG_LOCK=y
 540 +# CONFIG_BUSYBOX_CONFIG_MAKEDEVS is not set
 541 +# CONFIG_BUSYBOX_CONFIG_MOUNTPOINT is not set
 542 +# CONFIG_BUSYBOX_CONFIG_MT is not set
 543 +# CONFIG_BUSYBOX_CONFIG_NMETER is not set
 544 +# CONFIG_BUSYBOX_CONFIG_RAIDAUTORUN is not set
 545 +# CONFIG_BUSYBOX_CONFIG_RUNLEVEL is not set
 546 +# CONFIG_BUSYBOX_CONFIG_RX is not set
 547 +CONFIG_BUSYBOX_CONFIG_STRINGS=y
 548 +# CONFIG_BUSYBOX_CONFIG_SETSID is not set
 549 +# CONFIG_BUSYBOX_CONFIG_TASKSET is not set
 550 +CONFIG_BUSYBOX_CONFIG_TIME=y
 551 +CONFIG_BUSYBOX_CONFIG_WATCHDOG=y
 552 +
 553 +#
 554 +# Networking Utilities
 555 +#
 556 +CONFIG_BUSYBOX_CONFIG_FEATURE_IPV6=y
 557 +# CONFIG_BUSYBOX_CONFIG_ARP is not set
 558 +CONFIG_BUSYBOX_CONFIG_ARPING=y
 559 +# CONFIG_BUSYBOX_CONFIG_DNSD is not set
 560 +# CONFIG_BUSYBOX_CONFIG_ETHER_WAKE is not set
 561 +# CONFIG_BUSYBOX_CONFIG_FAKEIDENTD is not set
 562 +# CONFIG_BUSYBOX_CONFIG_FTPGET is not set
 563 +# CONFIG_BUSYBOX_CONFIG_FTPPUT is not set
 564 +# CONFIG_BUSYBOX_CONFIG_HOSTNAME is not set
 565 +CONFIG_BUSYBOX_CONFIG_HTTPD=y
 566 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
 567 +# CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_SETUID is not set
 568 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
 569 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_AUTH_MD5=y
 570 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
 571 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_CGI=y
 572 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
 573 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
 574 +CONFIG_BUSYBOX_CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
 575 +CONFIG_BUSYBOX_CONFIG_IFCONFIG=y
 576 +CONFIG_BUSYBOX_CONFIG_FEATURE_IFCONFIG_STATUS=y
 577 +# CONFIG_BUSYBOX_CONFIG_FEATURE_IFCONFIG_SLIP is not set
 578 +# CONFIG_BUSYBOX_CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set
 579 +CONFIG_BUSYBOX_CONFIG_FEATURE_IFCONFIG_HW=y
 580 +CONFIG_BUSYBOX_CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
 581 +# CONFIG_BUSYBOX_CONFIG_IFUPDOWN is not set
 582 +# CONFIG_BUSYBOX_CONFIG_INETD is not set
 583 +# CONFIG_BUSYBOX_CONFIG_IP is not set
 584 +# CONFIG_BUSYBOX_CONFIG_IPCALC is not set
 585 +# CONFIG_BUSYBOX_CONFIG_NAMEIF is not set
 586 +CONFIG_BUSYBOX_CONFIG_NC=y
 587 +CONFIG_BUSYBOX_CONFIG_NETMSG=y
 588 +# CONFIG_BUSYBOX_CONFIG_NC_SERVER is not set
 589 +# CONFIG_BUSYBOX_CONFIG_NC_EXTRA is not set
 590 +CONFIG_BUSYBOX_CONFIG_NETSTAT=y
 591 +CONFIG_BUSYBOX_CONFIG_NSLOOKUP=y
 592 +CONFIG_BUSYBOX_CONFIG_PING=y
 593 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_PING=y
 594 +CONFIG_BUSYBOX_CONFIG_PING6=y
 595 +CONFIG_BUSYBOX_CONFIG_FEATURE_FANCY_PING6=y
 596 +CONFIG_BUSYBOX_CONFIG_ROUTE=y
 597 +CONFIG_BUSYBOX_CONFIG_TELNET=y
 598 +CONFIG_BUSYBOX_CONFIG_FEATURE_TELNET_TTYPE=y
 599 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TELNET_AUTOLOGIN is not set
 600 +CONFIG_BUSYBOX_CONFIG_TELNETD=y
 601 +CONFIG_BUSYBOX_CONFIG_FEATURE_TELNETD_STANDALONE=y
 602 +# CONFIG_BUSYBOX_CONFIG_TFTP is not set
 603 +CONFIG_BUSYBOX_CONFIG_TRACEROUTE=y
 604 +CONFIG_BUSYBOX_CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
 605 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
 606 +# CONFIG_BUSYBOX_CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
 607 +# CONFIG_BUSYBOX_CONFIG_APP_UDHCPD is not set
 608 +CONFIG_BUSYBOX_CONFIG_APP_UDHCPC=y
 609 +# CONFIG_BUSYBOX_CONFIG_FEATURE_UDHCP_SYSLOG is not set
 610 +# CONFIG_BUSYBOX_CONFIG_FEATURE_UDHCP_DEBUG is not set
 611 +CONFIG_BUSYBOX_CONFIG_VCONFIG=y
 612 +CONFIG_BUSYBOX_CONFIG_WGET=y
 613 +CONFIG_BUSYBOX_CONFIG_FEATURE_WGET_STATUSBAR=y
 614 +CONFIG_BUSYBOX_CONFIG_FEATURE_WGET_AUTHENTICATION=y
 615 +CONFIG_BUSYBOX_CONFIG_FEATURE_WGET_IP6_LITERAL=y
 616 +CONFIG_BUSYBOX_CONFIG_FEATURE_WGET_LONG_OPTIONS=y
 617 +# CONFIG_BUSYBOX_CONFIG_ZCIP is not set
 618 +
 619 +#
 620 +# Process Utilities
 621 +#
 622 +CONFIG_BUSYBOX_CONFIG_FREE=y
 623 +# CONFIG_BUSYBOX_CONFIG_FUSER is not set
 624 +CONFIG_BUSYBOX_CONFIG_KILL=y
 625 +CONFIG_BUSYBOX_CONFIG_KILLALL=y
 626 +CONFIG_BUSYBOX_CONFIG_KILLALL5=y
 627 +CONFIG_BUSYBOX_CONFIG_PIDOF=y
 628 +# CONFIG_BUSYBOX_CONFIG_FEATURE_PIDOF_SINGLE is not set
 629 +# CONFIG_BUSYBOX_CONFIG_FEATURE_PIDOF_OMIT is not set
 630 +CONFIG_BUSYBOX_CONFIG_PS=y
 631 +CONFIG_BUSYBOX_CONFIG_FEATURE_PS_WIDE=y
 632 +# CONFIG_BUSYBOX_CONFIG_RENICE is not set
 633 +CONFIG_BUSYBOX_CONFIG_BB_SYSCTL=y
 634 +CONFIG_BUSYBOX_CONFIG_TOP=y
 635 +CONFIG_BUSYBOX_CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
 636 +CONFIG_BUSYBOX_CONFIG_UPTIME=y
 637 +
 638 +#
 639 +# Shells
 640 +#
 641 +CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_ASH=y
 642 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_HUSH is not set
 643 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_LASH is not set
 644 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_MSH is not set
 645 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_IS_NONE is not set
 646 +CONFIG_BUSYBOX_CONFIG_ASH=y
 647 +
 648 +#
 649 +# Ash Shell Options
 650 +#
 651 +CONFIG_BUSYBOX_CONFIG_ASH_JOB_CONTROL=y
 652 +# CONFIG_BUSYBOX_CONFIG_ASH_READ_NCHARS is not set
 653 +CONFIG_BUSYBOX_CONFIG_ASH_READ_TIMEOUT=y
 654 +CONFIG_BUSYBOX_CONFIG_ASH_ALIAS=y
 655 +CONFIG_BUSYBOX_CONFIG_ASH_MATH_SUPPORT=y
 656 +# CONFIG_BUSYBOX_CONFIG_ASH_MATH_SUPPORT_64 is not set
 657 +CONFIG_BUSYBOX_CONFIG_ASH_GETOPTS=y
 658 +CONFIG_BUSYBOX_CONFIG_ASH_BUILTIN_ECHO=y
 659 +CONFIG_BUSYBOX_CONFIG_ASH_BUILTIN_TEST=y
 660 +CONFIG_BUSYBOX_CONFIG_ASH_CMDCMD=y
 661 +# CONFIG_BUSYBOX_CONFIG_ASH_MAIL is not set
 662 +CONFIG_BUSYBOX_CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
 663 +# CONFIG_BUSYBOX_CONFIG_ASH_RANDOM_SUPPORT is not set
 664 +# CONFIG_BUSYBOX_CONFIG_ASH_EXPAND_PRMT is not set
 665 +# CONFIG_BUSYBOX_CONFIG_HUSH is not set
 666 +# CONFIG_BUSYBOX_CONFIG_LASH is not set
 667 +# CONFIG_BUSYBOX_CONFIG_MSH is not set
 668 +
 669 +#
 670 +# Bourne Shell Options
 671 +#
 672 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_EXTRA_QUIET is not set
 673 +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_STANDALONE_SHELL is not set
 674 +CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING=y
 675 +# CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_EDITING_VI is not set
 676 +CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_HISTORY=15
 677 +# CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set
 678 +CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_TAB_COMPLETION=y
 679 +# CONFIG_BUSYBOX_CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION is not set
 680 +CONFIG_BUSYBOX_CONFIG_FEATURE_SH_FANCY_PROMPT=y
 681 +
 682 +#
 683 +# System Logging Utilities
 684 +#
 685 +CONFIG_BUSYBOX_CONFIG_SYSLOGD=y
 686 +CONFIG_BUSYBOX_CONFIG_FEATURE_ROTATE_LOGFILE=y
 687 +CONFIG_BUSYBOX_CONFIG_FEATURE_REMOTE_LOG=y
 688 +CONFIG_BUSYBOX_CONFIG_FEATURE_IPC_SYSLOG=y
 689 +CONFIG_BUSYBOX_CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
 690 +CONFIG_BUSYBOX_CONFIG_LOGREAD=y
 691 +# CONFIG_BUSYBOX_CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
 692 +CONFIG_BUSYBOX_CONFIG_KLOGD=y
 693 +CONFIG_BUSYBOX_CONFIG_LOGGER=y
 694 +
 695 +#
 696 +# Runit Utilities
 697 +#
 698 +# CONFIG_BUSYBOX_CONFIG_RUNSV is not set
 699 +# CONFIG_BUSYBOX_CONFIG_RUNSVDIR is not set
 700 +# CONFIG_BUSYBOX_CONFIG_SV is not set
 701 +# CONFIG_BUSYBOX_CONFIG_SVLOGD is not set
 702 +# CONFIG_BUSYBOX_CONFIG_CHPST is not set
 703 +# CONFIG_BUSYBOX_CONFIG_SETUIDGID is not set
 704 +# CONFIG_BUSYBOX_CONFIG_ENVUIDGID is not set
 705 +# CONFIG_BUSYBOX_CONFIG_ENVDIR is not set
 706 +# CONFIG_BUSYBOX_CONFIG_SOFTLIMIT is not set
 707 +CONFIG_PACKAGE_dnsmasq=m
 708 +CONFIG_PACKAGE_dropbear=y
 709 +CONFIG_PACKAGE_iptables=y
 710 +# CONFIG_PACKAGE_iptables-mod-conntrack is not set
 711 +# CONFIG_PACKAGE_iptables-mod-extra is not set
 712 +# CONFIG_PACKAGE_iptables-mod-filter is not set
 713 +# CONFIG_PACKAGE_iptables-mod-imq is not set
 714 +# CONFIG_PACKAGE_iptables-mod-ipopt is not set
 715 +# CONFIG_PACKAGE_iptables-mod-iprange is not set
 716 +# CONFIG_PACKAGE_iptables-mod-ipsec is not set
 717 +# CONFIG_PACKAGE_iptables-mod-ipset is not set
 718 +# CONFIG_PACKAGE_iptables-mod-nat is not set
 719 +# CONFIG_PACKAGE_iptables-mod-ulog is not set
 720 +# CONFIG_PACKAGE_iptables-utils is not set
 721 +CONFIG_PACKAGE_libgcc=y
 722 +CONFIG_PACKAGE_libpthread=m
 723 +# CONFIG_PACKAGE_libssp is not set
 724 +CONFIG_PACKAGE_libstdcpp=m
 725 +CONFIG_PACKAGE_mtd=y
 726 +# CONFIG_PACKAGE_qos-scripts is not set
 727 +CONFIG_PACKAGE_uclibc=y
 728 +CONFIG_PACKAGE_wireless-tools=y
 729 +
 730 +#
 731 +# Utilities
 732 +#
 733 +CONFIG_DEFAULT_hotplug2=y
 734 +CONFIG_DEFAULT_udevtrigger=y
 735 +# CONFIG_PACKAGE_cfdisk is not set
 736 +# CONFIG_PACKAGE_comgt is not set
 737 +CONFIG_PACKAGE_cryptotest-bgp=y
 738 +# CONFIG_PACKAGE_dropbearconvert is not set
 739 +CONFIG_PACKAGE_e2fsprogs=y
 740 +CONFIG_PACKAGE_fdisk=y
 741 +# CONFIG_PACKAGE_fuse-utils is not set
 742 +CONFIG_PACKAGE_hotplug2=y
 743 +# CONFIG_PACKAGE_kexec-tools is not set
 744 +# CONFIG_PACKAGE_losetup is not set
 745 +CONFIG_PACKAGE_openssl-util=y
 746 +# CONFIG_PACKAGE_pcmcia-cs is not set
 747 +# CONFIG_PACKAGE_qc-usb-utils is not set
 748 +CONFIG_PACKAGE_resize2fs=y
 749 +# CONFIG_PACKAGE_robocfg is not set
 750 +CONFIG_PACKAGE_screen=y
 751 +# CONFIG_PACKAGE_shfs-utils is not set
 752 +# CONFIG_PACKAGE_spca5xx-view is not set
 753 +# CONFIG_PACKAGE_swap-utils is not set
 754 +CONFIG_PACKAGE_tune2fs=y
 755 +# CONFIG_PACKAGE_udev is not set
 756 +CONFIG_PACKAGE_udevtrigger=y
 757 +
 758 +#
 759 +# Libraries
 760 +#
 761 +CONFIG_DEFAULT_libopenssl-cryptodev=y
 762 +
 763 +#
 764 +# openssl
 765 +#
 766 +CONFIG_PACKAGE_libopenssl=y
 767 +CONFIG_PACKAGE_libopenssl-cryptodev=y
 768 +# CONFIG_PACKAGE_libblkid is not set
 769 +# CONFIG_PACKAGE_libfuse is not set
 770 +CONFIG_PACKAGE_libgmp=m
 771 +# CONFIG_PACKAGE_libjson is not set
 772 +CONFIG_PACKAGE_libncurses=y
 773 +CONFIG_PACKAGE_libpcap=y
 774 +CONFIG_PACKAGE_libuuid=y
 775 +# CONFIG_PACKAGE_linux-atm is not set
 776 +CONFIG_PACKAGE_zlib=y
 777 +
 778 +#
 779 +# Network
 780 +#
 781 +CONFIG_DEFAULT_ppp=y
 782 +CONFIG_DEFAULT_ppp-mod-pppoe=y
 783 +
 784 +#
 785 +# VPN
 786 +#
 787 +CONFIG_PACKAGE_openvpn=m
 788 +# CONFIG_PACKAGE_openvpn-easy-rsa is not set
 789 +# CONFIG_PACKAGE_arptables is not set
 790 +# CONFIG_PACKAGE_chat is not set
 791 +# CONFIG_PACKAGE_ebtables is not set
 792 +# CONFIG_PACKAGE_genl is not set
 793 +# CONFIG_PACKAGE_hostap-utils is not set
 794 +CONFIG_PACKAGE_hostapd=m
 795 +CONFIG_PACKAGE_hostapd-mini=m
 796 +CONFIG_PACKAGE_hostapd-utils=m
 797 +# CONFIG_PACKAGE_ifenslave is not set
 798 +CONFIG_PACKAGE_ip=y
 799 +CONFIG_PACKAGE_ip6tables=m
 800 +CONFIG_PACKAGE_ipsec-tools=m
 801 +CONFIG_PACKAGE_iptraf=y
 802 +CONFIG_PACKAGE_isakmpd=m
 803 +CONFIG_PACKAGE_keynote=m
 804 +CONFIG_PACKAGE_netperf=y
 805 +CONFIG_PACKAGE_olsrd=y
 806 +CONFIG_PACKAGE_olsrd-mod-bmf=m
 807 +CONFIG_PACKAGE_olsrd-mod-dot-draw=m
 808 +CONFIG_PACKAGE_olsrd-mod-dyn-gw=m
 809 +CONFIG_PACKAGE_olsrd-mod-httpinfo=y
 810 +CONFIG_PACKAGE_olsrd-mod-nameservice=m
 811 +CONFIG_PACKAGE_olsrd-mod-secure=m
 812 +CONFIG_PACKAGE_olsrd-mod-txtinfo=m
 813 +CONFIG_PACKAGE_ppp=y
 814 +# CONFIG_PACKAGE_ppp-mod-pppoa is not set
 815 +CONFIG_PACKAGE_ppp-mod-pppoe=y
 816 +# CONFIG_PACKAGE_ppp-mod-radius is not set
 817 +# CONFIG_PACKAGE_pppdump is not set
 818 +# CONFIG_PACKAGE_pppstats is not set
 819 +# CONFIG_PACKAGE_pptp is not set
 820 +CONFIG_PACKAGE_tc=m
 821 +CONFIG_PACKAGE_tcpdump=y
 822 +CONFIG_PACKAGE_wpa-supplicant=m
 823 +CONFIG_PACKAGE_wpa-cli=m
 824 +CONFIG_PACKAGE_zd1211-firmware=m
 825 +
 826 +#
 827 +# Kernel modules
 828 +#
 829 +CONFIG_DEFAULT_kmod-ipt-nathelper=y
 830 +CONFIG_DEFAULT_kmod-natsemi=y
 831 +CONFIG_DEFAULT_kmod-via-rhine=y
 832 +CONFIG_DEFAULT_kmod-ne2k-pci=y
 833 +CONFIG_DEFAULT_kmod-hw-rng=y
 834 +CONFIG_DEFAULT_kmod-hw-crypto=y
 835 +CONFIG_DEFAULT_kmod-linux-ocf=y
 836 +CONFIG_DEFAULT_kmod-leds-alix=y
 837 +
 838 +#
 839 +# Block Devices
 840 +#
 841 +CONFIG_PACKAGE_kmod-ata-piix=m
 842 +CONFIG_PACKAGE_kmod-libata=m
 843 +CONFIG_PACKAGE_kmod-pata-artop=m
 844 +
 845 +#
 846 +# Filesystems
 847 +#
 848 +CONFIG_PACKAGE_kmod-fs-cifs=m
 849 +CONFIG_PACKAGE_kmod-fs-ext2=m
 850 +CONFIG_PACKAGE_kmod-fs-ext3=m
 851 +CONFIG_PACKAGE_kmod-fs-hfsplus=m
 852 +CONFIG_PACKAGE_kmod-fs-isofs=m
 853 +CONFIG_PACKAGE_kmod-fs-minix=m
 854 +CONFIG_PACKAGE_kmod-fs-msdos=m
 855 +CONFIG_PACKAGE_kmod-fs-nfs=m
 856 +CONFIG_PACKAGE_kmod-fs-nfsd=m
 857 +CONFIG_PACKAGE_kmod-fs-udf=m
 858 +CONFIG_PACKAGE_kmod-fs-vfat=m
 859 +CONFIG_PACKAGE_kmod-fs-xfs=m
 860 +# CONFIG_PACKAGE_kmod-fuse is not set
 861 +CONFIG_PACKAGE_kmod-nls-base=m
 862 +CONFIG_PACKAGE_kmod-nls-cp1250=m
 863 +CONFIG_PACKAGE_kmod-nls-cp437=m
 864 +CONFIG_PACKAGE_kmod-nls-cp850=m
 865 +CONFIG_PACKAGE_kmod-nls-iso8859-1=m
 866 +CONFIG_PACKAGE_kmod-nls-iso8859-15=m
 867 +CONFIG_PACKAGE_kmod-nls-iso8859-2=m
 868 +CONFIG_PACKAGE_kmod-nls-koi8r=m
 869 +CONFIG_PACKAGE_kmod-nls-utf8=m
 870 +# CONFIG_PACKAGE_kmod-shfs is not set
 871 +
 872 +#
 873 +# I2C Bus
 874 +#
 875 +CONFIG_PACKAGE_kmod-i2c-core=m
 876 +CONFIG_PACKAGE_kmod-i2c-algos=m
 877 +
 878 +#
 879 +# Netfilter Extensions
 880 +#
 881 +CONFIG_PACKAGE_kmod-arptables=m
 882 +CONFIG_PACKAGE_kmod-ebtables=m
 883 +CONFIG_PACKAGE_kmod-ip6tables=m
 884 +CONFIG_PACKAGE_kmod-ipt-conntrack=m
 885 +CONFIG_PACKAGE_kmod-ipt-extra=m
 886 +CONFIG_PACKAGE_kmod-ipt-filter=m
 887 +CONFIG_PACKAGE_kmod-ipt-imq=m
 888 +CONFIG_PACKAGE_kmod-ipt-ipopt=m
 889 +CONFIG_PACKAGE_kmod-ipt-iprange=m
 890 +CONFIG_PACKAGE_kmod-ipt-ipsec=m
 891 +CONFIG_PACKAGE_kmod-ipt-ipset=m
 892 +CONFIG_PACKAGE_kmod-ipt-nat=m
 893 +CONFIG_PACKAGE_kmod-ipt-nathelper=y
 894 +CONFIG_PACKAGE_kmod-ipt-nathelper-extra=m
 895 +CONFIG_PACKAGE_kmod-ipt-queue=m
 896 +CONFIG_PACKAGE_kmod-ipt-ulog=m
 897 +
 898 +#
 899 +# Network Devices
 900 +#
 901 +CONFIG_PACKAGE_kmod-3c59x=m
 902 +CONFIG_PACKAGE_kmod-8139too=m
 903 +CONFIG_PACKAGE_kmod-e100=m
 904 +CONFIG_PACKAGE_kmod-e1000=m
 905 +CONFIG_PACKAGE_kmod-natsemi=m
 906 +CONFIG_PACKAGE_kmod-ne2k-pci=m
 907 +CONFIG_PACKAGE_kmod-r8169=m
 908 +CONFIG_PACKAGE_kmod-sis900=m
 909 +CONFIG_PACKAGE_kmod-via-rhine=y
 910 +
 911 +#
 912 +# Network Support
 913 +#
 914 +CONFIG_PACKAGE_kmod-atm=m
 915 +CONFIG_PACKAGE_kmod-atmtcp=m
 916 +CONFIG_PACKAGE_kmod-ax25=m
 917 +CONFIG_PACKAGE_kmod-bonding=m
 918 +CONFIG_PACKAGE_kmod-gre=m
 919 +CONFIG_PACKAGE_kmod-ipsec=m
 920 +CONFIG_PACKAGE_kmod-ipsec4=m
 921 +CONFIG_PACKAGE_kmod-ipsec6=m
 922 +CONFIG_PACKAGE_kmod-iptunnel4=m
 923 +CONFIG_PACKAGE_kmod-ipv6=m
 924 +CONFIG_PACKAGE_kmod-mp-alg=m
 925 +CONFIG_PACKAGE_kmod-ppp=y
 926 +CONFIG_PACKAGE_kmod-mppe=m
 927 +CONFIG_PACKAGE_kmod-pppoa=m
 928 +CONFIG_PACKAGE_kmod-pppoe=y
 929 +CONFIG_PACKAGE_kmod-sched=m
 930 +CONFIG_PACKAGE_kmod-tun=m
 931 +
 932 +#
 933 +# Other modules
 934 +#
 935 +CONFIG_PACKAGE_kmod-bluetooth=m
 936 +CONFIG_PACKAGE_kmod-capi=m
 937 +CONFIG_PACKAGE_kmod-crypto=m
 938 +# CONFIG_PACKAGE_kmod-gspca is not set
 939 +CONFIG_PACKAGE_kmod-hw-crypto=y
 940 +CONFIG_PACKAGE_kmod-hw-rng=y
 941 +CONFIG_PACKAGE_kmod-hwmon=m
 942 +CONFIG_PACKAGE_kmod-hwmon-pc87360=m
 943 +CONFIG_PACKAGE_kmod-ide-aec62xx=m
 944 +CONFIG_PACKAGE_kmod-ide-core=m
 945 +CONFIG_PACKAGE_kmod-ide-pdc202xx=m
 946 +CONFIG_PACKAGE_kmod-input-core=m
 947 +CONFIG_PACKAGE_kmod-input-evdev=m
 948 +CONFIG_PACKAGE_kmod-leds-alix=y
 949 +CONFIG_PACKAGE_kmod-linux-ocf=y
 950 +CONFIG_PACKAGE_kmod-loop=m
 951 +CONFIG_PACKAGE_kmod-lp=m
 952 +CONFIG_PACKAGE_kmod-nbd=m
 953 +CONFIG_PACKAGE_kmod-pcmcia-core=m
 954 +CONFIG_PACKAGE_kmod-pcmcia-serial=m
 955 +CONFIG_PACKAGE_kmod-scsi-core=m
 956 +CONFIG_PACKAGE_kmod-softdog=m
 957 +CONFIG_PACKAGE_kmod-sound-core=m
 958 +CONFIG_PACKAGE_kmod-videodev=m
 959 +# CONFIG_PACKAGE_kmod-spca5xx-le is not set
 960 +
 961 +#
 962 +# USB Support
 963 +#
 964 +CONFIG_PACKAGE_kmod-usb-core=m
 965 +CONFIG_PACKAGE_kmod-cpia2=m
 966 +CONFIG_PACKAGE_kmod-ueagle-atm=m
 967 +CONFIG_PACKAGE_kmod-usb-acm=m
 968 +CONFIG_PACKAGE_kmod-usb-atm=m
 969 +CONFIG_PACKAGE_kmod-usb-audio=m
 970 +CONFIG_PACKAGE_kmod-usb-hid=m
 971 +CONFIG_PACKAGE_kmod-usb-net=m
 972 +CONFIG_PACKAGE_kmod-usb-net-asix=m
 973 +CONFIG_PACKAGE_kmod-usb-net-kaweth=m
 974 +CONFIG_PACKAGE_kmod-usb-net-pegasus=m
 975 +CONFIG_PACKAGE_kmod-usb-ohci=m
 976 +CONFIG_PACKAGE_kmod-usb-printer=m
 977 +CONFIG_PACKAGE_kmod-usb-pwc=m
 978 +# CONFIG_PACKAGE_kmod-usb-qc is not set
 979 +CONFIG_PACKAGE_kmod-usb-serial=m
 980 +CONFIG_PACKAGE_kmod-usb-serial-airprime=m
 981 +CONFIG_PACKAGE_kmod-usb-serial-belkin=m
 982 +CONFIG_PACKAGE_kmod-usb-serial-ftdi=m
 983 +CONFIG_PACKAGE_kmod-usb-serial-mct=m
 984 +CONFIG_PACKAGE_kmod-usb-serial-option=m
 985 +CONFIG_PACKAGE_kmod-usb-serial-pl2303=m
 986 +CONFIG_PACKAGE_kmod-usb-serial-sierrawireless=m
 987 +CONFIG_PACKAGE_kmod-usb-serial-visor=m
 988 +CONFIG_PACKAGE_kmod-usb-speedtouch=m
 989 +CONFIG_PACKAGE_kmod-usb-storage=m
 990 +CONFIG_PACKAGE_kmod-usb-uhci=m
 991 +CONFIG_PACKAGE_kmod-usb-yealink=m
 992 +CONFIG_PACKAGE_kmod-usb2=m
 993 +
 994 +#
 995 +# Wireless Drivers
 996 +#
 997 +CONFIG_PACKAGE_kmod-acx=m
 998 +CONFIG_PACKAGE_kmod-hostap=m
 999 +CONFIG_PACKAGE_kmod-hostap-pci=m
1000 +CONFIG_PACKAGE_kmod-hostap-plx=m
1001 +CONFIG_PACKAGE_kmod-ieee80211=m
1002 +CONFIG_PACKAGE_kmod-ieee80211-softmac=m
1003 +CONFIG_PACKAGE_kmod-mac80211=m
1004 +CONFIG_PACKAGE_kmod-madwifi=y
1005 +CONFIG_PACKAGE_kmod-net-airo=m
1006 +CONFIG_PACKAGE_kmod-net-bcm43xx=m
1007 +CONFIG_PACKAGE_kmod-net-hermes=m
1008 +CONFIG_PACKAGE_kmod-net-hermes-pci=m
1009 +CONFIG_PACKAGE_kmod-net-hermes-plx=m
1010 +CONFIG_PACKAGE_kmod-net-ipw2100=m
1011 +CONFIG_PACKAGE_kmod-net-ipw2200=m
1012 +CONFIG_PACKAGE_kmod-net-prism54=m
1013 +CONFIG_PACKAGE_kmod-net-zd1211rw=m
1014 +CONFIG_PACKAGE_kmod-rt2500=m
1015 +CONFIG_PACKAGE_kmod-rt61=m
1016 +CONFIG_PACKAGE_kmod-zd1211=m
1017 diff -Nur kamikaze_7.09.orig/include/kernel.mk kamikaze_7.09/include/kernel.mk
1018 --- kamikaze_7.09.orig/include/kernel.mk	2007-09-20 10:53:15.000000000 +0200
1019 +++ kamikaze_7.09/include/kernel.mk	2008-06-19 17:34:17.000000000 +0200
1020 @@ -64,7 +64,7 @@
1021  			for mod in $$$$$$$$2; do \
1022  				getvar mod; \
1023  			done \
1024 -		) > $(2)/etc/modules.d/$$$$$$$$1-$(1); \
1025 +		) | sed -e 's|/| |g' > $(2)/etc/modules.d/$$$$$$$$1-$(1); \
1026  		modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$1-$(1)"; \
1027  	}; \
1028  	$(3) \
1029 diff -Nur kamikaze_7.09.orig/package/cryptotest-bgp/Makefile kamikaze_7.09/package/cryptotest-bgp/Makefile
1030 --- kamikaze_7.09.orig/package/cryptotest-bgp/Makefile	1970-01-01 01:00:00.000000000 +0100
1031 +++ kamikaze_7.09/package/cryptotest-bgp/Makefile	2008-06-19 17:34:17.000000000 +0200
1032 @@ -0,0 +1,50 @@
1033 +# 
1034 +# Copyright (C) 2006 OpenWrt.org
1035 +#
1036 +# This is free software, licensed under the GNU General Public License v2.
1037 +# See /LICENSE for more information.
1038 +#
1039 +# $Id: Makefile 8659 2007-09-07 08:34:51Z nico $
1040 +
1041 +include $(TOPDIR)/rules.mk
1042 +include $(INCLUDE_DIR)/kernel.mk
1043 +
1044 +PKG_NAME:=cryptotest-bgp
1045 +PKG_VERSION:=1.10
1046 +PKG_RELEASE:=1
1047 +
1048 +PKG_BUILD_DIR:=$(BUILD_DIR)/bgp/cryptotest
1049 +
1050 +include $(INCLUDE_DIR)/package.mk
1051 +
1052 +TARGET_CFLAGS+= -I$(LINUX_DIR)/crypto/ocf
1053 +
1054 +define Package/$(PKG_NAME)
1055 +  SECTION:=utils
1056 +  CATEGORY:=Utilities
1057 +  TITLE:=Simple tool for testing hardware/system crypto support.
1058 +endef
1059 +
1060 +define Package/$(PKG_NAME)/description
1061 +  Simple tool for testing hardware/system crypto support.
1062 +
1063 +  http://ocf-linux.sourceforge.net/
1064 +endef
1065 +
1066 +define Build/Prepare
1067 +	mkdir -p $(PKG_BUILD_DIR)
1068 +	$(CP) ./src/* $(PKG_BUILD_DIR)/
1069 +endef
1070 +
1071 +define Build/Compile
1072 +	$(TARGET_CC) $(TARGET_CFLAGS) \
1073 +		-o $(PKG_BUILD_DIR)/cryptotest \
1074 +		$(PKG_BUILD_DIR)/cryptotest.c
1075 +endef
1076 +
1077 +define Package/$(PKG_NAME)/install
1078 +	$(INSTALL_DIR) $(1)/bin
1079 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/cryptotest $(1)/bin/
1080 +endef
1081 +
1082 +$(eval $(call BuildPackage,$(PKG_NAME)))
1083 diff -Nur kamikaze_7.09.orig/package/cryptotest-bgp/src/cryptokeytest.c kamikaze_7.09/package/cryptotest-bgp/src/cryptokeytest.c
1084 --- kamikaze_7.09.orig/package/cryptotest-bgp/src/cryptokeytest.c	1970-01-01 01:00:00.000000000 +0100
1085 +++ kamikaze_7.09/package/cryptotest-bgp/src/cryptokeytest.c	2008-06-19 17:34:17.000000000 +0200
1086 @@ -0,0 +1,292 @@
1087 +/* $FreeBSD: src/tools/tools/crypto/cryptokeytest.c,v 1.2 2007/03/21 03:42:51 sam Exp $ */
1088 +/*
1089 + * The big num stuff is a bit broken at the moment and I've not yet fixed it.
1090 + * The symtom is that odd size big nums will fail.  Test code below (it only
1091 + * uses modexp currently).
1092 + * 
1093 + * --Jason L. Wright
1094 + */
1095 +#include <sys/types.h>
1096 +#include <sys/ioctl.h>
1097 +#include <endian.h>
1098 +#include <sys/time.h>
1099 +#include <cryptodev.h>
1100 +#include <openssl/bn.h>
1101 +
1102 +#include <paths.h>
1103 +#include <fcntl.h>
1104 +#include <err.h>
1105 +#include <string.h>
1106 +#include <unistd.h>
1107 +#include <stdlib.h>
1108 +
1109 +int	crid = CRYPTO_FLAG_HARDWARE;
1110 +int	verbose = 0;
1111 +static int errs;
1112 +
1113 +static int
1114 +devcrypto(void)
1115 +{
1116 +	static int fd = -1;
1117 +
1118 +	if (fd < 0) {
1119 +		fd = open(_PATH_DEV "crypto", O_RDWR, 0);
1120 +		if (fd < 0)
1121 +			err(1, _PATH_DEV "crypto");
1122 +		if (fcntl(fd, F_SETFD, 1) == -1)
1123 +			err(1, "fcntl(F_SETFD) (devcrypto)");
1124 +	}
1125 +	return fd;
1126 +}
1127 +
1128 +static int
1129 +crlookup(const char *devname)
1130 +{
1131 +	struct crypt_find_op find;
1132 +
1133 +	find.crid = -1;
1134 +	strlcpy(find.name, devname, sizeof(find.name));
1135 +	if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
1136 +		err(1, "ioctl(CIOCFINDDEV)");
1137 +	return find.crid;
1138 +}
1139 +
1140 +static const char *
1141 +crfind(int crid)
1142 +{
1143 +	static struct crypt_find_op find;
1144 +
1145 +	bzero(&find, sizeof(find));
1146 +	find.crid = crid;
1147 +	if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
1148 +		err(1, "ioctl(CIOCFINDDEV)");
1149 +	return find.name;
1150 +}
1151 +
1152 +/*
1153 + * Convert a little endian byte string in 'p' that
1154 + * is 'plen' bytes long to a BIGNUM. If 'dst' is NULL,
1155 + * a new BIGNUM is allocated.  Returns NULL on failure.
1156 + *
1157 + * XXX there has got to be a more efficient way to do
1158 + * this, but I haven't figured out enough of the OpenSSL
1159 + * magic.
1160 + */
1161 +BIGNUM *
1162 +le_to_bignum(BIGNUM *dst, u_int8_t *p, int plen)
1163 +{
1164 +	u_int8_t *pd;
1165 +	int i;
1166 +
1167 +	if (plen == 0)
1168 +		return (NULL);
1169 +
1170 +	if ((pd = (u_int8_t *)malloc(plen)) == NULL)
1171 +		return (NULL);
1172 +
1173 +	for (i = 0; i < plen; i++)
1174 +		pd[i] = p[plen - i - 1];
1175 +
1176 +	dst = BN_bin2bn(pd, plen, dst);
1177 +	free(pd);
1178 +	return (dst);
1179 +}
1180 +
1181 +/*
1182 + * Convert a BIGNUM to a little endian byte string.
1183 + * If 'rd' is NULL, allocate space for it, otherwise
1184 + * 'rd' is assumed to have room for BN_num_bytes(n)
1185 + * bytes.  Returns NULL on failure.
1186 + */
1187 +u_int8_t *
1188 +bignum_to_le(BIGNUM *n, u_int8_t *rd)
1189 +{
1190 +	int i, j, k;
1191 +	int blen = BN_num_bytes(n);
1192 +
1193 +	if (blen == 0)
1194 +		return (NULL);
1195 +	if (rd == NULL)
1196 +		rd = (u_int8_t *)malloc(blen);
1197 +	if (rd == NULL)
1198 +		return (NULL);
1199 +
1200 +	for (i = 0, j = 0; i < n->top; i++) {
1201 +		for (k = 0; k < BN_BITS2 / 8; k++) {
1202 +			if ((j + k) >= blen)
1203 +				goto out;
1204 +			rd[j + k] = n->d[i] >> (k * 8);
1205 +		}
1206 +		j += BN_BITS2 / 8;
1207 +	}
1208 +out:
1209 +	return (rd);
1210 +}
1211 +
1212 +int
1213 +UB_mod_exp(BIGNUM *res, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx)
1214 +{
1215 +	struct crypt_kop kop;
1216 +	u_int8_t *ale, *ble, *cle;
1217 +	static int crypto_fd = -1;
1218 +
1219 +	if (crypto_fd == -1 && ioctl(devcrypto(), CRIOGET, &crypto_fd) == -1)
1220 +		err(1, "CRIOGET");
1221 +
1222 +	if ((ale = bignum_to_le(a, NULL)) == NULL)
1223 +		err(1, "bignum_to_le, a");
1224 +	if ((ble = bignum_to_le(b, NULL)) == NULL)
1225 +		err(1, "bignum_to_le, b");
1226 +	if ((cle = bignum_to_le(c, NULL)) == NULL)
1227 +		err(1, "bignum_to_le, c");
1228 +
1229 +	bzero(&kop, sizeof(kop));
1230 +	kop.crk_op = CRK_MOD_EXP;
1231 +	kop.crk_iparams = 3;
1232 +	kop.crk_oparams = 1;
1233 +	kop.crk_crid = crid;
1234 +	kop.crk_param[0].crp_p = ale;
1235 +	kop.crk_param[0].crp_nbits = BN_num_bytes(a) * 8;
1236 +	kop.crk_param[1].crp_p = ble;
1237 +	kop.crk_param[1].crp_nbits = BN_num_bytes(b) * 8;
1238 +	kop.crk_param[2].crp_p = cle;
1239 +	kop.crk_param[2].crp_nbits = BN_num_bytes(c) * 8;
1240 +	kop.crk_param[3].crp_p = cle;
1241 +	kop.crk_param[3].crp_nbits = BN_num_bytes(c) * 8;
1242 +
1243 +	if (ioctl(crypto_fd, CIOCKEY2, &kop) == -1)
1244 +		warn("CIOCKEY");
1245 +	if (verbose)
1246 +		printf("device = %s\n", crfind(kop.crk_crid));
1247 +
1248 +	bzero(ale, BN_num_bytes(a));
1249 +	free(ale);
1250 +	bzero(ble, BN_num_bytes(b));
1251 +	free(ble);
1252 +
1253 +	if (kop.crk_status != 0) {
1254 +		printf("error %d\n", kop.crk_status);
1255 +		bzero(cle, BN_num_bytes(c));
1256 +		free(cle);
1257 +		return (-1);
1258 +	} else {
1259 +		res = le_to_bignum(res, cle, BN_num_bytes(c));
1260 +		bzero(cle, BN_num_bytes(c));
1261 +		free(cle);
1262 +		if (res == NULL)
1263 +			err(1, "le_to_bignum");
1264 +		return (0);
1265 +	}
1266 +	return (0);
1267 +}
1268 +
1269 +void
1270 +show_result(a, b, c, sw, hw)
1271 +BIGNUM *a, *b, *c, *sw, *hw;
1272 +{
1273 +	printf("\n");
1274 +
1275 +	printf("A = ");
1276 +	BN_print_fp(stdout, a);
1277 +	printf("\n");
1278 +
1279 +	printf("B = ");
1280 +	BN_print_fp(stdout, b);
1281 +	printf("\n");
1282 +
1283 +	printf("C = ");
1284 +	BN_print_fp(stdout, c);
1285 +	printf("\n");
1286 +
1287 +	printf("sw= ");
1288 +	BN_print_fp(stdout, sw);
1289 +	printf("\n");
1290 +
1291 +	printf("hw= ");
1292 +	BN_print_fp(stdout, hw);
1293 +	printf("\n");
1294 +
1295 +	printf("\n");
1296 +}
1297 +
1298 +void
1299 +testit(void)
1300 +{
1301 +	BIGNUM *a, *b, *c, *r1, *r2;
1302 +	BN_CTX *ctx;
1303 +
1304 +	ctx = BN_CTX_new();
1305 +
1306 +	a = BN_new();
1307 +	b = BN_new();
1308 +	c = BN_new();
1309 +	r1 = BN_new();
1310 +	r2 = BN_new();
1311 +
1312 +	BN_pseudo_rand(a, 1023, 0, 0);
1313 +	BN_pseudo_rand(b, 1023, 0, 0);
1314 +	do {
1315 +		BN_pseudo_rand(c, 1024, 0, 0);
1316 +	} while (!BN_is_odd(c));
1317 +	BN_set_bit(c, 1023);
1318 +
1319 +	if (BN_cmp(a, c) > 0) {
1320 +		BIGNUM *rem = BN_new();
1321 +
1322 +		BN_mod(rem, a, c, ctx);
1323 +		UB_mod_exp(r2, rem, b, c, ctx);
1324 +		BN_free(rem);
1325 +	} else {
1326 +		UB_mod_exp(r2, a, b, c, ctx);
1327 +	}
1328 +	BN_mod_exp(r1, a, b, c, ctx);
1329 +
1330 +	if (BN_cmp(r1, r2) != 0) {
1331 +		errs++;
1332 +		show_result(a, b, c, r1, r2);
1333 +	}
1334 +
1335 +	BN_free(r2);
1336 +	BN_free(r1);
1337 +	BN_free(c);
1338 +	BN_free(b);
1339 +	BN_free(a);
1340 +	BN_CTX_free(ctx);
1341 +}
1342 +
1343 +static void
1344 +usage(const char* cmd)
1345 +{
1346 +	printf("usage: %s [-d dev] [-v] [count]\n", cmd);
1347 +	printf("count is the number of bignum ops to do\n");
1348 +	printf("\n");
1349 +	printf("-d use specific device\n");
1350 +	printf("-v be verbose\n");
1351 +	exit(-1);
1352 +}
1353 +
1354 +int
1355 +main(int argc, char *argv[])
1356 +{
1357 +	int c, i;
1358 +
1359 +	while ((c = getopt(argc, argv, "d:v")) != -1) {
1360 +		switch (c) {
1361 +		case 'd':
1362 +			crid = crlookup(optarg);
1363 +			break;
1364 +		case 'v':
1365 +			verbose = 1;
1366 +			break;
1367 +		default:
1368 +			usage(argv[0]);
1369 +		}
1370 +	}
1371 +	argc -= optind, argv += optind;
1372 +
1373 +	for (i = 0; i < 1000; i++) {
1374 +		fprintf(stderr, "test %d, errs=%d\n", i, errs);
1375 +		testit();
1376 +	}
1377 +	return (0);
1378 +}
1379 diff -Nur kamikaze_7.09.orig/package/cryptotest-bgp/src/cryptotest.c kamikaze_7.09/package/cryptotest-bgp/src/cryptotest.c
1380 --- kamikaze_7.09.orig/package/cryptotest-bgp/src/cryptotest.c	1970-01-01 01:00:00.000000000 +0100
1381 +++ kamikaze_7.09/package/cryptotest-bgp/src/cryptotest.c	2008-06-19 17:34:17.000000000 +0200
1382 @@ -0,0 +1,741 @@
1383 +/*-
1384 + * Copyright (c) 2004 Sam Leffler, Errno Consulting
1385 + * All rights reserved.
1386 + *
1387 + * Redistribution and use in source and binary forms, with or without
1388 + * modification, are permitted provided that the following conditions
1389 + * are met:
1390 + * 1. Redistributions of source code must retain the above copyright
1391 + *    notice, this list of conditions and the following disclaimer,
1392 + *    without modification.
1393 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1394 + *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
1395 + *    redistribution must be conditioned upon including a substantially
1396 + *    similar Disclaimer requirement for further binary redistribution.
1397 + * 3. Neither the names of the above-listed copyright holders nor the names
1398 + *    of any contributors may be used to endorse or promote products derived
1399 + *    from this software without specific prior written permission.
1400 + *
1401 + * NO WARRANTY
1402 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1403 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1404 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
1405 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
1406 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
1407 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1408 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1409 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
1410 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1411 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1412 + * THE POSSIBILITY OF SUCH DAMAGES.
1413 + *
1414 + * $FreeBSD: src/tools/tools/crypto/cryptotest.c,v 1.9 2007/03/21 03:42:51 sam Exp $
1415 + */
1416 +
1417 +/*
1418 + * Simple tool for testing hardware/system crypto support.
1419 + *
1420 + * cryptotest [-czsbv] [-a algorithm] [count] [size ...]
1421 + *
1422 + * Run count iterations of a crypt+decrypt or mac operation on a buffer of
1423 + * size bytes.  A random key and iv are used.  Options:
1424 + *	-c	check the results
1425 + *	-d dev	pin work on device dev
1426 + *	-z	run all available algorithms on a variety of buffer sizes
1427 + *	-v	be verbose
1428 + *	-b	mark operations for batching
1429 + *	-p	profile kernel crypto operations (must be root)
1430 + *	-t n	fork n threads and run tests concurrently
1431 + * Known algorithms are:
1432 + *	null	null cbc
1433 + *	des	des cbc
1434 + *	3des	3des cbc
1435 + *	blf	blowfish cbc
1436 + *	cast	cast cbc
1437 + *	skj	skipjack cbc
1438 + *	aes	rijndael/aes 128-bit cbc
1439 + *	aes192	rijndael/aes 192-bit cbc
1440 + *	aes256	rijndael/aes 256-bit cbc
1441 + *	md5	md5 hmac
1442 + *	md5	md5 hmac
1443 + *	sha1	sha1
1444 + *	sha1_hmac	sha1 hmac
1445 + *	sha256	256-bit sha2
1446 + *	sha256_hmac	256-bit sha2 hmac
1447 + *	sha384	384-bit sha2
1448 + *	sha384_hmac	384-bit sha2 hmac
1449 + *	sha512	512--bit sha2
1450 + *	sha512_hmac	512--bit sha2 hmac
1451 + *
1452 + * For a test of how fast a crypto card is, use something like:
1453 + *	cryptotest -z 1024
1454 + * This will run a series of tests using the available crypto/cipher
1455 + * algorithms over a variety of buffer sizes.  The 1024 says to do 1024
1456 + * iterations.  Extra arguments can be used to specify one or more buffer
1457 + * sizes to use in doing tests.
1458 + *
1459 + * To fork multiple processes all doing the same work, specify -t X on the
1460 + * command line to get X "threads" running simultaneously.  No effort is made
1461 + * to synchronize the threads or otherwise maximize load.
1462 + *
1463 + * If the kernel crypto code is built with CRYPTO_TIMING and you run as root,
1464 + * then you can specify the -p option to get a "profile" of the time spent
1465 + * processing crypto operations.  At present this data is only meaningful for
1466 + * symmetric operations.  To get meaningful numbers you must run on an idle
1467 + * machine.
1468 + *
1469 + * Expect ~400 Mb/s for a Broadcom 582x for 8K buffers on a reasonable CPU
1470 + * (64-bit PCI helps).  Hifn 7811 parts top out at ~110 Mb/s.
1471 + */
1472 +#include <sys/types.h>
1473 +#include <sys/param.h>
1474 +#include <sys/time.h>
1475 +#include <sys/ioctl.h>
1476 +#include <stdio.h>
1477 +#include <fcntl.h>
1478 +#include <unistd.h>
1479 +#include <sys/wait.h>
1480 +#include <sys/mman.h>
1481 +#include <paths.h>
1482 +#include <stdlib.h>
1483 +#include <string.h>
1484 +#include <strings.h>
1485 +#include <err.h>
1486 +
1487 +#include <string.h>
1488 +#include <err.h>
1489 +
1490 +#include <sys/sysctl.h>
1491 +#include <time.h>
1492 +#include <sys/time.h>
1493 +#include <cryptodev.h>
1494 +
1495 +#define	CHUNK	64	/* how much to display */
1496 +#define	N(a)		(sizeof (a) / sizeof (a[0]))
1497 +#define	streq(a,b)	(strcasecmp(a,b) == 0)
1498 +
1499 +void	hexdump(char *, int);
1500 +
1501 +int	verbose = 0;
1502 +int	opflags = 0;
1503 +int	verify = 0;
1504 +int	crid = CRYPTO_FLAG_HARDWARE | CRYPTO_FLAG_SOFTWARE;
1505 +
1506 +int swap_iv = 0;
1507 +int swap_key = 0;
1508 +int swap_data = 0;
1509 +
1510 +static void swap_buf(char *buf, int len)
1511 +{
1512 +	int i;
1513 +	char tmp[4];
1514 +	for (i = 0; i < len; i += 4) {
1515 +		memcpy(tmp, &buf[i], 4);
1516 +		buf[i + 0] = tmp[3];
1517 +		buf[i + 1] = tmp[2];
1518 +		buf[i + 2] = tmp[1];
1519 +		buf[i + 3] = tmp[0];
1520 +	}
1521 +}
1522 +
1523 +#define MAX_IV_SIZE 16
1524 +
1525 +struct alg {
1526 +	const char* name;
1527 +	int	ishash;
1528 +	int	blocksize;
1529 +	int	minkeylen;
1530 +	int	maxkeylen;
1531 +	int	hashsize;
1532 +	int	code;
1533 +} algorithms[] = {
1534 +#ifdef CRYPTO_NULL_CBC
1535 +	{ "null",			0,	8,	1,	256,	0,	CRYPTO_NULL_CBC },
1536 +#endif
1537 +	{ "des",			0,	8,	8,	8,		0,	CRYPTO_DES_CBC },
1538 +	{ "3des",			0,	8,	24,	24,		0,	CRYPTO_3DES_CBC },
1539 +	{ "blf",			0,	8,	5,	56,		0,	CRYPTO_BLF_CBC },
1540 +	{ "cast",			0,	8,	5,	16,		0,	CRYPTO_CAST_CBC },
1541 +	{ "skj",			0,	8,	10,	10,		0,	CRYPTO_SKIPJACK_CBC },
1542 +	{ "aes",			0,	16,	16,	16,		0,	CRYPTO_RIJNDAEL128_CBC},
1543 +	{ "aes192",			0,	16,	24,	24,		0,	CRYPTO_RIJNDAEL128_CBC},
1544 +	{ "aes256",			0,	16,	32,	32,		0,	CRYPTO_RIJNDAEL128_CBC},
1545 +#ifdef notdef
1546 +	{ "arc4",			0,	8,	1,	32,		0,	CRYPTO_ARC4 },
1547 +#endif
1548 +	{ "md5",			1,	8,	0,	0,		16,	CRYPTO_MD5 },
1549 +	{ "md5_hmac",		1,	8,	1,	64,		16,	CRYPTO_MD5_HMAC },
1550 +	{ "sha1",			1,	8,	0,	0,		20,	CRYPTO_SHA1 },
1551 +	{ "sha1_hmac",		1,	1,	1,	64,		20,	CRYPTO_SHA1_HMAC },
1552 +	{ "sha256",			1,	8,	0,	0,		32,	CRYPTO_SHA2_256 },
1553 +	{ "sha256_hmac",	1,	1,	1,	64,		32,	CRYPTO_SHA2_256_HMAC },
1554 +	{ "sha384",			1,	8,	0,	0,		48,	CRYPTO_SHA2_384 },
1555 +	{ "sha384_hmac",	1,	1,	1,	64,		48,	CRYPTO_SHA2_384_HMAC },
1556 +	{ "sha512",			1,	8,	0,	0,		64,	CRYPTO_SHA2_512 },
1557 +	{ "sha512_hmac",	1,	1,	1,	64,		64,	CRYPTO_SHA2_512_HMAC },
1558 +};
1559 +
1560 +static void
1561 +usage(const char* cmd)
1562 +{
1563 +	printf("usage: %s [-czsbvVKD] [-d dev] [-a algorithm] [count] [size ...]\n",
1564 +		cmd);
1565 +	printf("where algorithm is one of:\n");
1566 +	printf("    des 3des (default) blf (blowfish) cast skj (skipjack)\n");
1567 +	printf("    aes (aka rijndael) aes192 aes256 arc4\n");
1568 +	printf("    md5 md5_hmac sha1 sha1_hmac sha256 sha256_hmac\n");
1569 +	printf("    sha384 sha384_hmac sha512 sha512_hmac\n");
1570 +	printf("count is the number of encrypt/decrypt ops to do\n");
1571 +	printf("size is the number of bytes of text to encrypt+decrypt\n");
1572 +	printf("\n");
1573 +	printf("-c check the results (slows timing)\n");
1574 +	printf("-d use specific device\n");
1575 +	printf("-z run all available algorithms on a variety of sizes\n");
1576 +	printf("-v be verbose\n");
1577 +	printf("-b mark operations for batching\n");
1578 +	printf("-p profile kernel crypto operation (must be root)\n");
1579 +	printf("-V swap IV\n");
1580 +	printf("-K swap KEY\n");
1581 +	printf("-D swap DATA\n");
1582 +	exit(-1);
1583 +}
1584 +
1585 +static struct alg*
1586 +getalgbycode(int cipher)
1587 +{
1588 +	int i;
1589 +
1590 +	for (i = 0; i < N(algorithms); i++)
1591 +		if (cipher == algorithms[i].code)
1592 +			return &algorithms[i];
1593 +	return NULL;
1594 +}
1595 +
1596 +static struct alg*
1597 +getalgbyname(const char* name)
1598 +{
1599 +	int i;
1600 +
1601 +	for (i = 0; i < N(algorithms); i++)
1602 +		if (streq(name, algorithms[i].name))
1603 +			return &algorithms[i];
1604 +	return NULL;
1605 +}
1606 +
1607 +static int
1608 +devcrypto(void)
1609 +{
1610 +	static int fd = -1;
1611 +
1612 +	if (fd < 0) {
1613 +		fd = open(_PATH_DEV "crypto", O_RDWR, 0);
1614 +		if (fd < 0)
1615 +			err(1, _PATH_DEV "crypto");
1616 +		if (fcntl(fd, F_SETFD, 1) == -1)
1617 +			err(1, "fcntl(F_SETFD) (devcrypto)");
1618 +	}
1619 +	return fd;
1620 +}
1621 +
1622 +static int
1623 +crlookup(const char *devname)
1624 +{
1625 +	struct crypt_find_op find;
1626 +
1627 +	find.crid = -1;
1628 +	strlcpy(find.name, devname, sizeof(find.name));
1629 +	if (ioctl(devcrypto(), CIOCFINDDEV, &find) == -1)
1630 +		err(1, "line %d:ioctl(CIOCFINDDEV)", __LINE__);
1631 +	return find.crid;
1632 +}
1633 +
1634 +static const char *
1635 +crfind(int crid)
1636 +{
1637 +	static struct crypt_find_op find;
1638 +
1639 +	bzero(&find, sizeof(find));
1640 +	find.crid = crid;
1641 +	if (ioctl(devcrypto(), CRIOFINDDEV, &find) == -1)
1642 +		err(1, "line %d:ioctl(CIOCFINDDEV): crid %d", __LINE__, crid);
1643 +	return find.name;
1644 +}
1645 +
1646 +static int
1647 +crget(void)
1648 +{
1649 +	int fd;
1650 +
1651 +	if (ioctl(devcrypto(), CRIOGET, &fd) == -1)
1652 +		err(1, "line %d:ioctl(CRIOGET)", __LINE__);
1653 +	if (fcntl(fd, F_SETFD, 1) == -1)
1654 +		err(1, "fcntl(F_SETFD) (crget)");
1655 +	return fd;
1656 +}
1657 +
1658 +static char
1659 +rdigit(void)
1660 +{
1661 +#if 1
1662 +	const char a[] = {
1663 +		0x10,0x54,0x11,0x48,0x45,0x12,0x4f,0x13,0x49,0x53,0x14,0x41,
1664 +		0x15,0x16,0x4e,0x55,0x54,0x17,0x18,0x4a,0x4f,0x42,0x19,0x01
1665 +	};
1666 +	return 0x20+a[random()%N(a)];
1667 +#else
1668 +	static unsigned char c = 0;
1669 +	return (c++);
1670 +#endif
1671 +}
1672 +
1673 +static void
1674 +runtest(struct alg *alg, int count, int size, u_long cmd, struct timeval *tv)
1675 +{
1676 +	int i, fd = crget();
1677 +	struct timeval start, stop;
1678 +	char *cleartext = NULL, *ciphertext = NULL, *originaltext = NULL;
1679 +	struct session2_op sop;
1680 +	struct crypt_op cop;
1681 +	char iv[MAX_IV_SIZE];
1682 +
1683 +	bzero(&sop, sizeof(sop));
1684 +	if (!alg->ishash) {
1685 +		sop.keylen = (alg->minkeylen + alg->maxkeylen)/2;
1686 +		sop.key = (char *) malloc(sop.keylen);
1687 +		if (sop.key == NULL)
1688 +			err(1, "malloc (key)");
1689 +		for (i = 0; i < sop.keylen; i++)
1690 +			sop.key[i] = rdigit();
1691 +		sop.cipher = alg->code;
1692 +		if (swap_key)
1693 +			swap_buf(sop.key, sop.keylen);
1694 +	} else {
1695 +		sop.mackeylen = (alg->minkeylen + alg->maxkeylen)/2;
1696 +		sop.mackey = (char *) malloc(sop.mackeylen);
1697 +		if (sop.mackey == NULL)
1698 +			err(1, "malloc (mac)");
1699 +		for (i = 0; i < sop.mackeylen; i++)
1700 +			sop.mackey[i] = rdigit();
1701 +		sop.mac = alg->code;
1702 +		if (swap_key)
1703 +			swap_buf(sop.mackey, sop.mackeylen);
1704 +	}
1705 +	sop.crid = crid;
1706 +	if (verbose)
1707 +		printf(" crid = %x\n", crid);
1708 +	if (ioctl(fd, cmd, &sop) < 0) {
1709 +		if (cmd == CIOCGSESSION || cmd == CIOCGSESSION2) {
1710 +			close(fd);
1711 +			if (verbose) {
1712 +				printf("cipher %s", alg->name);
1713 +				if (alg->ishash)
1714 +					printf(" mackeylen %u\n", sop.mackeylen);
1715 +				else {
1716 +					printf(" keylen %u", sop.keylen);
1717 +					printf(" mac %s", sop.mac);
1718 +					printf(" alg->code %d", alg->code);
1719 +					printf(" alg->name %s\n", alg->name);
1720 +				}
1721 +				perror("CIOCGSESSION");
1722 +			}
1723 +			/* hardware doesn't support algorithm; skip it */
1724 +			return;
1725 +		}
1726 +		printf("cipher %s keylen %u mackeylen %u\n",
1727 +			alg->name, sop.keylen, sop.mackeylen);
1728 +		err(1, "CIOCGSESSION");
1729 +	}
1730 +
1731 +	originaltext = (char *)malloc((alg->hashsize ? 2 : 3)*size + alg->hashsize);
1732 +	if (originaltext == NULL)
1733 +		err(1, "malloc (text)");
1734 +	cleartext = originaltext+size;
1735 +	ciphertext = cleartext+size;
1736 +	for (i = 0; i < size; i++)
1737 +		cleartext[i] = rdigit();
1738 +	memcpy(originaltext, cleartext, size);
1739 +	for (i = 0; i < N(iv); i++)
1740 +		iv[i] = rdigit();
1741 +
1742 +	if (verbose) {
1743 +		printf("alg = %s\n", alg->name);
1744 +		printf("session = 0x%x\n", sop.ses);
1745 +		printf("device = %s\n", crfind(sop.crid));
1746 +		printf("count = %d, size = %d\n", count, size);
1747 +		if (!alg->ishash) {
1748 +			printf("iv:");
1749 +			hexdump(iv, sizeof iv);
1750 +		}
1751 +		printf("cleartext:");
1752 +		hexdump(cleartext, MIN(size, CHUNK));
1753 +	}
1754 +
1755 +	gettimeofday(&start, NULL);
1756 +	if (!alg->ishash) {
1757 +		for (i = 0; i < count; i++) {
1758 +			cop.ses = sop.ses;
1759 +			cop.op = COP_ENCRYPT;
1760 +			cop.flags = opflags;
1761 +			cop.len = size;
1762 +			cop.src = cleartext;
1763 +			cop.dst = ciphertext;
1764 +			cop.mac = 0;
1765 +			cop.iv = iv;
1766 +
1767 +			if (swap_data)
1768 +				swap_buf(cleartext, size);
1769 +			if (swap_data)
1770 +				swap_buf(ciphertext, size);
1771 +			if (swap_iv)
1772 +				swap_buf(iv, N(iv));
1773 +
1774 +			if (ioctl(fd, CIOCCRYPT, &cop) < 0)
1775 +				err(1, "line %d:ioctl(CIOCCRYPT)", __LINE__);
1776 +
1777 +			if (swap_data)
1778 +				swap_buf(cleartext, size);
1779 +			if (swap_data)
1780 +				swap_buf(ciphertext, size);
1781 +			if (swap_iv)
1782 +				swap_buf(iv, N(iv));
1783 +
1784 +			if (verify && bcmp(ciphertext, cleartext, size) == 0) {
1785 +				printf("cipher text unchanged:");
1786 +				hexdump(ciphertext, size);
1787 +			}
1788 +
1789 +			if (verbose) {
1790 +				printf("ciphertext:");
1791 +				hexdump(ciphertext, MIN(size, CHUNK));
1792 +				printf("cipheriv:");
1793 +				hexdump(iv, MIN(size, CHUNK));
1794 +			}
1795 +
1796 +			memset(cleartext, 'x', MIN(size, CHUNK));
1797 +			cop.ses = sop.ses;
1798 +			cop.op = COP_DECRYPT;
1799 +			cop.flags = opflags;
1800 +			cop.len = size;
1801 +			cop.src = ciphertext;
1802 +			cop.dst = cleartext;
1803 +			cop.mac = 0;
1804 +			cop.iv = iv;
1805 +
1806 +			if (swap_data)
1807 +				swap_buf(cleartext, size);
1808 +			if (swap_data)
1809 +				swap_buf(ciphertext, size);
1810 +			if (swap_iv)
1811 +				swap_buf(iv, N(iv));
1812 +
1813 +			if (ioctl(fd, CIOCCRYPT, &cop) < 0)
1814 +				err(1, "line %d:ioctl(CIOCCRYPT)", __LINE__);
1815 +
1816 +			if (swap_data)
1817 +				swap_buf(cleartext, size);
1818 +			if (swap_data)
1819 +				swap_buf(ciphertext, size);
1820 +			if (swap_iv)
1821 +				swap_buf(iv, N(iv));
1822 +
1823 +			if (verify && bcmp(cleartext, originaltext, size) != 0) {
1824 +				printf("decrypt mismatch:\n");
1825 +				printf("original:");
1826 +				hexdump(originaltext, size);
1827 +				printf("cleartext:");
1828 +				hexdump(cleartext, size);
1829 +			}
1830 +		}
1831 +	} else {
1832 +		for (i = 0; i < count; i++) {
1833 +			cop.ses = sop.ses;
1834 +			cop.op = 0;
1835 +			cop.flags = opflags;
1836 +			cop.len = size;
1837 +			cop.src = cleartext;
1838 +			cop.dst = 0;
1839 +			cop.mac = ciphertext;
1840 +			cop.iv = 0;
1841 +
1842 +			if (ioctl(fd, CIOCCRYPT, &cop) < 0)
1843 +				err(1, "line %d:ioctl(CIOCCRYPT)", __LINE__);
1844 +
1845 +			if (verbose) {
1846 +				printf("ciphertext:");
1847 +				hexdump(ciphertext, size);
1848 +			}
1849 +		}
1850 +	}
1851 +	gettimeofday(&stop, NULL);
1852 + 
1853 +	if (ioctl(fd, CIOCFSESSION, &sop.ses) < 0)
1854 +		perror("ioctl(CIOCFSESSION)");
1855 +
1856 +	if (verbose) {
1857 +		printf("cleartext:");
1858 +		hexdump(cleartext, MIN(size, CHUNK));
1859 +	}
1860 +	timersub(&stop, &start, tv);
1861 +
1862 +	if (sop.key)
1863 +		free(sop.key);
1864 +	if (sop.mackey)
1865 +		free(sop.mackey);
1866 +	free(originaltext);
1867 +
1868 +	close(fd);
1869 +}
1870 +
1871 +#ifdef __FreeBSD__
1872 +static void
1873 +resetstats()
1874 +{
1875 +	struct cryptostats stats;
1876 +	size_t slen;
1877 +
1878 +	slen = sizeof (stats);
1879 +	if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0) {
1880 +		perror("kern.crypto_stats");
1881 +		return;
1882 +	}
1883 +	bzero(&stats.cs_invoke, sizeof (stats.cs_invoke));
1884 +	bzero(&stats.cs_done, sizeof (stats.cs_done));
1885 +	bzero(&stats.cs_cb, sizeof (stats.cs_cb));
1886 +	bzero(&stats.cs_finis, sizeof (stats.cs_finis));
1887 +	stats.cs_invoke.min.tv_sec = 10000;
1888 +	stats.cs_done.min.tv_sec = 10000;
1889 +	stats.cs_cb.min.tv_sec = 10000;
1890 +	stats.cs_finis.min.tv_sec = 10000;
1891 +	if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
1892 +		perror("kern.cryptostats");
1893 +}
1894 +
1895 +static void
1896 +printt(const char* tag, struct cryptotstat *ts)
1897 +{
1898 +	uint64_t avg, min, max;
1899 +
1900 +	if (ts->count == 0)
1901 +		return;
1902 +	avg = (1000000000LL*ts->acc.tv_sec + ts->acc.tv_nsec) / ts->count;
1903 +	min = 1000000000LL*ts->min.tv_sec + ts->min.tv_nsec;
1904 +	max = 1000000000LL*ts->max.tv_sec + ts->max.tv_nsec;
1905 +	printf("%16.16s: avg %6llu ns : min %6llu ns : max %7llu ns [%u samps]\n",
1906 +		tag, avg, min, max, ts->count);
1907 +}
1908 +#endif
1909 +
1910 +static void
1911 +runtests(struct alg *alg, int count, int size, u_long cmd, int threads, int profile)
1912 +{
1913 +	int i, status;
1914 +	double t;
1915 +	void *region;
1916 +	struct timeval *tvp;
1917 +#ifdef __FreeBSD__
1918 +	int otiming;
1919 +#endif
1920 +
1921 +	if (size % alg->blocksize) {
1922 +		if (verbose)
1923 +			printf("skipping blocksize %u 'cuz not a multiple of "
1924 +				"%s blocksize %u\n",
1925 +				size, alg->name, alg->blocksize);
1926 +		return;
1927 +	}
1928 +
1929 +	region = mmap(NULL, threads * sizeof (struct timeval),
1930 +			PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
1931 +	if (region == MAP_FAILED) {
1932 +		perror("mmap");
1933 +		return;
1934 +	}
1935 +	tvp = (struct timeval *) region;
1936 +#ifdef __FreeBSD__
1937 +	if (profile) {
1938 +		size_t tlen = sizeof (otiming);
1939 +		int timing = 1;
1940 +
1941 +		resetstats();
1942 +		if (sysctlbyname("debug.crypto_timing", &otiming, &tlen,
1943 +				&timing, sizeof (timing)) < 0)
1944 +			perror("debug.crypto_timing");
1945 +	}
1946 +#endif
1947 +
1948 +	if (threads > 1) {
1949 +		for (i = 0; i < threads; i++)
1950 +			if (fork() == 0) {
1951 +				runtest(alg, count, size, cmd, &tvp[i]);
1952 +				exit(0);
1953 +			}
1954 +		while (waitpid(WAIT_MYPGRP, &status, 0) != -1)
1955 +			;
1956 +	} else
1957 +		runtest(alg, count, size, cmd, tvp);
1958 +
1959 +	t = 0;
1960 +	for (i = 0; i < threads; i++)
1961 +		t += (((double)tvp[i].tv_sec * 1000000 + tvp[i].tv_usec) / 1000000);
1962 +	if (t) {
1963 +		int nops = alg->ishash ? count : 2*count;
1964 +
1965 +#if 0
1966 +		t /= threads;
1967 +		printf("%6.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf bytes/sec, %7.1lf Mbit/sec\n",
1968 +		    t, nops, alg->name, size, (double)nops*size / t,
1969 +		    (double)nops*size / t * 8 / 1024 / 1024);
1970 +#else
1971 +		nops *= threads;
1972 +		printf("%8.3lf sec, %7d %6s crypts, %7d bytes, %8.0lf byte/sec, %7.1lf Mb/sec\n",
1973 +		    t, nops, alg->name, size, (double)nops*size / t,
1974 +		    (double)nops*size / t * 8 / 1024 / 1024);
1975 +#endif
1976 +	}
1977 +#ifdef __FreeBSD__
1978 +	if (profile) {
1979 +		struct cryptostats stats;
1980 +		size_t slen = sizeof (stats);
1981 +
1982 +		if (sysctlbyname("debug.crypto_timing", NULL, NULL,
1983 +				&otiming, sizeof (otiming)) < 0)
1984 +			perror("debug.crypto_timing");
1985 +		if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, 0) < 0)
1986 +			perror("kern.cryptostats");
1987 +		if (stats.cs_invoke.count) {
1988 +			printt("dispatch->invoke", &stats.cs_invoke);
1989 +			printt("invoke->done", &stats.cs_done);
1990 +			printt("done->cb", &stats.cs_cb);
1991 +			printt("cb->finis", &stats.cs_finis);
1992 +		}
1993 +	}
1994 +#endif
1995 +	if (munmap(region, threads * sizeof (struct timeval)) != 0)
1996 +		perror("munmap");
1997 +
1998 +	fflush(stdout);
1999 +}
2000 +
2001 +int
2002 +main(int argc, char **argv)
2003 +{
2004 +	struct alg *alg = NULL;
2005 +	int count = 1;
2006 +	int sizes[128], nsizes = 0;
2007 +	u_long cmd = CIOCGSESSION2;
2008 +	int testall = 0;
2009 +	int maxthreads = 1;
2010 +	int profile = 0;
2011 +	int i, ch;
2012 +
2013 +	srandom(time(0));
2014 +
2015 +	while ((ch = getopt(argc, argv, "cpzsva:bd:t:S:VKD")) != -1) {
2016 +		switch (ch) {
2017 +		case 'V': swap_iv = 1; break;
2018 +		case 'K': swap_key = 1; break;
2019 +		case 'D': swap_data = 1; break;
2020 +#ifdef CIOCGSSESSION
2021 +		case 's':
2022 +			cmd = CIOCGSSESSION;
2023 +			break;
2024 +#endif
2025 +		case 'v':
2026 +			verbose++;
2027 +			break;
2028 +		case 'a':
2029 +			alg = getalgbyname(optarg);
2030 +			if (alg == NULL) {
2031 +				if (streq(optarg, "rijndael"))
2032 +					alg = getalgbyname("aes");
2033 +				else
2034 +					usage(argv[0]);
2035 +			}
2036 +			break;
2037 +		case 'S':
2038 +			srandom(atoi(optarg));
2039 +			break;
2040 +		case 'd':
2041 +			crid = crlookup(optarg);
2042 +			break;
2043 +		case 't':
2044 +			maxthreads = atoi(optarg);
2045 +			break;
2046 +		case 'z':
2047 +			testall = 1;
2048 +			break;
2049 +		case 'p':
2050 +			profile = 1;
2051 +			break;
2052 +		case 'b':
2053 +			opflags |= COP_F_BATCH;
2054 +			break;
2055 +		case 'c':
2056 +			verify = 1;
2057 +			break;
2058 +		default:
2059 +			usage(argv[0]);
2060 +		}
2061 +	}
2062 +	argc -= optind, argv += optind;
2063 +	if (argc > 0)
2064 +		count = atoi(argv[0]);
2065 +	while (argc > 1) {
2066 +		int s = atoi(argv[1]);
2067 +		if (nsizes < N(sizes)) {
2068 +			sizes[nsizes++] = s;
2069 +		} else {
2070 +			printf("Too many sizes, ignoring %u\n", s);
2071 +		}
2072 +		argc--, argv++;
2073 +	}
2074 +	if (nsizes == 0) {
2075 +		if (alg)
2076 +			sizes[nsizes++] = alg->blocksize;
2077 +		else
2078 +			sizes[nsizes++] = 8;
2079 +		if (testall) {
2080 +			/*
2081 +			 * OCF is limited to CRYPTO_MAX_DATA_LEN, so make it 256 bytes less
2082 +			 * for safety sakes.
2083 +			 */
2084 +			while (sizes[nsizes-1] < (CRYPTO_MAX_DATA_LEN - 256)) {
2085 +				sizes[nsizes] = sizes[nsizes-1]<<1;
2086 +				if (sizes[nsizes] > CRYPTO_MAX_DATA_LEN)
2087 +					sizes[nsizes] -= 256;
2088 +				nsizes++;
2089 +			}
2090 +		}
2091 +	}
2092 +
2093 +	if (testall) {
2094 +		for (i = 0; i < N(algorithms); i++) {
2095 +			int j;
2096 +			alg = &algorithms[i];
2097 +			for (j = 0; j < nsizes; j++)
2098 +				runtests(alg, count, sizes[j], cmd, maxthreads, profile);
2099 +		}
2100 +	} else {
2101 +		if (alg == NULL)
2102 +			alg = getalgbycode(CRYPTO_3DES_CBC);
2103 +		for (i = 0; i < nsizes; i++)
2104 +			runtests(alg, count, sizes[i], cmd, maxthreads, profile);
2105 +	}
2106 +
2107 +	return (0);
2108 +}
2109 +
2110 +void
2111 +hexdump(char *p, int n)
2112 +{
2113 +	int i, off;
2114 +
2115 +	for (off = 0; n > 0; off += 16, n -= 16) {
2116 +		printf("%s%04x:", off == 0 ? "\n" : "", off);
2117 +		i = (n >= 16 ? 16 : n);
2118 +		do {
2119 +			printf(" %02x", *p++ & 0xff);
2120 +		} while (--i);
2121 +		printf("\n");
2122 +	}
2123 +}
2124 diff -Nur kamikaze_7.09.orig/package/cryptotest-bgp/src/Makefile kamikaze_7.09/package/cryptotest-bgp/src/Makefile
2125 --- kamikaze_7.09.orig/package/cryptotest-bgp/src/Makefile	1970-01-01 01:00:00.000000000 +0100
2126 +++ kamikaze_7.09/package/cryptotest-bgp/src/Makefile	2008-06-19 17:34:17.000000000 +0200
2127 @@ -0,0 +1,42 @@
2128 +#	$FreeBSD: src/tools/tools/crypto/Makefile,v 1.8 2004/09/07 18:35:00 sam Exp $
2129 +#
2130 +# Copyright (c) 2002, 2003	Sam Leffler, Errno Consulting
2131 +# All rights reserved.
2132 +#
2133 +# Redistribution and use in source and binary forms, with or without
2134 +# modification, are permitted provided that the following conditions
2135 +# are met:
2136 +# 1. Redistributions of source code must retain the above copyright
2137 +#    notice, this list of conditions and the following disclaimer.
2138 +# 2. Redistributions in binary form must reproduce the above copyright
2139 +#    notice, this list of conditions and the following disclaimer in the
2140 +#    documentation and/or other materials provided with the distribution.
2141 +#
2142 +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2143 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2144 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2145 +# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2146 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2147 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2148 +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2149 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2150 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2151 +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2152 +# SUCH DAMAGE.
2153 +#
2154 +
2155 +ALL=	cryptotest cryptokeytest
2156 +
2157 +all:	${ALL}
2158 +
2159 +# program to test asymmetric crypto functions
2160 +cryptokeytest: cryptokeytest.c
2161 +	$(CC) $(CFLAGS) $(LDFLAGS) -o cryptokeytest cryptokeytest.c -lcrypto $(LDLIBS)
2162 +
2163 +clean:
2164 +	rm -f *.o ${ALL} core a.out
2165 +
2166 +romfs:
2167 +	$(ROMFSINST) -e CONFIG_USER_CRYPTO_TOOLS_CRYPTOTEST /bin/cryptotest
2168 +	$(ROMFSINST) -e CONFIG_USER_CRYPTO_TOOLS_CRYPTOKEYTEST /bin/cryptokeytest
2169 +
2170 diff -Nur kamikaze_7.09.orig/package/cryptotest-bgp/src/README kamikaze_7.09/package/cryptotest-bgp/src/README
2171 --- kamikaze_7.09.orig/package/cryptotest-bgp/src/README	1970-01-01 01:00:00.000000000 +0100
2172 +++ kamikaze_7.09/package/cryptotest-bgp/src/README	2008-06-19 17:34:17.000000000 +0200
2173 @@ -0,0 +1,44 @@
2174 +$FreeBSD: src/tools/tools/crypto/README,v 1.1 2002/12/14 06:23:58 sam Exp $
2175 +
2176 +The cryptotest program repeatedly encrypts and decrypts a buffer
2177 +with the built-in iv and key, using hardware crypto.  At the end,
2178 +it computes the data rate achieved.  Operations are carried out by
2179 +making ioctl calls to /dev/crypto.
2180 +
2181 +For a test of how fast a crypto card is, use something like:
2182 +
2183 +	cryptotest -z 1024
2184 +
2185 +This will run a series of tests using the available crypto/cipher
2186 +algorithms over a variety of buffer sizes.  The 1024 says to do
2187 +1024 iterations.  Extra arguments can be used to specify one or
2188 +more buffer sizes to use in doing tests.
2189 +
2190 +A sample run is:
2191 +
2192 + 0.129 sec,    2048    des crypts,       8 bytes,   127120 byte/sec,     1.0 Mb/sec
2193 + 0.129 sec,    2048    des crypts,      16 bytes,   253915 byte/sec,     1.9 Mb/sec
2194 + 0.129 sec,    2048    des crypts,      32 bytes,   508942 byte/sec,     3.9 Mb/sec
2195 + 0.128 sec,    2048    des crypts,      64 bytes,  1020135 byte/sec,     7.8 Mb/sec
2196 + 0.134 sec,    2048    des crypts,     128 bytes,  1954869 byte/sec,    14.9 Mb/sec
2197 + 0.142 sec,    2048    des crypts,     256 bytes,  3698107 byte/sec,    28.2 Mb/sec
2198 + 0.190 sec,    2048    des crypts,    1024 bytes, 11037700 byte/sec,    84.2 Mb/sec
2199 + 0.264 sec,    2048    des crypts,    2048 bytes, 15891127 byte/sec,   121.2 Mb/sec
2200 + 0.403 sec,    2048    des crypts,    4096 bytes, 20828998 byte/sec,   158.9 Mb/sec
2201 + 0.687 sec,    2048    des crypts,    8192 bytes, 24426602 byte/sec,   186.4 Mb/sec
2202 + 0.129 sec,    2048   3des crypts,       8 bytes,   127321 byte/sec,     1.0 Mb/sec
2203 + 0.131 sec,    2048   3des crypts,      16 bytes,   249773 byte/sec,     1.9 Mb/sec
2204 + 0.128 sec,    2048   3des crypts,      32 bytes,   512304 byte/sec,     3.9 Mb/sec
2205 + 0.128 sec,    2048   3des crypts,      64 bytes,  1021685 byte/sec,     7.8 Mb/sec
2206 + 0.132 sec,    2048   3des crypts,     128 bytes,  1986511 byte/sec,    15.2 Mb/sec
2207 + 0.142 sec,    2048   3des crypts,     256 bytes,  3695005 byte/sec,    28.2 Mb/sec
2208 + 0.190 sec,    2048   3des crypts,    1024 bytes, 11024876 byte/sec,    84.1 Mb/sec
2209 + 0.264 sec,    2048   3des crypts,    2048 bytes, 15887997 byte/sec,   121.2 Mb/sec
2210 + 0.402 sec,    2048   3des crypts,    4096 bytes, 20850846 byte/sec,   159.1 Mb/sec
2211 + 0.689 sec,    2048   3des crypts,    8192 bytes, 24333532 byte/sec,   185.7 Mb/sec
2212 +
2213 +Expect ~400 Mb/s for a Broadcom 582x for 16K buffers on a reasonable
2214 +CPU.  Hifn 7811 parts top out at ~120 Mb/s.  Performance depends
2215 +heavily on memory and bus performance.
2216 +
2217 +This code originally came from openbsd; give them all the credit.
2218 diff -Nur kamikaze_7.09.orig/package/iptraf/Makefile kamikaze_7.09/package/iptraf/Makefile
2219 --- kamikaze_7.09.orig/package/iptraf/Makefile	1970-01-01 01:00:00.000000000 +0100
2220 +++ kamikaze_7.09/package/iptraf/Makefile	2008-06-19 17:34:17.000000000 +0200
2221 @@ -0,0 +1,60 @@
2222 +#
2223 +# Copyright (C) 2006 OpenWrt.org
2224 +#
2225 +# This is free software, licensed under the GNU General Public License v2.
2226 +# See /LICENSE for more information.
2227 +#
2228 +# $Id: Makefile 9349 2007-10-18 18:46:37Z blogic $
2229 +
2230 +include $(TOPDIR)/rules.mk
2231 +
2232 +PKG_NAME:=iptraf
2233 +PKG_VERSION:=3.0.0
2234 +PKG_RELEASE:=1
2235 +
2236 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
2237 +PKG_SOURCE_URL:=ftp://iptraf.seul.org/pub/iptraf/ \
2238 +	ftp://the.wiretapped.net/pub/security/network-monitoring/iptraf/
2239 +PKG_MD5SUM:=377371c28ee3c21a76f7024920649ea8
2240 +
2241 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
2242 +
2243 +include $(INCLUDE_DIR)/package.mk
2244 +
2245 +define Package/iptraf
2246 +  SECTION:=net
2247 +  CATEGORY:=Network
2248 +  DEPENDS:=+libncurses
2249 +  TITLE:=A console-based network monitoring program
2250 +  URL:=http://iptraf.seul.org/
2251 +endef
2252 +
2253 +define Package/iptraf/description
2254 +	IPTraf is a console-based network statistics utility for Linux. It gathers 
2255 +	a variety of figures such as TCP connection packet and byte counts, 
2256 +	interface statistics and activity indicators, TCP/UDP traffic breakdowns, 
2257 +	and LAN station packet and byte counts.
2258 +endef
2259 +
2260 +define Build/Compile	
2261 +	$(MAKE) -C $(PKG_BUILD_DIR)/src \
2262 +		$(TARGET_CONFIGURE_OPTS) \
2263 +		CFLAGS="$(TARGET_CFLAGS)" \
2264 +		DEBUG="" \
2265 +		INCLUDEDIR="-I../support -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
2266 +		LDOPTS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
2267 +		PLATFORM="-DPLATFORM=\\\"Linux/$(ARCH)\\\"" \
2268 +		TARGET="/usr/bin" \
2269 +		WORKDIR="/var/lib/iptraf" \
2270 +		all
2271 +endef
2272 +
2273 +define Package/iptraf/install	
2274 +	$(INSTALL_DIR) $(1)/usr/bin
2275 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/iptraf $(1)/usr/bin/
2276 +	$(INSTALL_DIR) $(1)/var/lib/iptraf/
2277 +	echo "$(PKG_VERSION)" > $(1)/var/lib/iptraf/version
2278 +	$(INSTALL_DIR) $(1)/var/log/iptraf $(1)/var/run/iptraf
2279 +endef
2280 +
2281 +$(eval $(call BuildPackage,iptraf))
2282 diff -Nur kamikaze_7.09.orig/package/iptraf/patches/001-cross_compile.patch kamikaze_7.09/package/iptraf/patches/001-cross_compile.patch
2283 --- kamikaze_7.09.orig/package/iptraf/patches/001-cross_compile.patch	1970-01-01 01:00:00.000000000 +0100
2284 +++ kamikaze_7.09/package/iptraf/patches/001-cross_compile.patch	2008-06-19 17:34:17.000000000 +0200
2285 @@ -0,0 +1,24 @@
2286 +diff -urN iptraf-3.0.0/support/Makefile iptraf-3.0.0.new/support/Makefile
2287 +--- iptraf-3.0.0/support/Makefile	2002-07-19 18:31:48.000000000 +0200
2288 ++++ iptraf-3.0.0.new/support/Makefile	2006-04-16 16:07:58.000000000 +0200
2289 +@@ -3,16 +3,14 @@
2290 + OBJS			= input.o menurt.o listbox.o winops.o labels.o \
2291 + 				msgboxes.o txbox.o
2292 + 
2293 +-all: libtextbox.a
2294 +-
2295 + libtextbox.a: $(OBJS)
2296 + 	rm -rf libtextbox.a
2297 +-	ar cq libtextbox.a $(OBJS)
2298 +-	ranlib libtextbox.a
2299 +-#	gcc -shared -o libtextbox.so $(OBJS)
2300 ++	$(AR) cq libtextbox.a $(OBJS)
2301 ++	$(RANLIB) libtextbox.a
2302 ++#	$(CC) -shared -o libtextbox.so $(OBJS)
2303 + 
2304 + %.o: %.c *.h
2305 +-	gcc -O2 -g -Wall -fPIC $(INCLUDEDIR) -c -o $*.o $<
2306 ++	$(CC) $(CFLAGS) -Wall -fPIC $(INCLUDEDIR) -c -o $*.o $<
2307 + 
2308 + clean:
2309 + 	rm -rf *.o *~ libtextbox.a libtextbox.so
2310 diff -Nur kamikaze_7.09.orig/package/iptraf/patches/002-ifaces.patch kamikaze_7.09/package/iptraf/patches/002-ifaces.patch
2311 --- kamikaze_7.09.orig/package/iptraf/patches/002-ifaces.patch	1970-01-01 01:00:00.000000000 +0100
2312 +++ kamikaze_7.09/package/iptraf/patches/002-ifaces.patch	2008-06-19 17:34:17.000000000 +0200
2313 @@ -0,0 +1,294 @@
2314 +diff -urN iptraf-3.0.0/src/dirs.h iptraf-3.0.0.new/src/dirs.h
2315 +--- iptraf-3.0.0/src/dirs.h	2005-09-13 08:42:54.000000000 +0200
2316 ++++ iptraf-3.0.0.new/src/dirs.h	2006-04-16 16:08:27.000000000 +0200
2317 +@@ -155,7 +155,6 @@
2318 +  */
2319 + 
2320 + #define ETHFILE		get_path(T_WORKDIR, "ethernet.desc")
2321 +-#define FDDIFILE	get_path(T_WORKDIR, "fddi.desc")
2322 + 
2323 + /*
2324 +  * The rvnamed program file
2325 +diff -urN iptraf-3.0.0/src/hostmon.c iptraf-3.0.0.new/src/hostmon.c
2326 +--- iptraf-3.0.0/src/hostmon.c	2005-09-13 08:42:54.000000000 +0200
2327 ++++ iptraf-3.0.0.new/src/hostmon.c	2006-04-16 16:29:27.000000000 +0200
2328 +@@ -30,7 +30,6 @@
2329 + #include <netinet/in.h>
2330 + #include <linux/if_packet.h>
2331 + #include <linux/if_ether.h>
2332 +-#include <linux/if_fddi.h>
2333 + #include <linux/if_tr.h>
2334 + #include <net/if_arp.h>
2335 + #include <stdlib.h>
2336 +@@ -293,8 +292,6 @@
2337 +             wprintw(table->tabwin, "Ethernet");
2338 +         else if (entry->un.desc.linktype == LINK_PLIP)
2339 +             wprintw(table->tabwin, "PLIP");
2340 +-        else if (entry->un.desc.linktype == LINK_FDDI)
2341 +-            wprintw(table->tabwin, "FDDI");
2342 + 
2343 +         wprintw(table->tabwin, " HW addr: %s", entry->un.desc.ascaddr);
2344 + 
2345 +@@ -722,7 +719,7 @@
2346 +     unsigned long long updtime_usec = 0;
2347 + 
2348 +     struct desclist elist;      /* Ethernet description list */
2349 +-    struct desclist flist;      /* FDDI description list */
2350 ++    struct desclist flist;	/* Other links description list */
2351 +     struct desclist *list = NULL;
2352 + 
2353 +     FILE *logfile = NULL;
2354 +@@ -786,7 +783,6 @@
2355 + 
2356 +     initethtab(&table, options->actmode);
2357 +     loaddesclist(&elist, LINK_ETHERNET, WITHETCETHERS);
2358 +-    loaddesclist(&flist, LINK_FDDI, WITHETCETHERS);
2359 + 
2360 +     if (logging) {
2361 +         if (strcmp(current_logfile, "") == 0) {
2362 +@@ -900,9 +896,7 @@
2363 +             if (pkt_result != PACKET_OK)
2364 +                 continue;
2365 + 
2366 +-            if ((linktype == LINK_ETHERNET) || (linktype == LINK_FDDI)
2367 +-                || (linktype == LINK_PLIP) || (linktype == LINK_TR) ||
2368 +-                (linktype == LINK_VLAN)) {
2369 ++            if ((linktype == LINK_ETHERNET) || (linktype == LINK_PLIP) || (linktype == LINK_TR) || (linktype == LINK_VLAN)) {
2370 + 
2371 +                 if (fromaddr.sll_protocol == htons(ETH_P_IP))
2372 +                     is_ip = 1;
2373 +@@ -920,12 +914,6 @@
2374 +                     memcpy(scratch_daddr, ((struct ethhdr *) buf)->h_dest,
2375 +                            ETH_ALEN);
2376 +                     list = &elist;
2377 +-                } else if (linktype == LINK_FDDI) {
2378 +-                    memcpy(scratch_saddr, ((struct fddihdr *) buf)->saddr,
2379 +-                           FDDI_K_ALEN);
2380 +-                    memcpy(scratch_daddr, ((struct fddihdr *) buf)->daddr,
2381 +-                           FDDI_K_ALEN);
2382 +-                    list = &flist;
2383 +                 } else if (linktype == LINK_TR) {
2384 +                     memcpy(scratch_saddr, ((struct trh_hdr *) buf)->saddr,
2385 +                            TR_ALEN);
2386 +diff -urN iptraf-3.0.0/src/ifaces.c iptraf-3.0.0.new/src/ifaces.c
2387 +--- iptraf-3.0.0/src/ifaces.c	2005-09-13 08:42:54.000000000 +0200
2388 ++++ iptraf-3.0.0.new/src/ifaces.c	2006-04-16 16:10:10.000000000 +0200
2389 +@@ -37,7 +37,7 @@
2390 + extern int daemonized;
2391 + 
2392 + char ifaces[][6] =
2393 +-    { "lo", "eth", "sl", "ppp", "ippp", "plip", "fddi", "isdn", "dvb",
2394 ++    { "lo", "eth", "sl", "ppp", "ippp", "plip", "isdn", "dvb",
2395 +     "pvc", "hdlc", "ipsec", "sbni", "tr", "wvlan", "wlan", "sm2", "sm3",
2396 +     "pent", "lec", "brg", "tun", "tap", "cipcb", "tunl", "vlan"
2397 + };
2398 +diff -urN iptraf-3.0.0/src/landesc.c iptraf-3.0.0.new/src/landesc.c
2399 +--- iptraf-3.0.0/src/landesc.c	2005-09-13 08:42:54.000000000 +0200
2400 ++++ iptraf-3.0.0.new/src/landesc.c	2006-04-16 16:10:29.000000000 +0200
2401 +@@ -83,8 +83,6 @@
2402 + 
2403 +     if (linktype == LINK_ETHERNET)
2404 +         fd = fopen(ETHFILE, "r");
2405 +-    else if (linktype == LINK_FDDI)
2406 +-        fd = fopen(FDDIFILE, "r");
2407 + 
2408 +     if (fd == NULL) {
2409 +         return;
2410 +@@ -205,8 +203,6 @@
2411 + 
2412 +     if (linktype == LINK_ETHERNET)
2413 +         fd = fopen(ETHFILE, "w");
2414 +-    else if (linktype == LINK_FDDI)
2415 +-        fd = fopen(FDDIFILE, "w");
2416 + 
2417 +     if (fd < 0) {
2418 +         etherr();
2419 +diff -urN iptraf-3.0.0/src/links.h iptraf-3.0.0.new/src/links.h
2420 +--- iptraf-3.0.0/src/links.h	2005-09-13 08:42:54.000000000 +0200
2421 ++++ iptraf-3.0.0.new/src/links.h	2006-04-16 16:10:39.000000000 +0200
2422 +@@ -6,7 +6,6 @@
2423 + #define LINK_ISDN_RAWIP		6
2424 + #define LINK_ISDN_CISCOHDLC	7
2425 + #define LINK_CISCOHDLC  7
2426 +-#define LINK_FDDI		8
2427 + #define LINK_FRAD		9
2428 + #define LINK_DLCI		10
2429 + #define LINK_TR			11
2430 +diff -urN iptraf-3.0.0/src/log.c iptraf-3.0.0.new/src/log.c
2431 +--- iptraf-3.0.0/src/log.c	2005-09-13 08:42:54.000000000 +0200
2432 ++++ iptraf-3.0.0.new/src/log.c	2006-04-16 16:10:53.000000000 +0200
2433 +@@ -491,8 +491,6 @@
2434 +                         ptmp->un.desc.ascaddr);
2435 +             else if (ptmp->un.desc.linktype == LINK_PLIP)
2436 +                 fprintf(fd, "\nPLIP address: %s", ptmp->un.desc.ascaddr);
2437 +-            else if (ptmp->un.desc.linktype == LINK_FDDI)
2438 +-                fprintf(fd, "\nFDDI address: %s", ptmp->un.desc.ascaddr);
2439 + 
2440 +             if (ptmp->un.desc.withdesc)
2441 +                 fprintf(fd, " (%s)", ptmp->un.desc.desc);
2442 +diff -urN iptraf-3.0.0/src/options.c iptraf-3.0.0.new/src/options.c
2443 +--- iptraf-3.0.0/src/options.c	2005-09-13 08:42:54.000000000 +0200
2444 ++++ iptraf-3.0.0.new/src/options.c	2006-04-16 16:23:52.000000000 +0200
2445 +@@ -68,8 +68,6 @@
2446 +     tx_additem(menu, NULL, NULL);
2447 +     tx_additem(menu, " ^E^thernet/PLIP host descriptions...",
2448 +                "Manages descriptions for Ethernet and PLIP addresses");
2449 +-    tx_additem(menu, " ^F^DDI/Token Ring host descriptions...",
2450 +-               "Manages descriptions for FDDI and FDDI addresses");
2451 +     tx_additem(menu, NULL, NULL);
2452 +     tx_additem(menu, " E^x^it configuration", "Returns to main menu");
2453 + }
2454 +@@ -371,9 +369,6 @@
2455 +         case 14:
2456 +             ethdescmgr(LINK_ETHERNET);
2457 +             break;
2458 +-        case 15:
2459 +-            ethdescmgr(LINK_FDDI);
2460 +-            break;
2461 +         }
2462 + 
2463 +         indicatesetting(row, options, statwin);
2464 +diff -urN iptraf-3.0.0/src/othptab.c iptraf-3.0.0.new/src/othptab.c
2465 +--- iptraf-3.0.0/src/othptab.c	2005-09-13 08:42:54.000000000 +0200
2466 ++++ iptraf-3.0.0.new/src/othptab.c	2006-04-16 16:24:21.000000000 +0200
2467 +@@ -19,7 +19,6 @@
2468 + #include <asm/types.h>
2469 + #include <linux/if_ether.h>
2470 + #include <linux/if_tr.h>
2471 +-#include <linux/if_fddi.h>
2472 + #include <winops.h>
2473 + #include "arphdr.h"
2474 + #include "options.h"
2475 +@@ -139,11 +138,6 @@
2476 +                         new_entry->smacaddr);
2477 +             convmacaddr(((struct ethhdr *) packet)->h_dest,
2478 +                         new_entry->dmacaddr);
2479 +-        } else if (linkproto == LINK_FDDI) {
2480 +-            convmacaddr(((struct fddihdr *) packet)->saddr,
2481 +-                        new_entry->smacaddr);
2482 +-            convmacaddr(((struct fddihdr *) packet)->daddr,
2483 +-                        new_entry->dmacaddr);
2484 +         } else if (linkproto == LINK_TR) {
2485 +             convmacaddr(((struct trh_hdr *) packet)->saddr,
2486 +                         new_entry->smacaddr);
2487 +@@ -373,8 +367,7 @@
2488 +         strcat(msgstring, scratchpad);
2489 + 
2490 +         if ((entry->linkproto == LINK_ETHERNET) ||
2491 +-            (entry->linkproto == LINK_PLIP) ||
2492 +-            (entry->linkproto == LINK_FDDI)) {
2493 ++            (entry->linkproto == LINK_PLIP)) {
2494 +             sprintf(scratchpad, " from %s to %s on %s",
2495 +                     entry->smacaddr, entry->dmacaddr, entry->iface);
2496 + 
2497 +diff -urN iptraf-3.0.0/src/packet.c iptraf-3.0.0.new/src/packet.c
2498 +--- iptraf-3.0.0/src/packet.c	2005-09-13 08:42:54.000000000 +0200
2499 ++++ iptraf-3.0.0.new/src/packet.c	2006-04-16 16:11:55.000000000 +0200
2500 +@@ -35,7 +35,6 @@
2501 + #include <sys/ioctl.h>
2502 + #include <linux/if_packet.h>
2503 + #include <linux/if_ether.h>
2504 +-#include <linux/if_fddi.h>
2505 + #include <linux/if_tr.h>
2506 + #include <linux/isdn.h>
2507 + #include <linux/sockios.h>
2508 +@@ -81,8 +80,6 @@
2509 +             result = LINK_ETHERNET;
2510 +         else if (strncmp(ifname, "plip", 4) == 0)
2511 +             result = LINK_PLIP;
2512 +-        else if (strncmp(ifname, "fddi", 4) == 0)       /* For some Ethernet- */
2513 +-            result = LINK_ETHERNET;     /* emulated FDDI ifaces */
2514 +         else if (strncmp(ifname, "dvb", 3) == 0)
2515 +             result = LINK_ETHERNET;
2516 +         else if (strncmp(ifname, "sbni", 4) == 0)
2517 +@@ -136,9 +133,6 @@
2518 +     case ARPHRD_PPP:
2519 +         result = LINK_PPP;
2520 +         break;
2521 +-    case ARPHRD_FDDI:
2522 +-        result = LINK_FDDI;
2523 +-        break;
2524 +     case ARPHRD_IEEE802:
2525 +     case ARPHRD_IEEE802_TR:
2526 +         result = LINK_TR;
2527 +@@ -194,19 +188,6 @@
2528 +         *packet = tpacket + 4;
2529 +         *readlen -= 4;
2530 +         break;
2531 +-    case LINK_FDDI:
2532 +-        *packet = tpacket + sizeof(struct fddihdr);
2533 +-        *readlen -= sizeof(struct fddihdr);
2534 +-
2535 +-        /*
2536 +-         * Move IP data into an aligned buffer.  96 bytes should be sufficient
2537 +-         * for IP and TCP headers with reasonable numbers of options and some
2538 +-         * data.
2539 +-         */
2540 +-
2541 +-        memmove(aligned_buf, *packet, min(SNAPSHOT_LEN, *readlen));
2542 +-        *packet = aligned_buf;
2543 +-        break;
2544 +     case LINK_TR:
2545 +         /*
2546 +          * Token Ring patch supplied by Tomas Dvorak 
2547 +diff -urN iptraf-3.0.0/src/promisc.c iptraf-3.0.0.new/src/promisc.c
2548 +--- iptraf-3.0.0/src/promisc.c	2005-09-13 08:42:54.000000000 +0200
2549 ++++ iptraf-3.0.0.new/src/promisc.c	2006-04-16 16:12:56.000000000 +0200
2550 +@@ -81,8 +81,8 @@
2551 +              */
2552 + 
2553 +             if ((strncmp(buf, "eth", 3) == 0) ||
2554 +-                (strncmp(buf, "fddi", 4) == 0) ||
2555 +                 (strncmp(buf, "tr", 2) == 0) ||
2556 ++		(strncmp(buf, "vlan", 4) == 0) ||
2557 +                 (strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
2558 +                 (strncmp(ptmp->params.ifname, "lec", 3) == 0) ||
2559 +                 (accept_unsupported_interfaces)) {
2560 +@@ -195,7 +195,7 @@
2561 + 
2562 +     while (ptmp != NULL) {
2563 +         if (((strncmp(ptmp->params.ifname, "eth", 3) == 0) ||
2564 +-             (strncmp(ptmp->params.ifname, "fddi", 4) == 0) ||
2565 ++             (strncmp(ptmp->params.ifname, "vlan", 4) == 0) ||
2566 +              (strncmp(ptmp->params.ifname, "tr", 2) == 0) ||
2567 +              (strncmp(ptmp->params.ifname, "wvlan", 4) == 0) ||
2568 +              (strncmp(ptmp->params.ifname, "lec", 3) == 0)) &&
2569 +diff -urN iptraf-3.0.0/src/rvnamed.h iptraf-3.0.0.new/src/rvnamed.h
2570 +--- iptraf-3.0.0/src/rvnamed.h	2005-09-13 08:42:54.000000000 +0200
2571 ++++ iptraf-3.0.0.new/src/rvnamed.h	2006-04-16 16:13:39.000000000 +0200
2572 +@@ -1,9 +1,9 @@
2573 + #include <netinet/in.h>
2574 + #include <arpa/inet.h>
2575 + 
2576 +-#define CHILDSOCKNAME "/dev/rvndcldcomsk"
2577 +-#define PARENTSOCKNAME "/dev/rvndpntcomsk"
2578 +-#define IPTSOCKNAME "/dev/rvndiptcomsk"
2579 ++#define CHILDSOCKNAME "/tmp/rvndcldcomsk"
2580 ++#define PARENTSOCKNAME "/tmp/rvndpntcomsk"
2581 ++#define IPTSOCKNAME "/tmp/rvndiptcomsk"
2582 + 
2583 + #define SOCKET_PREFIX	"isock"
2584 + 
2585 +diff -urN iptraf-3.0.0/src/tcptable.c iptraf-3.0.0.new/src/tcptable.c
2586 +--- iptraf-3.0.0/src/tcptable.c	2005-09-13 08:42:54.000000000 +0200
2587 ++++ iptraf-3.0.0.new/src/tcptable.c	2006-04-16 16:13:54.000000000 +0200
2588 +@@ -600,8 +600,6 @@
2589 + 
2590 +         if ((linkproto == LINK_ETHERNET) || (linkproto == LINK_PLIP)) {
2591 +             convmacaddr(((struct ethhdr *) packet)->h_source, newmacaddr);
2592 +-        } else if (linkproto == LINK_FDDI) {
2593 +-            convmacaddr(((struct fddihdr *) packet)->saddr, newmacaddr);
2594 +         } else if (linkproto == LINK_TR) {
2595 +             convmacaddr(((struct trh_hdr *) packet)->saddr, newmacaddr);
2596 +         }
2597 +diff -urN iptraf-3.0.0/src/tcptable.h iptraf-3.0.0.new/src/tcptable.h
2598 +--- iptraf-3.0.0/src/tcptable.h	2005-09-13 08:42:54.000000000 +0200
2599 ++++ iptraf-3.0.0.new/src/tcptable.h	2006-04-16 16:14:03.000000000 +0200
2600 +@@ -22,7 +22,6 @@
2601 + #include <asm/types.h>
2602 + #include <linux/if_packet.h>
2603 + #include <linux/if_ether.h>
2604 +-#include <linux/if_fddi.h>
2605 + #include <linux/if_tr.h>
2606 + #include <net/if.h>
2607 + #include <netinet/ip.h>
2608 diff -Nur kamikaze_7.09.orig/package/iptraf/patches/003-exit_menu.patch kamikaze_7.09/package/iptraf/patches/003-exit_menu.patch
2609 --- kamikaze_7.09.orig/package/iptraf/patches/003-exit_menu.patch	1970-01-01 01:00:00.000000000 +0100
2610 +++ kamikaze_7.09/package/iptraf/patches/003-exit_menu.patch	2008-06-19 17:34:17.000000000 +0200
2611 @@ -0,0 +1,12 @@
2612 +diff -urN iptraf-3.0.0/src/options.c iptraf-3.0.0.new/src/options.c
2613 +--- iptraf-3.0.0/src/options.c	2005-09-13 08:42:54.000000000 +0200
2614 ++++ iptraf-3.0.0.new/src/options.c	2007-03-23 13:31:37.000000000 +0100
2615 +@@ -377,7 +377,7 @@
2616 +         }
2617 + 
2618 +         indicatesetting(row, options, statwin);
2619 +-    } while (row != 17);
2620 ++    } while (row != 16);
2621 + 
2622 +     tx_destroymenu(&menu);
2623 +     del_panel(statpanel);
2624 diff -Nur kamikaze_7.09.orig/package/kernel/modules/other.mk kamikaze_7.09/package/kernel/modules/other.mk
2625 --- kamikaze_7.09.orig/package/kernel/modules/other.mk	2007-09-22 15:50:44.000000000 +0200
2626 +++ kamikaze_7.09/package/kernel/modules/other.mk	2008-06-19 17:34:17.000000000 +0200
2627 @@ -85,6 +85,64 @@
2628  endef
2629  $(eval $(call KernelPackage,scsi-core))
2630  
2631 +define KernelPackage/hw-rng
2632 +  SUBMENU:=$(EMENU)
2633 +  TITLE:=Geode Random Number Generator
2634 +  DEPENDS:=@LINUX_2_6
2635 +  KCONFIG:= \
2636 +	$(CONFIG_HW_RANDOM_GEODE) \
2637 +	$(CONFIG_HW_RANDOM_VIA)
2638 +  FILES:= \
2639 +	$(LINUX_DIR)/drivers/char/hw_random/geode-rng.$(LINUX_KMOD_SUFFIX) \
2640 +	$(LINUX_DIR)/drivers/char/hw_random/via-rng.$(LINUX_KMOD_SUFFIX)
2641 +  AUTOLOAD:=$(call AutoLoad,15,geode-rng via-rng)
2642 +endef
2643 +
2644 +$(eval $(call KernelPackage,hw-rng))
2645 +
2646 +
2647 +define KernelPackage/hw-crypto
2648 +  SUBMENU:=$(EMENU)
2649 +  TITLE:=Geode AES/Padlock Encryption Engine
2650 +  DEPENDS:=@LINUX_2_6
2651 +  KCONFIG:= \
2652 +	$(CONFIG_CRYPTO_HW) \
2653 +	$(CONFIG_CRYPTO_DEV_GEODE)
2654 +  FILES:= \
2655 +	$(LINUX_DIR)/drivers/crypto/geode-aes.$(LINUX_KMOD_SUFFIX) 
2656 +  AUTOLOAD:=$(call AutoLoad,15,geode-aes)
2657 +endef
2658 +
2659 +$(eval $(call KernelPackage,hw-crypto))
2660 +
2661 +
2662 +define KernelPackage/linux-ocf
2663 +  SUBMENU:=$(EMENU)
2664 +  TITLE:=Linux OCF (OpenBSD Crypto Framework) Modules
2665 +  DEPENDS:=@LINUX_2_6
2666 +  KCONFIG:= \
2667 +	$(CONFIG_OCF_OCF) \
2668 +	$(CONFIG_OCF_CRYPTODEV) \
2669 +	$(CONFIG_OCF_CRYPTOSOFT) \
2670 +	$(CONFIG_OCF_RANDOMHARVEST) \
2671 +	$(CONFIG_OCF_FIPS) \
2672 +	$(CONFIG_OCF_SAFE) \
2673 +	$(CONFIG_OCF_IXP4XX) \
2674 +	$(CONFIG_OCF_HIFN) \
2675 +	$(CONFIG_OCF_HIFNHIPP) \
2676 +	$(CONFIG_OCF_TALITOS) \
2677 +	$(CONFIG_OCF_OCFNULL) \
2678 +	$(CONFIG_OCF_BENCH)
2679 +  FILES:= \
2680 +	$(LINUX_DIR)/crypto/ocf/ocf.$(LINUX_KMOD_SUFFIX) \
2681 +	$(LINUX_DIR)/crypto/ocf/cryptosoft.$(LINUX_KMOD_SUFFIX) \
2682 +	$(LINUX_DIR)/crypto/ocf/cryptodev.$(LINUX_KMOD_SUFFIX)
2683 +  AUTOLOAD:=$(call AutoLoad,20,ocf cryptosoft cryptodev)
2684 +endef
2685 +
2686 +$(eval $(call KernelPackage,linux-ocf))
2687 +
2688 +
2689  define KernelPackage/lp
2690    TITLE:=Parallel port and line printer support
2691    KCONFIG:=$(CONFIG_PARPORT)
2692 @@ -297,6 +355,20 @@
2693  endef
2694  $(eval $(call KernelPackage,videodev))
2695  
2696 +
2697 +define KernelPackage/leds-alix
2698 +  TITLE:=PCengines ALIX LED support
2699 +  DESCRIPTION:=Kernel module for PCengines ALIX LEDs
2700 +  DEPENDS:=@LINUX_2_6_X86_Alix
2701 +  SUBMENU:=$(EMENU)
2702 +  KCONFIG:=$(CONFIG_LEDS_ALIX)
2703 +  FILES:=$(LINUX_DIR)/drivers/leds/leds-alix.$(LINUX_KMOD_SUFFIX)
2704 +  AUTOLOAD:=$(call AutoLoad,50,leds-alix)
2705 +endef
2706 +$(eval $(call KernelPackage,leds-alix))
2707 +
2708 +
2709 +
2710  define KernelPackage/leds-net48xx
2711    TITLE:=Soekris Net48xx LED support
2712    DESCRIPTION:=Kernel module for Soekris Net48xx LEDs
2713 Binärdateien kamikaze_7.09.orig/package/madwifi/ath_hal-20080528.tgz and kamikaze_7.09/package/madwifi/ath_hal-20080528.tgz sind verschieden.
2714 diff -Nur kamikaze_7.09.orig/package/madwifi/Config.in kamikaze_7.09/package/madwifi/Config.in
2715 --- kamikaze_7.09.orig/package/madwifi/Config.in	1970-01-01 01:00:00.000000000 +0100
2716 +++ kamikaze_7.09/package/madwifi/Config.in	2008-06-19 17:34:17.000000000 +0200
2717 @@ -0,0 +1,70 @@
2718 +# MadWifi configuration
2719 +
2720 +config MADWIFI_DEBUG
2721 +	bool "Enable compilation of debugging features"
2722 +	depends on EXPERIMENTAL && PACKAGE_kmod-madwifi
2723 +	default n
2724 +
2725 +choice
2726 +	prompt "Rate control algorithm selection"
2727 +	depends on PACKAGE_kmod-madwifi
2728 +	default MADWIFI_RCA_MINSTREL
2729 +	help
2730 +	  This option controls how MadWifi chooses its bitrate.
2731 +
2732 +config MADWIFI_RCA_MINSTREL
2733 +	bool "Use the Minstrel rate control algorithm"
2734 +	help
2735 +	  This code is takes a wandering minstrel approach. Wander around the
2736 +	  different rates, singing wherever you can. And then, look at the
2737 +	  performance, and make a choice. Note that the wandering minstrel will
2738 +	  always wander in directions where he/she feels he/she will get paid
2739 +	  the best for his/her work.
2740 +
2741 +config MADWIFI_RCA_ONOE
2742 +	bool "Use the Onoe rate control algorithm"
2743 +	help
2744 +	  Onoe is a credit based RCA where the value of the credit is determined
2745 +	  by the frequency of successful, erroneous and retransmissions
2746 +	  accumulated during a fixed invocation period of 1000 ms. If less than
2747 +	  10% of the packets need to be retransmitted at a particular rate, Onoe
2748 +	  keeps increasing its credit point till the threshold value of 10 is
2749 +	  reached. At this point, the current transmission rate is increased to
2750 +	  the next available higher rate and the process repeated with credit
2751 +	  score of zero. Similar logic holds for deducting the credit score and
2752 +	  moving to a lower bit-rate for failed packet
2753 +	  transmission/retransmission attempts. However, once a bit-rate has
2754 +	  been marked as failure in the previous attempt, Onoe will not attempt
2755 +	  to select that bit-rate until 10 seconds have elapsed since the last
2756 +	  attempt. Due to the manner in which it operates, Onoe is conservative
2757 +	  in rate selection and is less sensitive to individual packet failure.
2758 +
2759 +config MADWIFI_RCA_AMRR
2760 +	bool "Use the AMRR rate control algorithm"
2761 +	help
2762 +	  AMRR uses Binary Exponential Backoff (BEB) technique to adapt the
2763 +	  length (threshold) of the sampling period used to change the values of
2764 +	  bit-rate and transmission count parameters. It uses probe packets and
2765 +	  depending on their transmission status adaptively changes the threshold
2766 +	  value. The adaptation mechanism ensures fewer failed
2767 +	  transmission/retransmission and higher throughput by not switching to a
2768 +	  higher rate as specified by the backoff mechanism. In addition to this,
2769 +	  the AMRR employs heuristics to capture the short-term variations of the
2770 +	  channel by judiciously setting the rate and transmission count
2771 +	  parameters.
2772 +
2773 +config MADWIFI_RCA_SAMPLERATE
2774 +	bool "Use the SampleRate rate control algorithm"
2775 +	help
2776 +	  SampleRate decides on the transmission bit-rate based on the past
2777 +	  history of performance; it keeps a record of the number of successive
2778 +	  failures, the number of successful transmits and the total transmission
2779 +	  time along with the destination for that bit-rate. Stale samples are
2780 +	  removed based on a EWMA windowing mechanism. If in the sampling
2781 +	  process, no successful acknowledgment is received or the number of
2782 +	  packets sent is multiple of 10 on a specific link, it transmits the
2783 +	  packet with the highest rate which has not failed 4 successive times.
2784 +	  Other than that it transmits packets at the rate which has the lowest
2785 +	  average transmission time.
2786 +
2787 +endchoice
2788 diff -Nur kamikaze_7.09.orig/package/madwifi/files/lib/wifi/madwifi.sh kamikaze_7.09/package/madwifi/files/lib/wifi/madwifi.sh
2789 --- kamikaze_7.09.orig/package/madwifi/files/lib/wifi/madwifi.sh	2007-09-30 20:03:49.000000000 +0200
2790 +++ kamikaze_7.09/package/madwifi/files/lib/wifi/madwifi.sh	2008-06-19 17:34:17.000000000 +0200
2791 @@ -71,9 +71,12 @@
2792  )
2793  
2794  enable_atheros() {
2795 +	local device="$1"
2796  	config_get channel "$device" channel
2797  	config_get vifs "$device" vifs
2798 -	
2799 +
2800 +	[ auto = "$channel" ] && channel=0
2801 +
2802  	local first=1
2803  	for vif in $vifs; do
2804  		nosbeacon=
2805 @@ -113,8 +116,10 @@
2806  		config_get_bool hidden "$vif" hidden 0
2807  		iwpriv "$ifname" hide_ssid "$hidden"
2808  
2809 -		config_get_bool ff "$vif" ff 0
2810 -		iwpriv "$ifname" ff "$ff"
2811 +		config_get ff "$vif" ff
2812 +		if [ -n "$ff" ]; then
2813 +			iwpriv "$ifname" ff "$ff"
2814 +		fi
2815  
2816  		config_get wds "$vif" wds
2817  		case "$wds" in
2818 @@ -156,43 +161,88 @@
2819  		esac
2820  		config_get ssid "$vif" ssid
2821  
2822 -		[ "$mode" = "sta" ] && {
2823 -			config_get_bool bgscan "$vif" bgscan 1
2824 -			iwpriv "$ifname" bgscan "$bgscan"
2825 -		}
2826 +		config_get_bool bgscan "$vif" bgscan
2827 +		[ -n "$bgscan" ] && iwpriv "$ifname" bgscan "$bgscan"
2828  
2829 -		config_get_bool antdiv "$device" diversity 1
2830 -		sysctl -w dev."$device".diversity="$antdiv" >&-
2831 +		config_get_bool antdiv "$device" diversity
2832 +		[ -n "$antdiv" ] && sysctl -w dev."$device".diversity="$antdiv" >&-
2833  
2834  		config_get antrx "$device" rxantenna
2835 -		if [ -n "$antrx" ]; then
2836 -			sysctl -w dev."$device".rxantenna="$antrx" >&-
2837 -		fi
2838 +		[ -n "$antrx" ] && sysctl -w dev."$device".rxantenna="$antrx" >&-
2839  
2840  		config_get anttx "$device" txantenna
2841 -		if [ -n "$anttx" ]; then
2842 -			sysctl -w dev."$device".txantenna="$anttx" >&-
2843 -		fi
2844 +		[ -n "$anttx" ] && sysctl -w dev."$device".txantenna="$anttx" >&-
2845  
2846  		config_get distance "$device" distance
2847 -		if [ -n "$distance" ]; then
2848 -			athctrl -i "$device" -d "$distance" >&-
2849 -		fi
2850 +		[ -n "$distance" ] && athctrl -i "$device" -d "$distance" >&-
2851  
2852  		config_get txpwr "$vif" txpower
2853 -		if [ -n "$txpwr" ]; then
2854 -			iwconfig "$ifname" txpower "${txpwr%%.*}"
2855 -		fi
2856 +		[ -n "$txpwr" ] && iwconfig "$ifname" txpower "${txpwr%%.*}"
2857 +
2858 +		config_get rate "$vif" rate
2859 +		[ -n "$rate" ] && iwconfig "$ifname" rate "${rate%%.*}"
2860 +
2861 +		config_get mcast_rate "$vif" mcast_rate
2862 +		[ -n "$mcast_rate" ] && iwpriv "$ifname" mcast_rate "${mcast_rate%%.*}"
2863  
2864  		config_get frag "$vif" frag
2865 -		if [ -n "$frag" ]; then
2866 -			iwconfig "$ifname" frag "${frag%%.*}"
2867 -		fi
2868 +		[ -n "$frag" ] && iwconfig "$ifname" frag "${frag%%.*}"
2869  
2870  		config_get rts "$vif" rts
2871 -		if [ -n "$rts" ]; then
2872 -			iwconfig "$ifname" rts "${rts%%.*}"
2873 -		fi
2874 +		[ -n "$rts" ] && iwconfig "$ifname" rts "${rts%%.*}"
2875 +
2876 +		config_get_bool doth "$vif" 80211h
2877 +		[ -n "$doth" ] && iwpriv "$ifname" doth "$doth"
2878 +
2879 +		config_get_bool comp "$vif" compression
2880 +		[ -n "$comp" ] && iwpriv "$ifname" compression "$comp"
2881 +
2882 +		config_get_bool minrate "$vif" minrate
2883 +		[ -n "$minrate" ] && iwpriv "$ifname" minrate "$minrate"
2884 +
2885 +		config_get_bool maxrate "$vif" maxrate
2886 +		[ -n "$maxrate" ] && iwpriv "$ifname" maxrate "$maxrate"
2887 +
2888 +		config_get_bool burst "$vif" bursting
2889 +		[ -n "$burst" ] && iwpriv "$ifname" burst "$burst"
2890 +
2891 +		config_get_bool wmm "$vif" wmm
2892 +		[ -n "$wmm" ] && iwpriv "$ifname" wmm "$wmm"
2893 +
2894 +		config_get_bool xr "$vif" xr
2895 +		[ -n "$xr" ] && iwpriv "$ifname" xr "$xr"
2896 +
2897 +		config_get_bool ar "$vif" ar
2898 +		[ -n "$ar" ] && iwpriv "$ifname" ar "$ar"
2899 +
2900 +		config_get_bool turbo "$vif" turbo
2901 +		[ -n "$turbo" ] && iwpriv "$ifname" turbo "$turbo"
2902 +
2903 +		config_get_bool doth "$vif" doth 0
2904 +		[ -n "$doth" ] && iwpriv "$ifname" doth "$doth"
2905 +
2906 +		config_get maclist "$vif" maclist
2907 +		[ -n "$maclist" ] && {
2908 +			# flush MAC list
2909 +			iwpriv "$ifname" maccmd 3
2910 +			for mac in $maclist; do
2911 +				iwpriv "$ifname" addmac "$mac"
2912 +			done
2913 +		}
2914 +
2915 +		config_get macpolicy "$vif" macpolicy
2916 +		case "$macpolicy" in
2917 +			allow)
2918 +				iwpriv "$ifname" maccmd 1
2919 +			;;
2920 +			deny)
2921 +				iwpriv "$ifname" maccmd 2
2922 +			;;
2923 +			*)
2924 +				# default deny policy if mac list exists
2925 +				[ -n "$maclist" ] && iwpriv "$ifname" maccmd 2
2926 +			;;
2927 +		esac
2928  
2929  		ifconfig "$ifname" up
2930  		iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null 
2931 @@ -222,22 +272,34 @@
2932  				fi
2933  			;;
2934  			wds|sta)
2935 -				case "$enc" in 
2936 +				config_get_bool usepassphrase "$vif" passphrase 1
2937 +				case "$enc" in
2938  					PSK|psk|PSK2|psk2)
2939  						case "$enc" in
2940  							PSK|psk)
2941 -								proto='proto=WPA';;
2942 +								proto='proto=WPA'
2943 +								if [ "$usepassphrase" = "1" ]; then
2944 +									passphrase="psk=\"${key}\""
2945 +								else
2946 +									passphrase="psk=${key}"
2947 +								fi
2948 +								;;
2949  							PSK2|psk2)
2950 -								proto='proto=RSN';;
2951 +								proto='proto=RSN'
2952 +                                                                if [ "$usepassphrase" = "1" ]; then
2953 +                                                                        passphrase="psk=\"${key}\""
2954 +                                                                else
2955 +                                                                        passphrase="psk=${key}"
2956 +                                                                fi
2957 +								;;
2958  						esac
2959  						cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
2960 -ctrl_interface=/var/run/wpa_supplicant
2961  network={
2962  	scan_ssid=1
2963  	ssid="$ssid"
2964  	key_mgmt=WPA-PSK
2965  	$proto
2966 -	psk="$key"
2967 +	$passphrase
2968  }
2969  EOF
2970  					;;
2971 @@ -262,7 +324,7 @@
2972  		cat <<EOF
2973  config wifi-device  $dev
2974  	option type     atheros
2975 -	option channel  5
2976 +	option channel  auto
2977  
2978  	# REMOVE THIS LINE TO ENABLE WIFI:
2979  	option disabled 1
2980 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/include/compat.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/include/compat.h
2981 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/include/compat.h	1970-01-01 01:00:00.000000000 +0100
2982 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/include/compat.h	2008-06-19 17:34:17.000000000 +0200
2983 @@ -0,0 +1,194 @@
2984 +/*-
2985 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
2986 + * All rights reserved.
2987 + *
2988 + * Redistribution and use in source and binary forms, with or without
2989 + * modification, are permitted provided that the following conditions
2990 + * are met:
2991 + * 1. Redistributions of source code must retain the above copyright
2992 + *    notice, this list of conditions and the following disclaimer,
2993 + *    without modification.
2994 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
2995 + *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
2996 + *    redistribution must be conditioned upon including a substantially
2997 + *    similar Disclaimer requirement for further binary redistribution.
2998 + * 3. Neither the names of the above-listed copyright holders nor the names
2999 + *    of any contributors may be used to endorse or promote products derived
3000 + *    from this software without specific prior written permission.
3001 + *
3002 + * Alternatively, this software may be distributed under the terms of the
3003 + * GNU General Public License ("GPL") version 2 as published by the Free
3004 + * Software Foundation.
3005 + *
3006 + * NO WARRANTY
3007 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3008 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3009 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
3010 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
3011 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
3012 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3013 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3014 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
3015 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3016 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3017 + * THE POSSIBILITY OF SUCH DAMAGES.
3018 + *
3019 + * $Id: compat.h 3310 2008-01-30 20:23:49Z mentor $
3020 + */
3021 +#ifndef _ATH_COMPAT_H_
3022 +#define _ATH_COMPAT_H_
3023 +
3024 +/* Compatibility with older Linux kernels */
3025 +#ifdef __KERNEL__
3026 +#include <linux/types.h>
3027 +#include <linux/time.h>
3028 +#include <linux/netdevice.h>
3029 +#endif
3030 +
3031 +#if !defined(__KERNEL__) || !defined (__bitwise)
3032 +#define __le16 u_int16_t
3033 +#define __le32 u_int32_t
3034 +#define __le64 u_int64_t
3035 +#define __be16 u_int16_t
3036 +#define __be32 u_int32_t
3037 +#define __be64 u_int64_t
3038 +#define __force
3039 +#endif
3040 +
3041 +#ifndef container_of
3042 +#define container_of(ptr, type, member) ({				\
3043 +	    const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
3044 +	    (type *)( (char *)__mptr - offsetof(type,member) );})
3045 +#endif
3046 +
3047 +#ifndef list_for_each_entry_reverse
3048 +#define list_for_each_entry_reverse(pos, head, member)			\
3049 +	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
3050 +	     prefetch(pos->member.prev), &pos->member != (head); 	\
3051 +	     pos = list_entry(pos->member.prev, typeof(*pos), member))
3052 +#endif
3053 +
3054 +#ifndef NETDEV_TX_OK
3055 +#define NETDEV_TX_OK    0
3056 +#define NETDEV_TX_BUSY  1
3057 +#endif
3058 +
3059 +/*
3060 + * BSD/Linux compatibility shims.  These are used mainly to
3061 + * minimize differences when importing necesary BSD code.
3062 + */
3063 +#define	NBBY	8			/* number of bits/byte */
3064 +
3065 +/* roundup() appears in Linux 2.6.18 */
3066 +#include <linux/kernel.h>
3067 +#ifndef roundup
3068 +#define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))  /* to any y */
3069 +#endif
3070 +
3071 +#define	howmany(x, y)	(((x)+((y)-1))/(y))
3072 +
3073 +/* Bit map related macros. */
3074 +#define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
3075 +#define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
3076 +#define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
3077 +#define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
3078 +
3079 +#ifndef __packed
3080 +#define	__packed	__attribute__((__packed__))
3081 +#endif
3082 +
3083 +#define	__offsetof(t,m)	offsetof(t,m)
3084 +
3085 +#ifndef ALIGNED_POINTER
3086 +/*
3087 + * ALIGNED_POINTER is a boolean macro that checks whether an address
3088 + * is valid to fetch data elements of type t from on this architecture.
3089 + * This does not reflect the optimal alignment, just the possibility
3090 + * (within reasonable limits). 
3091 + *
3092 + */
3093 +#define ALIGNED_POINTER(p,t)	1
3094 +#endif
3095 +
3096 +#ifdef __KERNEL__
3097 +#define	KASSERT(exp, msg) do {			\
3098 +	if (unlikely(!(exp))) {			\
3099 +		printk msg;			\
3100 +		BUG();				\
3101 +	}					\
3102 +} while (0)
3103 +#endif /* __KERNEL__ */
3104 +
3105 +/*
3106 + * NetBSD/FreeBSD defines for file version.
3107 + */
3108 +#define	__FBSDID(_s)
3109 +#define	__KERNEL_RCSID(_n,_s)
3110 +
3111 +/*
3112 + * Fixes for Linux API changes
3113 + */
3114 +#ifdef __KERNEL__
3115 +
3116 +#include <linux/version.h>
3117 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
3118 +#define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t, 1)
3119 +#else
3120 +#define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t)
3121 +#endif
3122 +
3123 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
3124 +#define __user
3125 +#define __kernel
3126 +#define __iomem
3127 +#endif
3128 +
3129 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
3130 +typedef int gfp_t;
3131 +#endif
3132 +
3133 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
3134 +static inline int timeval_compare(struct timeval *lhs, struct timeval *rhs)
3135 +{
3136 +	if (lhs->tv_sec < rhs->tv_sec)
3137 +		return -1;
3138 +	if (lhs->tv_sec > rhs->tv_sec)
3139 +		return 1;
3140 +	return lhs->tv_usec - rhs->tv_usec;
3141 +}
3142 +#endif
3143 +
3144 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
3145 +#define IRQF_SHARED SA_SHIRQ
3146 +#endif
3147 +
3148 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
3149 +#define skb_end_pointer(_skb) ((_skb)->end)
3150 +#define skb_tail_pointer(_skb) ((_skb)->tail)
3151 +#define skb_set_network_header(_skb, _offset) \
3152 +	do { (_skb)->nh.raw = (_skb)->data + (_offset); } while(0)
3153 +#define skb_reset_network_header(_skb) \
3154 +	do { (_skb)->nh.raw = (_skb)->data; } while(0)
3155 +#define skb_mac_header(_skb) ((_skb)->mac.raw)
3156 +#define skb_reset_mac_header(_skb) \
3157 +	do { (_skb)->mac.raw = (_skb)->data; } while(0)
3158 +#endif
3159 +
3160 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
3161 +#define CTL_AUTO -2
3162 +#define DEV_ATH 9
3163 +#else
3164 +#define CTL_AUTO CTL_UNNUMBERED
3165 +#define DEV_ATH CTL_UNNUMBERED
3166 +#endif
3167 +
3168 +/* __skb_append got a third parameter in 2.6.14 */
3169 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
3170 +#define __skb_queue_after(_list, _old, _new)	__skb_append(_old, _new)
3171 +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
3172 +#define __skb_queue_after(_list, _old, _new)	__skb_append(_old, _new, _list)
3173 +#endif
3174 +
3175 +#endif /* __KERNEL__ */
3176 +
3177 +#endif /* _ATH_COMPAT_H_ */
3178 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/include/sys/queue.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/include/sys/queue.h
3179 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/include/sys/queue.h	1970-01-01 01:00:00.000000000 +0100
3180 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/include/sys/queue.h	2008-06-19 17:34:17.000000000 +0200
3181 @@ -0,0 +1,560 @@
3182 +/*
3183 + * Copyright (c) 1991, 1993
3184 + *	The Regents of the University of California.  All rights reserved.
3185 + *
3186 + * Redistribution and use in source and binary forms, with or without
3187 + * modification, are permitted provided that the following conditions
3188 + * are met:
3189 + * 1. Redistributions of source code must retain the above copyright
3190 + *    notice, this list of conditions and the following disclaimer.
3191 + * 2. Redistributions in binary form must reproduce the above copyright
3192 + *    notice, this list of conditions and the following disclaimer in the
3193 + *    documentation and/or other materials provided with the distribution.
3194 + * 4. Neither the name of the University nor the names of its contributors
3195 + *    may be used to endorse or promote products derived from this software
3196 + *    without specific prior written permission.
3197 + *
3198 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3199 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3200 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3201 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3202 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3203 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3204 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3205 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3206 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3207 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3208 + * SUCH DAMAGE.
3209 + *
3210 + * $Id: queue.h 2392 2007-05-29 21:55:25Z mtaylor $
3211 + */
3212 +
3213 +#ifndef _SYS_QUEUE_H_
3214 +#define	_SYS_QUEUE_H_
3215 +
3216 +/*
3217 + * This file defines four types of data structures: singly-linked lists,
3218 + * singly-linked tail queues, lists and tail queues.
3219 + *
3220 + * A singly-linked list is headed by a single forward pointer. The elements
3221 + * are singly linked for minimum space and pointer manipulation overhead at
3222 + * the expense of O(n) removal for arbitrary elements. New elements can be
3223 + * added to the list after an existing element or at the head of the list.
3224 + * Elements being removed from the head of the list should use the explicit
3225 + * macro for this purpose for optimum efficiency. A singly-linked list may
3226 + * only be traversed in the forward direction.  Singly-linked lists are ideal
3227 + * for applications with large datasets and few or no removals or for
3228 + * implementing a LIFO queue.
3229 + *
3230 + * A singly-linked tail queue is headed by a pair of pointers, one to the
3231 + * head of the list and the other to the tail of the list. The elements are
3232 + * singly linked for minimum space and pointer manipulation overhead at the
3233 + * expense of O(n) removal for arbitrary elements. New elements can be added
3234 + * to the list after an existing element, at the head of the list, or at the
3235 + * end of the list. Elements being removed from the head of the tail queue
3236 + * should use the explicit macro for this purpose for optimum efficiency.
3237 + * A singly-linked tail queue may only be traversed in the forward direction.
3238 + * Singly-linked tail queues are ideal for applications with large datasets
3239 + * and few or no removals or for implementing a FIFO queue.
3240 + *
3241 + * A list is headed by a single forward pointer (or an array of forward
3242 + * pointers for a hash table header). The elements are doubly linked
3243 + * so that an arbitrary element can be removed without a need to
3244 + * traverse the list. New elements can be added to the list before
3245 + * or after an existing element or at the head of the list. A list
3246 + * may only be traversed in the forward direction.
3247 + *
3248 + * A tail queue is headed by a pair of pointers, one to the head of the
3249 + * list and the other to the tail of the list. The elements are doubly
3250 + * linked so that an arbitrary element can be removed without a need to
3251 + * traverse the list. New elements can be added to the list before or
3252 + * after an existing element, at the head of the list, or at the end of
3253 + * the list. A tail queue may be traversed in either direction.
3254 + *
3255 + * For details on the use of these macros, see the queue(3) manual page.
3256 + *
3257 + *
3258 + *				SLIST	LIST	STAILQ	TAILQ
3259 + * _HEAD			+	+	+	+
3260 + * _HEAD_INITIALIZER		+	+	+	+
3261 + * _ENTRY			+	+	+	+
3262 + * _INIT			+	+	+	+
3263 + * _EMPTY			+	+	+	+
3264 + * _FIRST			+	+	+	+
3265 + * _NEXT			+	+	+	+
3266 + * _PREV			-	-	-	+
3267 + * _LAST			-	-	+	+
3268 + * _FOREACH			+	+	+	+
3269 + * _FOREACH_SAFE		+	+	+	+
3270 + * _FOREACH_REVERSE		-	-	-	+
3271 + * _FOREACH_REVERSE_SAFE	-	-	-	+
3272 + * _INSERT_HEAD			+	+	+	+
3273 + * _INSERT_BEFORE		-	+	-	+
3274 + * _INSERT_AFTER		+	+	+	+
3275 + * _INSERT_TAIL			-	-	+	+
3276 + * _CONCAT			-	-	+	+
3277 + * _REMOVE_HEAD			+	-	+	-
3278 + * _REMOVE			+	+	+	+
3279 + *
3280 + */
3281 +#define	QUEUE_MACRO_DEBUG 0
3282 +#if QUEUE_MACRO_DEBUG
3283 +/* Store the last 2 places the queue element or head was altered */
3284 +struct qm_trace {
3285 +	char *lastfile;
3286 +	int lastline;
3287 +	char *prevfile;
3288 +	int prevline;
3289 +};
3290 +
3291 +#define	TRACEBUF	struct qm_trace trace;
3292 +#define	TRASHIT(x)	do {(x) = (void *)-1;} while (0)
3293 +
3294 +#define	QMD_TRACE_HEAD(head) do {					\
3295 +	(head)->trace.prevline = (head)->trace.lastline;		\
3296 +	(head)->trace.prevfile = (head)->trace.lastfile;		\
3297 +	(head)->trace.lastline = __LINE__;				\
3298 +	(head)->trace.lastfile = __FILE__;				\
3299 +} while (0)
3300 +
3301 +#define	QMD_TRACE_ELEM(elem) do {					\
3302 +	(elem)->trace.prevline = (elem)->trace.lastline;		\
3303 +	(elem)->trace.prevfile = (elem)->trace.lastfile;		\
3304 +	(elem)->trace.lastline = __LINE__;				\
3305 +	(elem)->trace.lastfile = __FILE__;				\
3306 +} while (0)
3307 +
3308 +#else
3309 +#define	QMD_TRACE_ELEM(elem)
3310 +#define	QMD_TRACE_HEAD(head)
3311 +#define	TRACEBUF
3312 +#define	TRASHIT(x)
3313 +#endif	/* QUEUE_MACRO_DEBUG */
3314 +
3315 +/*
3316 + * Singly-linked List declarations.
3317 + */
3318 +#define	SLIST_HEAD(name, type)						\
3319 +struct name {								\
3320 +	struct type *slh_first;	/* first element */			\
3321 +}
3322 +
3323 +#define	SLIST_HEAD_INITIALIZER(head)					\
3324 +	{ NULL }
3325 +
3326 +#define	SLIST_ENTRY(type)						\
3327 +struct {								\
3328 +	struct type *sle_next;	/* next element */			\
3329 +}
3330 +
3331 +/*
3332 + * Singly-linked List functions.
3333 + */
3334 +#define	SLIST_EMPTY(head)	((head)->slh_first == NULL)
3335 +
3336 +#define	SLIST_FIRST(head)	((head)->slh_first)
3337 +
3338 +#define	SLIST_FOREACH(var, head, field)					\
3339 +	for ((var) = SLIST_FIRST((head));				\
3340 +	    (var);							\
3341 +	    (var) = SLIST_NEXT((var), field))
3342 +
3343 +#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\
3344 +	for ((var) = SLIST_FIRST((head));				\
3345 +	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
3346 +	    (var) = (tvar))
3347 +
3348 +#define	SLIST_FOREACH_PREVPTR(var, varp, head, field)			\
3349 +	for ((varp) = &SLIST_FIRST((head));				\
3350 +	    ((var) = *(varp)) != NULL;					\
3351 +	    (varp) = &SLIST_NEXT((var), field))
3352 +
3353 +#define	SLIST_INIT(head) do {						\
3354 +	SLIST_FIRST((head)) = NULL;					\
3355 +} while (0)
3356 +
3357 +#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
3358 +	SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field);	\
3359 +	SLIST_NEXT((slistelm), field) = (elm);				\
3360 +} while (0)
3361 +
3362 +#define	SLIST_INSERT_HEAD(head, elm, field) do {			\
3363 +	SLIST_NEXT((elm), field) = SLIST_FIRST((head));			\
3364 +	SLIST_FIRST((head)) = (elm);					\
3365 +} while (0)
3366 +
3367 +#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
3368 +
3369 +#define	SLIST_REMOVE(head, elm, type, field) do {			\
3370 +	if (SLIST_FIRST((head)) == (elm)) {				\
3371 +		SLIST_REMOVE_HEAD((head), field);			\
3372 +	}								\
3373 +	else {								\
3374 +		struct type *curelm = SLIST_FIRST((head));		\
3375 +		while (SLIST_NEXT(curelm, field) != (elm))		\
3376 +			curelm = SLIST_NEXT(curelm, field);		\
3377 +		SLIST_NEXT(curelm, field) =				\
3378 +		    SLIST_NEXT(SLIST_NEXT(curelm, field), field);	\
3379 +	}								\
3380 +} while (0)
3381 +
3382 +#define	SLIST_REMOVE_HEAD(head, field) do {				\
3383 +	SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field);	\
3384 +} while (0)
3385 +
3386 +/*
3387 + * Singly-linked Tail queue declarations.
3388 + */
3389 +#define	STAILQ_HEAD(name, type)						\
3390 +struct name {								\
3391 +	struct type *stqh_first;/* first element */			\
3392 +	struct type **stqh_last;/* addr of last next element */		\
3393 +}
3394 +
3395 +#define	STAILQ_HEAD_INITIALIZER(head)					\
3396 +	{ NULL, &(head).stqh_first }
3397 +
3398 +#define	STAILQ_ENTRY(type)						\
3399 +struct {								\
3400 +	struct type *stqe_next;	/* next element */			\
3401 +}
3402 +
3403 +/*
3404 + * Singly-linked Tail queue functions.
3405 + */
3406 +#define	STAILQ_CONCAT(head1, head2) do {				\
3407 +	if (!STAILQ_EMPTY((head2))) {					\
3408 +		*(head1)->stqh_last = (head2)->stqh_first;		\
3409 +		(head1)->stqh_last = (head2)->stqh_last;		\
3410 +		STAILQ_INIT((head2));					\
3411 +	}								\
3412 +} while (0)
3413 +
3414 +#define	STAILQ_EMPTY(head)	((head)->stqh_first == NULL)
3415 +
3416 +#define	STAILQ_FIRST(head)	((head)->stqh_first)
3417 +
3418 +#define	STAILQ_FOREACH(var, head, field)				\
3419 +	for ((var) = STAILQ_FIRST((head));				\
3420 +	   (var);							\
3421 +	   (var) = STAILQ_NEXT((var), field))
3422 +
3423 +
3424 +#define	STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
3425 +	for ((var) = STAILQ_FIRST((head));				\
3426 +	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
3427 +	    (var) = (tvar))
3428 +
3429 +#define	STAILQ_INIT(head) do {						\
3430 +	STAILQ_FIRST((head)) = NULL;					\
3431 +	(head)->stqh_last = &STAILQ_FIRST((head));			\
3432 +} while (0)
3433 +
3434 +#define	STAILQ_INSERT_AFTER(head, tqelm, elm, field) do {		\
3435 +	if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
3436 +		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
3437 +	STAILQ_NEXT((tqelm), field) = (elm);				\
3438 +} while (0)
3439 +
3440 +#define	STAILQ_INSERT_HEAD(head, elm, field) do {			\
3441 +	if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL)	\
3442 +		(head)->stqh_last = &STAILQ_NEXT((elm), field);		\
3443 +	STAILQ_FIRST((head)) = (elm);					\
3444 +} while (0)
3445 +
3446 +#define	STAILQ_INSERT_TAIL(head, elm, field) do {			\
3447 +	STAILQ_NEXT((elm), field) = NULL;				\
3448 +	*(head)->stqh_last = (elm);					\
3449 +	(head)->stqh_last = &STAILQ_NEXT((elm), field);			\
3450 +} while (0)
3451 +
3452 +#define	STAILQ_LAST(head, type, field)					\
3453 +	(STAILQ_EMPTY((head)) ?						\
3454 +		NULL :							\
3455 +	        ((struct type *)					\
3456 +		((char *)((head)->stqh_last) - __offsetof(struct type, field))))
3457 +
3458 +#define	STAILQ_NEXT(elm, field)	((elm)->field.stqe_next)
3459 +
3460 +#define	STAILQ_REMOVE(head, elm, type, field) do {			\
3461 +	if (STAILQ_FIRST((head)) == (elm)) {				\
3462 +		STAILQ_REMOVE_HEAD((head), field);			\
3463 +	}								\
3464 +	else {								\
3465 +		struct type *curelm = STAILQ_FIRST((head));		\
3466 +		while (STAILQ_NEXT(curelm, field) != (elm))		\
3467 +			curelm = STAILQ_NEXT(curelm, field);		\
3468 +		if ((STAILQ_NEXT(curelm, field) =			\
3469 +		     STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
3470 +			(head)->stqh_last = &STAILQ_NEXT((curelm), field);\
3471 +	}								\
3472 +} while (0)
3473 +
3474 +
3475 +#define	STAILQ_REMOVE_AFTER(head, elm, field) do {			\
3476 +	if (STAILQ_NEXT(elm, field)) {		\
3477 +		if ((STAILQ_NEXT(elm, field) =			\
3478 +	 	    STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)\
3479 +			(head)->stqh_last = &STAILQ_NEXT((elm), field); \
3480 +	}								\
3481 +} while (0)
3482 +
3483 +
3484 +#define	STAILQ_REMOVE_HEAD(head, field) do {				\
3485 +	if ((STAILQ_FIRST((head)) =					\
3486 +	     STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL)		\
3487 +		(head)->stqh_last = &STAILQ_FIRST((head));		\
3488 +} while (0)
3489 +
3490 +#define	STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do {			\
3491 +	if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL)	\
3492 +		(head)->stqh_last = &STAILQ_FIRST((head));		\
3493 +} while (0)
3494 +
3495 +/*
3496 + * List declarations.
3497 + */
3498 +#define	ATH_LIST_HEAD(name, type)					\
3499 +struct name {								\
3500 +	struct type *lh_first;	/* first element */			\
3501 +}
3502 +
3503 +#define	LIST_HEAD_INITIALIZER(head)					\
3504 +	{ NULL }
3505 +
3506 +#define	LIST_ENTRY(type)						\
3507 +struct {								\
3508 +	struct type *le_next;	/* next element */			\
3509 +	struct type **le_prev;	/* address of previous next element */	\
3510 +}
3511 +
3512 +/*
3513 + * List functions.
3514 + */
3515 +
3516 +#define	LIST_EMPTY(head)	((head)->lh_first == NULL)
3517 +
3518 +#define	LIST_FIRST(head)	((head)->lh_first)
3519 +
3520 +#define	LIST_FOREACH(var, head, field)					\
3521 +	for ((var) = LIST_FIRST((head));				\
3522 +	    (var);							\
3523 +	    (var) = LIST_NEXT((var), field))
3524 +
3525 +#define	LIST_FOREACH_SAFE(var, head, field, tvar)			\
3526 +	for ((var) = LIST_FIRST((head));				\
3527 +	    (var) && ((tvar) = LIST_NEXT((var), field), 1);		\
3528 +	    (var) = (tvar))
3529 +
3530 +#define	LIST_INIT(head) do {						\
3531 +	LIST_FIRST((head)) = NULL;					\
3532 +} while (0)
3533 +
3534 +#define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
3535 +	if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
3536 +		LIST_NEXT((listelm), field)->field.le_prev =		\
3537 +		    &LIST_NEXT((elm), field);				\
3538 +	LIST_NEXT((listelm), field) = (elm);				\
3539 +	(elm)->field.le_prev = &LIST_NEXT((listelm), field);		\
3540 +} while (0)
3541 +
3542 +#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
3543 +	(elm)->field.le_prev = (listelm)->field.le_prev;		\
3544 +	LIST_NEXT((elm), field) = (listelm);				\
3545 +	*(listelm)->field.le_prev = (elm);				\
3546 +	(listelm)->field.le_prev = &LIST_NEXT((elm), field);		\
3547 +} while (0)
3548 +
3549 +#define	LIST_INSERT_HEAD(head, elm, field) do {				\
3550 +	if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL)	\
3551 +		LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
3552 +	LIST_FIRST((head)) = (elm);					\
3553 +	(elm)->field.le_prev = &LIST_FIRST((head));			\
3554 +} while (0)
3555 +
3556 +#define	LIST_NEXT(elm, field)	((elm)->field.le_next)
3557 +
3558 +#define	LIST_REMOVE(elm, field) do {					\
3559 +	if (LIST_NEXT((elm), field) != NULL)				\
3560 +		LIST_NEXT((elm), field)->field.le_prev = 		\
3561 +		    (elm)->field.le_prev;				\
3562 +	*(elm)->field.le_prev = LIST_NEXT((elm), field);		\
3563 +} while (0)
3564 +
3565 +/*
3566 + * Tail queue declarations.
3567 + */
3568 +#define	TAILQ_HEAD(name, type)						\
3569 +struct name {								\
3570 +	struct type *tqh_first;	/* first element */			\
3571 +	struct type **tqh_last;	/* addr of last next element */		\
3572 +	TRACEBUF							\
3573 +}
3574 +
3575 +#define	TAILQ_HEAD_INITIALIZER(head)					\
3576 +	{ NULL, &(head).tqh_first }
3577 +
3578 +#define	TAILQ_ENTRY(type)						\
3579 +struct {								\
3580 +	struct type *tqe_next;	/* next element */			\
3581 +	struct type **tqe_prev;	/* address of previous next element */	\
3582 +	TRACEBUF							\
3583 +}
3584 +
3585 +/*
3586 + * Tail queue functions.
3587 + */
3588 +#define	TAILQ_CONCAT(head1, head2, field) do {				\
3589 +	if (!TAILQ_EMPTY(head2)) {					\
3590 +		*(head1)->tqh_last = (head2)->tqh_first;		\
3591 +		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\
3592 +		(head1)->tqh_last = (head2)->tqh_last;			\
3593 +		TAILQ_INIT((head2));					\
3594 +		QMD_TRACE_HEAD(head);					\
3595 +		QMD_TRACE_HEAD(head2);					\
3596 +	}								\
3597 +} while (0)
3598 +
3599 +#define	TAILQ_EMPTY(head)	((head)->tqh_first == NULL)
3600 +
3601 +#define	TAILQ_FIRST(head)	((head)->tqh_first)
3602 +
3603 +#define	TAILQ_FOREACH(var, head, field)					\
3604 +	for ((var) = TAILQ_FIRST((head));				\
3605 +	    (var);							\
3606 +	    (var) = TAILQ_NEXT((var), field))
3607 +
3608 +#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
3609 +	for ((var) = TAILQ_FIRST((head));				\
3610 +	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
3611 +	    (var) = (tvar))
3612 +
3613 +#define	TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
3614 +	for ((var) = TAILQ_LAST((head), headname);			\
3615 +	    (var);							\
3616 +	    (var) = TAILQ_PREV((var), headname, field))
3617 +
3618 +#define	TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\
3619 +	for ((var) = TAILQ_LAST((head), headname);			\
3620 +	    (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1);	\
3621 +	    (var) = (tvar))
3622 +
3623 +#define	TAILQ_INIT(head) do {						\
3624 +	TAILQ_FIRST((head)) = NULL;					\
3625 +	(head)->tqh_last = &TAILQ_FIRST((head));			\
3626 +	QMD_TRACE_HEAD(head);						\
3627 +} while (0)
3628 +
3629 +#define	TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
3630 +	if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
3631 +		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
3632 +		    &TAILQ_NEXT((elm), field);				\
3633 +	else {								\
3634 +		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
3635 +		QMD_TRACE_HEAD(head);					\
3636 +	}								\
3637 +	TAILQ_NEXT((listelm), field) = (elm);				\
3638 +	(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);		\
3639 +	QMD_TRACE_ELEM(&(elm)->field);					\
3640 +	QMD_TRACE_ELEM(&listelm->field);				\
3641 +} while (0)
3642 +
3643 +#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
3644 +	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
3645 +	TAILQ_NEXT((elm), field) = (listelm);				\
3646 +	*(listelm)->field.tqe_prev = (elm);				\
3647 +	(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);		\
3648 +	QMD_TRACE_ELEM(&(elm)->field);					\
3649 +	QMD_TRACE_ELEM(&listelm->field);				\
3650 +} while (0)
3651 +
3652 +#define	TAILQ_INSERT_HEAD(head, elm, field) do {			\
3653 +	if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)	\
3654 +		TAILQ_FIRST((head))->field.tqe_prev =			\
3655 +		    &TAILQ_NEXT((elm), field);				\
3656 +	else								\
3657 +		(head)->tqh_last = &TAILQ_NEXT((elm), field);		\
3658 +	TAILQ_FIRST((head)) = (elm);					\
3659 +	(elm)->field.tqe_prev = &TAILQ_FIRST((head));			\
3660 +	QMD_TRACE_HEAD(head);						\
3661 +	QMD_TRACE_ELEM(&(elm)->field);					\
3662 +} while (0)
3663 +
3664 +#define	TAILQ_INSERT_TAIL(head, elm, field) do {			\
3665 +	TAILQ_NEXT((elm), field) = NULL;				\
3666 +	(elm)->field.tqe_prev = (head)->tqh_last;			\
3667 +	*(head)->tqh_last = (elm);					\
3668 +	(head)->tqh_last = &TAILQ_NEXT((elm), field);			\
3669 +	QMD_TRACE_HEAD(head);						\
3670 +	QMD_TRACE_ELEM(&(elm)->field);					\
3671 +} while (0)
3672 +
3673 +#define	TAILQ_LAST(head, headname)					\
3674 +	(*(((struct headname *)((head)->tqh_last))->tqh_last))
3675 +
3676 +#define	TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
3677 +
3678 +#define	TAILQ_PREV(elm, headname, field)				\
3679 +	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
3680 +
3681 +#define	TAILQ_REMOVE(head, elm, field) do {				\
3682 +	if ((TAILQ_NEXT((elm), field)) != NULL)				\
3683 +		TAILQ_NEXT((elm), field)->field.tqe_prev = 		\
3684 +		    (elm)->field.tqe_prev;				\
3685 +	else {								\
3686 +		(head)->tqh_last = (elm)->field.tqe_prev;		\
3687 +		QMD_TRACE_HEAD(head);					\
3688 +	}								\
3689 +	*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);		\
3690 +	TRASHIT((elm)->field.tqe_next);					\
3691 +	TRASHIT((elm)->field.tqe_prev);					\
3692 +	QMD_TRACE_ELEM(&(elm)->field);					\
3693 +} while (0)
3694 +
3695 +
3696 +#ifdef _KERNEL
3697 +
3698 +/*
3699 + * XXX insque() and remque() are an old way of handling certain queues.
3700 + * They bogusly assumes that all queue heads look alike.
3701 + */
3702 +
3703 +struct quehead {
3704 +	struct quehead *qh_link;
3705 +	struct quehead *qh_rlink;
3706 +};
3707 +
3708 +#if defined(__GNUC__) || defined(__INTEL_COMPILER)
3709 +
3710 +static __inline void
3711 +insque(void *a, void *b)
3712 +{
3713 +	struct quehead *element = (struct quehead *)a,
3714 +		 *head = (struct quehead *)b;
3715 +
3716 +	element->qh_link = head->qh_link;
3717 +	element->qh_rlink = head;
3718 +	head->qh_link = element;
3719 +	element->qh_link->qh_rlink = element;
3720 +}
3721 +
3722 +static __inline void
3723 +remque(void *a)
3724 +{
3725 +	struct quehead *element = (struct quehead *)a;
3726 +
3727 +	element->qh_link->qh_rlink = element->qh_rlink;
3728 +	element->qh_rlink->qh_link = element->qh_link;
3729 +	element->qh_rlink = 0;
3730 +}
3731 +
3732 +#else /* !(__GNUC__ || __INTEL_COMPILER) */
3733 +
3734 +void	insque(void *a, void *b);
3735 +void	remque(void *a);
3736 +
3737 +#endif /* __GNUC__ || __INTEL_COMPILER */
3738 +
3739 +#endif /* _KERNEL */
3740 +
3741 +#endif /* !_SYS_QUEUE_H_ */
3742 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_crypto.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_crypto.h
3743 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_crypto.h	1970-01-01 01:00:00.000000000 +0100
3744 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_crypto.h	2008-06-19 17:34:17.000000000 +0200
3745 @@ -0,0 +1,207 @@
3746 +/*-
3747 + * Copyright (c) 2001 Atsushi Onoe
3748 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3749 + * All rights reserved.
3750 + *
3751 + * Redistribution and use in source and binary forms, with or without
3752 + * modification, are permitted provided that the following conditions
3753 + * are met:
3754 + * 1. Redistributions of source code must retain the above copyright
3755 + *    notice, this list of conditions and the following disclaimer.
3756 + * 2. Redistributions in binary form must reproduce the above copyright
3757 + *    notice, this list of conditions and the following disclaimer in the
3758 + *    documentation and/or other materials provided with the distribution.
3759 + * 3. The name of the author may not be used to endorse or promote products
3760 + *    derived from this software without specific prior written permission.
3761 + *
3762 + * Alternatively, this software may be distributed under the terms of the
3763 + * GNU General Public License ("GPL") version 2 as published by the Free
3764 + * Software Foundation.
3765 + *
3766 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
3767 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3768 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
3769 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
3770 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3771 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3772 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3773 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3774 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3775 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3776 + *
3777 + * $Id: ieee80211_crypto.h 3068 2007-12-21 17:46:02Z mentor $
3778 + */
3779 +#ifndef _NET80211_IEEE80211_CRYPTO_H_
3780 +#define _NET80211_IEEE80211_CRYPTO_H_
3781 +
3782 +/*
3783 + * 802.11 protocol crypto-related definitions.
3784 + */
3785 +#define	IEEE80211_KEYBUF_SIZE	16
3786 +#define	IEEE80211_MICBUF_SIZE	(8 + 8)		/* space for both TX & RX keys */
3787 +#define IEEE80211_TID_SIZE	17		/* total number of TIDs */
3788 +
3789 +/*
3790 + * Old WEP-style key.  Deprecated.
3791 + */
3792 +struct ieee80211_wepkey {
3793 +	u_int wk_len;				/* key length in bytes */
3794 +	u_int8_t wk_key[IEEE80211_KEYBUF_SIZE];
3795 +};
3796 +
3797 +struct ieee80211_cipher;
3798 +
3799 +/*
3800 + * Crypto key state.  There is sufficient room for all supported
3801 + * ciphers (see below).  The underlying ciphers are handled
3802 + * separately through loadable cipher modules that register with
3803 + * the generic crypto support.  A key has a reference to an instance
3804 + * of the cipher; any per-key state is hung off wk_private by the
3805 + * cipher when it is attached.  Ciphers are automatically called
3806 + * to detach and cleanup any such state when the key is deleted.
3807 + *
3808 + * The generic crypto support handles encap/decap of cipher-related
3809 + * frame contents for both hardware- and software-based implementations.
3810 + * A key requiring software crypto support is automatically flagged and
3811 + * the cipher is expected to honor this and do the necessary work.
3812 + * Ciphers such as TKIP may also support mixed hardware/software
3813 + * encrypt/decrypt and MIC processing.
3814 + */
3815 +
3816 +typedef u_int16_t ieee80211_keyix_t;
3817 +
3818 +/* XXX pack better? */
3819 +/* XXX 48-bit rsc/tsc */
3820 +struct ieee80211_key {
3821 +	u_int8_t wk_keylen;		/* key length in bytes */
3822 +	u_int8_t wk_flags;
3823 +#define	IEEE80211_KEY_XMIT	0x01	/* key used for xmit */
3824 +#define	IEEE80211_KEY_RECV	0x02	/* key used for recv */
3825 +#define	IEEE80211_KEY_GROUP	0x04	/* key used for WPA group operation */
3826 +#define	IEEE80211_KEY_SWCRYPT	0x10	/* host-based encrypt/decrypt */
3827 +#define	IEEE80211_KEY_SWMIC	0x20	/* host-based enmic/demic */
3828 +	ieee80211_keyix_t wk_keyix;	/* key index */
3829 +	u_int8_t wk_key[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
3830 +#define	wk_txmic	wk_key+IEEE80211_KEYBUF_SIZE+0	/* XXX can't () right */
3831 +#define	wk_rxmic	wk_key+IEEE80211_KEYBUF_SIZE+8	/* XXX can't () right */
3832 +	u_int64_t wk_keyrsc[IEEE80211_TID_SIZE];	/* key receive sequence counter */
3833 +	u_int64_t wk_keytsc;		/* key transmit sequence counter */
3834 +	const struct ieee80211_cipher *wk_cipher;
3835 +	void *wk_private;		/* private cipher state */
3836 +};
3837 +#define	IEEE80211_KEY_COMMON 		/* common flags passed in by apps */\
3838 +	(IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV | IEEE80211_KEY_GROUP)
3839 +
3840 +/*
3841 + * NB: these values are ordered carefully; there are lots of
3842 + * of implications in any reordering.  In particular beware
3843 + * that 4 is not used to avoid conflicting with IEEE80211_F_PRIVACY.
3844 + */
3845 +#define	IEEE80211_CIPHER_WEP		0
3846 +#define	IEEE80211_CIPHER_TKIP		1
3847 +#define	IEEE80211_CIPHER_AES_OCB	2
3848 +#define	IEEE80211_CIPHER_AES_CCM	3
3849 +#define	IEEE80211_CIPHER_CKIP		5
3850 +#define	IEEE80211_CIPHER_NONE		6	/* pseudo value */
3851 +
3852 +#define	IEEE80211_CIPHER_MAX		(IEEE80211_CIPHER_NONE + 1)
3853 +
3854 +#define	IEEE80211_KEYIX_NONE	((ieee80211_keyix_t)-1)
3855 +
3856 +#if defined(__KERNEL__) || defined(_KERNEL)
3857 +
3858 +struct ieee80211com;
3859 +struct ieee80211vap;
3860 +struct ieee80211_node;
3861 +struct sk_buff;
3862 +
3863 +void ieee80211_crypto_attach(struct ieee80211com *);
3864 +void ieee80211_crypto_detach(struct ieee80211com *);
3865 +void ieee80211_crypto_vattach(struct ieee80211vap *);
3866 +void ieee80211_crypto_vdetach(struct ieee80211vap *);
3867 +int ieee80211_crypto_newkey(struct ieee80211vap *, int, int,
3868 +	struct ieee80211_key *);
3869 +int ieee80211_crypto_delkey(struct ieee80211vap *, struct ieee80211_key *,
3870 +	struct ieee80211_node *);
3871 +int ieee80211_crypto_setkey(struct ieee80211vap *, struct ieee80211_key *,
3872 +	const u_int8_t macaddr[IEEE80211_ADDR_LEN], struct ieee80211_node *);
3873 +void ieee80211_crypto_delglobalkeys(struct ieee80211vap *);
3874 +
3875 +/*
3876 + * Template for a supported cipher.  Ciphers register with the
3877 + * crypto code and are typically loaded as separate modules
3878 + * (the null cipher is always present).
3879 + * XXX may need refcnts
3880 + */
3881 +struct ieee80211_cipher {
3882 +	const char *ic_name;		/* printable name */
3883 +	u_int ic_cipher;		/* IEEE80211_CIPHER_* */
3884 +	u_int ic_header;		/* size of privacy header (bytes) */
3885 +	u_int ic_trailer;		/* size of privacy trailer (bytes) */
3886 +	u_int ic_miclen;		/* size of mic trailer (bytes) */
3887 +	void *(*ic_attach)(struct ieee80211vap *, struct ieee80211_key *);
3888 +	void (*ic_detach)(struct ieee80211_key *);
3889 +	int (*ic_setkey)(struct ieee80211_key *);
3890 +	int (*ic_encap)(struct ieee80211_key *, struct sk_buff *, u_int8_t);
3891 +	int (*ic_decap)(struct ieee80211_key *, struct sk_buff *, int);
3892 +	int (*ic_enmic)(struct ieee80211_key *, struct sk_buff *, int);
3893 +	int (*ic_demic)(struct ieee80211_key *, struct sk_buff *, int, int);
3894 +};
3895 +extern const struct ieee80211_cipher ieee80211_cipher_none;
3896 +
3897 +void ieee80211_crypto_register(const struct ieee80211_cipher *);
3898 +void ieee80211_crypto_unregister(const struct ieee80211_cipher *);
3899 +int ieee80211_crypto_available(struct ieee80211vap*, u_int);
3900 +
3901 +struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211_node *,
3902 +	struct sk_buff *);
3903 +struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211_node *,
3904 +	struct sk_buff *, int);
3905 +
3906 +/*
3907 + * Check and remove any MIC.
3908 + */
3909 +static __inline int
3910 +ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k,
3911 +	struct sk_buff *skb, int hdrlen, int force)
3912 +{
3913 +	const struct ieee80211_cipher *cip = k->wk_cipher;
3914 +	return (cip->ic_miclen > 0 ? cip->ic_demic(k, skb, hdrlen, force) : 1);
3915 +}
3916 +
3917 +/*
3918 + * Add any MIC.
3919 + */
3920 +static __inline int
3921 +ieee80211_crypto_enmic(struct ieee80211vap *vap, struct ieee80211_key *k,
3922 +	struct sk_buff *skb, int force)
3923 +{
3924 +	const struct ieee80211_cipher *cip = k->wk_cipher;
3925 +	return (cip->ic_miclen > 0 ? cip->ic_enmic(k, skb, force) : 1);
3926 +}
3927 +
3928 +/* 
3929 + * Reset key state to an unused state.  The crypto
3930 + * key allocation mechanism ensures other state (e.g.
3931 + * key data) is properly setup before a key is used.
3932 + */
3933 +static __inline void
3934 +ieee80211_crypto_resetkey(struct ieee80211vap *vap, struct ieee80211_key *k,
3935 +	ieee80211_keyix_t ix)
3936 +{
3937 +	k->wk_cipher = &ieee80211_cipher_none;;
3938 +	k->wk_private = k->wk_cipher->ic_attach(vap, k);
3939 +	k->wk_keyix = ix;
3940 +	k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
3941 +}
3942 +
3943 +/*
3944 + * Crypto-related notification methods.
3945 + */
3946 +void ieee80211_notify_replay_failure(struct ieee80211vap *,
3947 +	const struct ieee80211_frame *, const struct ieee80211_key *,
3948 +	u_int64_t rsc);
3949 +void ieee80211_notify_michael_failure(struct ieee80211vap *,
3950 +	const struct ieee80211_frame *, ieee80211_keyix_t keyix);
3951 +#endif /* defined(__KERNEL__) || defined(_KERNEL) */
3952 +#endif /* _NET80211_IEEE80211_CRYPTO_H_ */
3953 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_debug.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_debug.h
3954 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_debug.h	1970-01-01 01:00:00.000000000 +0100
3955 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_debug.h	2008-06-19 17:34:17.000000000 +0200
3956 @@ -0,0 +1,130 @@
3957 +/*-
3958 + * Copyright (c) 2001 Atsushi Onoe
3959 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3960 + * All rights reserved.
3961 + *
3962 + * Redistribution and use in source and binary forms, with or without
3963 + * modification, are permitted provided that the following conditions
3964 + * are met:
3965 + * 1. Redistributions of source code must retain the above copyright
3966 + *    notice, this list of conditions and the following disclaimer.
3967 + * 2. Redistributions in binary form must reproduce the above copyright
3968 + *    notice, this list of conditions and the following disclaimer in the
3969 + *    documentation and/or other materials provided with the distribution.
3970 + * 3. The name of the author may not be used to endorse or promote products
3971 + *    derived from this software without specific prior written permission.
3972 + *
3973 + * Alternatively, this software may be distributed under the terms of the
3974 + * GNU General Public License ("GPL") version 2 as published by the Free
3975 + * Software Foundation.
3976 + *
3977 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
3978 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3979 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
3980 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
3981 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3982 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3983 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3984 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3985 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3986 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3987 + *
3988 + * $Id: ieee80211_var.h 1969 2007-01-16 03:05:18Z scottr $
3989 + */
3990 +#ifndef _NET80211_IEEE80211_DEBUG_H_
3991 +#define _NET80211_IEEE80211_DEBUG_H_
3992 +
3993 +#include <net80211/ieee80211_var.h>
3994 +#include <net80211/ieee80211.h>
3995 +
3996 +/* Set to true if ANY sc has skb debugging on */
3997 +extern int ath_debug_global;
3998 +enum {
3999 +	GLOBAL_DEBUG_SKB_REF  = 0x00000040,	/* SKB reference counting */
4000 +	GLOBAL_DEBUG_SKB      = 0x40000000,     /* SKB usage/leak debugging,
4001 +	                                           must match ATH_DEBUG_SKB */
4002 +};
4003 +
4004 +#define IEEE80211_MSG_NODE_REF  0x80000000      /* node ref counting */
4005 +#define	IEEE80211_MSG_DEBUG	0x40000000	/* IFF_DEBUG equivalent */
4006 +#define	IEEE80211_MSG_DUMPPKTS	0x20000000	/* IFF_LINK2 equivalent */
4007 +#define	IEEE80211_MSG_CRYPTO	0x10000000	/* crypto work */
4008 +#define	IEEE80211_MSG_INPUT	0x08000000	/* input handling */
4009 +#define	IEEE80211_MSG_XRATE	0x04000000	/* rate set handling */
4010 +#define	IEEE80211_MSG_ELEMID	0x02000000	/* element id parsing */
4011 +#define	IEEE80211_MSG_NODE	0x01000000	/* node management */
4012 +#define	IEEE80211_MSG_ASSOC	0x00800000	/* association handling */
4013 +#define	IEEE80211_MSG_AUTH	0x00400000	/* authentication handling */
4014 +#define	IEEE80211_MSG_SCAN	0x00200000	/* scanning */
4015 +#define	IEEE80211_MSG_OUTPUT	0x00100000	/* output handling */
4016 +#define	IEEE80211_MSG_STATE	0x00080000	/* state machine */
4017 +#define	IEEE80211_MSG_POWER	0x00040000	/* power save handling */
4018 +#define	IEEE80211_MSG_DOT1X	0x00020000	/* 802.1x authenticator */
4019 +#define	IEEE80211_MSG_DOT1XSM	0x00010000	/* 802.1x state machine */
4020 +#define	IEEE80211_MSG_RADIUS	0x00008000	/* 802.1x radius client */
4021 +#define	IEEE80211_MSG_RADDUMP	0x00004000	/* dump 802.1x radius packets */
4022 +#define	IEEE80211_MSG_RADKEYS	0x00002000	/* dump 802.1x keys */
4023 +#define	IEEE80211_MSG_WPA	0x00001000	/* WPA/RSN protocol */
4024 +#define	IEEE80211_MSG_ACL	0x00000800	/* ACL handling */
4025 +#define	IEEE80211_MSG_WME	0x00000400	/* WME protocol */
4026 +#define	IEEE80211_MSG_SUPG	0x00000200	/* SUPERG */
4027 +#define	IEEE80211_MSG_DOTH	0x00000100	/* 11.h */
4028 +#define	IEEE80211_MSG_INACT	0x00000080	/* inactivity handling */
4029 +#define	IEEE80211_MSG_ROAM	0x00000040	/* sta-mode roaming */
4030 +
4031 +#define	IEEE80211_MSG_ANY	0xffffffff	/* anything */
4032 +
4033 +#define IEEE80211_MSG_IC	(IEEE80211_MSG_NODE_REF) /* shared for all VAP */
4034 +
4035 +#ifdef IEEE80211_DEBUG
4036 +#define ieee80211_msg_is_reported(_vap, m) \
4037 +	(!!(((_vap)->iv_debug | (_vap)->iv_ic->ic_debug) & (m)))
4038 +#define	IEEE80211_DPRINTF(_vap, _m, _fmt, ...) do {			\
4039 +	if (ieee80211_msg_is_reported(_vap, _m))					\
4040 +		ieee80211_note(_vap, _fmt, __VA_ARGS__);		\
4041 +} while (0)
4042 +#define	IEEE80211_NOTE(_vap, _m, _ni, _fmt, ...) do {			\
4043 +	if (ieee80211_msg_is_reported(_vap, _m))					\
4044 +		ieee80211_note_mac(_vap, (_ni)->ni_macaddr, _fmt, __VA_ARGS__);\
4045 +} while (0)
4046 +#define	IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...) do {		\
4047 +	if (ieee80211_msg_is_reported(_vap, _m))					\
4048 +		ieee80211_note_mac(_vap, _mac, _fmt, __VA_ARGS__);	\
4049 +} while (0)
4050 +#define	IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...) do {		\
4051 +	if (ieee80211_msg_is_reported(_vap, _m))					\
4052 +		ieee80211_note_frame(_vap, _wh, _fmt, __VA_ARGS__);	\
4053 +} while (0)
4054 +struct ieee80211vap;
4055 +struct ieee80211_frame;
4056 +void ieee80211_note(struct ieee80211vap *, const char *, ...);
4057 +void ieee80211_note_mac(struct ieee80211vap *,
4058 +	const u_int8_t mac[IEEE80211_ADDR_LEN], const char *, ...);
4059 +void ieee80211_note_frame(struct ieee80211vap *,
4060 +	const struct ieee80211_frame *, const char *, ...);
4061 +#define	ieee80211_msg_debug(_vap) \
4062 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_DEBUG)
4063 +#define	ieee80211_msg_dumppkts(_vap) \
4064 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_DUMPPKTS)
4065 +#define	ieee80211_msg_input(_vap) \
4066 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_INPUT)
4067 +#define	ieee80211_msg_radius(_vap) \
4068 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_RADIUS)
4069 +#define	ieee80211_msg_dumpradius(_vap) \
4070 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_RADDUMP)
4071 +#define	ieee80211_msg_dumpradkeys(_vap) \
4072 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_RADKEYS)
4073 +#define	ieee80211_msg_scan(_vap) \
4074 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_SCAN)
4075 +#define	ieee80211_msg_assoc(_vap) \
4076 +	ieee80211_msg_is_reported(_vap, IEEE80211_MSG_ASSOC)
4077 +#else /* IEEE80211_DEBUG */
4078 +#define	ieee80211_msg_is_reported(_vap, _m)	(0)
4079 +#define	IEEE80211_DPRINTF(_vap, _m, _fmt, ...)
4080 +#define	IEEE80211_NOTE(_vap, _m, _wh, _fmt, ...)
4081 +#define	IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...)
4082 +#define	IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...)
4083 +#endif /* IEEE80211_DEBUG */
4084 +
4085 +#endif /* _NET80211_IEEE80211_DEBUG_H_ */
4086 +
4087 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/_ieee80211.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/_ieee80211.h
4088 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/_ieee80211.h	1970-01-01 01:00:00.000000000 +0100
4089 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/_ieee80211.h	2008-06-19 17:34:17.000000000 +0200
4090 @@ -0,0 +1,324 @@
4091 +/*-
4092 + * Copyright (c) 2001 Atsushi Onoe
4093 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4094 + * All rights reserved.
4095 + *
4096 + * Redistribution and use in source and binary forms, with or without
4097 + * modification, are permitted provided that the following conditions
4098 + * are met:
4099 + * 1. Redistributions of source code must retain the above copyright
4100 + *    notice, this list of conditions and the following disclaimer.
4101 + * 2. Redistributions in binary form must reproduce the above copyright
4102 + *    notice, this list of conditions and the following disclaimer in the
4103 + *    documentation and/or other materials provided with the distribution.
4104 + * 3. The name of the author may not be used to endorse or promote products
4105 + *    derived from this software without specific prior written permission.
4106 + *
4107 + * Alternatively, this software may be distributed under the terms of the
4108 + * GNU General Public License ("GPL") version 2 as published by the Free
4109 + * Software Foundation.
4110 + *
4111 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4112 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4113 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4114 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4115 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4116 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4117 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4118 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4119 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
4120 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4121 + *
4122 + * $Id: _ieee80211.h 3207 2008-01-18 21:25:05Z mtaylor $
4123 + */
4124 +#ifndef _NET80211__IEEE80211_H_
4125 +#define _NET80211__IEEE80211_H_
4126 +
4127 +enum ieee80211_phytype {
4128 +	IEEE80211_T_DS,			/* direct sequence spread spectrum */
4129 +	IEEE80211_T_FH,			/* frequency hopping */
4130 +	IEEE80211_T_OFDM,		/* frequency division multiplexing */
4131 +	IEEE80211_T_TURBO,		/* high rate OFDM, aka turbo mode */
4132 +};
4133 +#define	IEEE80211_T_CCK	IEEE80211_T_DS	/* more common nomenclature */
4134 +
4135 +/* XXX: not really a mode; there are really multiple PHYs */
4136 +enum ieee80211_phymode {
4137 +	IEEE80211_MODE_AUTO	= 0,	/* autoselect */
4138 +	IEEE80211_MODE_11A	= 1,	/* 5GHz, OFDM */
4139 +	IEEE80211_MODE_11B	= 2,	/* 2GHz, CCK */
4140 +	IEEE80211_MODE_11G	= 3,	/* 2GHz, OFDM */
4141 +	IEEE80211_MODE_FH	= 4,	/* 2GHz, GFSK */
4142 +	IEEE80211_MODE_TURBO_A	= 5,	/* 5GHz, OFDM, 2x clock dynamic turbo */
4143 +	IEEE80211_MODE_TURBO_G	= 6,	/* 2GHz, OFDM, 2x clock  dynamic turbo*/
4144 +};
4145 +#define	IEEE80211_MODE_MAX	(IEEE80211_MODE_TURBO_G+1)
4146 +
4147 +enum ieee80211_opmode {
4148 +	IEEE80211_M_STA		= 1,	/* infrastructure station */
4149 +	IEEE80211_M_IBSS 	= 0,	/* IBSS (adhoc) station */
4150 +	IEEE80211_M_AHDEMO	= 3,	/* Old lucent compatible adhoc demo */
4151 +	IEEE80211_M_HOSTAP	= 6,	/* Software Access Point */
4152 +	IEEE80211_M_MONITOR	= 8,	/* Monitor mode */
4153 +	IEEE80211_M_WDS		= 2	/* WDS link */
4154 +};
4155 +
4156 +/*
4157 + * True if this mode will send beacon on a regular interval, like AP
4158 + * or IBSS
4159 + */
4160 +#define IEEE80211_IS_MODE_BEACON(_opmode) \
4161 +	((_opmode == IEEE80211_M_IBSS) || \
4162 +	 (_opmode == IEEE80211_M_HOSTAP))
4163 +
4164 +/*
4165 + * True if this mode must behave like a DFS master, ie do Channel
4166 + * Check Availability and In Service Monitoring. We need to make sure
4167 + * that all modes cannot send data without being authorized. Such
4168 + * enforcement is not done in monitor mode however.
4169 + */
4170 +
4171 +#define IEEE80211_IS_MODE_DFS_MASTER(_opmode) \
4172 +	((_opmode == IEEE80211_M_IBSS) || \
4173 +	 (_opmode == IEEE80211_M_AHDEMO) || \
4174 +	 (_opmode == IEEE80211_M_HOSTAP) || \
4175 +	 (_opmode == IEEE80211_M_WDS))
4176 +
4177 +/*
4178 + * 802.11g protection mode.
4179 + */
4180 +enum ieee80211_protmode {
4181 +	IEEE80211_PROT_NONE	= 0,	/* no protection */
4182 +	IEEE80211_PROT_CTSONLY	= 1,	/* CTS to self */
4183 +	IEEE80211_PROT_RTSCTS	= 2,	/* RTS-CTS */
4184 +};
4185 +
4186 +/*
4187 + * Authentication mode.
4188 + */
4189 +enum ieee80211_authmode {
4190 +	IEEE80211_AUTH_NONE	= 0,
4191 +	IEEE80211_AUTH_OPEN	= 1,	/* open */
4192 +	IEEE80211_AUTH_SHARED	= 2,	/* shared-key */
4193 +	IEEE80211_AUTH_8021X	= 3,	/* 802.1x */
4194 +	IEEE80211_AUTH_AUTO	= 4,	/* auto-select/accept */
4195 +	/* NB: these are used only for ioctls */
4196 +	IEEE80211_AUTH_WPA	= 5,	/* WPA/RSN w/ 802.1x/PSK */
4197 +};
4198 +
4199 +/*
4200 + * Roaming mode is effectively who controls the operation
4201 + * of the 802.11 state machine when operating as a station.
4202 + * State transitions are controlled either by the driver
4203 + * (typically when management frames are processed by the
4204 + * hardware/firmware), the host (auto/normal operation of
4205 + * the 802.11 layer), or explicitly through ioctl requests
4206 + * when applications like wpa_supplicant want control.
4207 + */
4208 +enum ieee80211_roamingmode {
4209 +	IEEE80211_ROAMING_DEVICE= 0,	/* driver/hardware control */
4210 +	IEEE80211_ROAMING_AUTO	= 1,	/* 802.11 layer control */
4211 +	IEEE80211_ROAMING_MANUAL= 2,	/* application control */
4212 +};
4213 +
4214 +/*
4215 + * Scanning mode controls station scanning work; this is
4216 + * used only when roaming mode permits the host to select
4217 + * the bss to join/channel to use.
4218 + */
4219 +enum ieee80211_scanmode {
4220 +	IEEE80211_SCAN_DEVICE	= 0,	/* driver/hardware control */
4221 +	IEEE80211_SCAN_BEST	= 1,	/* 802.11 layer selects best */
4222 +	IEEE80211_SCAN_FIRST	= 2,	/* take first suitable candidate */
4223 +};
4224 +
4225 +enum ieee80211_scanflags {
4226 +	IEEE80211_NOSCAN_DEFAULT = (1 << 0),
4227 +	IEEE80211_NOSCAN_SET     = (1 << 1),
4228 +};
4229 +
4230 +/*
4231 + * Channels are specified by frequency and attributes.
4232 + */
4233 +struct ieee80211_channel {
4234 +	u_int16_t ic_freq;	/* setting in MHz */
4235 +	u_int16_t ic_flags;	/* see below */
4236 +	u_int8_t ic_ieee;	/* IEEE channel number */
4237 +	int8_t ic_maxregpower;	/* maximum regulatory tx power in dBm */
4238 +	int8_t ic_maxpower;	/* maximum tx power in dBm */
4239 +	int8_t ic_minpower;	/* minimum tx power in dBm */
4240 +	u_int8_t ic_scanflags;
4241 +};
4242 +
4243 +#define	IEEE80211_CHAN_MAX	255
4244 +#define	IEEE80211_CHAN_BYTES	32	/* howmany(IEEE80211_CHAN_MAX, NBBY) */
4245 +#define	IEEE80211_CHAN_ANY	0xffff	/* token for ``any channel'' */
4246 +#define	IEEE80211_CHAN_ANYC 	((struct ieee80211_channel *) IEEE80211_CHAN_ANY)
4247 +
4248 +#define	IEEE80211_RADAR_CHANCHANGE_TBTT_COUNT	0
4249 +#define IEEE80211_DEFAULT_CHANCHANGE_TBTT_COUNT	3
4250 +
4251 +#define	IEEE80211_RADAR_TEST_MUTE_CHAN	36	/* Move to channel 36 for mute test */
4252 +
4253 +/* bits 0-3 are for private use by drivers */
4254 +/* channel attributes */
4255 +#define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
4256 +#define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
4257 +#define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
4258 +#define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
4259 +#define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
4260 +#define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
4261 +#define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
4262 +#define	IEEE80211_CHAN_GFSK	0x0800	/* GFSK channel (FHSS PHY) */
4263 +#define IEEE80211_CHAN_RADAR	0x1000	/* Radar found on channel */
4264 +#define	IEEE80211_CHAN_STURBO	0x2000	/* 11a static turbo channel only */
4265 +#define	IEEE80211_CHAN_HALF	0x4000	/* Half rate channel */
4266 +#define	IEEE80211_CHAN_QUARTER	0x8000	/* Quarter rate channel */
4267 +
4268 +/*
4269 + * Useful combinations of channel characteristics.
4270 + */
4271 +#define	IEEE80211_CHAN_FHSS \
4272 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
4273 +#define	IEEE80211_CHAN_A \
4274 +	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
4275 +#define	IEEE80211_CHAN_B \
4276 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
4277 +#define	IEEE80211_CHAN_PUREG \
4278 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
4279 +#define	IEEE80211_CHAN_G \
4280 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
4281 +#define IEEE80211_CHAN_108A \
4282 +	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
4283 +#define	IEEE80211_CHAN_108G \
4284 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
4285 +#define	IEEE80211_CHAN_ST \
4286 +	(IEEE80211_CHAN_108A | IEEE80211_CHAN_STURBO)
4287 +
4288 +#define	IEEE80211_CHAN_ALL \
4289 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_GFSK | \
4290 +	 IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_DYN)
4291 +#define	IEEE80211_CHAN_ALLTURBO \
4292 +	(IEEE80211_CHAN_ALL | IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)
4293 +
4294 +#define	IEEE80211_IS_CHAN_FHSS(_c) \
4295 +	(((_c)->ic_flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
4296 +#define	IEEE80211_IS_CHAN_A(_c) \
4297 +	(((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
4298 +#define	IEEE80211_IS_CHAN_B(_c) \
4299 +	(((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
4300 +#define	IEEE80211_IS_CHAN_PUREG(_c) \
4301 +	(((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
4302 +#define	IEEE80211_IS_CHAN_G(_c) \
4303 +	(((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
4304 +#define	IEEE80211_IS_CHAN_ANYG(_c) \
4305 +	(IEEE80211_IS_CHAN_PUREG(_c) || IEEE80211_IS_CHAN_G(_c))
4306 +#define	IEEE80211_IS_CHAN_ST(_c) \
4307 +	(((_c)->ic_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST)
4308 +#define	IEEE80211_IS_CHAN_108A(_c) \
4309 +	(((_c)->ic_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A)
4310 +#define	IEEE80211_IS_CHAN_108G(_c) \
4311 +	(((_c)->ic_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G)
4312 +
4313 +#define	IEEE80211_IS_CHAN_2GHZ(_c) \
4314 +	(((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0)
4315 +#define	IEEE80211_IS_CHAN_5GHZ(_c) \
4316 +	(((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0)
4317 +#define	IEEE80211_IS_CHAN_OFDM(_c) \
4318 +	(((_c)->ic_flags & IEEE80211_CHAN_OFDM) != 0)
4319 +#define	IEEE80211_IS_CHAN_CCK(_c) \
4320 +	(((_c)->ic_flags & IEEE80211_CHAN_CCK) != 0)
4321 +#define	IEEE80211_IS_CHAN_GFSK(_c) \
4322 +	(((_c)->ic_flags & IEEE80211_CHAN_GFSK) != 0)
4323 +#define	IEEE80211_IS_CHAN_TURBO(_c) \
4324 +	(((_c)->ic_flags & IEEE80211_CHAN_TURBO) != 0)
4325 +#define	IEEE80211_IS_CHAN_STURBO(_c) \
4326 +	(((_c)->ic_flags & IEEE80211_CHAN_STURBO) != 0)
4327 +#define	IEEE80211_IS_CHAN_DTURBO(_c) \
4328 +	(((_c)->ic_flags & \
4329 +	(IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)) == IEEE80211_CHAN_TURBO)
4330 +#define	IEEE80211_IS_CHAN_HALF(_c) \
4331 +	(((_c)->ic_flags & IEEE80211_CHAN_HALF) != 0)
4332 +#define	IEEE80211_IS_CHAN_QUARTER(_c) \
4333 +	(((_c)->ic_flags & IEEE80211_CHAN_QUARTER) != 0)
4334 +
4335 +#define	IEEE80211_IS_CHAN_RADAR(_c) \
4336 +	(((_c)->ic_flags & IEEE80211_CHAN_RADAR) != 0)
4337 +#define	IEEE80211_IS_CHAN_PASSIVE(_c) \
4338 +	(((_c)->ic_flags & IEEE80211_CHAN_PASSIVE) != 0)
4339 +#define	IEEE80211_ARE_CHANS_SAME_MODE(_a, _b) \
4340 +	(((_a)->ic_flags & IEEE80211_CHAN_ALLTURBO) == ((_b)->ic_flags & IEEE80211_CHAN_ALLTURBO))
4341 +
4342 +/* ni_chan encoding for FH phy */
4343 +#define	IEEE80211_FH_CHANMOD		80
4344 +#define	IEEE80211_FH_CHAN(set,pat)	(((set) - 1) * IEEE80211_FH_CHANMOD + (pat))
4345 +#define	IEEE80211_FH_CHANSET(chan)	((chan) / IEEE80211_FH_CHANMOD + 1)
4346 +#define	IEEE80211_FH_CHANPAT(chan)	((chan) % IEEE80211_FH_CHANMOD)
4347 +
4348 +/*
4349 + * Spectrum Management (IEEE 802.11h-2003)
4350 + */
4351 +
4352 +/* algorithm for (re)association based on supported channels
4353 + * (the one mentioned in 11.6.1 as out of scope of .11h) */
4354 +enum ieee80211_sc_algorithm {
4355 +	IEEE80211_SC_NONE,
4356 +	/*
4357 +	 * Do not disallow anyone from associating. When needed, channel will
4358 +	 * be switched to the most suitable channel, no matter client stations
4359 +	 * support it or not.
4360 +	 */
4361 +
4362 +	IEEE80211_SC_LOOSE,
4363 +	/*
4364 +	 * Do not disallow anyone from associating. When needed, channel will
4365 +	 * be switched to a suitable channel, which will be chosen taking
4366 +	 * ni->ni_suppchans and ic->ic_sc_sldg under consideration.
4367 +	 */
4368 +
4369 +	IEEE80211_SC_TIGHT,
4370 +	/*
4371 +	 * Allow to associate if there are at least ic->ic_mincom channels
4372 +	 * common to the associating station and all of the already associated
4373 +	 * stations. If the number of new common channels is less than
4374 +	 * required, consider disassociating some other STAs. Such a
4375 +	 * disassociation will be performed if (and only if) the association we
4376 +	 * are currently considering would be then possible and the count of
4377 +	 * the resultant set of common channels (ic_chan_nodes[i] ==
4378 +	 * ic_cn_total) would increase by some amount. Whether the number of
4379 +	 * the new channels that could be gained is enough to sacrifice a
4380 +	 * number of STAs is determined by the ic->ic_slcg parameter.
4381 +	 */
4382 +
4383 +	IEEE80211_SC_STRICT
4384 +	/*
4385 +	 * Basically the same behavior as IEEE80211_SC_TIGHT, except that if a
4386 +	 * station does not specify Supported Channels, then it is denied to
4387 +	 * associate.
4388 +	 */
4389 +};
4390 +
4391 +/*
4392 + * 802.11 rate set.
4393 + */
4394 +#define	IEEE80211_RATE_SIZE	8		/* 802.11 standard */
4395 +#define	IEEE80211_RATE_MAXSIZE	15		/* max rates we'll handle */
4396 +#define	IEEE80211_SANITISE_RATESIZE(_rsz) \
4397 +	((_rsz > IEEE80211_RATE_MAXSIZE) ? IEEE80211_RATE_MAXSIZE : _rsz)
4398 +
4399 +struct ieee80211_rateset {
4400 +	u_int8_t rs_nrates;
4401 +	u_int8_t rs_rates[IEEE80211_RATE_MAXSIZE];
4402 +};
4403 +
4404 +struct ieee80211_roam {
4405 +	int8_t rssi11a;		/* rssi thresh for 11a bss */
4406 +	int8_t rssi11b;		/* for 11g sta in 11b bss */
4407 +	int8_t rssi11bOnly;	/* for 11b sta */
4408 +	u_int8_t pad1;
4409 +	u_int8_t rate11a;	/* rate thresh for 11a bss */
4410 +	u_int8_t rate11b;	/* for 11g sta in 11b bss */
4411 +	u_int8_t rate11bOnly;	/* for 11b sta */
4412 +	u_int8_t pad2;
4413 +};
4414 +#endif /* _NET80211__IEEE80211_H_ */
4415 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211.h
4416 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211.h	1970-01-01 01:00:00.000000000 +0100
4417 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211.h	2008-06-19 17:34:17.000000000 +0200
4418 @@ -0,0 +1,999 @@
4419 +/*-
4420 + * Copyright (c) 2001 Atsushi Onoe
4421 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4422 + * All rights reserved.
4423 + *
4424 + * Redistribution and use in source and binary forms, with or without
4425 + * modification, are permitted provided that the following conditions
4426 + * are met:
4427 + * 1. Redistributions of source code must retain the above copyright
4428 + *    notice, this list of conditions and the following disclaimer.
4429 + * 2. Redistributions in binary form must reproduce the above copyright
4430 + *    notice, this list of conditions and the following disclaimer in the
4431 + *    documentation and/or other materials provided with the distribution.
4432 + * 3. The name of the author may not be used to endorse or promote products
4433 + *    derived from this software without specific prior written permission.
4434 + *
4435 + * Alternatively, this software may be distributed under the terms of the
4436 + * GNU General Public License ("GPL") version 2 as published by the Free
4437 + * Software Foundation.
4438 + *
4439 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4440 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4441 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4442 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4443 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4444 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4445 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4446 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4447 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
4448 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4449 + *
4450 + * $Id: ieee80211.h 3268 2008-01-26 20:48:11Z mtaylor $
4451 + */
4452 +#ifndef _NET80211_IEEE80211_H_
4453 +#define _NET80211_IEEE80211_H_
4454 +
4455 +/*
4456 + * 802.11 protocol definitions.
4457 + */
4458 +
4459 +#define	IEEE80211_ADDR_LEN		6		/* size of 802.11 address */
4460 +/* is 802.11 address multicast/broadcast? */
4461 +#define	IEEE80211_IS_MULTICAST(_a)	(*(_a) & 0x01)
4462 +
4463 +/* IEEE 802.11 PLCP header */
4464 +struct ieee80211_plcp_hdr {
4465 +	u_int16_t i_sfd;
4466 +	u_int8_t i_signal;
4467 +	u_int8_t i_service;
4468 +	u_int16_t i_length;
4469 +	u_int16_t i_crc;
4470 +} __packed;
4471 +
4472 +#define IEEE80211_PLCP_SFD      0xF3A0
4473 +#define IEEE80211_PLCP_SERVICE  0x00
4474 +
4475 +/*
4476 + * generic definitions for IEEE 802.11 frames
4477 + */
4478 +struct ieee80211_frame {
4479 +	u_int8_t i_fc[2];
4480 +	__le16 i_dur;
4481 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
4482 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
4483 +	u_int8_t i_addr3[IEEE80211_ADDR_LEN];
4484 +	u_int8_t i_seq[2];
4485 +	/* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
4486 +	/* see below */
4487 +} __packed;
4488 +
4489 +struct ieee80211_qosframe {
4490 +	u_int8_t i_fc[2];
4491 +	__le16 i_dur;
4492 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
4493 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
4494 +	u_int8_t i_addr3[IEEE80211_ADDR_LEN];
4495 +	u_int8_t i_seq[2];
4496 +	u_int8_t i_qos[2];
4497 +	/* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
4498 +	/* see below */
4499 +} __packed;
4500 +
4501 +struct ieee80211_qoscntl {
4502 +	u_int8_t i_qos[2];
4503 +};
4504 +
4505 +struct ieee80211_frame_addr4 {
4506 +	u_int8_t i_fc[2];
4507 +	__le16 i_dur;
4508 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
4509 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
4510 +	u_int8_t i_addr3[IEEE80211_ADDR_LEN];
4511 +	u_int8_t i_seq[2];
4512 +	u_int8_t i_addr4[IEEE80211_ADDR_LEN];
4513 +} __packed;
4514 +
4515 +
4516 +struct ieee80211_qosframe_addr4 {
4517 +	u_int8_t i_fc[2];
4518 +	__le16 i_dur;
4519 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
4520 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
4521 +	u_int8_t i_addr3[IEEE80211_ADDR_LEN];
4522 +	u_int8_t i_seq[2];
4523 +	u_int8_t i_addr4[IEEE80211_ADDR_LEN];
4524 +	u_int8_t i_qos[2];
4525 +} __packed;
4526 +
4527 +struct ieee80211_ctlframe_addr2 {
4528 +	u_int8_t i_fc[2];
4529 +	__le16 i_aidordur; /* AID or duration */
4530 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
4531 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
4532 +} __packed;
4533 +
4534 +#define	IEEE80211_FC0_VERSION_MASK		0x03
4535 +#define	IEEE80211_FC0_VERSION_SHIFT		0
4536 +#define	IEEE80211_FC0_VERSION_0			0x00
4537 +#define	IEEE80211_FC0_TYPE_MASK			0x0c
4538 +#define	IEEE80211_FC0_TYPE_SHIFT		2
4539 +#define	IEEE80211_FC0_TYPE_MGT			0x00
4540 +#define	IEEE80211_FC0_TYPE_CTL			0x04
4541 +#define	IEEE80211_FC0_TYPE_DATA			0x08
4542 +
4543 +#define	IEEE80211_FC0_SUBTYPE_MASK		0xf0
4544 +#define	IEEE80211_FC0_SUBTYPE_SHIFT		4
4545 +/* for TYPE_MGT */
4546 +#define	IEEE80211_FC0_SUBTYPE_ASSOC_REQ		0x00
4547 +#define	IEEE80211_FC0_SUBTYPE_ASSOC_RESP	0x10
4548 +#define	IEEE80211_FC0_SUBTYPE_REASSOC_REQ	0x20
4549 +#define	IEEE80211_FC0_SUBTYPE_REASSOC_RESP	0x30
4550 +#define	IEEE80211_FC0_SUBTYPE_PROBE_REQ		0x40
4551 +#define	IEEE80211_FC0_SUBTYPE_PROBE_RESP	0x50
4552 +#define	IEEE80211_FC0_SUBTYPE_BEACON		0x80
4553 +#define	IEEE80211_FC0_SUBTYPE_ATIM		0x90
4554 +#define	IEEE80211_FC0_SUBTYPE_DISASSOC		0xa0
4555 +#define	IEEE80211_FC0_SUBTYPE_AUTH		0xb0
4556 +#define	IEEE80211_FC0_SUBTYPE_DEAUTH		0xc0
4557 +#define IEEE80211_FC0_SUBTYPE_ACTION		0xd0
4558 +/* for TYPE_CTL */
4559 +#define	IEEE80211_FC0_SUBTYPE_PS_POLL		0xa0
4560 +#define	IEEE80211_FC0_SUBTYPE_RTS		0xb0
4561 +#define	IEEE80211_FC0_SUBTYPE_CTS		0xc0
4562 +#define	IEEE80211_FC0_SUBTYPE_ACK		0xd0
4563 +#define	IEEE80211_FC0_SUBTYPE_CF_END		0xe0
4564 +#define	IEEE80211_FC0_SUBTYPE_CF_END_ACK	0xf0
4565 +/* for TYPE_DATA (bit combination) */
4566 +#define	IEEE80211_FC0_SUBTYPE_DATA		0x00
4567 +#define	IEEE80211_FC0_SUBTYPE_CF_ACK		0x10
4568 +#define	IEEE80211_FC0_SUBTYPE_CF_POLL		0x20
4569 +#define	IEEE80211_FC0_SUBTYPE_CF_ACPL		0x30
4570 +#define	IEEE80211_FC0_SUBTYPE_NODATA		0x40
4571 +#define	IEEE80211_FC0_SUBTYPE_CFACK		0x50
4572 +#define	IEEE80211_FC0_SUBTYPE_CFPOLL		0x60
4573 +#define	IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK	0x70
4574 +#define	IEEE80211_FC0_SUBTYPE_QOS		0x80
4575 +#define	IEEE80211_FC0_SUBTYPE_QOS_NULL		0xc0
4576 +
4577 +#define	IEEE80211_FC1_DIR_MASK			0x03
4578 +#define	IEEE80211_FC1_DIR_NODS			0x00	/* STA->STA */
4579 +#define	IEEE80211_FC1_DIR_TODS			0x01	/* STA->AP  */
4580 +#define	IEEE80211_FC1_DIR_FROMDS		0x02	/* AP ->STA */
4581 +#define	IEEE80211_FC1_DIR_DSTODS		0x03	/* AP ->AP  */
4582 +
4583 +#define	IEEE80211_FC1_MORE_FRAG			0x04
4584 +#define	IEEE80211_FC1_RETRY			0x08
4585 +#define	IEEE80211_FC1_PWR_MGT			0x10
4586 +#define	IEEE80211_FC1_MORE_DATA			0x20
4587 +#define	IEEE80211_FC1_PROT			0x40
4588 +#define	IEEE80211_FC1_ORDER			0x80
4589 +
4590 +#define	IEEE80211_SEQ_FRAG_MASK			0x000f
4591 +#define	IEEE80211_SEQ_FRAG_SHIFT		0
4592 +#define	IEEE80211_SEQ_SEQ_MASK			0xfff0
4593 +#define	IEEE80211_SEQ_SEQ_SHIFT			4
4594 +
4595 +#define	IEEE80211_SEQ_LEQ(a,b)	((int)((a)-(b)) <= 0)
4596 +
4597 +#define	IEEE80211_NWID_LEN			32
4598 +
4599 +#define	IEEE80211_QOS_TXOP			0x00ff
4600 +/* bit 8 is reserved */
4601 +#define	IEEE80211_QOS_ACKPOLICY			0x60
4602 +#define	IEEE80211_QOS_ACKPOLICY_S		5
4603 +#define	IEEE80211_QOS_EOSP			0x10
4604 +#define	IEEE80211_QOS_EOSP_S			4
4605 +#define	IEEE80211_QOS_TID			0x0f
4606 +
4607 +#define IEEE80211_FRM_HAS_BODY(_wh)			\
4608 +	(((_wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=	\
4609 +			IEEE80211_FC0_TYPE_CTL)
4610 +
4611 +/*
4612 + * Country/Region Codes from MS WINNLS.H
4613 + * Numbering from ISO 3166
4614 + * XXX belongs elsewhere
4615 + */
4616 +enum CountryCode {
4617 +	CTRY_ALBANIA              = 8,       /* Albania */
4618 +	CTRY_ALGERIA              = 12,      /* Algeria */
4619 +	CTRY_ARGENTINA            = 32,      /* Argentina */
4620 +	CTRY_ARMENIA              = 51,      /* Armenia */
4621 +	CTRY_AUSTRALIA            = 36,      /* Australia */
4622 +	CTRY_AUSTRIA              = 40,      /* Austria */
4623 +	CTRY_AZERBAIJAN           = 31,      /* Azerbaijan */
4624 +	CTRY_BAHRAIN              = 48,      /* Bahrain */
4625 +	CTRY_BELARUS              = 112,     /* Belarus */
4626 +	CTRY_BELGIUM              = 56,      /* Belgium */
4627 +	CTRY_BELIZE               = 84,      /* Belize */
4628 +	CTRY_BOLIVIA              = 68,      /* Bolivia */
4629 +	CTRY_BRAZIL               = 76,      /* Brazil */
4630 +	CTRY_BRUNEI_DARUSSALAM    = 96,      /* Brunei Darussalam */
4631 +	CTRY_BULGARIA             = 100,     /* Bulgaria */
4632 +	CTRY_CANADA               = 124,     /* Canada */
4633 +	CTRY_CHILE                = 152,     /* Chile */
4634 +	CTRY_CHINA                = 156,     /* People's Republic of China */
4635 +	CTRY_COLOMBIA             = 170,     /* Colombia */
4636 +	CTRY_COSTA_RICA           = 188,     /* Costa Rica */
4637 +	CTRY_CROATIA              = 191,     /* Croatia */
4638 +	CTRY_CYPRUS               = 196,
4639 +	CTRY_CZECH                = 203,     /* Czech Republic */
4640 +	CTRY_DENMARK              = 208,     /* Denmark */
4641 +	CTRY_DOMINICAN_REPUBLIC   = 214,     /* Dominican Republic */
4642 +	CTRY_ECUADOR              = 218,     /* Ecuador */
4643 +	CTRY_EGYPT                = 818,     /* Egypt */
4644 +	CTRY_EL_SALVADOR          = 222,     /* El Salvador */
4645 +	CTRY_ESTONIA              = 233,     /* Estonia */
4646 +	CTRY_FAEROE_ISLANDS       = 234,     /* Faeroe Islands */
4647 +	CTRY_FINLAND              = 246,     /* Finland */
4648 +	CTRY_FRANCE               = 250,     /* France */
4649 +	CTRY_FRANCE2              = 255,     /* France2 */
4650 +	CTRY_GEORGIA              = 268,     /* Georgia */
4651 +	CTRY_GERMANY              = 276,     /* Germany */
4652 +	CTRY_GREECE               = 300,     /* Greece */
4653 +	CTRY_GUATEMALA            = 320,     /* Guatemala */
4654 +	CTRY_HONDURAS             = 340,     /* Honduras */
4655 +	CTRY_HONG_KONG            = 344,     /* Hong Kong S.A.R., P.R.C. */
4656 +	CTRY_HUNGARY              = 348,     /* Hungary */
4657 +	CTRY_ICELAND              = 352,     /* Iceland */
4658 +	CTRY_INDIA                = 356,     /* India */
4659 +	CTRY_INDONESIA            = 360,     /* Indonesia */
4660 +	CTRY_IRAN                 = 364,     /* Iran */
4661 +	CTRY_IRAQ                 = 368,     /* Iraq */
4662 +	CTRY_IRELAND              = 372,     /* Ireland */
4663 +	CTRY_ISRAEL               = 376,     /* Israel */
4664 +	CTRY_ITALY                = 380,     /* Italy */
4665 +	CTRY_JAMAICA              = 388,     /* Jamaica */
4666 +	CTRY_JAPAN                = 392,     /* Japan */
4667 +	CTRY_JAPAN1               = 393,     /* Japan (JP1) */
4668 +	CTRY_JAPAN2               = 394,     /* Japan (JP0) */
4669 +	CTRY_JAPAN3               = 395,     /* Japan (JP1-1) */
4670 +	CTRY_JAPAN4               = 396,     /* Japan (JE1) */
4671 +	CTRY_JAPAN5               = 397,     /* Japan (JE2) */
4672 +	CTRY_JAPAN6               = 399,	 /* Japan (JP6) */
4673 +	CTRY_JAPAN7               = 900,	 /* Japan */
4674 +	CTRY_JAPAN8               = 901,	 /* Japan */
4675 +	CTRY_JAPAN9               = 902,	 /* Japan */
4676 +	CTRY_JAPAN10	      = 903,	 /* Japan */
4677 +	CTRY_JAPAN11	      = 904,	 /* Japan */
4678 +	CTRY_JAPAN12	      = 905,	 /* Japan */
4679 +	CTRY_JAPAN13	      = 906,	 /* Japan */
4680 +	CTRY_JAPAN14	      = 907,	 /* Japan */
4681 +	CTRY_JAPAN15	      = 908,	 /* Japan */
4682 +	CTRY_JAPAN16	      = 909,	 /* Japan */
4683 +	CTRY_JAPAN17	      = 910,	 /* Japan */
4684 +	CTRY_JAPAN18	      = 911,	 /* Japan */
4685 +	CTRY_JAPAN19	      = 912,	 /* Japan */
4686 +	CTRY_JAPAN20	      = 913,	 /* Japan */
4687 +	CTRY_JAPAN21	      = 914,	 /* Japan */
4688 +	CTRY_JAPAN22	      = 915,	 /* Japan */
4689 +	CTRY_JAPAN23	      = 916,	 /* Japan */
4690 +	CTRY_JAPAN24	      = 917,	 /* Japan */
4691 +	CTRY_JAPAN25	      = 918,	 /* Japan */
4692 +	CTRY_JAPAN26	      = 919,	 /* Japan */
4693 +	CTRY_JAPAN27	      = 920,	 /* Japan */
4694 +	CTRY_JAPAN28	      = 921,	 /* Japan */
4695 +	CTRY_JAPAN29	      = 922,	 /* Japan */
4696 +	CTRY_JAPAN30	      = 923,	 /* Japan */
4697 +	CTRY_JAPAN31	      = 924,	 /* Japan */
4698 +	CTRY_JAPAN32	      = 925,	 /* Japan */
4699 +	CTRY_JAPAN33	      = 926,	 /* Japan */
4700 +	CTRY_JAPAN34	      = 927,	 /* Japan */
4701 +	CTRY_JAPAN35	      = 928,	 /* Japan */
4702 +	CTRY_JAPAN36	      = 929,	 /* Japan */
4703 +	CTRY_JAPAN37	      = 930,	 /* Japan */
4704 +	CTRY_JAPAN38	      = 931,	 /* Japan */
4705 +	CTRY_JAPAN39	      = 932,	 /* Japan */
4706 +	CTRY_JAPAN40	      = 933,	 /* Japan */
4707 +	CTRY_JAPAN41	      = 934,	 /* Japan */
4708 +	CTRY_JAPAN42	      = 935,	 /* Japan */
4709 +	CTRY_JAPAN43	      = 936,	 /* Japan */
4710 +	CTRY_JAPAN44	      = 937,	 /* Japan */
4711 +	CTRY_JAPAN45	      = 938,	 /* Japan */
4712 +	CTRY_JAPAN46	      = 939,	 /* Japan */
4713 +	CTRY_JAPAN47	      = 940,	 /* Japan */
4714 +	CTRY_JAPAN48	      = 941,	 /* Japan */
4715 +	CTRY_JORDAN               = 400,     /* Jordan */
4716 +	CTRY_KAZAKHSTAN           = 398,     /* Kazakhstan */
4717 +	CTRY_KENYA                = 404,     /* Kenya */
4718 +	CTRY_KOREA_NORTH          = 408,     /* North Korea */
4719 +	CTRY_KOREA_ROC            = 410,     /* South Korea */
4720 +	CTRY_KOREA_ROC2           = 411,     /* South Korea */
4721 +	CTRY_KUWAIT               = 414,     /* Kuwait */
4722 +	CTRY_LATVIA               = 428,     /* Latvia */
4723 +	CTRY_LEBANON              = 422,     /* Lebanon */
4724 +	CTRY_LIBYA                = 434,     /* Libya */
4725 +	CTRY_LIECHTENSTEIN        = 438,     /* Liechtenstein */
4726 +	CTRY_LITHUANIA            = 440,     /* Lithuania */
4727 +	CTRY_LUXEMBOURG           = 442,     /* Luxembourg */
4728 +	CTRY_MACAU                = 446,     /* Macau */
4729 +	CTRY_MACEDONIA            = 807,     /* the Former Yugoslav Republic of Macedonia */
4730 +	CTRY_MALAYSIA             = 458,     /* Malaysia */
4731 +	CTRY_MEXICO               = 484,     /* Mexico */
4732 +	CTRY_MONACO               = 492,     /* Principality of Monaco */
4733 +	CTRY_MOROCCO              = 504,     /* Morocco */
4734 +	CTRY_NETHERLANDS          = 528,     /* Netherlands */
4735 +	CTRY_NEW_ZEALAND          = 554,     /* New Zealand */
4736 +	CTRY_NICARAGUA            = 558,     /* Nicaragua */
4737 +	CTRY_NORWAY               = 578,     /* Norway */
4738 +	CTRY_OMAN                 = 512,     /* Oman */
4739 +	CTRY_PAKISTAN             = 586,     /* Islamic Republic of Pakistan */
4740 +	CTRY_PANAMA               = 591,     /* Panama */
4741 +	CTRY_PARAGUAY             = 600,     /* Paraguay */
4742 +	CTRY_PERU                 = 604,     /* Peru */
4743 +	CTRY_PHILIPPINES          = 608,     /* Republic of the Philippines */
4744 +	CTRY_POLAND               = 616,     /* Poland */
4745 +	CTRY_PORTUGAL             = 620,     /* Portugal */
4746 +	CTRY_PUERTO_RICO          = 630,     /* Puerto Rico */
4747 +	CTRY_QATAR                = 634,     /* Qatar */
4748 +	CTRY_ROMANIA              = 642,     /* Romania */
4749 +	CTRY_RUSSIA               = 643,     /* Russia */
4750 +	CTRY_SAUDI_ARABIA         = 682,     /* Saudi Arabia */
4751 +	CTRY_SINGAPORE            = 702,     /* Singapore */
4752 +	CTRY_SLOVAKIA             = 703,     /* Slovak Republic */
4753 +	CTRY_SLOVENIA             = 705,     /* Slovenia */
4754 +	CTRY_SOUTH_AFRICA         = 710,     /* South Africa */
4755 +	CTRY_SPAIN                = 724,     /* Spain */
4756 +	CTRY_SWEDEN               = 752,     /* Sweden */
4757 +	CTRY_SWITZERLAND          = 756,     /* Switzerland */
4758 +	CTRY_SYRIA                = 760,     /* Syria */
4759 +	CTRY_TAIWAN               = 158,     /* Taiwan */
4760 +	CTRY_THAILAND             = 764,     /* Thailand */
4761 +	CTRY_TRINIDAD_Y_TOBAGO    = 780,     /* Trinidad y Tobago */
4762 +	CTRY_TUNISIA              = 788,     /* Tunisia */
4763 +	CTRY_TURKEY               = 792,     /* Turkey */
4764 +	CTRY_UAE                  = 784,     /* U.A.E. */
4765 +	CTRY_UKRAINE              = 804,     /* Ukraine */
4766 +	CTRY_UNITED_KINGDOM       = 826,     /* United Kingdom */
4767 +	CTRY_UNITED_STATES        = 840,     /* United States */
4768 +	CTRY_UNITED_STATES_FCC49  = 842,     /* United States (Public Safety)*/
4769 +	CTRY_URUGUAY              = 858,     /* Uruguay */
4770 +	CTRY_UZBEKISTAN           = 860,     /* Uzbekistan */
4771 +	CTRY_VENEZUELA            = 862,     /* Venezuela */
4772 +	CTRY_VIET_NAM             = 704,     /* Viet Nam */
4773 +	CTRY_YEMEN                = 887,     /* Yemen */
4774 +	CTRY_ZIMBABWE             = 716      /* Zimbabwe */
4775 +};
4776 +
4777 +/* 
4778 + * Generic information element
4779 + */
4780 +struct ieee80211_ie {
4781 +	u_int8_t id;
4782 +	u_int8_t len;
4783 +	u_int8_t info[0];
4784 +} __packed;
4785 +
4786 +/* 
4787 + * Country information element.
4788 + */
4789 +#define IEEE80211_COUNTRY_MAX_TRIPLETS (83)
4790 +struct ieee80211_ie_country {
4791 +	u_int8_t country_id;
4792 +	u_int8_t country_len;
4793 +	u_int8_t country_str[3];
4794 +	u_int8_t country_triplet[IEEE80211_COUNTRY_MAX_TRIPLETS * 3];
4795 +} __packed;
4796 +
4797 +/*
4798 + * Power Constraint information element.
4799 + */
4800 +struct ieee80211_ie_pwrcnstr {
4801 +	u_int8_t pc_id;			/* IEEE80211_ELEMID_PWRCNSTR */
4802 +	u_int8_t pc_len;		/* == 2 */
4803 +	u_int8_t pc_lpc;		/* Local Power Constraint [dB] */
4804 +} __packed;
4805 +
4806 +/*
4807 + * Power Capability information element.
4808 + */
4809 +struct ieee80211_ie_pwrcap {
4810 +	u_int8_t pc_id;			/* IEEE80211_ELEMID_PWRCAP */
4811 +	u_int8_t pc_len;		/* == 2 */
4812 +	int8_t pc_mintxpow;		/* Minimum Transmit Power Capability [dBm] */
4813 +	int8_t pc_maxtxpow;		/* Maximum Transmit Power Capability [dBm] */
4814 +} __packed;
4815 +
4816 +/*
4817 + * Supported Channels information element.
4818 + */
4819 +#define IEEE80211_SUPPCHAN_MAX_PAIRS (127)
4820 +struct ieee80211_ie_sc {
4821 +	u_int8_t sc_id;			/* IEEE80211_ELEMID_SUPPCHAN */
4822 +	u_int8_t sc_len;		/* == 2 * number of sc_subband elements */
4823 +	struct {
4824 +		u_int8_t sc_first;	/* First Channel Number */
4825 +		u_int8_t sc_number;	/* Number of Channels */
4826 +	} __packed sc_subband[IEEE80211_SUPPCHAN_MAX_PAIRS];
4827 +} __packed;
4828 +
4829 +/*
4830 + * Channel Switch Announcement information element.
4831 + */
4832 +struct ieee80211_ie_csa {
4833 +	u_int8_t csa_id;	/* IEEE80211_ELEMID_CHANSWITCHANN */
4834 +	u_int8_t csa_len;	/* == 3 */
4835 +	u_int8_t csa_mode;	/* Channel Switch Mode: 1 == stop transmission until CS */
4836 +	u_int8_t csa_chan;	/* New Channel Number */
4837 +	u_int8_t csa_count;	/* TBTTs until Channel Switch happens */
4838 +} __packed;
4839 +
4840 +/* minimal Channel Switch Count in the initial announcement */
4841 +#define IEEE80211_CSA_PROTECTION_PERIOD 3
4842 +
4843 +/* maximum allowed deviance of measurement of intervals between CSA in Beacons */
4844 +#define IEEE80211_CSA_SANITY_THRESHOLD 100
4845 +
4846 +
4847 +/* does frame have QoS sequence control data */
4848 +#define	IEEE80211_QOS_HAS_SEQ(wh) \
4849 +	(((wh)->i_fc[0] & \
4850 +	  (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
4851 +	  (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
4852 +
4853 +#define WME_QOSINFO_COUNT	0x0f  /* Mask for Param Set Count field */
4854 +/*
4855 + * WME/802.11e information element.
4856 + */
4857 +struct ieee80211_ie_wme {
4858 +	u_int8_t wme_id;		/* IEEE80211_ELEMID_VENDOR */
4859 +	u_int8_t wme_len;	/* length in bytes */
4860 +	u_int8_t wme_oui[3];	/* 0x00, 0x50, 0xf2 */
4861 +	u_int8_t wme_type;	/* OUI type */
4862 +	u_int8_t wme_subtype;	/* OUI subtype */
4863 +	u_int8_t wme_version;	/* spec revision */
4864 +	u_int8_t wme_info;	/* QoS info */
4865 +} __packed;
4866 +
4867 +/*
4868 + * WME/802.11e Tspec Element
4869 + */
4870 +struct ieee80211_wme_tspec {
4871 +	u_int8_t ts_id;
4872 +	u_int8_t ts_len;
4873 +	u_int8_t ts_oui[3];
4874 +	u_int8_t ts_oui_type;
4875 +	u_int8_t ts_oui_subtype;
4876 +	u_int8_t ts_version;
4877 +	u_int8_t ts_tsinfo[3];
4878 +	u_int8_t ts_nom_msdu[2];
4879 +	u_int8_t ts_max_msdu[2];
4880 +	u_int8_t ts_min_svc[4];
4881 +	u_int8_t ts_max_svc[4];
4882 +	u_int8_t ts_inactv_intv[4];
4883 +	u_int8_t ts_susp_intv[4];
4884 +	u_int8_t ts_start_svc[4];
4885 +	u_int8_t ts_min_rate[4];
4886 +	u_int8_t ts_mean_rate[4];
4887 +	u_int8_t ts_max_burst[4];
4888 +	u_int8_t ts_min_phy[4];
4889 +	u_int8_t ts_peak_rate[4];
4890 +	u_int8_t ts_delay[4];
4891 +	u_int8_t ts_surplus[2];
4892 +	u_int8_t ts_medium_time[2];
4893 +} __packed;
4894 +
4895 +/*
4896 + * WME AC parameter field
4897 + */
4898 +
4899 +struct ieee80211_wme_acparams {
4900 +	u_int8_t acp_aci_aifsn;
4901 +	u_int8_t acp_logcwminmax;
4902 +	u_int16_t acp_txop;
4903 +} __packed;
4904 +
4905 +#define IEEE80211_WME_PARAM_LEN 24
4906 +#define WME_NUM_AC		4	/* 4 AC categories */
4907 +
4908 +#define WME_PARAM_ACI		0x60	/* Mask for ACI field */
4909 +#define WME_PARAM_ACI_S		5	/* Shift for ACI field */
4910 +#define WME_PARAM_ACM		0x10	/* Mask for ACM bit */
4911 +#define WME_PARAM_ACM_S		4	/* Shift for ACM bit */
4912 +#define WME_PARAM_AIFSN		0x0f	/* Mask for aifsn field */
4913 +#define WME_PARAM_AIFSN_S	0	/* Shift for aifsn field */
4914 +#define WME_PARAM_LOGCWMIN	0x0f	/* Mask for CwMin field (in log) */
4915 +#define WME_PARAM_LOGCWMIN_S	0	/* Shift for CwMin field */
4916 +#define WME_PARAM_LOGCWMAX	0xf0	/* Mask for CwMax field (in log) */
4917 +#define WME_PARAM_LOGCWMAX_S	4	/* Shift for CwMax field */
4918 +
4919 +#define WME_AC_TO_TID(_ac) (       \
4920 +	((_ac) == WME_AC_VO) ? 6 : \
4921 +	((_ac) == WME_AC_VI) ? 5 : \
4922 +	((_ac) == WME_AC_BK) ? 1 : \
4923 +	0)
4924 +
4925 +#define TID_TO_WME_AC(_tid) (      \
4926 +	((_tid) < 1) ? WME_AC_BE : \
4927 +	((_tid) < 3) ? WME_AC_BK : \
4928 +	((_tid) < 6) ? WME_AC_VI : \
4929 +	WME_AC_VO)
4930 +
4931 +/*
4932 + * WME Parameter Element
4933 + */
4934 +
4935 +struct ieee80211_wme_param {
4936 +	u_int8_t param_id;
4937 +	u_int8_t param_len;
4938 +	u_int8_t param_oui[3];
4939 +	u_int8_t param_oui_type;
4940 +	u_int8_t param_oui_sybtype;
4941 +	u_int8_t param_version;
4942 +	u_int8_t param_qosInfo;
4943 +	u_int8_t param_reserved;
4944 +	struct ieee80211_wme_acparams	params_acParams[WME_NUM_AC];
4945 +} __packed;
4946 +
4947 +/*
4948 + * WME U-APSD qos info field defines
4949 + */
4950 +#define WME_CAPINFO_UAPSD_EN			0x00000080
4951 +#define WME_CAPINFO_UAPSD_VO			0x00000001
4952 +#define WME_CAPINFO_UAPSD_VI			0x00000002
4953 +#define WME_CAPINFO_UAPSD_BK			0x00000004
4954 +#define WME_CAPINFO_UAPSD_BE			0x00000008
4955 +#define WME_CAPINFO_UAPSD_ACFLAGS_SHIFT		0
4956 +#define WME_CAPINFO_UAPSD_ACFLAGS_MASK		0xF
4957 +#define WME_CAPINFO_UAPSD_MAXSP_SHIFT		5
4958 +#define WME_CAPINFO_UAPSD_MAXSP_MASK		0x3
4959 +#define WME_CAPINFO_IE_OFFSET			8
4960 +#define WME_UAPSD_MAXSP(_qosinfo)					\
4961 +		(((_qosinfo) >> WME_CAPINFO_UAPSD_MAXSP_SHIFT) & 	\
4962 +		 WME_CAPINFO_UAPSD_MAXSP_MASK)
4963 +#define WME_UAPSD_AC_ENABLED(_ac, _qosinfo)				\
4964 +		((1 << (3 - (_ac))) & (					\
4965 +		 ((_qosinfo) >> WME_CAPINFO_UAPSD_ACFLAGS_SHIFT) &	\
4966 +		 WME_CAPINFO_UAPSD_ACFLAGS_MASK))
4967 +
4968 +/*
4969 + * Atheros Advanced Capability information element.
4970 + */
4971 +struct ieee80211_ie_athAdvCap {
4972 +	u_int8_t athAdvCap_id;		/* IEEE80211_ELEMID_VENDOR */
4973 +	u_int8_t athAdvCap_len;		/* length in bytes */
4974 +	u_int8_t athAdvCap_oui[3];	/* 0x00, 0x03, 0x7f */
4975 +	u_int8_t athAdvCap_type;	/* OUI type */
4976 +	u_int8_t athAdvCap_subtype;	/* OUI subtype */
4977 +	u_int8_t athAdvCap_version;	/* spec revision */
4978 +	u_int8_t athAdvCap_capability;	/* Capability info */
4979 +	u_int16_t athAdvCap_defKeyIndex;
4980 +} __packed;
4981 +
4982 +/*
4983 + * Atheros XR information element.
4984 + */
4985 +struct ieee80211_xr_param {
4986 +	u_int8_t param_id;
4987 +	u_int8_t param_len;
4988 +	u_int8_t param_oui[3];
4989 +	u_int8_t param_oui_type;
4990 +	u_int8_t param_oui_sybtype;
4991 +	u_int8_t param_version;
4992 +	u_int8_t param_Info;
4993 +	u_int8_t param_base_bssid[IEEE80211_ADDR_LEN];
4994 +	u_int8_t param_xr_bssid[IEEE80211_ADDR_LEN];
4995 +	u_int16_t param_xr_beacon_interval;
4996 +	u_int8_t param_base_ath_capability;
4997 +	u_int8_t param_xr_ath_capability;
4998 +} __packed;
4999 +
5000 +/* Atheros capabilities */
5001 +#define IEEE80211_ATHC_TURBOP	0x0001		/* Turbo Prime */
5002 +#define IEEE80211_ATHC_COMP	0x0002		/* Compression */
5003 +#define IEEE80211_ATHC_FF	0x0004		/* Fast Frames */
5004 +#define IEEE80211_ATHC_XR	0x0008		/* Xtended Range support */
5005 +#define IEEE80211_ATHC_AR	0x0010		/* Advanced Radar support */
5006 +#define IEEE80211_ATHC_BURST	0x0020		/* Bursting - not negotiated */
5007 +#define IEEE80211_ATHC_WME	0x0040		/* CWMin tuning */
5008 +#define IEEE80211_ATHC_BOOST	0x0080		/* Boost */
5009 +
5010 +/*
5011 + * Management Notification Frame
5012 + */
5013 +struct ieee80211_mnf {
5014 +	u_int8_t mnf_category;
5015 +	u_int8_t mnf_action;
5016 +	u_int8_t mnf_dialog;
5017 +	u_int8_t mnf_status;
5018 +} __packed;
5019 +#define	MNF_SETUP_REQ	0
5020 +#define	MNF_SETUP_RESP	1
5021 +#define	MNF_TEARDOWN	2
5022 +
5023 +/*
5024 + * Control frames.
5025 + */
5026 +struct ieee80211_frame_min {
5027 +	u_int8_t i_fc[2];
5028 +	__le16 i_dur;
5029 +	u_int8_t i_addr1[IEEE80211_ADDR_LEN];
5030 +	u_int8_t i_addr2[IEEE80211_ADDR_LEN];
5031 +	/* FCS */
5032 +} __packed;
5033 +
5034 +struct ieee80211_frame_rts {
5035 +	u_int8_t i_fc[2];
5036 +	__le16 i_dur;
5037 +	u_int8_t i_ra[IEEE80211_ADDR_LEN];
5038 +	u_int8_t i_ta[IEEE80211_ADDR_LEN];
5039 +	/* FCS */
5040 +} __packed;
5041 +
5042 +struct ieee80211_frame_cts {
5043 +	u_int8_t i_fc[2];
5044 +	__le16 i_dur;
5045 +	u_int8_t i_ra[IEEE80211_ADDR_LEN];
5046 +	/* FCS */
5047 +} __packed;
5048 +
5049 +struct ieee80211_frame_ack {
5050 +	u_int8_t i_fc[2];
5051 +	__le16 i_dur;
5052 +	u_int8_t i_ra[IEEE80211_ADDR_LEN];
5053 +	/* FCS */
5054 +} __packed;
5055 +
5056 +struct ieee80211_frame_pspoll {
5057 +	u_int8_t i_fc[2];
5058 +	u_int8_t i_aid[2];
5059 +	u_int8_t i_bssid[IEEE80211_ADDR_LEN];
5060 +	u_int8_t i_ta[IEEE80211_ADDR_LEN];
5061 +	/* FCS */
5062 +} __packed;
5063 +
5064 +struct ieee80211_frame_cfend {		/* NB: also CF-End+CF-Ack */
5065 +	u_int8_t i_fc[2];
5066 +	__le16 i_dur;	/* should be zero */
5067 +	u_int8_t i_ra[IEEE80211_ADDR_LEN];
5068 +	u_int8_t i_bssid[IEEE80211_ADDR_LEN];
5069 +	/* FCS */
5070 +} __packed;
5071 +
5072 +/*
5073 + * BEACON management packets
5074 + *
5075 + *	octet timestamp[8]
5076 + *	octet beacon interval[2]
5077 + *	octet capability information[2]
5078 + *	information element
5079 + *		octet elemid
5080 + *		octet length
5081 + *		octet information[length]
5082 + */
5083 +
5084 +typedef u_int8_t *ieee80211_mgt_beacon_t;
5085 +
5086 +#define	IEEE80211_BEACON_INTERVAL(beacon) \
5087 +	((beacon)[8] | ((beacon)[9] << 8))
5088 +#define	IEEE80211_BEACON_CAPABILITY(beacon) \
5089 +	((beacon)[10] | ((beacon)[11] << 8))
5090 +
5091 +#define	IEEE80211_CAPINFO_ESS			0x0001
5092 +#define	IEEE80211_CAPINFO_IBSS			0x0002
5093 +#define	IEEE80211_CAPINFO_CF_POLLABLE		0x0004
5094 +#define	IEEE80211_CAPINFO_CF_POLLREQ		0x0008
5095 +#define	IEEE80211_CAPINFO_PRIVACY		0x0010
5096 +#define	IEEE80211_CAPINFO_SHORT_PREAMBLE	0x0020
5097 +#define	IEEE80211_CAPINFO_PBCC			0x0040
5098 +#define	IEEE80211_CAPINFO_CHNL_AGILITY		0x0080
5099 +/* bits 8-9 are reserved (8 now for spectrum management) */
5100 +#define IEEE80211_CAPINFO_SPECTRUM_MGMT		0x0100
5101 +#define	IEEE80211_CAPINFO_SHORT_SLOTTIME	0x0400
5102 +#define	IEEE80211_CAPINFO_RSN			0x0800
5103 +/* bit 12 is reserved */
5104 +#define	IEEE80211_CAPINFO_DSSSOFDM		0x2000
5105 +/* bits 14-15 are reserved */
5106 +
5107 +/*
5108 + * 802.11i/WPA information element (maximally sized).
5109 + */
5110 +struct ieee80211_ie_wpa {
5111 +	u_int8_t wpa_id;			/* IEEE80211_ELEMID_VENDOR */
5112 +	u_int8_t wpa_len;		/* length in bytes */
5113 +	u_int8_t wpa_oui[3];		/* 0x00, 0x50, 0xf2 */
5114 +	u_int8_t wpa_type;		/* OUI type */
5115 +	u_int16_t wpa_version;		/* spec revision */
5116 +	u_int32_t wpa_mcipher[1];	/* multicast/group key cipher */
5117 +	u_int16_t wpa_uciphercnt;	/* # pairwise key ciphers */
5118 +	u_int32_t wpa_uciphers[8];	/* ciphers */
5119 +	u_int16_t wpa_authselcnt;	/* authentication selector cnt*/
5120 +	u_int32_t wpa_authsels[8];	/* selectors */
5121 +	u_int16_t wpa_caps;		/* 802.11i capabilities */
5122 +	u_int16_t wpa_pmkidcnt;		/* 802.11i pmkid count */
5123 +	u_int16_t wpa_pmkids[8];	/* 802.11i pmkids */
5124 +} __packed;
5125 +
5126 +/*
5127 + * Management information element payloads.
5128 + */
5129 +
5130 +enum {
5131 +	IEEE80211_ELEMID_SSID		= 0,
5132 +	IEEE80211_ELEMID_RATES		= 1,
5133 +	IEEE80211_ELEMID_FHPARMS	= 2,
5134 +	IEEE80211_ELEMID_DSPARMS	= 3,
5135 +	IEEE80211_ELEMID_CFPARMS	= 4,
5136 +	IEEE80211_ELEMID_TIM		= 5,
5137 +	IEEE80211_ELEMID_IBSSPARMS	= 6,
5138 +	IEEE80211_ELEMID_COUNTRY	= 7,
5139 +	IEEE80211_ELEMID_HOPPATRNPARMS  = 8,
5140 +	IEEE80211_ELEMID_HOPPATRNTABLE  = 9,
5141 +	IEEE80211_ELEMID_REQINFO	= 10,
5142 +	IEEE80211_ELEMID_QBSSLOAD       = 11,
5143 +	IEEE80211_ELEMID_EDCAPARAM      = 12,
5144 +	IEEE80211_ELEMID_TSPEC		= 13,
5145 +	IEEE80211_ELEMID_TRAFCLASS      = 14,
5146 +	IEEE80211_ELEMID_SCHEDULE       = 15,
5147 +	IEEE80211_ELEMID_CHALLENGE	= 16,
5148 +	/* 17-31 reserved for challenge text extension */
5149 +	IEEE80211_ELEMID_PWRCNSTR	= 32,
5150 +	IEEE80211_ELEMID_PWRCAP		= 33,
5151 +	IEEE80211_ELEMID_TPCREQ		= 34,
5152 +	IEEE80211_ELEMID_TPCREP		= 35,
5153 +	IEEE80211_ELEMID_SUPPCHAN	= 36,
5154 +	IEEE80211_ELEMID_CHANSWITCHANN	= 37,
5155 +	IEEE80211_ELEMID_MEASREQ	= 38,
5156 +	IEEE80211_ELEMID_MEASREP	= 39,
5157 +	IEEE80211_ELEMID_QUIET		= 40,
5158 +	IEEE80211_ELEMID_IBSSDFS	= 41,
5159 +	IEEE80211_ELEMID_ERP		= 42,
5160 +	IEEE80211_ELEMID_TSDELAY	= 43,
5161 +	IEEE80211_ELEMID_TCLASSPROC     = 44,
5162 +	IEEE80211_ELEMID_QOS		= 46,
5163 +	IEEE80211_ELEMID_RSN		= 48,
5164 +	/* 49 reserved */
5165 +	IEEE80211_ELEMID_XRATES		= 50,
5166 +	/* 128-129 proprietary elements used by Agere chipsets */
5167 +	IEEE80211_ELEMID_AGERE1		= 128,
5168 +	IEEE80211_ELEMID_AGERE2		= 129,
5169 +	IEEE80211_ELEMID_TPC		= 150,
5170 +	IEEE80211_ELEMID_CCKM		= 156,
5171 +	IEEE80211_ELEMID_VENDOR		= 221,	/* vendor private */
5172 +};
5173 +
5174 +#define IEEE80211_CHANSWITCHANN_BYTES 	5
5175 +#define BITCTL_BUFD_MCAST       	1
5176 +#define BITCTL_BUFD_UCAST_AID_MASK 	((u_int8_t)~(BITCTL_BUFD_MCAST))
5177 +#define BITCTL_BUFD_UCAST_AID_SHIFT 	1
5178 +
5179 +struct ieee80211_tim_ie {
5180 +	u_int8_t	tim_ie;			/* IEEE80211_ELEMID_TIM */
5181 +	u_int8_t	tim_len;
5182 +	u_int8_t	tim_count;		/* DTIM count */
5183 +	u_int8_t	tim_period;		/* DTIM period */
5184 +	u_int8_t	tim_bitctl;		/* bitmap control */
5185 +	u_int8_t	tim_bitmap[1];		/* variable-length bitmap */
5186 +} __packed;
5187 +
5188 +struct ieee80211_country_ie {
5189 +	u_int8_t	ie;			/* IEEE80211_ELEMID_COUNTRY */
5190 +	u_int8_t	len;
5191 +	u_int8_t	cc[3];			/* ISO CC+(I)ndoor/(O)utdoor */
5192 +	struct {
5193 +		u_int8_t schan;			/* starting channel */
5194 +		u_int8_t nchan;			/* number channels */
5195 +		u_int8_t maxtxpwr;		/* tx power cap */
5196 +	} __packed band[4];			/* up to 4 sub bands */
5197 +} __packed;
5198 +
5199 +#define IEEE80211_CHALLENGE_LEN		128
5200 +
5201 +#define IEEE80211_SUPPCHAN_LEN		26
5202 +
5203 +#define	IEEE80211_RATE_BASIC		0x80
5204 +#define	IEEE80211_RATE_VAL		0x7f
5205 +
5206 +/* EPR information element flags */
5207 +#define	IEEE80211_ERP_NON_ERP_PRESENT	0x01
5208 +#define	IEEE80211_ERP_USE_PROTECTION	0x02
5209 +#define	IEEE80211_ERP_LONG_PREAMBLE	0x04
5210 +
5211 +/* Atheros private advanced capabilities info */
5212 +#define	ATHEROS_CAP_TURBO_PRIME		0x01
5213 +#define	ATHEROS_CAP_COMPRESSION		0x02
5214 +#define	ATHEROS_CAP_FAST_FRAME		0x04
5215 +/* bits 3-6 reserved */
5216 +#define	ATHEROS_CAP_BOOST		0x80
5217 +
5218 +#define	ATH_OUI			0x7f0300		/* Atheros OUI */
5219 +#define	ATH_OUI_TYPE		0x01
5220 +#define	ATH_OUI_SUBTYPE		0x01
5221 +#define	ATH_OUI_VERSION		0x00
5222 +#define	ATH_OUI_TYPE_XR		0x03
5223 +#define	ATH_OUI_SUBTYPE_XR	0x01
5224 +#define	ATH_OUI_VER_XR		0x00
5225 +
5226 +#define	WPA_OUI			0xf25000
5227 +#define	WPA_OUI_TYPE		0x01
5228 +#define	WPA_VERSION		1		/* current supported version */
5229 +
5230 +#define	WPA_CSE_NULL		0x00
5231 +#define	WPA_CSE_WEP40		0x01
5232 +#define	WPA_CSE_TKIP		0x02
5233 +#define	WPA_CSE_CCMP		0x04
5234 +#define	WPA_CSE_WEP104		0x05
5235 +
5236 +#define	WPA_ASE_NONE		0x00
5237 +#define	WPA_ASE_8021X_UNSPEC	0x01
5238 +#define	WPA_ASE_8021X_PSK	0x02
5239 +
5240 +#define	RSN_OUI			0xac0f00
5241 +#define	RSN_VERSION		1		/* current supported version */
5242 +
5243 +#define	RSN_CSE_NULL		0x00
5244 +#define	RSN_CSE_WEP40		0x01
5245 +#define	RSN_CSE_TKIP		0x02
5246 +#define	RSN_CSE_WRAP		0x03
5247 +#define	RSN_CSE_CCMP		0x04
5248 +#define	RSN_CSE_WEP104		0x05
5249 +
5250 +#define	RSN_ASE_NONE		0x00
5251 +#define	RSN_ASE_8021X_UNSPEC	0x01
5252 +#define	RSN_ASE_8021X_PSK	0x02
5253 +
5254 +#define	RSN_CAP_PREAUTH		0x01
5255 +
5256 +#define	WME_OUI			0xf25000
5257 +#define	WME_OUI_TYPE		0x02
5258 +#define	WME_INFO_OUI_SUBTYPE	0x00
5259 +#define	WME_PARAM_OUI_SUBTYPE	0x01
5260 +#define	WME_VERSION		1
5261 +
5262 +/* WME stream classes */
5263 +#define	WME_AC_BE	0		/* best effort */
5264 +#define	WME_AC_BK	1		/* background */
5265 +#define	WME_AC_VI	2		/* video */
5266 +#define	WME_AC_VO	3		/* voice */
5267 +
5268 +/*
5269 + * AUTH management packets
5270 + *
5271 + *	octet algo[2]
5272 + *	octet seq[2]
5273 + *	octet status[2]
5274 + *	octet chal.id
5275 + *	octet chal.length
5276 + *	octet chal.text[253]
5277 + */
5278 +
5279 +typedef u_int8_t *ieee80211_mgt_auth_t;
5280 +
5281 +#define	IEEE80211_AUTH_ALGORITHM(auth) \
5282 +	((auth)[0] | ((auth)[1] << 8))
5283 +#define	IEEE80211_AUTH_TRANSACTION(auth) \
5284 +	((auth)[2] | ((auth)[3] << 8))
5285 +#define	IEEE80211_AUTH_STATUS(auth) \
5286 +	((auth)[4] | ((auth)[5] << 8))
5287 +
5288 +#define	IEEE80211_AUTH_ALG_OPEN		0x0000
5289 +#define	IEEE80211_AUTH_ALG_SHARED	0x0001
5290 +#define	IEEE80211_AUTH_ALG_LEAP		0x0080
5291 +
5292 +enum {
5293 +	IEEE80211_AUTH_OPEN_REQUEST		= 1,
5294 +	IEEE80211_AUTH_OPEN_RESPONSE		= 2,
5295 +};
5296 +
5297 +enum {
5298 +	IEEE80211_AUTH_SHARED_REQUEST		= 1,
5299 +	IEEE80211_AUTH_SHARED_CHALLENGE		= 2,
5300 +	IEEE80211_AUTH_SHARED_RESPONSE		= 3,
5301 +	IEEE80211_AUTH_SHARED_PASS		= 4,
5302 +};
5303 +
5304 +/*
5305 + * Reason codes
5306 + *
5307 + * Unlisted codes are reserved
5308 + */
5309 +
5310 +enum {
5311 +	IEEE80211_REASON_UNSPECIFIED		= 1,
5312 +	IEEE80211_REASON_AUTH_EXPIRE		= 2,
5313 +	IEEE80211_REASON_AUTH_LEAVE		= 3,
5314 +	IEEE80211_REASON_ASSOC_EXPIRE		= 4,
5315 +	IEEE80211_REASON_ASSOC_TOOMANY		= 5,
5316 +	IEEE80211_REASON_NOT_AUTHED		= 6,
5317 +	IEEE80211_REASON_NOT_ASSOCED		= 7,
5318 +	IEEE80211_REASON_ASSOC_LEAVE		= 8,
5319 +	IEEE80211_REASON_ASSOC_NOT_AUTHED	= 9,
5320 +
5321 +	IEEE80211_REASON_PWRCAP_UNACCEPTABLE	= 10,
5322 +	IEEE80211_REASON_SUPPCHAN_UNACCEPTABLE	= 11,
5323 +	IEEE80211_REASON_RSN_REQUIRED		= 11,
5324 +	IEEE80211_REASON_RSN_INCONSISTENT	= 12,
5325 +	IEEE80211_REASON_IE_INVALID		= 13,
5326 +	IEEE80211_REASON_MIC_FAILURE		= 14,
5327 +
5328 +	IEEE80211_STATUS_SUCCESS		= 0,
5329 +	IEEE80211_STATUS_UNSPECIFIED		= 1,
5330 +	IEEE80211_STATUS_CAPINFO		= 10,
5331 +	IEEE80211_STATUS_NOT_ASSOCED		= 11,
5332 +	IEEE80211_STATUS_OTHER			= 12,
5333 +	IEEE80211_STATUS_ALG			= 13,
5334 +	IEEE80211_STATUS_SEQUENCE		= 14,
5335 +	IEEE80211_STATUS_CHALLENGE		= 15,
5336 +	IEEE80211_STATUS_TIMEOUT		= 16,
5337 +	IEEE80211_STATUS_TOOMANY		= 17,
5338 +	IEEE80211_STATUS_BASIC_RATE		= 18,
5339 +	IEEE80211_STATUS_SP_REQUIRED		= 19,
5340 +	IEEE80211_STATUS_PBCC_REQUIRED		= 20,
5341 +	IEEE80211_STATUS_CA_REQUIRED		= 21,
5342 +	IEEE80211_STATUS_SM_REQUIRED		= 22,
5343 +	IEEE80211_STATUS_PWRCAP_UNACCEPTABLE	= 23,
5344 +	IEEE80211_STATUS_SUPPCHAN_UNACCEPTABLE	= 24,
5345 +	IEEE80211_STATUS_TOO_MANY_STATIONS	= 22,
5346 +	IEEE80211_STATUS_RATES			= 23,
5347 +	IEEE80211_STATUS_SHORTSLOT_REQUIRED	= 25,
5348 +	IEEE80211_STATUS_DSSSOFDM_REQUIRED	= 26,
5349 +};
5350 +
5351 +#define	IEEE80211_WEP_KEYLEN		5	/* 40bit */
5352 +#define	IEEE80211_WEP_IVLEN		3	/* 24bit */
5353 +#define	IEEE80211_WEP_KIDLEN		1	/* 1 octet */
5354 +#define	IEEE80211_WEP_CRCLEN		4	/* CRC-32 */
5355 +#define	IEEE80211_WEP_NKID		4	/* number of key ids */
5356 +
5357 +/*
5358 + * 802.11i defines an extended IV for use with non-WEP ciphers.
5359 + * When the EXTIV bit is set in the key id byte an additional
5360 + * 4 bytes immediately follow the IV for TKIP.  For CCMP the
5361 + * EXTIV bit is likewise set but the 8 bytes represent the
5362 + * CCMP header rather than IV+extended-IV.
5363 + */
5364 +#define	IEEE80211_WEP_EXTIV		0x20
5365 +#define	IEEE80211_WEP_EXTIVLEN		4	/* extended IV length */
5366 +#define	IEEE80211_WEP_MICLEN		8	/* trailing MIC */
5367 +
5368 +#define	IEEE80211_CRC_LEN		4
5369 +
5370 +/*
5371 + * Maximum acceptable MTU is:
5372 + *	IEEE80211_MAX_LEN - WEP overhead - CRC -
5373 + *		QoS overhead - RSN/WPA overhead
5374 + * Min is arbitrarily chosen > IEEE80211_MIN_LEN.  The default
5375 + * mtu is Ethernet-compatible; it's set by ether_ifattach.
5376 + */
5377 +#define	IEEE80211_MTU_MAX		2290
5378 +#define	IEEE80211_MTU_MIN		32
5379 +
5380 +#define	IEEE80211_MAX_LEN		(2300 + IEEE80211_CRC_LEN + \
5381 +	(IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
5382 +#define	IEEE80211_ACK_LEN \
5383 +	(sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
5384 +#define	IEEE80211_MIN_LEN \
5385 +	(sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
5386 +
5387 +/*
5388 + * The 802.11 spec says at most 2007 stations may be
5389 + * associated at once.  For most APs this is way more
5390 + * than is feasible so we use a default of 128.  This
5391 + * number may be overridden by the driver and/or by
5392 + * user configuration.
5393 + */
5394 +#define	IEEE80211_AID_MAX		2007
5395 +#define	IEEE80211_AID_DEF		128
5396 +
5397 +#define	IEEE80211_AID(b)	((b) &~ 0xc000)
5398 +
5399 +/* 
5400 + * RTS frame length parameters.  The default is specified in
5401 + * the 802.11 spec.  The max may be wrong for jumbo frames.
5402 + */
5403 +#define	IEEE80211_RTS_DEFAULT		512
5404 +#define	IEEE80211_RTS_MIN		1
5405 +#define	IEEE80211_RTS_MAX		2346
5406 +
5407 +/* 
5408 + * Regulatory extension identifier for country IE.
5409 + */
5410 +#define IEEE80211_REG_EXT_ID		201
5411 +
5412 +/*
5413 + * IEEE 802.11 timer synchronization function (TSF) timestamp length
5414 + */
5415 +#define IEEE80211_TSF_LEN		8
5416 +
5417 +#endif /* _NET80211_IEEE80211_H_ */
5418 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_ioctl.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_ioctl.h
5419 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_ioctl.h	1970-01-01 01:00:00.000000000 +0100
5420 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_ioctl.h	2008-06-19 17:34:17.000000000 +0200
5421 @@ -0,0 +1,707 @@
5422 +/*-
5423 + * Copyright (c) 2001 Atsushi Onoe
5424 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
5425 + * All rights reserved.
5426 + *
5427 + * Redistribution and use in source and binary forms, with or without
5428 + * modification, are permitted provided that the following conditions
5429 + * are met:
5430 + * 1. Redistributions of source code must retain the above copyright
5431 + *    notice, this list of conditions and the following disclaimer.
5432 + * 2. Redistributions in binary form must reproduce the above copyright
5433 + *    notice, this list of conditions and the following disclaimer in the
5434 + *    documentation and/or other materials provided with the distribution.
5435 + * 3. The name of the author may not be used to endorse or promote products
5436 + *    derived from this software without specific prior written permission.
5437 + *
5438 + * Alternatively, this software may be distributed under the terms of the
5439 + * GNU General Public License ("GPL") version 2 as published by the Free
5440 + * Software Foundation.
5441 + *
5442 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5443 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5444 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5445 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5446 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5447 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5448 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5449 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5450 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5451 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5452 + *
5453 + * $Id: ieee80211_ioctl.h 3314 2008-01-30 23:50:16Z mtaylor $
5454 + */
5455 +#ifndef _NET80211_IEEE80211_IOCTL_H_
5456 +#define _NET80211_IEEE80211_IOCTL_H_
5457 +
5458 +/*
5459 + * IEEE 802.11 ioctls.
5460 + */
5461 +#include <net80211/_ieee80211.h>
5462 +#include <net80211/ieee80211.h>
5463 +#include <net80211/ieee80211_crypto.h>
5464 +
5465 +/*
5466 + * Per/node (station) statistics available when operating as an AP.
5467 + */
5468 +struct ieee80211_nodestats {
5469 +	u_int32_t ns_rx_data;		/* rx data frames */
5470 +	u_int32_t ns_rx_mgmt;		/* rx management frames */
5471 +	u_int32_t ns_rx_ctrl;		/* rx control frames */
5472 +	u_int32_t ns_rx_ucast;		/* rx unicast frames */
5473 +	u_int32_t ns_rx_mcast;		/* rx multi/broadcast frames */
5474 +	u_int64_t ns_rx_bytes;		/* rx data count (bytes) */
5475 +	u_int64_t ns_rx_beacons;		/* rx beacon frames */
5476 +	u_int32_t ns_rx_proberesp;	/* rx probe response frames */
5477 +
5478 +	u_int32_t ns_rx_dup;		/* rx discard because it's a dup */
5479 +	u_int32_t ns_rx_noprivacy;	/* rx w/ wep but privacy off */
5480 +	u_int32_t ns_rx_wepfail;		/* rx wep processing failed */
5481 +	u_int32_t ns_rx_demicfail;	/* rx demic failed */
5482 +	u_int32_t ns_rx_decap;		/* rx decapsulation failed */
5483 +	u_int32_t ns_rx_defrag;		/* rx defragmentation failed */
5484 +	u_int32_t ns_rx_disassoc;	/* rx disassociation */
5485 +	u_int32_t ns_rx_deauth;		/* rx deauthentication */
5486 +	u_int32_t ns_rx_decryptcrc;	/* rx decrypt failed on crc */
5487 +	u_int32_t ns_rx_unauth;		/* rx on unauthorized port */
5488 +	u_int32_t ns_rx_unencrypted;	/* rx unecrypted w/ privacy */
5489 +
5490 +	u_int32_t ns_tx_data;		/* tx data frames */
5491 +	u_int32_t ns_tx_mgmt;		/* tx management frames */
5492 +	u_int32_t ns_tx_ucast;		/* tx unicast frames */
5493 +	u_int32_t ns_tx_mcast;		/* tx multi/broadcast frames */
5494 +	u_int64_t ns_tx_bytes;		/* tx data count (bytes) */
5495 +	u_int32_t ns_tx_probereq;	/* tx probe request frames */
5496 +	u_int32_t ns_tx_uapsd;		/* tx on uapsd queue */
5497 +
5498 +	u_int32_t ns_tx_novlantag;	/* tx discard due to no tag */
5499 +	u_int32_t ns_tx_vlanmismatch;	/* tx discard due to of bad tag */
5500 +
5501 +	u_int32_t ns_tx_eosplost;	/* uapsd EOSP retried out */
5502 +
5503 +	u_int32_t ns_ps_discard;		/* ps discard due to of age */
5504 +
5505 +	u_int32_t ns_uapsd_triggers;	/* uapsd triggers */
5506 +
5507 +	/* MIB-related state */
5508 +	u_int32_t ns_tx_assoc;		/* [re]associations */
5509 +	u_int32_t ns_tx_assoc_fail;	/* [re]association failures */
5510 +	u_int32_t ns_tx_auth;		/* [re]authentications */
5511 +	u_int32_t ns_tx_auth_fail;	/* [re]authentication failures*/
5512 +	u_int32_t ns_tx_deauth;		/* deauthentications */
5513 +	u_int32_t ns_tx_deauth_code;	/* last deauth reason */
5514 +	u_int32_t ns_tx_disassoc;	/* disassociations */
5515 +	u_int32_t ns_tx_disassoc_code;	/* last disassociation reason */
5516 +	u_int32_t ns_psq_drops;		/* power save queue drops */
5517 +};
5518 +
5519 +/*
5520 + * Summary statistics.
5521 + */
5522 +struct ieee80211_stats {
5523 +	u_int32_t is_rx_badversion;	/* rx frame with bad version */
5524 +	u_int32_t is_rx_tooshort;	/* rx frame too short */
5525 +	u_int32_t is_rx_wrongbss;	/* rx from wrong bssid */
5526 +	u_int32_t is_rx_dup;		/* rx discard due to it's a dup */
5527 +	u_int32_t is_rx_wrongdir;	/* rx w/ wrong direction */
5528 +	u_int32_t is_rx_mcastecho;	/* rx discard due to of mcast echo */
5529 +	u_int32_t is_rx_mcastdisabled;	/* rx discard due to of mcast disabled */
5530 +	u_int32_t is_rx_notassoc;	/* rx discard due to sta !assoc */
5531 +	u_int32_t is_rx_noprivacy;	/* rx w/ wep but privacy off */
5532 +	u_int32_t is_rx_unencrypted;	/* rx w/o wep and privacy on */
5533 +	u_int32_t is_rx_wepfail;		/* rx wep processing failed */
5534 +	u_int32_t is_rx_decap;		/* rx decapsulation failed */
5535 +	u_int32_t is_rx_mgtdiscard;	/* rx discard mgt frames */
5536 +	u_int32_t is_rx_ctl;		/* rx discard ctrl frames */
5537 +	u_int32_t is_rx_beacon;		/* rx beacon frames */
5538 +	u_int32_t is_rx_rstoobig;	/* rx rate set truncated */
5539 +	u_int32_t is_rx_elem_missing;	/* rx required element missing*/
5540 +	u_int32_t is_rx_elem_toobig;	/* rx element too big */
5541 +	u_int32_t is_rx_elem_toosmall;	/* rx element too small */
5542 +	u_int32_t is_rx_elem_unknown;	/* rx element unknown */
5543 +	u_int32_t is_rx_badchan;		/* rx frame w/ invalid chan */
5544 +	u_int32_t is_rx_chanmismatch;	/* rx frame chan mismatch */
5545 +	u_int32_t is_rx_nodealloc;	/* rx frame dropped */
5546 +	u_int32_t is_rx_ssidmismatch;	/* rx frame ssid mismatch  */
5547 +	u_int32_t is_rx_auth_unsupported;/* rx w/ unsupported auth alg */
5548 +	u_int32_t is_rx_auth_fail;	/* rx sta auth failure */
5549 +	u_int32_t is_rx_auth_countermeasures;/* rx auth discard due to CM */
5550 +	u_int32_t is_rx_assoc_bss;	/* rx assoc from wrong bssid */
5551 +	u_int32_t is_rx_assoc_notauth;	/* rx assoc w/o auth */
5552 +	u_int32_t is_rx_assoc_capmismatch;/* rx assoc w/ cap mismatch */
5553 +	u_int32_t is_rx_assoc_norate;	/* rx assoc w/ no rate match */
5554 +	u_int32_t is_rx_assoc_badwpaie;	/* rx assoc w/ bad WPA IE */
5555 +	u_int32_t is_rx_assoc_badscie;	/* rx assoc w/ bad SC IE */
5556 +	u_int32_t is_rx_deauth;		/* rx deauthentication */
5557 +	u_int32_t is_rx_disassoc;	/* rx disassociation */
5558 +	u_int32_t is_rx_badsubtype;	/* rx frame w/ unknown subtype*/
5559 +	u_int32_t is_rx_nobuf;		/* rx failed for lack of buf */
5560 +	u_int32_t is_rx_decryptcrc;	/* rx decrypt failed on crc */
5561 +	u_int32_t is_rx_ahdemo_mgt;	/* rx discard ahdemo mgt frame*/
5562 +	u_int32_t is_rx_bad_auth;	/* rx bad auth request */
5563 +	u_int32_t is_rx_unauth;		/* rx on unauthorized port */
5564 +	u_int32_t is_rx_badkeyid;	/* rx w/ incorrect keyid */
5565 +	u_int32_t is_rx_ccmpreplay;	/* rx seq# violation (CCMP) */
5566 +	u_int32_t is_rx_ccmpformat;	/* rx format bad (CCMP) */
5567 +	u_int32_t is_rx_ccmpmic;		/* rx MIC check failed (CCMP) */
5568 +	u_int32_t is_rx_tkipreplay;	/* rx seq# violation (TKIP) */
5569 +	u_int32_t is_rx_tkipformat;	/* rx format bad (TKIP) */
5570 +	u_int32_t is_rx_tkipmic;		/* rx MIC check failed (TKIP) */
5571 +	u_int32_t is_rx_tkipicv;		/* rx ICV check failed (TKIP) */
5572 +	u_int32_t is_rx_badcipher;	/* rx failed due to of key type */
5573 +	u_int32_t is_rx_nocipherctx;	/* rx failed due to key !setup */
5574 +	u_int32_t is_rx_acl;		/* rx discard due to of acl policy */
5575 +	u_int32_t is_rx_ffcnt;		/* rx fast frames */
5576 +	u_int32_t is_rx_badathtnl;   	/* driver key alloc failed */
5577 +	u_int32_t is_tx_nobuf;		/* tx failed for lack of buf */
5578 +	u_int32_t is_tx_nonode;		/* tx failed for no node */
5579 +	u_int32_t is_tx_unknownmgt;	/* tx of unknown mgt frame */
5580 +	u_int32_t is_tx_badcipher;	/* tx failed due to of key type */
5581 +	u_int32_t is_tx_nodefkey;	/* tx failed due to no defkey */
5582 +	u_int32_t is_tx_noheadroom;	/* tx failed due to no space */
5583 +	u_int32_t is_tx_ffokcnt;		/* tx fast frames sent success */
5584 +	u_int32_t is_tx_fferrcnt;	/* tx fast frames sent success */
5585 +	u_int32_t is_scan_active;	/* active scans started */
5586 +	u_int32_t is_scan_passive;	/* passive scans started */
5587 +	u_int32_t is_node_timeout;	/* nodes timed out inactivity */
5588 +	u_int32_t is_node_fdisassoc;	/* forced node disassociation */
5589 +	u_int32_t is_crypto_nomem;	/* no memory for crypto ctx */
5590 +	u_int32_t is_crypto_tkip;	/* tkip crypto done in s/w */
5591 +	u_int32_t is_crypto_tkipenmic;	/* tkip en-MIC done in s/w */
5592 +	u_int32_t is_crypto_tkipdemic;	/* tkip de-MIC done in s/w */
5593 +	u_int32_t is_crypto_tkipcm;	/* tkip counter measures */
5594 +	u_int32_t is_crypto_ccmp;	/* ccmp crypto done in s/w */
5595 +	u_int32_t is_crypto_wep;		/* wep crypto done in s/w */
5596 +	u_int32_t is_crypto_setkey_cipher;/* cipher rejected key */
5597 +	u_int32_t is_crypto_setkey_nokey;/* no key index for setkey */
5598 +	u_int32_t is_crypto_delkey;	/* driver key delete failed */
5599 +	u_int32_t is_crypto_badcipher;	/* unknown cipher */
5600 +	u_int32_t is_crypto_nocipher;	/* cipher not available */
5601 +	u_int32_t is_crypto_attachfail;	/* cipher attach failed */
5602 +	u_int32_t is_crypto_swfallback;	/* cipher fallback to s/w */
5603 +	u_int32_t is_crypto_keyfail;	/* driver key alloc failed */
5604 +	u_int32_t is_crypto_enmicfail;	/* en-MIC failed */
5605 +	u_int32_t is_ibss_capmismatch;	/* merge failed-cap mismatch */
5606 +	u_int32_t is_ibss_norate;	/* merge failed-rate mismatch */
5607 +	u_int32_t is_ps_unassoc;		/* ps-poll for unassoc. sta */
5608 +	u_int32_t is_ps_badaid;		/* ps-poll w/ incorrect aid */
5609 +	u_int32_t is_ps_qempty;		/* ps-poll w/ nothing to send */
5610 +};
5611 +
5612 +/*
5613 + * Max size of optional information elements.  We artificially
5614 + * constrain this; it's limited only by the max frame size (and
5615 + * the max parameter size of the wireless extensions).
5616 + */
5617 +#define	IEEE80211_MAX_OPT_IE	256
5618 +
5619 +/*
5620 + * WPA/RSN get/set key request.  Specify the key/cipher
5621 + * type and whether the key is to be used for sending and/or
5622 + * receiving.  The key index should be set only when working
5623 + * with global keys (use IEEE80211_KEYIX_NONE for ``no index'').
5624 + * Otherwise a unicast/pairwise key is specified by the bssid
5625 + * (on a station) or mac address (on an ap).  They key length
5626 + * must include any MIC key data; otherwise it should be no
5627 + more than IEEE80211_KEYBUF_SIZE.
5628 + */
5629 +struct ieee80211req_key {
5630 +	u_int8_t ik_type;		/* key/cipher type */
5631 +	u_int8_t ik_pad;
5632 +	ieee80211_keyix_t ik_keyix;	/* key index */
5633 +	u_int8_t ik_keylen;		/* key length in bytes */
5634 +	u_int8_t ik_flags;
5635 +/* NB: IEEE80211_KEY_XMIT and IEEE80211_KEY_RECV defined elsewhere */
5636 +#define	IEEE80211_KEY_DEFAULT	0x80	/* default xmit key */
5637 +	u_int8_t ik_macaddr[IEEE80211_ADDR_LEN];
5638 +	u_int64_t ik_keyrsc;		/* key receive sequence counter */
5639 +	u_int64_t ik_keytsc;		/* key transmit sequence counter */
5640 +	u_int8_t ik_keydata[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
5641 +};
5642 +
5643 +/*
5644 + * Delete a key either by index or address.  Set the index
5645 + * to IEEE80211_KEYIX_NONE when deleting a unicast key.
5646 + */
5647 +struct ieee80211req_del_key {
5648 +	/* NB: This is different to ieee80211_keyix_t, but this is OK as 
5649 +	 * values are unique over the low order bits. */
5650 +	u_int8_t idk_keyix;	/* key index */
5651 +	u_int8_t idk_macaddr[IEEE80211_ADDR_LEN];
5652 +};
5653 +
5654 +/*
5655 + * MLME state manipulation request.  IEEE80211_MLME_ASSOC
5656 + * only makes sense when operating as a station.  The other
5657 + * requests can be used when operating as a station or an
5658 + * ap (to effect a station).
5659 + */
5660 +struct ieee80211req_mlme {
5661 +	u_int8_t im_op;			/* operation to perform */
5662 +#define	IEEE80211_MLME_ASSOC		1	/* associate station */
5663 +#define	IEEE80211_MLME_DISASSOC		2	/* disassociate station */
5664 +#define	IEEE80211_MLME_DEAUTH		3	/* deauthenticate station */
5665 +#define	IEEE80211_MLME_AUTHORIZE	4	/* authorize station */
5666 +#define	IEEE80211_MLME_UNAUTHORIZE	5	/* unauthorize station */
5667 +#define IEEE80211_MLME_CLEAR_STATS	6	/* clear station statistic */
5668 +	u_int8_t im_ssid_len;		/* length of optional ssid */
5669 +	u_int16_t im_reason;		/* 802.11 reason code */
5670 +	u_int8_t im_macaddr[IEEE80211_ADDR_LEN];
5671 +	u_int8_t im_ssid[IEEE80211_NWID_LEN];
5672 +};
5673 +
5674 +/* 
5675 + * MAC ACL operations.
5676 + */
5677 +enum {
5678 +	IEEE80211_MACCMD_POLICY_OPEN	= 0,	/* set policy: no ACLs */
5679 +	IEEE80211_MACCMD_POLICY_ALLOW	= 1,	/* set policy: allow traffic */
5680 +	IEEE80211_MACCMD_POLICY_DENY	= 2,	/* set policy: deny traffic */
5681 +	IEEE80211_MACCMD_FLUSH		= 3,	/* flush ACL database */
5682 +	IEEE80211_MACCMD_DETACH		= 4,	/* detach ACL policy */
5683 +};
5684 +
5685 +/*
5686 + * Set the active channel list.  Note this list is
5687 + * intersected with the available channel list in
5688 + * calculating the set of channels actually used in
5689 + * scanning.
5690 + */
5691 +struct ieee80211req_chanlist {
5692 +	u_int8_t ic_channels[IEEE80211_CHAN_BYTES];
5693 +};
5694 +
5695 +/*
5696 + * Get the active channel list info.
5697 + */
5698 +struct ieee80211req_chaninfo {
5699 +	u_int ic_nchans;
5700 +	struct ieee80211_channel ic_chans[IEEE80211_CHAN_MAX];
5701 +};
5702 +
5703 +/*
5704 + * Retrieve the WPA/RSN information element for an associated station.
5705 + */
5706 +struct ieee80211req_wpaie {
5707 +	u_int8_t	wpa_macaddr[IEEE80211_ADDR_LEN];
5708 +	u_int8_t	wpa_ie[IEEE80211_MAX_OPT_IE];
5709 +	u_int8_t	rsn_ie[IEEE80211_MAX_OPT_IE];
5710 +};
5711 +
5712 +/*
5713 + * Retrieve per-node statistics.
5714 + */
5715 +struct ieee80211req_sta_stats {
5716 +	union {
5717 +		/* NB: explicitly force 64-bit alignment */
5718 +		u_int8_t macaddr[IEEE80211_ADDR_LEN];
5719 +		u_int64_t pad;
5720 +	} is_u;
5721 +	struct ieee80211_nodestats is_stats;
5722 +};
5723 +
5724 +/*
5725 + * Station information block; the mac address is used
5726 + * to retrieve other data like stats, unicast key, etc.
5727 + */
5728 +struct ieee80211req_sta_info {
5729 +	u_int16_t isi_len;		/* length (mult of 4) */
5730 +	u_int16_t isi_freq;		/* MHz */
5731 +	u_int16_t isi_flags;		/* channel flags */
5732 +	u_int16_t isi_state;		/* state flags */
5733 +	u_int8_t isi_authmode;		/* authentication algorithm */
5734 +	u_int8_t isi_rssi;
5735 +	int8_t isi_noise;
5736 +	u_int16_t isi_capinfo;		/* capabilities */
5737 +	u_int8_t isi_athflags;		/* Atheros capabilities */
5738 +	u_int8_t isi_erp;		/* ERP element */
5739 +	u_int8_t isi_macaddr[IEEE80211_ADDR_LEN];
5740 +	u_int8_t isi_nrates;		/* negotiated rates */
5741 +	u_int8_t isi_rates[IEEE80211_RATE_MAXSIZE];
5742 +	u_int8_t isi_txrate;		/* index to isi_rates[] */
5743 +	u_int16_t isi_ie_len;		/* IE length */
5744 +	u_int16_t isi_associd;		/* assoc response */
5745 +	u_int16_t isi_txpower;		/* current tx power */
5746 +	u_int16_t isi_vlan;		/* vlan tag */
5747 +	u_int16_t isi_txseqs[17];	/* seq to be transmitted */
5748 +	u_int16_t isi_rxseqs[17];	/* seq previous for qos frames*/
5749 +	u_int16_t isi_inact;		/* inactivity timer */
5750 +	u_int8_t isi_uapsd;		/* UAPSD queues */
5751 +	u_int8_t isi_opmode;		/* sta operating mode */
5752 +
5753 +	/* XXX frag state? */
5754 +	/* variable length IE data */
5755 +};
5756 +
5757 +enum {
5758 +	IEEE80211_STA_OPMODE_NORMAL,
5759 +	IEEE80211_STA_OPMODE_XR
5760 +};
5761 +
5762 +/*
5763 + * Retrieve per-station information; to retrieve all
5764 + * specify a mac address of ff:ff:ff:ff:ff:ff.
5765 + */
5766 +struct ieee80211req_sta_req {
5767 +	union {
5768 +		/* NB: explicitly force 64-bit alignment */
5769 +		u_int8_t macaddr[IEEE80211_ADDR_LEN];
5770 +		u_int64_t pad;
5771 +	} is_u;
5772 +	struct ieee80211req_sta_info info[1];	/* variable length */
5773 +};
5774 +
5775 +/*
5776 + * Get/set per-station tx power cap.
5777 + */
5778 +struct ieee80211req_sta_txpow {
5779 +	u_int8_t	it_macaddr[IEEE80211_ADDR_LEN];
5780 +	u_int8_t	it_txpow;
5781 +};
5782 +
5783 +/*
5784 + * WME parameters are set and return using i_val and i_len.
5785 + * i_val holds the value itself.  i_len specifies the AC
5786 + * and, as appropriate, then high bit specifies whether the
5787 + * operation is to be applied to the BSS or ourself.
5788 + */
5789 +#define	IEEE80211_WMEPARAM_SELF	0x0000		/* parameter applies to self */
5790 +#define	IEEE80211_WMEPARAM_BSS	0x8000		/* parameter applies to BSS */
5791 +#define	IEEE80211_WMEPARAM_VAL	0x7fff		/* parameter value */
5792 +
5793 +/*
5794 + * Scan result data returned for IEEE80211_IOC_SCAN_RESULTS.
5795 + */
5796 +struct ieee80211req_scan_result {
5797 +	u_int16_t isr_len;		/* length (mult of 4) */
5798 +	u_int16_t isr_freq;		/* MHz */
5799 +	u_int16_t isr_flags;		/* channel flags */
5800 +	u_int8_t isr_noise;
5801 +	u_int8_t isr_rssi;
5802 +	u_int8_t isr_intval;		/* beacon interval */
5803 +	u_int16_t isr_capinfo;		/* capabilities */
5804 +	u_int8_t isr_erp;		/* ERP element */
5805 +	u_int8_t isr_bssid[IEEE80211_ADDR_LEN];
5806 +	u_int8_t isr_nrates;
5807 +	u_int8_t isr_rates[IEEE80211_RATE_MAXSIZE];
5808 +	u_int8_t isr_ssid_len;		/* SSID length */
5809 +	u_int8_t isr_ie_len;		/* IE length */
5810 +	u_int8_t isr_pad[5];
5811 +	/* variable length SSID followed by IE data */
5812 +};
5813 +
5814 +#ifdef __FreeBSD__
5815 +/*
5816 + * FreeBSD-style ioctls.
5817 + */
5818 +/* the first member must be matched with struct ifreq */
5819 +struct ieee80211req {
5820 +	char i_name[IFNAMSIZ];	/* if_name, e.g. "wi0" */
5821 +	u_int16_t i_type;	/* req type */
5822 +	int16_t 	i_val;		/* Index or simple value */
5823 +	int16_t 	i_len;		/* Index or simple value */
5824 +	void *i_data;		/* Extra data */
5825 +};
5826 +#define	SIOCS80211		 _IOW('i', 234, struct ieee80211req)
5827 +#define	SIOCG80211		_IOWR('i', 235, struct ieee80211req)
5828 +#define	SIOCG80211STATS		_IOWR('i', 236, struct ifreq)
5829 +#define	SIOC80211IFCREATE	_IOWR('i', 237, struct ifreq)
5830 +#define	SIOC80211IFDESTROY	 _IOW('i', 238, struct ifreq)
5831 +
5832 +#define IEEE80211_IOC_SSID		1
5833 +#define IEEE80211_IOC_NUMSSIDS		2
5834 +#define IEEE80211_IOC_WEP		3
5835 +#define 	IEEE80211_WEP_NOSUP		-1
5836 +#define 	IEEE80211_WEP_OFF		0
5837 +#define 	IEEE80211_WEP_ON		1
5838 +#define 	IEEE80211_WEP_MIXED		2
5839 +#define IEEE80211_IOC_WEPKEY		4
5840 +#define IEEE80211_IOC_NUMWEPKEYS	5
5841 +#define IEEE80211_IOC_WEPTXKEY		6
5842 +#define IEEE80211_IOC_AUTHMODE		7
5843 +#define IEEE80211_IOC_STATIONNAME	8
5844 +#define IEEE80211_IOC_CHANNEL		9
5845 +#define IEEE80211_IOC_POWERSAVE		10
5846 +#define 	IEEE80211_POWERSAVE_NOSUP	-1
5847 +#define 	IEEE80211_POWERSAVE_OFF		0
5848 +#define 	IEEE80211_POWERSAVE_CAM		1
5849 +#define 	IEEE80211_POWERSAVE_PSP		2
5850 +#define 	IEEE80211_POWERSAVE_PSP_CAM	3
5851 +#define 	IEEE80211_POWERSAVE_ON		IEEE80211_POWERSAVE_CAM
5852 +#define IEEE80211_IOC_POWERSAVESLEEP	11
5853 +#define	IEEE80211_IOC_RTSTHRESHOLD	12
5854 +#define IEEE80211_IOC_PROTMODE		13
5855 +#define 	IEEE80211_PROTMODE_OFF		0
5856 +#define 	IEEE80211_PROTMODE_CTS		1
5857 +#define 	IEEE80211_PROTMODE_RTSCTS	2
5858 +#define	IEEE80211_IOC_TXPOWER		14	/* global tx power limit */
5859 +#define	IEEE80211_IOC_BSSID		15
5860 +#define	IEEE80211_IOC_ROAMING		16	/* roaming mode */
5861 +#define	IEEE80211_IOC_PRIVACY		17	/* privacy invoked */
5862 +#define	IEEE80211_IOC_DROPUNENCRYPTED	18	/* discard unencrypted frames */
5863 +#define	IEEE80211_IOC_WPAKEY		19
5864 +#define	IEEE80211_IOC_DELKEY		20
5865 +#define	IEEE80211_IOC_MLME		21
5866 +#define	IEEE80211_IOC_OPTIE		22	/* optional info. element */
5867 +#define	IEEE80211_IOC_SCAN_REQ		23
5868 +#define	IEEE80211_IOC_SCAN_RESULTS	24
5869 +#define	IEEE80211_IOC_COUNTERMEASURES	25	/* WPA/TKIP countermeasures */
5870 +#define	IEEE80211_IOC_WPA		26	/* WPA mode (0,1,2) */
5871 +#define	IEEE80211_IOC_CHANLIST		27	/* channel list */
5872 +#define	IEEE80211_IOC_WME		28	/* WME mode (on, off) */
5873 +#define	IEEE80211_IOC_HIDESSID		29	/* hide SSID mode (on, off) */
5874 +#define IEEE80211_IOC_APBRIDGE		30	/* AP inter-sta bridging */
5875 +#define	IEEE80211_IOC_MCASTCIPHER	31	/* multicast/default cipher */
5876 +#define	IEEE80211_IOC_MCASTKEYLEN	32	/* multicast key length */
5877 +#define	IEEE80211_IOC_UCASTCIPHERS	33	/* unicast cipher suites */
5878 +#define	IEEE80211_IOC_UCASTCIPHER	34	/* unicast cipher */
5879 +#define	IEEE80211_IOC_UCASTKEYLEN	35	/* unicast key length */
5880 +#define	IEEE80211_IOC_DRIVER_CAPS	36	/* driver capabilities */
5881 +#define	IEEE80211_IOC_KEYMGTALGS	37	/* key management algorithms */
5882 +#define	IEEE80211_IOC_RSNCAPS		38	/* RSN capabilities */
5883 +#define	IEEE80211_IOC_WPAIE		39	/* WPA information element */
5884 +#define	IEEE80211_IOC_STA_STATS		40	/* per-station statistics */
5885 +#define	IEEE80211_IOC_MACCMD		41	/* MAC ACL operation */
5886 +#define	IEEE80211_IOC_TXPOWMAX		43	/* max tx power for channel */
5887 +#define	IEEE80211_IOC_STA_TXPOW		44	/* per-station tx power limit */
5888 +#define	IEEE80211_IOC_STA_INFO		45	/* station/neighbor info */
5889 +#define	IEEE80211_IOC_WME_CWMIN		46	/* WME: ECWmin */
5890 +#define	IEEE80211_IOC_WME_CWMAX		47	/* WME: ECWmax */
5891 +#define	IEEE80211_IOC_WME_AIFS		48	/* WME: AIFSN */
5892 +#define	IEEE80211_IOC_WME_TXOPLIMIT	49	/* WME: txops limit */
5893 +#define	IEEE80211_IOC_WME_ACM		50	/* WME: ACM (bss only) */
5894 +#define	IEEE80211_IOC_WME_ACKPOLICY	51	/* WME: ACK policy (!bss only)*/
5895 +#define	IEEE80211_IOC_DTIM_PERIOD	52	/* DTIM period (beacons) */
5896 +#define	IEEE80211_IOC_BEACON_INTERVAL	53	/* beacon interval (ms) */
5897 +#define	IEEE80211_IOC_ADDMAC		54	/* add sta to MAC ACL table */
5898 +#define	IEEE80211_IOC_DELMAC		55	/* del sta from MAC ACL table */
5899 +#define	IEEE80211_IOC_FF		56	/* ATH fast frames (on, off) */
5900 +#define	IEEE80211_IOC_TURBOP		57	/* ATH turbo' (on, off) */
5901 +#define	IEEE80211_IOC_APPIEBUF		58	/* IE in the management frame */
5902 +#define	IEEE80211_IOC_FILTERFRAME	59	/* management frame filter */
5903 +
5904 +/*
5905 + * Scan result data returned for IEEE80211_IOC_SCAN_RESULTS.
5906 + */
5907 +struct ieee80211req_scan_result {
5908 +	u_int16_t isr_len;		/* length (mult of 4) */
5909 +	u_int16_t isr_freq;		/* MHz */
5910 +	u_int16_t isr_flags;		/* channel flags */
5911 +	u_int8_t isr_noise;
5912 +	u_int8_t isr_rssi;
5913 +	u_int8_t isr_intval;		/* beacon interval */
5914 +	u_int16_t isr_capinfo;		/* capabilities */
5915 +	u_int8_t isr_erp;		/* ERP element */
5916 +	u_int8_t isr_bssid[IEEE80211_ADDR_LEN];
5917 +	u_int8_t isr_nrates;
5918 +	u_int8_t isr_rates[IEEE80211_RATE_MAXSIZE];
5919 +	u_int8_t isr_ssid_len;		/* SSID length */
5920 +	u_int8_t isr_ie_len;		/* IE length */
5921 +	u_int8_t isr_pad[5];
5922 +	/* variable length SSID followed by IE data */
5923 +};
5924 +
5925 +#endif /* __FreeBSD__ */
5926 +
5927 +#ifdef __linux__
5928 +/*
5929 + * Wireless Extensions API, private ioctl interfaces.
5930 + *
5931 + * NB: Even-numbered ioctl numbers have set semantics and are privileged!
5932 + *     (regardless of the incorrect comment in wireless.h!)
5933 + */
5934 +#ifdef __KERNEL__
5935 +#include <linux/if.h>
5936 +#endif
5937 +/* The maximum size of a iwpriv structure is IW_PRIV_SIZE_MASK, which was 
5938 + * exceeded for some time by chaninfo ioctl.  These macros change the size 
5939 + * encoding for anything larger than IW_PRIV_SIZE_MASK from bytes to 4-byte
5940 + * multiples so that the padded size fits under IW_PRIV_SIZE_MASK. */
5941 +#define IW_PRIV_BLOB_LENGTH_ENCODING(_SIZE) \
5942 +	(((_SIZE) == ((_SIZE) & IW_PRIV_SIZE_MASK)) ? \
5943 +		(_SIZE) : \
5944 +		(((_SIZE) / sizeof(uint32_t)) + \
5945 +			(((_SIZE) == (((_SIZE) / sizeof(uint32_t)) * sizeof(int))) ? \
5946 +				0 : 1)))
5947 +#define IW_PRIV_BLOB_TYPE_ENCODING(_SIZE) \
5948 +	(((_SIZE) == ((_SIZE) & IW_PRIV_SIZE_MASK)) ? \
5949 +		(IW_PRIV_TYPE_BYTE | (_SIZE)) : \
5950 +		(IW_PRIV_TYPE_INT  | IW_PRIV_BLOB_LENGTH_ENCODING((_SIZE))))
5951 +
5952 +#define	IEEE80211_IOCTL_SETPARAM	(SIOCIWFIRSTPRIV+0)
5953 +#define	IEEE80211_IOCTL_GETPARAM	(SIOCIWFIRSTPRIV+1)
5954 +#define	IEEE80211_IOCTL_SETMODE		(SIOCIWFIRSTPRIV+2)
5955 +#define	IEEE80211_IOCTL_GETMODE		(SIOCIWFIRSTPRIV+3)
5956 +#define	IEEE80211_IOCTL_SETWMMPARAMS	(SIOCIWFIRSTPRIV+4)
5957 +#define	IEEE80211_IOCTL_GETWMMPARAMS	(SIOCIWFIRSTPRIV+5)
5958 +#define	IEEE80211_IOCTL_SETCHANLIST	(SIOCIWFIRSTPRIV+6)
5959 +#define	IEEE80211_IOCTL_GETCHANLIST	(SIOCIWFIRSTPRIV+7)
5960 +#define	IEEE80211_IOCTL_CHANSWITCH	(SIOCIWFIRSTPRIV+8)
5961 +#define	IEEE80211_IOCTL_GET_APPIEBUF	(SIOCIWFIRSTPRIV+9)
5962 +#define	IEEE80211_IOCTL_SET_APPIEBUF	(SIOCIWFIRSTPRIV+10)
5963 +#define	IEEE80211_IOCTL_READREG		(SIOCIWFIRSTPRIV+11)
5964 +#define	IEEE80211_IOCTL_FILTERFRAME	(SIOCIWFIRSTPRIV+12)
5965 +#define	IEEE80211_IOCTL_GETCHANINFO	(SIOCIWFIRSTPRIV+13)
5966 +#define	IEEE80211_IOCTL_SETOPTIE	(SIOCIWFIRSTPRIV+14)
5967 +#define	IEEE80211_IOCTL_GETOPTIE	(SIOCIWFIRSTPRIV+15)
5968 +#define	IEEE80211_IOCTL_SETMLME		(SIOCIWFIRSTPRIV+16)
5969 +#define	IEEE80211_IOCTL_RADAR		(SIOCIWFIRSTPRIV+17)
5970 +#define	IEEE80211_IOCTL_SETKEY		(SIOCIWFIRSTPRIV+18)
5971 +#define	IEEE80211_IOCTL_WRITEREG	(SIOCIWFIRSTPRIV+19)
5972 +#define	IEEE80211_IOCTL_DELKEY		(SIOCIWFIRSTPRIV+20)
5973 +#define	IEEE80211_IOCTL_HALMAP		(SIOCIWFIRSTPRIV+21)
5974 +#define	IEEE80211_IOCTL_ADDMAC		(SIOCIWFIRSTPRIV+22)
5975 +#define	IEEE80211_IOCTL_DELMAC		(SIOCIWFIRSTPRIV+24)
5976 +#define	IEEE80211_IOCTL_WDSADDMAC	(SIOCIWFIRSTPRIV+26)
5977 +#define	IEEE80211_IOCTL_WDSDELMAC	(SIOCIWFIRSTPRIV+28)
5978 +#define	IEEE80211_IOCTL_KICKMAC		(SIOCIWFIRSTPRIV+30)
5979 +#define	IEEE80211_IOCTL_SETSCANLIST	(SIOCIWFIRSTPRIV+31)
5980 +
5981 +enum {
5982 +	IEEE80211_WMMPARAMS_CWMIN       = 1,
5983 +	IEEE80211_WMMPARAMS_CWMAX       = 2,
5984 +	IEEE80211_WMMPARAMS_AIFS       	= 3,
5985 +	IEEE80211_WMMPARAMS_TXOPLIMIT	= 4,
5986 +	IEEE80211_WMMPARAMS_ACM		= 5,
5987 +	IEEE80211_WMMPARAMS_NOACKPOLICY	= 6,
5988 +};
5989 +enum {
5990 +	IEEE80211_PARAM_TURBO			= 1,	/* turbo mode */
5991 +	IEEE80211_PARAM_MODE			= 2,	/* phy mode (11a, 11b, etc.) */
5992 +	IEEE80211_PARAM_AUTHMODE		= 3,	/* authentication mode */
5993 +	IEEE80211_PARAM_PROTMODE		= 4,	/* 802.11g protection */
5994 +	IEEE80211_PARAM_MCASTCIPHER		= 5,	/* multicast/default cipher */
5995 +	IEEE80211_PARAM_MCASTKEYLEN		= 6,	/* multicast key length */
5996 +	IEEE80211_PARAM_UCASTCIPHERS		= 7,	/* unicast cipher suites */
5997 +	IEEE80211_PARAM_UCASTCIPHER		= 8,	/* unicast cipher */
5998 +	IEEE80211_PARAM_UCASTKEYLEN		= 9,	/* unicast key length */
5999 +	IEEE80211_PARAM_WPA			= 10,	/* WPA mode (0,1,2) */
6000 +	IEEE80211_PARAM_ROAMING			= 12,	/* roaming mode */
6001 +	IEEE80211_PARAM_PRIVACY			= 13,	/* privacy invoked */
6002 +	IEEE80211_PARAM_COUNTERMEASURES		= 14,	/* WPA/TKIP countermeasures */
6003 +	IEEE80211_PARAM_DROPUNENCRYPTED		= 15,	/* discard unencrypted frames */
6004 +	IEEE80211_PARAM_DRIVER_CAPS		= 16,	/* driver capabilities */
6005 +	IEEE80211_PARAM_MACCMD			= 17,	/* MAC ACL operation */
6006 +	IEEE80211_PARAM_WMM			= 18,	/* WMM mode (on, off) */
6007 +	IEEE80211_PARAM_HIDESSID		= 19,	/* hide SSID mode (on, off) */
6008 +	IEEE80211_PARAM_APBRIDGE    		= 20,   /* AP inter-sta bridging */
6009 +	IEEE80211_PARAM_KEYMGTALGS		= 21,	/* key management algorithms */
6010 +	IEEE80211_PARAM_RSNCAPS			= 22,	/* RSN capabilities */
6011 +	IEEE80211_PARAM_INACT			= 23,	/* station inactivity timeout */
6012 +	IEEE80211_PARAM_INACT_AUTH		= 24,	/* station auth inact timeout */
6013 +	IEEE80211_PARAM_INACT_INIT		= 25,	/* station init inact timeout */
6014 +	IEEE80211_PARAM_ABOLT			= 26,	/* Atheros Adv. Capabilities */
6015 +	IEEE80211_PARAM_DTIM_PERIOD		= 28,	/* DTIM period (beacons) */
6016 +	IEEE80211_PARAM_BEACON_INTERVAL		= 29,	/* beacon interval (ms) */
6017 +	IEEE80211_PARAM_DOTH			= 30,	/* 11.h is on/off */
6018 +	IEEE80211_PARAM_PWRTARGET		= 31,	/* Current Channel Pwr Constraint */
6019 +	IEEE80211_PARAM_GENREASSOC		= 32,	/* Generate a reassociation request */
6020 +	IEEE80211_PARAM_COMPRESSION		= 33,	/* compression */
6021 +	IEEE80211_PARAM_FF			= 34,	/* fast frames support  */
6022 +	IEEE80211_PARAM_XR			= 35,	/* XR support */
6023 +	IEEE80211_PARAM_BURST			= 36,	/* burst mode */
6024 +	IEEE80211_PARAM_PUREG			= 37,	/* pure 11g (no 11b stations) */
6025 +	IEEE80211_PARAM_AR			= 38,	/* AR support */
6026 +	IEEE80211_PARAM_WDS			= 39,	/* Enable 4 address processing */
6027 +	IEEE80211_PARAM_BGSCAN			= 40,	/* bg scanning (on, off) */
6028 +	IEEE80211_PARAM_BGSCAN_IDLE		= 41,	/* bg scan idle threshold */
6029 +	IEEE80211_PARAM_BGSCAN_INTERVAL		= 42,	/* bg scan interval */
6030 +	IEEE80211_PARAM_MCAST_RATE		= 43,	/* Multicast Tx Rate */
6031 +	IEEE80211_PARAM_COVERAGE_CLASS		= 44,	/* coverage class */
6032 +	IEEE80211_PARAM_COUNTRY_IE		= 45,	/* enable country IE */
6033 +	IEEE80211_PARAM_SCANVALID		= 46,	/* scan cache valid threshold */
6034 +	IEEE80211_PARAM_ROAM_RSSI_11A		= 47,	/* rssi threshold in 11a */
6035 +	IEEE80211_PARAM_ROAM_RSSI_11B		= 48,	/* rssi threshold in 11b */
6036 +	IEEE80211_PARAM_ROAM_RSSI_11G		= 49,	/* rssi threshold in 11g */
6037 +	IEEE80211_PARAM_ROAM_RATE_11A		= 50,	/* tx rate threshold in 11a */
6038 +	IEEE80211_PARAM_ROAM_RATE_11B		= 51,	/* tx rate threshold in 11b */
6039 +	IEEE80211_PARAM_ROAM_RATE_11G		= 52,	/* tx rate threshold in 11g */
6040 +	IEEE80211_PARAM_UAPSDINFO		= 53,	/* value for qos info field */
6041 +	IEEE80211_PARAM_SLEEP			= 54,	/* force sleep/wake */
6042 +	IEEE80211_PARAM_QOSNULL			= 55,	/* force sleep/wake */
6043 +	IEEE80211_PARAM_PSPOLL			= 56,	/* force ps-poll generation (sta only) */
6044 +	IEEE80211_PARAM_EOSPDROP		= 57,	/* force uapsd EOSP drop (ap only) */
6045 +	IEEE80211_PARAM_MARKDFS			= 58,	/* mark a dfs interference channel when found */
6046 +	IEEE80211_PARAM_REGCLASS		= 59,	/* enable regclass ids in country IE */
6047 +	IEEE80211_PARAM_DROPUNENC_EAPOL		= 60,	/* drop unencrypted eapol frames */
6048 +	IEEE80211_PARAM_SHPREAMBLE		= 61,	/* Short Preamble */
6049 +	IEEE80211_PARAM_DUMPREGS		= 62,	/* Pretty printed dump of Atheros hardware registers */
6050 +	IEEE80211_PARAM_DOTH_ALGORITHM		= 63,	/* spectrum management algorithm */
6051 +	IEEE80211_PARAM_DOTH_MINCOM   		= 64,	/* minimum number of common channels */
6052 +	IEEE80211_PARAM_DOTH_SLCG		= 65,	/* permil of Stations Lost per Channel Gained */
6053 +	IEEE80211_PARAM_DOTH_SLDG		= 66,	/* permil of Stations Lost per rssi Db Gained */
6054 +	IEEE80211_PARAM_TXCONT			= 67,	/* continuous transmit mode (boolean) */
6055 +	IEEE80211_PARAM_TXCONT_RATE		= 68,	/* continuous transmit mode data rate (in mbit/sec) - will use closest match from current rate table */
6056 +	IEEE80211_PARAM_TXCONT_POWER		= 69,	/* power level in units of 0.5dBm */
6057 +	IEEE80211_PARAM_DFS_TESTMODE		= 70,	/* do not perform DFS actions (i.e. markng DFS and channel change on interference), just report them via debug. */
6058 +	IEEE80211_PARAM_DFS_CACTIME		= 71,	/* how long do we wait for chan availability
6059 +							   scans ?
6060 +							   FCC requires 60s, so that is the default. */
6061 +	IEEE80211_PARAM_DFS_EXCLPERIOD		= 72,	/* DFS no-occupancy limit - how long do we stay
6062 +							   off a channel once radar is detected?
6063 +							   FCC requires 30m, so that is the default. */
6064 +	IEEE80211_PARAM_BEACON_MISS_THRESH	= 73,	/* Beacon miss threshold (in beacons) */
6065 +	IEEE80211_PARAM_BEACON_MISS_THRESH_MS	= 74,	/* Beacon miss threshold (in ms) */
6066 +	IEEE80211_PARAM_MAXRATE			= 75,	/* Maximum rate (by table index) */
6067 +	IEEE80211_PARAM_MINRATE			= 76,	/* Maximum rate (by table index) */
6068 +	IEEE80211_PARAM_PROTMODE_RSSI		= 77,	/* RSSI Threshold for enabling protection mode */
6069 +	IEEE80211_PARAM_PROTMODE_TIMEOUT	= 78,	/* Timeout for expiring protection mode */
6070 +};
6071 +
6072 +#define	SIOCG80211STATS			(SIOCDEVPRIVATE+2)
6073 +/* NB: require in+out parameters so cannot use wireless extensions, yech */
6074 +#define	IEEE80211_IOCTL_GETKEY		(SIOCDEVPRIVATE+3)
6075 +#define	IEEE80211_IOCTL_GETWPAIE	(SIOCDEVPRIVATE+4)
6076 +#define	IEEE80211_IOCTL_STA_STATS	(SIOCDEVPRIVATE+5)
6077 +#define	IEEE80211_IOCTL_STA_INFO	(SIOCDEVPRIVATE+6)
6078 +#define	SIOC80211IFCREATE		(SIOCDEVPRIVATE+7)
6079 +#define	SIOC80211IFDESTROY	 	(SIOCDEVPRIVATE+8)
6080 +#define	IEEE80211_IOCTL_SCAN_RESULTS	(SIOCDEVPRIVATE+9)
6081 +
6082 +struct ieee80211_clone_params {
6083 +	char icp_name[IFNAMSIZ];		/* device name */
6084 +	u_int16_t icp_opmode;			/* operating mode */
6085 +	u_int16_t icp_flags;			/* see below */
6086 +#define	IEEE80211_CLONE_BSSID	0x0001		/* allocate unique mac/bssid */
6087 +#define	IEEE80211_NO_STABEACONS	0x0002		/* Do not setup the station beacon timers */
6088 +};
6089 +
6090 +/* APPIEBUF related definitions */
6091 +
6092 +/* Management frame type to which application IE is added */
6093 +enum {
6094 +	IEEE80211_APPIE_FRAME_BEACON		= 0,
6095 +	IEEE80211_APPIE_FRAME_PROBE_REQ		= 1,
6096 +	IEEE80211_APPIE_FRAME_PROBE_RESP	= 2,
6097 +	IEEE80211_APPIE_FRAME_ASSOC_REQ		= 3,
6098 +	IEEE80211_APPIE_FRAME_ASSOC_RESP	= 4,
6099 +	IEEE80211_APPIE_NUM_OF_FRAME		= 5
6100 +};
6101 +
6102 +struct ieee80211req_getset_appiebuf {
6103 +	u_int32_t	app_frmtype;		/* management frame type for which buffer is added */
6104 +	u_int32_t	app_buflen;		/* application-supplied buffer length */
6105 +	u_int8_t	app_buf[0];		/* application-supplied IE(s) */
6106 +};
6107 +
6108 +/* Flags ORed by application to set filter for receiving management frames */
6109 +enum {
6110 +	IEEE80211_FILTER_TYPE_BEACON		= 1<<0,
6111 +	IEEE80211_FILTER_TYPE_PROBE_REQ		= 1<<1,
6112 +	IEEE80211_FILTER_TYPE_PROBE_RESP	= 1<<2,
6113 +	IEEE80211_FILTER_TYPE_ASSOC_REQ		= 1<<3,
6114 +	IEEE80211_FILTER_TYPE_ASSOC_RESP	= 1<<4,
6115 +	IEEE80211_FILTER_TYPE_AUTH		= 1<<5,
6116 +	IEEE80211_FILTER_TYPE_DEAUTH		= 1<<6,
6117 +	IEEE80211_FILTER_TYPE_DISASSOC		= 1<<7,
6118 +	IEEE80211_FILTER_TYPE_ALL		= 0xFF	/* used to check the valid filter bits */
6119 +};
6120 +
6121 +struct ieee80211req_set_filter {
6122 +	u_int32_t app_filterype;		/* management frame filter type */
6123 +};
6124 +
6125 +
6126 +#endif /* __linux__ */
6127 +
6128 +#endif /* _NET80211_IEEE80211_IOCTL_H_ */
6129 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_linux.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_linux.h
6130 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_linux.h	1970-01-01 01:00:00.000000000 +0100
6131 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_linux.h	2008-06-19 17:34:17.000000000 +0200
6132 @@ -0,0 +1,647 @@
6133 +/*-
6134 + * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
6135 + * All rights reserved.
6136 + *
6137 + * Redistribution and use in source and binary forms, with or without
6138 + * modification, are permitted provided that the following conditions
6139 + * are met:
6140 + * 1. Redistributions of source code must retain the above copyright
6141 + *    notice, this list of conditions and the following disclaimer.
6142 + * 2. Redistributions in binary form must reproduce the above copyright
6143 + *    notice, this list of conditions and the following disclaimer in the
6144 + *    documentation and/or other materials provided with the distribution.
6145 + * 3. The name of the author may not be used to endorse or promote products
6146 + *    derived from this software without specific prior written permission.
6147 + *
6148 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6149 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6150 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6151 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6152 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6153 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6154 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6155 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6156 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6157 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6158 + *
6159 + * $Id: ieee80211_linux.h 3269 2008-01-26 20:56:20Z mtaylor $
6160 + */
6161 +#ifndef _NET80211_IEEE80211_LINUX_H_
6162 +#define _NET80211_IEEE80211_LINUX_H_
6163 +
6164 +/* #define ATH_DEBUG_SPINLOCKS */		/* announce before spinlocking */
6165 +
6166 +#include <linux/wireless.h>
6167 +#include <linux/fs.h>
6168 +
6169 +/*
6170 + * Compatibility definition of statistics flags
6171 + * (bitmask in (struct iw_quality *)->updated)
6172 + */
6173 +#ifndef IW_QUAL_QUAL_UPDATED
6174 +#define IW_QUAL_QUAL_UPDATED	0x01	/* Value was updated since last read */
6175 +#define IW_QUAL_LEVEL_UPDATED	0x02
6176 +#define IW_QUAL_NOISE_UPDATED	0x04
6177 +#define IW_QUAL_QUAL_INVALID	0x10	/* Driver doesn't provide value */
6178 +#define IW_QUAL_LEVEL_INVALID	0x20
6179 +#define IW_QUAL_NOISE_INVALID	0x40
6180 +#endif /* IW_QUAL_QUAL_UPDATED */
6181 +
6182 +#ifndef IW_QUAL_ALL_UPDATED
6183 +#define IW_QUAL_ALL_UPDATED \
6184 +	(IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED)
6185 +#endif
6186 +#ifndef IW_QUAL_ALL_INVALID
6187 +#define IW_QUAL_ALL_INVALID \
6188 +	(IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID | IW_QUAL_NOISE_INVALID)
6189 +#endif
6190 +
6191 +/*
6192 + * The RSSI values reported in the TX/RX descriptors in the driver are the SNR 
6193 + * expressed in dBm. Thus 'rssi' is signal level above the noise floor in dBm.
6194 + *
6195 + * Noise is measured in dBm and is negative unless there is an unimaginable 
6196 + * level of RF noise. 
6197 + *
6198 + * The signal level is noise + rssi.
6199 + *
6200 + * Note that the iw_quality values are 1 byte, and can be signed, unsigned or 
6201 + * negative depending on context.
6202 + *
6203 + */
6204 +static __inline void
6205 +set_quality(struct iw_quality *iq, u_int rssi, int noise)
6206 +{
6207 +	iq->qual = rssi;
6208 +	iq->noise = noise;
6209 +	iq->level = ((((int)rssi + noise) <= 0) ? ((int)rssi + noise) : 0);
6210 +	iq->updated = IW_QUAL_ALL_UPDATED;
6211 +#if WIRELESS_EXT >= 19
6212 +	iq->updated |= IW_QUAL_DBM;
6213 +#endif
6214 +}
6215 +
6216 +/*
6217 + * Task deferral
6218 + *
6219 + * Deduce if tasklets are available.  If not then
6220 + * fall back to using the immediate work queue.
6221 + */
6222 +#include <linux/interrupt.h>
6223 +#ifdef DECLARE_TASKLET			/* native tasklets */
6224 +#define IEEE80211_TQ_STRUCT tasklet_struct
6225 +#define IEEE80211_INIT_TQUEUE(a,b,c)	tasklet_init((a), (b), (unsigned long)(c))
6226 +#define IEEE80211_SCHEDULE_TQUEUE(a)	tasklet_schedule((a))
6227 +#define IEEE80211_CANCEL_TQUEUE(a)	if (!in_interrupt()) tasklet_kill((a))
6228 +typedef unsigned long IEEE80211_TQUEUE_ARG;
6229 +#define mark_bh(a) do {} while (0)
6230 +#else					/* immediate work queue */
6231 +#define IEEE80211_TQ_STRUCT tq_struct
6232 +#define IEEE80211_INIT_TQUEUE(a,b,c)		INIT_TQUEUE(a,b,c)
6233 +#define IEEE80211_SCHEDULE_TQUEUE(a) do { \
6234 +	int __macro_needmark;		\
6235 +	__macro_needmark |= queue_task((a), &tq_immediate);	\
6236 +	if (__macro_needmark)		\
6237 +		mark_bh(IMMEDIATE_BH);	\
6238 +} while (0)
6239 +typedef void *IEEE80211_TQUEUE_ARG;
6240 +#define	tasklet_disable(t)	do { (void) t; local_bh_disable(); } while (0)
6241 +#define	tasklet_enable(t)	do { (void) t; local_bh_enable(); } while (0)
6242 +/* XXX: not supporting cancel in old kernels! */
6243 +#define IEEE80211_CANCEL_TQUEUE(a)	((a), 0)
6244 +#endif /* !DECLARE_TASKLET */
6245 +
6246 +#define	IEEE80211_RESCHEDULE	schedule
6247 +
6248 +/* Locking */
6249 +/* NB: beware, spin_is_locked() is not usefully defined for !(DEBUG || SMP)
6250 + * because spinlocks do not exist in this configuration. Instead IRQs 
6251 + * or pre-emption are simply disabled, as this is all that is needed.
6252 + */
6253 +
6254 +/*
6255 + * Beacon handler locking definitions.
6256 + * Beacon locking 
6257 + * UAPSD locking 
6258 + */
6259 +typedef spinlock_t ieee80211com_lock_t;
6260 +#define	IEEE80211_LOCK_INIT(_ic, _name)					\
6261 +	spin_lock_init(&(_ic)->ic_comlock)
6262 +#define	IEEE80211_LOCK_DESTROY(_ic)
6263 +#define	IEEE80211_LOCK_IRQ(_ic) do {					\
6264 +	unsigned long __ilockflags;					\
6265 +	IEEE80211_LOCK_CHECK(_ic);					\
6266 +	spin_lock_irqsave(&(_ic)->ic_comlock, __ilockflags);
6267 +#define	IEEE80211_UNLOCK_IRQ(_ic)					\
6268 +	IEEE80211_LOCK_ASSERT(_ic);					\
6269 +	spin_unlock_irqrestore(&(_ic)->ic_comlock, __ilockflags);	\
6270 +} while (0)
6271 +#define	IEEE80211_UNLOCK_IRQ_EARLY(_ic)					\
6272 +	IEEE80211_LOCK_ASSERT(_ic);					\
6273 +	spin_unlock_irqrestore(&(_ic)->ic_comlock, __ilockflags);
6274 +
6275 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6276 +#define	IEEE80211_LOCK_ASSERT(_ic) \
6277 +	KASSERT(spin_is_locked(&(_ic)->ic_comlock), ("ieee80211com not locked!"))
6278 +#if (defined(ATH_DEBUG_SPINLOCKS))
6279 +#define	IEEE80211_LOCK_CHECK(_ic) do { \
6280 +	if (spin_is_locked(&(_ic)->ic_comlock)) \
6281 +		printk("%s:%d - about to block on ieee80211com lock!\n", __func__, __LINE__); \
6282 +} while(0)
6283 +#else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6284 +#define	IEEE80211_LOCK_CHECK(_ic)
6285 +#endif 
6286 +#else
6287 +#define	IEEE80211_LOCK_ASSERT(_ic)
6288 +#define	IEEE80211_LOCK_CHECK(_ic)
6289 +#endif
6290 +
6291 +
6292 +#define IEEE80211_VAPS_LOCK_INIT(_ic, _name)		\
6293 +	spin_lock_init(&(_ic)->ic_vapslock)
6294 +#define IEEE80211_VAPS_LOCK_DESTROY(_ic)
6295 +#define IEEE80211_VAPS_LOCK_BH(_ic)	do { 		\
6296 +	IEEE80211_VAPS_LOCK_CHECK(_ic);		\
6297 +	spin_lock_bh(&(_ic)->ic_vapslock);
6298 +#define IEEE80211_VAPS_UNLOCK_BH(_ic)			\
6299 +	IEEE80211_VAPS_LOCK_ASSERT(_ic);		\
6300 +	spin_unlock_bh(&(_ic)->ic_vapslock);		\
6301 +} while (0)
6302 +
6303 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6304 +#define IEEE80211_VAPS_LOCK_ASSERT(_ic) \
6305 +	KASSERT(spin_is_locked(&(_ic)->ic_vapslock), \
6306 +		("ieee80211com_vaps not locked!"))
6307 +#if (defined(ATH_DEBUG_SPINLOCKS))
6308 +#define	IEEE80211_VAPS_LOCK_CHECK(_ic) do { \
6309 +	if (spin_is_locked(&(_ic)->ic_vapslock)) \
6310 +		printk("%s:%d - about to block on ieee80211com_vaps lock!\n", __func__, __LINE__); \
6311 +} while(0)
6312 +#else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6313 +#define IEEE80211_VAPS_LOCK_CHECK(_ic)
6314 +#endif /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6315 +#else
6316 +#define IEEE80211_VAPS_LOCK_ASSERT(_ic)
6317 +#define IEEE80211_VAPS_LOCK_CHECK(_ic)
6318 +#endif
6319 +
6320 +
6321 +/*
6322 + * Node locking definitions.
6323 + */
6324 +#if 0
6325 +
6326 +typedef spinlock_t ieee80211_node_lock_t;
6327 +#define	IEEE80211_NODE_LOCK_INIT(_ni, _name)	spin_lock_init(&(_ni)->ni_nodelock)
6328 +#define	IEEE80211_NODE_LOCK_DESTROY(_ni)
6329 +#define	IEEE80211_NODE_LOCK_IRQ(_ni)	do {	\
6330 +	unsigned long __node_lockflags;		\
6331 +	IEEE80211_NODE_LOCK_CHECK(_ni); 	\
6332 +	spin_lock_irqsave(&(_ni)->ni_nodelock, __node_lockflags);
6333 +#define	IEEE80211_NODE_UNLOCK_IRQ(_ni) \
6334 +	IEEE80211_NODE_LOCK_ASSERT(_ni); \
6335 +	spin_unlock_irqrestore(&(_ni)->ni_nodelock, __node_lockflags); \
6336 +} while (0)
6337 +#define	IEEE80211_NODE_UNLOCK_IRQ_EARLY(_ni)		\
6338 +	IEEE80211_NODE_LOCK_ASSERT(_ni); \
6339 +	spin_unlock_irqrestore(&(_ni)->ni_nodelock, __node_lockflags);
6340 +
6341 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6342 +#define	IEEE80211_NODE_LOCK_ASSERT(_ni) \
6343 +	KASSERT(spin_is_locked(&(_ni)->ni_nodelock), \
6344 +		("802.11 node not locked!"))
6345 +#if (defined(ATH_DEBUG_SPINLOCKS))
6346 +#define	IEEE80211_NODE_LOCK_CHECK(_ni) do { \
6347 +	if (spin_is_locked(&(_ni)->ni_nodelock)) \
6348 +		printk("%s:%d - about to block on node lock!\n", __func__, __LINE__); \
6349 +} while(0)
6350 +#else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6351 +#define	IEEE80211_NODE_LOCK_CHECK(_ni)
6352 +#endif /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6353 +#else
6354 +#define	IEEE80211_NODE_LOCK_ASSERT(_ni)
6355 +#define	IEEE80211_NODE_LOCK_CHECK(_ni)
6356 +#endif
6357 +
6358 +#endif /* node lock */
6359 +
6360 +/*
6361 + * Node table locking definitions.
6362 + */
6363 +typedef spinlock_t ieee80211_node_table_lock_t;
6364 +#define	IEEE80211_NODE_TABLE_LOCK_INIT(_nt, _name)	spin_lock_init(&(_nt)->nt_nodelock)
6365 +#define	IEEE80211_NODE_TABLE_LOCK_DESTROY(_nt)
6366 +#if 0	/* We should always be contesting in the same contexts */
6367 +#define	IEEE80211_NODE_TABLE_LOCK(_nt)	spin_lock(&(_nt)->nt_nodelock)
6368 +#define	IEEE80211_NODE_TABLE_UNLOCK(_nt)	spin_unlock(&(_nt)->nt_nodelock)
6369 +#define	IEEE80211_NODE_TABLE_LOCK_BH(_nt)	spin_lock_bh(&(_nt)->nt_nodelock)
6370 +#define	IEEE80211_NODE_TABLE_UNLOCK_BH(_nt)	spin_unlock_bh(&(_nt)->nt_nodelock)
6371 +#endif
6372 +#define	IEEE80211_NODE_TABLE_LOCK_IRQ(_nt)	do {	\
6373 +	unsigned long __node_lockflags;		\
6374 +	spin_lock_irqsave(&(_nt)->nt_nodelock, __node_lockflags);
6375 +#define	IEEE80211_NODE_TABLE_UNLOCK_IRQ(_nt)		\
6376 +	spin_unlock_irqrestore(&(_nt)->nt_nodelock, __node_lockflags); \
6377 +} while (0)
6378 +#define	IEEE80211_NODE_TABLE_UNLOCK_IRQ_EARLY(_nt)		\
6379 +	spin_unlock_irqrestore(&(_nt)->nt_nodelock, __node_lockflags);
6380 +
6381 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6382 +#define	IEEE80211_NODE_TABLE_LOCK_ASSERT(_nt) \
6383 +	KASSERT(spin_is_locked(&(_nt)->nt_nodelock), \
6384 +		("802.11 node table not locked!"))
6385 +#else
6386 +#define	IEEE80211_NODE_TABLE_LOCK_ASSERT(_nt)
6387 +#endif
6388 +
6389 +/*
6390 + * Node table scangen locking definitions.
6391 + */
6392 +typedef spinlock_t ieee80211_scan_lock_t;
6393 +#define	IEEE80211_SCAN_LOCK_INIT(_nt, _name) spin_lock_init(&(_nt)->nt_scanlock)
6394 +#define	IEEE80211_SCAN_LOCK_DESTROY(_nt)
6395 +#define	IEEE80211_SCAN_LOCK_IRQ(_nt)	do {	\
6396 +	unsigned long __scan_lockflags;		\
6397 +	spin_lock_irqsave(&(_nt)->nt_scanlock, __scan_lockflags);
6398 +#define	IEEE80211_SCAN_UNLOCK_IRQ(_nt)		\
6399 +	spin_unlock_irqrestore(&(_nt)->nt_scanlock, __scan_lockflags); \
6400 +} while (0)
6401 +#define	IEEE80211_SCAN_UNLOCK_IRQ_EARLY(_nt)		\
6402 +	spin_unlock_irqrestore(&(_nt)->nt_scanlock, __scan_lockflags);
6403 +
6404 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6405 +#define	IEEE80211_SCAN_LOCK_ASSERT(_nt) \
6406 +	KASSERT(spin_is_locked(&(_nt)->nt_scanlock), ("scangen not locked!"))
6407 +#else
6408 +#define	IEEE80211_SCAN_LOCK_ASSERT(_nt)
6409 +#endif
6410 +
6411 +/*
6412 + * 802.1x MAC ACL database locking definitions.
6413 + */
6414 +typedef spinlock_t acl_lock_t;
6415 +#define	ACL_LOCK_INIT(_as, _name)	spin_lock_init(&(_as)->as_lock)
6416 +#define	ACL_LOCK_DESTROY(_as)
6417 +#define	ACL_LOCK(_as)			do { 	\
6418 +	ACL_LOCK_CHECK(_as); 		\
6419 +	spin_lock(&(_as)->as_lock);
6420 +#define	ACL_UNLOCK(_as)				\
6421 +	ACL_LOCK_ASSERT(_as); 			\
6422 +	spin_unlock(&(_as)->as_lock); 		\
6423 +} while(0)
6424 +#define ACL_UNLOCK_EARLY(_as)			\
6425 +	ACL_LOCK_ASSERT(_as); 			\
6426 +	spin_unlock(&(_as)->as_lock);
6427 +
6428 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6429 +#define	ACL_LOCK_ASSERT(_as) \
6430 +	KASSERT(spin_is_locked(&(_as)->as_lock), ("ACL not locked!"))
6431 +#if (defined(ATH_DEBUG_SPINLOCKS))
6432 +#define	ACL_LOCK_CHECK(_as) do { \
6433 +	if (spin_is_locked(&(_as)->as_lock)) \
6434 +		printk("%s:%d - about to block on ACL lock!\n", __func__, __LINE__); \
6435 +} while(0)
6436 +#else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6437 +#define	ACL_LOCK_CHECK(_as)
6438 +#endif /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6439 +#else
6440 +#define	ACL_LOCK_ASSERT(_as)
6441 +#define	ACL_LOCK_CHECK(_as)
6442 +#endif
6443 +
6444 +/*
6445 + * Per-node power-save queue definitions.  Beware of control
6446 + * flow with IEEE80211_NODE_SAVEQ_LOCK/IEEE80211_NODE_SAVEQ_UNLOCK.
6447 + */
6448 +#define	IEEE80211_NODE_SAVEQ_INIT(_ni, _name) do {		\
6449 +	skb_queue_head_init(&(_ni)->ni_savedq);			\
6450 +} while (0)
6451 +#define	IEEE80211_NODE_SAVEQ_DESTROY(_ni)
6452 +#define	IEEE80211_NODE_SAVEQ_QLEN(_ni)		skb_queue_len(&(_ni)->ni_savedq)
6453 +#define	IEEE80211_NODE_SAVEQ_LOCK_IRQ(_ni) do {			\
6454 +	unsigned long __qlockflags;				\
6455 +	IEEE80211_NODE_SAVEQ_LOCK_CHECK(_ni);		\
6456 +	spin_lock_irqsave(&(_ni)->ni_savedq.lock, __qlockflags);
6457 +#define	IEEE80211_NODE_SAVEQ_UNLOCK_IRQ(_ni)    		\
6458 +	IEEE80211_NODE_SAVEQ_LOCK_ASSERT(_ni);			\
6459 +	spin_unlock_irqrestore(&(_ni)->ni_savedq.lock, __qlockflags); \
6460 +} while (0)
6461 +#define	IEEE80211_NODE_SAVEQ_UNLOCK_IRQ_EARLY(_ni)		\
6462 +	IEEE80211_NODE_SAVEQ_LOCK_ASSERT(_ni);			\
6463 +	spin_unlock_irqrestore(&(_ni)->ni_savedq.lock, __qlockflags);
6464 +
6465 +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
6466 +#define IEEE80211_NODE_SAVEQ_LOCK_ASSERT(_ni) \
6467 +	KASSERT(spin_is_locked(&(_ni)->ni_savedq.lock), \
6468 +		("node saveq not locked!"))
6469 +#if (defined(ATH_DEBUG_SPINLOCKS))
6470 +#define IEEE80211_NODE_SAVEQ_LOCK_CHECK(_ni) do { \
6471 +	if (spin_is_locked(&(_ni)->ni_savedq.lock)) \
6472 +		printk("%s:%d - about to block on node saveq lock!\n", __func__, __LINE__); \
6473 +} while(0)
6474 +#else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6475 +#define IEEE80211_NODE_SAVEQ_LOCK_CHECK(_ni)
6476 +#endif /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
6477 +#else
6478 +#define IEEE80211_NODE_SAVEQ_LOCK_ASSERT(_ni)
6479 +#define IEEE80211_NODE_SAVEQ_LOCK_CHECK(_ni)
6480 +#endif
6481 +
6482 +/* caller MUST lock IEEE80211_NODE_SAVEQ */
6483 +#define	IEEE80211_NODE_SAVEQ_DEQUEUE(_ni, _skb, _qlen) do {	\
6484 +	_skb = __skb_dequeue(&(_ni)->ni_savedq);		\
6485 +	(_qlen) = skb_queue_len(&(_ni)->ni_savedq);		\
6486 +} while (0)
6487 +#define	_IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _skb, _qlen, _age) do {	\
6488 +	struct sk_buff *tail = skb_peek_tail(&(_ni)->ni_savedq);	\
6489 +	if (tail != NULL) {						\
6490 +		_age -= M_AGE_GET(tail);				\
6491 +		__skb_queue_after(&(_ni)->ni_savedq, tail, _skb);	\
6492 +	} else { 							\
6493 +		__skb_queue_head(&(_ni)->ni_savedq, _skb);		\
6494 +	}								\
6495 +	M_AGE_SET(_skb, _age);						\
6496 +	(_qlen) = skb_queue_len(&(_ni)->ni_savedq); 			\
6497 +} while (0)
6498 +
6499 +/*
6500 + * Transmitted frames have the following information
6501 + * held in the sk_buff control buffer.  This is used to
6502 + * communicate various inter-procedural state that needs
6503 + * to be associated with the frame for the duration of
6504 + * its existence.
6505 + *
6506 + * NB: sizeof(cb) == 48 and the vlan code grabs the first
6507 + *     8 bytes so we reserve/avoid it.
6508 + */
6509 +	struct ieee80211_cb {
6510 +	u_int8_t vlan[8];			/* reserve for vlan tag info */
6511 +	struct ieee80211_node *ni;
6512 +	u_int32_t flags;
6513 +#define	M_LINK0		0x01			/* frame needs WEP encryption */
6514 +#define	M_FF		0x02			/* fast frame */
6515 +#define	M_PWR_SAV	0x04			/* bypass power save handling */
6516 +#define M_UAPSD		0x08			/* frame flagged for u-apsd handling */
6517 +#define M_RAW           0x10
6518 +#ifdef IEEE80211_DEBUG_REFCNT
6519 +	int tracked;
6520 +	void		(*next_destructor)(struct sk_buff *skb);
6521 +#endif
6522 +	struct sk_buff *next;			/* fast frame sk_buf chain */
6523 +};
6524 +
6525 +
6526 +#define	SKB_CB(_skb) 		((struct ieee80211_cb *)(_skb)->cb)
6527 +
6528 +#define M_FLAG_SET(_skb, _flag) \
6529 +	(SKB_CB(_skb)->flags |= (_flag))
6530 +#define	M_FLAG_CLR(_skb, _flag) \
6531 +	(SKB_CB(_skb)->flags &= ~(_flag))
6532 +#define	M_FLAG_GET(_skb, _flag) \
6533 +	(SKB_CB(_skb)->flags & (_flag))
6534 +#define M_FLAG_KEEP_ONLY(_skb, _flag) \
6535 +	(SKB_CB(_skb)->flags &= (_flag))
6536 +
6537 +#define	M_PWR_SAV_SET(skb) M_FLAG_SET((skb), M_PWR_SAV)
6538 +#define	M_PWR_SAV_CLR(skb) M_FLAG_CLR((skb), M_PWR_SAV)
6539 +#define	M_PWR_SAV_GET(skb) M_FLAG_GET((skb), M_PWR_SAV)
6540 +
6541 +/*
6542 + * Skbufs on the power save queue are tagged with an age and
6543 + * timed out.  We reuse the hardware checksum field in the
6544 + * mbuf packet header to store this data.
6545 + * XXX use private cb area
6546 + */
6547 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
6548 +#define skb_age csum_offset
6549 +#else
6550 +#define skb_age csum
6551 +#endif
6552 +
6553 +#define	M_AGE_SET(skb,v)	(skb->skb_age = v)
6554 +#define	M_AGE_GET(skb)		(skb->skb_age)
6555 +#define	M_AGE_SUB(skb,adj)	(skb->skb_age -= adj)
6556 +
6557 +struct ieee80211com;
6558 +struct ieee80211vap;
6559 +
6560 +int ieee80211_load_module(const char *);
6561 +
6562 +#define	le16toh(_x)	le16_to_cpu(_x)
6563 +#define	htole16(_x)	cpu_to_le16(_x)
6564 +#define	le32toh(_x)	le32_to_cpu(_x)
6565 +#define	htole32(_x)	cpu_to_le32(_x)
6566 +#define	be32toh(_x)	be32_to_cpu(_x)
6567 +#define	htobe32(_x)	cpu_to_be32(_x)
6568 +
6569 +/*
6570 + * Linux has no equivalents to malloc types so null these out.
6571 + */
6572 +#define	MALLOC_DEFINE(type, shortdesc, longdesc)
6573 +#define	MALLOC_DECLARE(type)
6574 +
6575 +/*
6576 + * flags to malloc.
6577 + */
6578 +#define	M_NOWAIT	0x0001		/* do not block */
6579 +#define	M_WAITOK	0x0002		/* ok to block */
6580 +#define	M_ZERO		0x0100		/* bzero the allocation */
6581 +
6582 +static __inline void *
6583 +ieee80211_malloc(size_t size, int flags)
6584 +{
6585 +	void *p = kmalloc(size, flags & M_NOWAIT ? GFP_ATOMIC : GFP_KERNEL);
6586 +	if (p && (flags & M_ZERO))
6587 +		memset(p, 0, size);
6588 +	return p;
6589 +}
6590 +#define	MALLOC(_ptr, cast, _size, _type, _flags) \
6591 +	((_ptr) = (cast)ieee80211_malloc(_size, _flags))
6592 +#define	FREE(addr, type)	kfree((addr))
6593 +
6594 +/*
6595 + * This unlikely to be popular but it dramatically reduces diffs.
6596 + */
6597 +#define printf(...) printk(__VA_ARGS__)
6598 +struct ieee80211com;
6599 +extern void if_printf(struct net_device *, const char *, ...);
6600 +
6601 +/*
6602 + * Queue write-arounds and support routines.
6603 + */
6604 +#ifdef IEEE80211_DEBUG_REFCNT
6605 +#define ieee80211_getmgtframe(_ppfrm, _pktlen) \
6606 +	ieee80211_getmgtframe_debug(_ppfrm, _pktlen, __func__, __LINE__)
6607 +extern struct sk_buff * ieee80211_getmgtframe_debug(u_int8_t **frm, u_int pktlen, 
6608 +						    const char* func, int line);
6609 +#else
6610 +extern struct sk_buff * ieee80211_getmgtframe(u_int8_t **frm, u_int pktlen);
6611 +#endif
6612 +
6613 +#define	IF_ENQUEUE(_q,_skb)	skb_queue_tail(_q, _skb)
6614 +#define	IF_DEQUEUE(_q,_skb)	(_skb = skb_dequeue(_q))
6615 +#define	_IF_QLEN(_q)		skb_queue_len(_q)
6616 +#define	IF_DRAIN(_q)		skb_queue_drain(_q)
6617 +extern	void skb_queue_drain(struct sk_buff_head *q);
6618 +
6619 +#ifndef __MOD_INC_USE_COUNT
6620 +#define	_MOD_INC_USE(_m, _err)						\
6621 +	if (!try_module_get(_m)) {					\
6622 +		printk(KERN_WARNING "%s: try_module_get failed\n",	\
6623 +			__func__); 					\
6624 +		_err;							\
6625 +	}
6626 +#define	_MOD_DEC_USE(_m)		module_put(_m)
6627 +#else
6628 +#define	_MOD_INC_USE(_m, _err)	MOD_INC_USE_COUNT
6629 +#define	_MOD_DEC_USE(_m)	MOD_DEC_USE_COUNT
6630 +#endif
6631 +
6632 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
6633 +static __inline u_int64_t
6634 +get_jiffies_64(void)
6635 +{
6636 +	return (u_int64_t) jiffies;		/* XXX not right */
6637 +}
6638 +#endif
6639 +
6640 +/* msecs_to_jiffies appeared in 2.6.7 and 2.4.29 */
6641 +#include <linux/delay.h>
6642 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
6643 +	 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)) || \
6644 +	LINUX_VERSION_CODE < KERNEL_VERSION(2,4,29)
6645 +
6646 +/* The following definitions and inline functions are
6647 + * copied from the kernel src, include/linux/jiffies.h */
6648 +
6649 +#ifndef MSEC_PER_SEC
6650 +#define MSEC_PER_SEC (1000L)
6651 +#endif
6652 +
6653 +#ifndef MAX_JIFFY_OFFSET
6654 +#define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
6655 +#endif
6656 +
6657 +static __inline unsigned int jiffies_to_msecs(const unsigned long j)
6658 +{
6659 +#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
6660 +	return (MSEC_PER_SEC / HZ) * j;
6661 +#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
6662 +	return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
6663 +#else
6664 +	return (j * MSEC_PER_SEC) / HZ;
6665 +#endif
6666 +}
6667 +
6668 +static __inline unsigned long msecs_to_jiffies(const unsigned int m)
6669 +{
6670 +	if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
6671 +		return MAX_JIFFY_OFFSET;
6672 +#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
6673 +	return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
6674 +#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
6675 +	return m * (HZ / MSEC_PER_SEC);
6676 +#else
6677 +	return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
6678 +#endif
6679 +}
6680 +
6681 +#endif
6682 +
6683 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,7)
6684 +#include <linux/jiffies.h>
6685 +#endif
6686 +
6687 +#ifndef CLONE_KERNEL
6688 +/*
6689 + * List of flags we want to share for kernel threads,
6690 + * if only because they are not used by them anyway.
6691 + */
6692 +#define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
6693 +#endif
6694 +
6695 +#include <linux/mm.h>
6696 +#ifndef offset_in_page
6697 +#define	offset_in_page(p) ((unsigned long) (p) & ~PAGE_MASK)
6698 +#endif
6699 +
6700 +#ifndef module_put_and_exit
6701 +#define module_put_and_exit(code) do {	\
6702 +	_MOD_DEC_USE(THIS_MODULE);	\
6703 +	do_exit(code);			\
6704 +} while (0)
6705 +#endif
6706 +
6707 +/*
6708 + * Linux uses __BIG_ENDIAN and __LITTLE_ENDIAN while BSD uses _foo
6709 + * and an explicit _BYTE_ORDER.  Sorry, BSD got there first--define
6710 + * things in the BSD way...
6711 + */
6712 +#undef _LITTLE_ENDIAN
6713 +#define	_LITTLE_ENDIAN	1234	/* LSB first: i386, vax */
6714 +#undef _BIG_ENDIAN
6715 +#define	_BIG_ENDIAN	4321	/* MSB first: 68000, ibm, net */
6716 +#include <asm/byteorder.h>
6717 +#if defined(__LITTLE_ENDIAN)
6718 +#define	_BYTE_ORDER	_LITTLE_ENDIAN
6719 +#elif defined(__BIG_ENDIAN)
6720 +#define	_BYTE_ORDER	_BIG_ENDIAN
6721 +#else
6722 +#error "Please fix asm/byteorder.h"
6723 +#endif
6724 +
6725 +
6726 +/*
6727 + * Deal with the sysctl handler api changing.
6728 + */
6729 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)
6730 +#define	IEEE80211_SYSCTL_DECL(f, ctl, write, filp, buffer, lenp, ppos) \
6731 +	f(ctl_table *ctl, int write, struct file *filp, \
6732 +	  void __user *buffer, size_t *lenp)
6733 +#define	IEEE80211_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \
6734 +	proc_dointvec(ctl, write, filp, buffer, lenp)
6735 +#else
6736 +#define	IEEE80211_SYSCTL_DECL(f, ctl, write, filp, buffer, lenp, ppos) \
6737 +	f(ctl_table *ctl, int write, struct file *filp, \
6738 +	  void __user *buffer, size_t *lenp, loff_t *ppos)
6739 +#define	IEEE80211_SYSCTL_PROC_DOINTVEC(ctl, write, filp, buffer, lenp, ppos) \
6740 +	proc_dointvec(ctl, write, filp, buffer, lenp, ppos)
6741 +#endif
6742 +
6743 +void ieee80211_virtfs_latevattach(struct ieee80211vap *);
6744 +void ieee80211_virtfs_vdetach(struct ieee80211vap *);
6745 +int ieee80211_proc_vcreate(struct ieee80211vap *, struct file_operations *,
6746 +	       char *);
6747 +void ieee80211_proc_cleanup(struct ieee80211vap *);
6748 +
6749 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6750 +#define IEEE80211_VLAN_TAG_USED 1
6751 +
6752 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20)
6753 +#define	vlan_hwaccel_receive_skb(skb, grp, tag)	vlan_hwaccel_rx(skb, grp, tag)
6754 +#endif
6755 +
6756 +#ifndef VLAN_GROUP_ARRAY_PART_LEN
6757 +#define vlan_group_set_device(group, vid, dev) do { \
6758 +	group->vlan_devices[vid] = dev; \
6759 +} while (0);
6760 +#endif
6761 +
6762 +#else
6763 +#define IEEE80211_VLAN_TAG_USED 0
6764 +#endif
6765 +void ieee80211_vlan_vattach(struct ieee80211vap *);
6766 +void ieee80211_vlan_vdetach(struct ieee80211vap *);
6767 +
6768 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
6769 +#define	free_netdev(dev)	kfree(dev)
6770 +#endif
6771 +
6772 +void ieee80211_ioctl_vattach(struct ieee80211vap *);
6773 +void ieee80211_ioctl_vdetach(struct ieee80211vap *);
6774 +struct ifreq;
6775 +int ieee80211_ioctl_create_vap(struct ieee80211com *, struct ifreq *,
6776 +	struct net_device *);
6777 +struct ieee80211vap *ieee80211_create_vap(struct ieee80211com *, char *,
6778 +	struct net_device *, int, int);
6779 +#endif /* _NET80211_IEEE80211_LINUX_H_ */
6780 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_monitor.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_monitor.h
6781 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_monitor.h	1970-01-01 01:00:00.000000000 +0100
6782 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_monitor.h	2008-06-19 17:34:17.000000000 +0200
6783 @@ -0,0 +1,161 @@
6784 +/*-
6785 + * Copyright (c) 2005 John Bicket
6786 + * All rights reserved.
6787 + *
6788 + * Redistribution and use in source and binary forms, with or without
6789 + * modification, are permitted provided that the following conditions
6790 + * are met:
6791 + * 1. Redistributions of source code must retain the above copyright
6792 + *    notice, this list of conditions and the following disclaimer.
6793 + * 2. Redistributions in binary form must reproduce the above copyright
6794 + *    notice, this list of conditions and the following disclaimer in the
6795 + *    documentation and/or other materials provided with the distribution.
6796 + * 3. The name of the author may not be used to endorse or promote products
6797 + *    derived from this software without specific prior written permission.
6798 + *
6799 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6800 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6801 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6802 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6803 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6804 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6805 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6806 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6807 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6808 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6809 + *
6810 + * $Id: ieee80211_monitor.h 3014 2007-12-10 23:13:33Z scottr $
6811 + */
6812 +#ifndef _NET80211_IEEE80211_MONITOR_H_
6813 +#define _NET80211_IEEE80211_MONITOR_H_
6814 +
6815 +#ifndef ARPHRD_IEEE80211_RADIOTAP
6816 +#define ARPHRD_IEEE80211_RADIOTAP	803 /* IEEE 802.11 + radiotap header */
6817 +#endif /* ARPHRD_IEEE80211_RADIOTAP */
6818 +
6819 +#ifndef ARPHRD_IEEE80211_ATHDESC
6820 +#define ARPHRD_IEEE80211_ATHDESC	804 /* IEEE 802.11 + atheros descriptor */
6821 +#endif /* ARPHRD_IEEE80211_RADIOTAP */
6822 +
6823 +#define ATHDESC_HEADER_SIZE	32
6824 +
6825 +#include <net80211/ieee80211_radiotap.h>
6826 +#include <ah_desc.h>
6827 +#include <ath/if_athvar.h>
6828 +
6829 +struct ieee80211_phy_params {
6830 +	u_int8_t rate0;
6831 +	u_int8_t rate1;
6832 +	u_int8_t rate2;
6833 +	u_int8_t rate3;
6834 +
6835 +	u_int8_t try0;
6836 +	u_int8_t try1;
6837 +	u_int8_t try2;
6838 +	u_int8_t try3;
6839 +
6840 +	u_int8_t power;
6841 +	u_int32_t flags;
6842 +};
6843 +
6844 +enum {
6845 +	DIDmsg_lnxind_wlansniffrm		= 0x00000044,
6846 +	DIDmsg_lnxind_wlansniffrm_hosttime	= 0x00010044,
6847 +	DIDmsg_lnxind_wlansniffrm_mactime	= 0x00020044,
6848 +	DIDmsg_lnxind_wlansniffrm_channel	= 0x00030044,
6849 +	DIDmsg_lnxind_wlansniffrm_rssi		= 0x00040044,
6850 +	DIDmsg_lnxind_wlansniffrm_sq		= 0x00050044,
6851 +	DIDmsg_lnxind_wlansniffrm_signal	= 0x00060044,
6852 +	DIDmsg_lnxind_wlansniffrm_noise		= 0x00070044,
6853 +	DIDmsg_lnxind_wlansniffrm_rate		= 0x00080044,
6854 +	DIDmsg_lnxind_wlansniffrm_istx		= 0x00090044,
6855 +	DIDmsg_lnxind_wlansniffrm_frmlen	= 0x000A0044
6856 +};
6857 +enum {
6858 +	P80211ENUM_msgitem_status_no_value	= 0x00
6859 +};
6860 +enum {
6861 +	P80211ENUM_truth_false			= 0x00,
6862 +	P80211ENUM_truth_true			= 0x01
6863 +};
6864 +
6865 +struct p80211item_uint32 {
6866 +	u_int32_t did;
6867 +	u_int16_t status;
6868 +	u_int16_t len;
6869 +	u_int32_t data;
6870 +};
6871 +
6872 +struct wlan_ng_prism2_header {
6873 +	u_int32_t msgcode;
6874 +	u_int32_t msglen;
6875 +#define WLAN_DEVNAMELEN_MAX 16
6876 +	u_int8_t devname[WLAN_DEVNAMELEN_MAX];
6877 +	struct p80211item_uint32 hosttime;
6878 +	struct p80211item_uint32 mactime;
6879 +	struct p80211item_uint32 channel;
6880 +	struct p80211item_uint32 rssi;
6881 +	struct p80211item_uint32 sq;
6882 +	struct p80211item_uint32 signal;
6883 +	struct p80211item_uint32 noise;
6884 +	struct p80211item_uint32 rate;
6885 +	struct p80211item_uint32 istx;
6886 +	struct p80211item_uint32 frmlen;
6887 +};
6888 +
6889 +#define ATH_RX_RADIOTAP_PRESENT (               \
6890 +	(1 << IEEE80211_RADIOTAP_TSFT)		| \
6891 +	(1 << IEEE80211_RADIOTAP_FLAGS)         | \
6892 +	(1 << IEEE80211_RADIOTAP_RATE)          | \
6893 +	(1 << IEEE80211_RADIOTAP_CHANNEL)       | \
6894 +	(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL)	| \
6895 +	(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)	| \
6896 +	(1 << IEEE80211_RADIOTAP_ANTENNA)       | \
6897 +	(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)  | \
6898 +	0)
6899 +
6900 +struct ath_rx_radiotap_header {
6901 +	struct ieee80211_radiotap_header wr_ihdr;
6902 +	__le64		wr_tsft;
6903 +	u_int8_t	wr_flags;
6904 +	u_int8_t	wr_rate;
6905 +	__le16		wr_chan_freq;
6906 +	__le16		wr_chan_flags;
6907 +	int8_t		wr_dbm_antsignal;
6908 +	int8_t		wr_dbm_antnoise;
6909 +	u_int8_t	wr_antenna;
6910 +	u_int8_t	wr_antsignal;
6911 +}__attribute__((__packed__));
6912 +
6913 +#define ATH_TX_RADIOTAP_PRESENT (               \
6914 +	(1 << IEEE80211_RADIOTAP_TSFT)		| \
6915 +	(1 << IEEE80211_RADIOTAP_FLAGS)         | \
6916 +	(1 << IEEE80211_RADIOTAP_RATE)          | \
6917 +	(1 << IEEE80211_RADIOTAP_ANTENNA)       | \
6918 +	(1 << IEEE80211_RADIOTAP_TX_FLAGS)	| \
6919 +	(1 << IEEE80211_RADIOTAP_DATA_RETRIES)	| \
6920 +	0)
6921 +
6922 +struct ath_tx_radiotap_header {
6923 +	struct ieee80211_radiotap_header wt_ihdr;
6924 +	__le64		wt_tsft;
6925 +	u_int8_t	wt_flags;
6926 +	u_int8_t	wt_rate;
6927 +	u_int8_t	wt_antenna;
6928 +	u_int8_t	wt_pad; /* Padding to ensure txflags is aligned */
6929 +	__le16		wt_txflags;
6930 +	u_int8_t	wt_dataretries;
6931 +}__attribute__((__packed__));
6932 +
6933 +/*
6934 + * Dispatch an skb to monitor-mode VAPs.  The skb is assumed
6935 + * to have space at the front to push a wlan_ng_prims2_header.
6936 + */
6937 +void ieee80211_input_monitor(struct ieee80211com *, struct sk_buff *,
6938 +	const struct ath_buf *, int, u_int64_t, struct ath_softc *);
6939 +
6940 +
6941 +void ieee80211_monitor_encap(struct ieee80211vap *, struct sk_buff *);
6942 +
6943 +
6944 +#endif /* _NET80211_IEEE80211_MONITOR_H_ */
6945 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_node.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_node.h
6946 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_node.h	1970-01-01 01:00:00.000000000 +0100
6947 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_node.h	2008-06-19 17:34:17.000000000 +0200
6948 @@ -0,0 +1,434 @@
6949 +/*-
6950 + * Copyright (c) 2001 Atsushi Onoe
6951 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
6952 + * All rights reserved.
6953 + *
6954 + * Redistribution and use in source and binary forms, with or without
6955 + * modification, are permitted provided that the following conditions
6956 + * are met:
6957 + * 1. Redistributions of source code must retain the above copyright
6958 + *    notice, this list of conditions and the following disclaimer.
6959 + * 2. Redistributions in binary form must reproduce the above copyright
6960 + *    notice, this list of conditions and the following disclaimer in the
6961 + *    documentation and/or other materials provided with the distribution.
6962 + * 3. The name of the author may not be used to endorse or promote products
6963 + *    derived from this software without specific prior written permission.
6964 + *
6965 + * Alternatively, this software may be distributed under the terms of the
6966 + * GNU General Public License ("GPL") version 2 as published by the Free
6967 + * Software Foundation.
6968 + *
6969 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6970 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6971 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
6972 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
6973 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
6974 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6975 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6976 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6977 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6978 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6979 + *
6980 + * $Id: ieee80211_node.h 3268 2008-01-26 20:48:11Z mtaylor $
6981 + */
6982 +#ifndef _NET80211_IEEE80211_NODE_H_
6983 +#define _NET80211_IEEE80211_NODE_H_
6984 +
6985 +#include <net80211/ieee80211_var.h>
6986 +#include <net80211/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
6987 +#include <net80211/ieee80211_proto.h>		/* for proto macros on node */
6988 +
6989 +/*
6990 + * Each ieee80211com instance has a single timer that fires once a
6991 + * second.  This is used to initiate various work depending on the
6992 + * state of the instance: scanning (passive or active), ``transition''
6993 + * (waiting for a response to a management frame when operating
6994 + * as a station), and node inactivity processing (when operating
6995 + * as an AP).  For inactivity processing each node has a timeout
6996 + * set in its ni_inact field that is decremented on each timeout
6997 + * and the node is reclaimed when the counter goes to zero.  We
6998 + * use different inactivity timeout values depending on whether
6999 + * the node is associated and authorized (either by 802.1x or
7000 + * open/shared key authentication) or associated but yet to be
7001 + * authorized.  The latter timeout is shorter to more aggressively
7002 + * reclaim nodes that leave part way through the 802.1x exchange.
7003 + */
7004 +#define	IEEE80211_INACT_WAIT	15				/* inactivity interval (secs) */
7005 +#define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
7006 +#define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
7007 +#define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
7008 +#define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
7009 +#define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
7010 +
7011 +#define	IEEE80211_TRANS_WAIT 	5				/* mgt frame tx timer (secs) */
7012 +
7013 +#define	IEEE80211_NODE_HASHSIZE	32
7014 +/* simple hash is enough for variation of macaddr */
7015 +#define	IEEE80211_NODE_HASH(addr)	\
7016 +	(((const u_int8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
7017 +		IEEE80211_NODE_HASHSIZE)
7018 +
7019 +struct ieee80211_rsnparms {
7020 +	u_int8_t rsn_mcastcipher;	/* mcast/group cipher */
7021 +	u_int8_t rsn_mcastkeylen;	/* mcast key length */
7022 +	u_int8_t rsn_ucastcipherset;	/* unicast cipher set */
7023 +	u_int8_t rsn_ucastcipher;	/* selected unicast cipher */
7024 +	u_int8_t rsn_ucastkeylen;	/* unicast key length */
7025 +	u_int8_t rsn_keymgmtset;	/* key management algorithms */
7026 +	u_int8_t rsn_keymgmt;		/* selected key mgmt algo */
7027 +	u_int16_t rsn_caps;		/* capabilities */
7028 +};
7029 +
7030 +struct ieee80211_node_table;
7031 +struct ieee80211com;
7032 +struct ieee80211vap;
7033 +struct ath_buf;
7034 +struct ath_softc;
7035 +
7036 +/*
7037 + * Node specific information.  Note that drivers are expected
7038 + * to derive from this structure to add device-specific per-node
7039 + * state.  This is done by overriding the ic_node_* methods in
7040 + * the ieee80211com structure.
7041 + */
7042 +struct ieee80211_node {
7043 +	struct ieee80211vap *ni_vap;
7044 +	struct ieee80211com *ni_ic;
7045 +	struct ieee80211_node_table *ni_table;
7046 +	TAILQ_ENTRY(ieee80211_node) ni_list;
7047 +	LIST_ENTRY(ieee80211_node) ni_hash;
7048 +	atomic_t ni_refcnt;
7049 +	u_int ni_scangen;			/* gen# for timeout scan */
7050 +	u_int8_t ni_authmode;			/* authentication algorithm */
7051 +	u_int16_t ni_flags;			/* special-purpose state */
7052 +#define	IEEE80211_NODE_AUTH	0x0001		/* authorized for data */
7053 +#define	IEEE80211_NODE_QOS	0x0002		/* QoS enabled */
7054 +#define	IEEE80211_NODE_ERP	0x0004		/* ERP enabled */
7055 +/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
7056 +#define	IEEE80211_NODE_PWR_MGT	0x0010		/* power save mode enabled */
7057 +#define	IEEE80211_NODE_AREF	0x0020		/* authentication ref held */
7058 +#define IEEE80211_NODE_UAPSD	0x0040		/* U-APSD power save enabled */
7059 +#define IEEE80211_NODE_UAPSD_TRIG 0x0080	/* U-APSD triggerable state */
7060 +#define IEEE80211_NODE_UAPSD_SP	0x0100		/* U-APSD SP in progress */
7061 +#define IEEE80211_NODE_PS_CHANGED	0x0200	/* PS state change */
7062 +	u_int8_t ni_ath_flags;			/* Atheros feature flags */
7063 +	/* NB: These must have the same values as IEEE80211_ATHC_* */
7064 +#define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
7065 +#define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
7066 +#define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
7067 +#define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
7068 +#define IEEE80211_NODE_AR	0x0010		/* AR capable */
7069 +#define IEEE80211_NODE_BOOST	0x0080
7070 +	u_int16_t ni_ath_defkeyindex;		/* Atheros def key index */
7071 +#define IEEE80211_INVAL_DEFKEY	0x7FFF
7072 +	u_int16_t ni_associd;			/* assoc response */
7073 +	u_int16_t ni_txpower;			/* current transmit power (in 0.5 dBm) */
7074 +	u_int16_t ni_vlan;			/* vlan tag */
7075 +	u_int32_t *ni_challenge;		/* shared-key challenge */
7076 +	u_int8_t *ni_wpa_ie;			/* captured WPA ie */
7077 +	u_int8_t *ni_rsn_ie;			/* captured RSN ie */
7078 +	u_int8_t *ni_wme_ie;			/* captured WME ie */
7079 +	u_int8_t *ni_ath_ie;			/* captured Atheros ie */
7080 +	u_int8_t *ni_suppchans;			/* supported channels */
7081 +	u_int8_t *ni_suppchans_new;		/* supported channels of ongoing association */
7082 +	u_int8_t *ni_needed_chans;		/* nodes which don't support these will be removed */
7083 +	u_int8_t ni_n_needed_chans;		/* size of ni_needed_chans list */
7084 +	u_int16_t ni_txseqs[17];		/* tx seq per-tid */
7085 +	u_int16_t ni_rxseqs[17];		/* rx seq previous per-tid*/
7086 +	u_int32_t ni_rxfragstamp;		/* time stamp of last rx frag */
7087 +	struct sk_buff *ni_rxfrag;		/* rx frag reassembly */
7088 +	struct ieee80211_rsnparms ni_rsn;	/* RSN/WPA parameters */
7089 +	struct ieee80211_key ni_ucastkey;	/* unicast key */
7090 +	int ni_rxkeyoff;    			/* Receive key offset */
7091 +
7092 +	/* hardware */
7093 +	u_int64_t ni_rtsf;			/* recv timestamp */
7094 +	u_int32_t ni_last_rx;			/* recv jiffies */
7095 +	u_int8_t ni_rssi;			/* recv ssi */
7096 +
7097 +	/* header */
7098 +	u_int8_t ni_macaddr[IEEE80211_ADDR_LEN];
7099 +	u_int8_t ni_bssid[IEEE80211_ADDR_LEN];
7100 +
7101 +	/* beacon, probe response */
7102 +	union {
7103 +		u_int8_t data[8];
7104 +		__le64 tsf;
7105 +	} ni_tstamp;				/* from last rcv'd beacon */
7106 +
7107 +	u_int16_t ni_intval;			/* beacon interval */
7108 +	u_int16_t ni_intval_old;		/* beacon interval before first change */
7109 +	u_int16_t ni_intval_cnt;		/* count of ni_intval != ni_intval_old */
7110 +	unsigned long ni_intval_end;		/* end of transition interval jiffies */
7111 +
7112 +	u_int16_t ni_capinfo;			/* capabilities */
7113 +	u_int8_t ni_esslen;
7114 +	u_int8_t ni_essid[IEEE80211_NWID_LEN];
7115 +	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
7116 +	struct ieee80211_channel *ni_chan;
7117 +	u_int16_t ni_fhdwell;			/* FH only */
7118 +	u_int8_t ni_fhindex;			/* FH only */
7119 +	u_int8_t ni_erp;			/* ERP from beacon/probe resp */
7120 +	u_int16_t ni_timoff;			/* byte offset to TIM ie */
7121 +
7122 +	/* others */
7123 +	struct sk_buff_head ni_savedq;		/* packets queued for pspoll */
7124 +	short ni_inact;				/* inactivity mark count */
7125 +	short ni_inact_reload;			/* inactivity reload value */
7126 +	int ni_txrate;				/* index to ni_rates[] */
7127 +	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
7128 +	struct ieee80211vap *ni_prev_vap;  	/* previously associated vap */
7129 +	u_int8_t ni_uapsd;			/* U-APSD per-node flags matching WMM STA Qos Info field */
7130 +	u_int8_t ni_uapsd_maxsp; 		/* maxsp from flags above */
7131 +	u_int16_t ni_uapsd_trigseq[WME_NUM_AC];	/* trigger suppression on retry */
7132 +	__le16 ni_pschangeseq;
7133 +};
7134 +MALLOC_DECLARE(M_80211_NODE);
7135 +
7136 +#define	IEEE80211_NODE_AID(ni)			IEEE80211_AID(ni->ni_associd)
7137 +
7138 +#define	IEEE80211_NODE_STAT(ni,stat)		(ni->ni_stats.ns_##stat++)
7139 +#define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
7140 +#define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
7141 +
7142 +#define WME_UAPSD_AC_CAN_TRIGGER(_ac, _ni) (				\
7143 +		((_ni)->ni_flags & IEEE80211_NODE_UAPSD_TRIG) &&	\
7144 +		WME_UAPSD_AC_ENABLED((_ac), (_ni)->ni_uapsd))
7145 +#define WME_UAPSD_NODE_MAXQDEPTH	8
7146 +#define IEEE80211_NODE_UAPSD_USETIM(_ni) (((_ni)->ni_uapsd & 0xF) == 0xF)
7147 +#define WME_UAPSD_NODE_INVALIDSEQ	0xffff
7148 +#define WME_UAPSD_NODE_TRIGSEQINIT(_ni)					\
7149 +		(memset(&(_ni)->ni_uapsd_trigseq[0],			\
7150 +		 0xff, sizeof((_ni)->ni_uapsd_trigseq)))
7151 +
7152 +void ieee80211_node_attach(struct ieee80211com *);
7153 +void ieee80211_node_detach(struct ieee80211com *);
7154 +void ieee80211_node_vattach(struct ieee80211vap *);
7155 +void ieee80211_node_latevattach(struct ieee80211vap *);
7156 +void ieee80211_node_vdetach(struct ieee80211vap *);
7157 +
7158 +static __inline int
7159 +ieee80211_node_is_authorized(const struct ieee80211_node *ni)
7160 +{
7161 +	return (ni->ni_flags & IEEE80211_NODE_AUTH);
7162 +}
7163 +
7164 +void ieee80211_node_authorize(struct ieee80211_node *);
7165 +void ieee80211_node_unauthorize(struct ieee80211_node *);
7166 +
7167 +void ieee80211_create_ibss(struct ieee80211vap *, struct ieee80211_channel *);
7168 +void ieee80211_reset_bss(struct ieee80211vap *);
7169 +int ieee80211_ibss_merge(struct ieee80211_node *);
7170 +struct ieee80211_scan_entry;
7171 +int ieee80211_sta_join(struct ieee80211vap *, const struct ieee80211_scan_entry *);
7172 +void ieee80211_sta_join1_tasklet(IEEE80211_TQUEUE_ARG);
7173 +void ieee80211_sta_leave(struct ieee80211_node *);
7174 +
7175 +#define WDS_AGING_TIME		600   /* 10 minutes */
7176 +#define WDS_AGING_COUNT 	2
7177 +#define WDS_AGING_STATIC 	0xffff
7178 +#define WDS_AGING_TIMER_VAL 	(WDS_AGING_TIME / 2)
7179 +
7180 +struct ieee80211_wds_addr {
7181 +	LIST_ENTRY(ieee80211_wds_addr) wds_hash;
7182 +	u_int8_t	wds_macaddr[IEEE80211_ADDR_LEN];
7183 +	struct ieee80211_node *wds_ni;
7184 +	u_int16_t wds_agingcount;
7185 +};
7186 +
7187 +/*
7188 + * Table of ieee80211_node instances.  Each ieee80211com
7189 + * has at least one for holding the scan candidates.
7190 + * When operating as an access point or in ibss mode there
7191 + * is a second table for associated stations or neighbors.
7192 + */
7193 +struct ieee80211_node_table {
7194 +	const char *nt_name;			/* for debugging */
7195 +	struct ieee80211com *nt_ic;		/* back reference */
7196 +	ieee80211_node_table_lock_t nt_nodelock;	/* on node table */
7197 +	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
7198 +	ATH_LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
7199 +	ATH_LIST_HEAD(, ieee80211_wds_addr) nt_wds_hash[IEEE80211_NODE_HASHSIZE];
7200 +	ieee80211_scan_lock_t nt_scanlock;	/* on nt_scangen */
7201 +	u_int nt_scangen;			/* gen# for timeout scan */
7202 +	int nt_inact_init;			/* initial node inact setting */
7203 +	struct timer_list nt_wds_aging_timer;	/* timer to age out wds entries */
7204 +};
7205 +
7206 +/* Allocates a new ieee80211_node* that has a reference count of one, and 
7207 + * adds it to the node table. */
7208 +#ifdef IEEE80211_DEBUG_REFCNT
7209 +#define ieee80211_alloc_node_table(_vap, _mac) \
7210 +	ieee80211_alloc_node_table_debug(_vap, _mac, __func__, __LINE__)
7211 +struct ieee80211_node *ieee80211_alloc_node_table_debug(struct ieee80211vap *,
7212 +	const u_int8_t *, const char* name, int line);
7213 +#else
7214 +struct ieee80211_node *ieee80211_alloc_node_table(struct ieee80211vap *,
7215 +	const u_int8_t *);
7216 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7217 +
7218 +/* Allocates a new ieee80211_node* that has a reference count.  
7219 + * If tmp is 0, it is added to the node table and the reference is used.
7220 + * If tmp is 1, then the caller gets to use the reference. */
7221 +#ifdef IEEE80211_DEBUG_REFCNT
7222 +#define ieee80211_dup_bss(_vap, _mac, _tmp) \
7223 +	ieee80211_dup_bss_debug(_vap, _mac, _tmp, __func__, __LINE__)
7224 +struct ieee80211_node *ieee80211_dup_bss_debug(struct ieee80211vap *,
7225 +	const u_int8_t *, unsigned char tmp, const char*, int);
7226 +#else
7227 +struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
7228 +	const u_int8_t *, unsigned char tmp);
7229 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7230 +
7231 +void ieee80211_node_reset(struct ieee80211_node *, struct ieee80211vap *);
7232 +
7233 +/* Returns a ieee80211_node* with refcount incremented, if found */
7234 +#ifdef IEEE80211_DEBUG_REFCNT
7235 +#define	ieee80211_find_node(_nt, _mac) \
7236 +	ieee80211_find_node_debug(_nt, _mac, __func__, __LINE__)
7237 +struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
7238 +	const u_int8_t *, const char *, int);
7239 +#else
7240 +struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
7241 +	const u_int8_t *);
7242 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7243 +
7244 +/* Returns a ieee80211_node* with refcount incremented, if found */
7245 +#ifdef IEEE80211_DEBUG_REFCNT
7246 +#define	ieee80211_find_rxnode(_nt, _wh) \
7247 +	ieee80211_find_rxnode_debug(_nt, _wh, __func__, __LINE__)
7248 +struct ieee80211_node *ieee80211_find_rxnode_debug(struct ieee80211com *,
7249 +	const struct ieee80211_frame_min *, const char *, int);
7250 +#else
7251 +struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
7252 +	const struct ieee80211_frame_min *);
7253 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7254 +
7255 +/* Returns a ieee80211_node* with refcount incremented, if found */
7256 +#ifdef IEEE80211_DEBUG_REFCNT
7257 +#define	ieee80211_find_txnode(_nt, _mac) \
7258 +	ieee80211_find_txnode_debug(_nt, _mac, __func__, __LINE__)
7259 +struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
7260 +	const u_int8_t *, const char *, int);
7261 +#else
7262 +struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
7263 +	const u_int8_t *);
7264 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7265 +
7266 +#ifdef IEEE80211_DEBUG_REFCNT
7267 +#define ieee80211_free_node(_ni) \
7268 +	ieee80211_free_node_debug(_ni, __func__, __LINE__)
7269 +void ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line);
7270 +#else
7271 +void ieee80211_free_node(struct ieee80211_node *ni);
7272 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7273 +
7274 +/* Reference counting only needs to be locked out against the transitions,
7275 + * 0->1 and 1->0 (i.e., when we do not own the reference we are getting).
7276 + * This only happens when finding the a node reference from the node table,
7277 + * which is locked seperately. Thus, we do not need to lock the follwoing 
7278 + * functions. 
7279 + * Increment the reference counter for ieee80211_node*
7280 + */
7281 +#ifdef IEEE80211_DEBUG_REFCNT
7282 +#define ieee80211_ref_node(_ni) \
7283 +	ieee80211_ref_node_debug(_ni, __func__, __LINE__)
7284 +struct ieee80211_node *
7285 +ieee80211_ref_node_debug(struct ieee80211_node *ni, const char *func, int line);
7286 +#else
7287 +struct ieee80211_node *
7288 +ieee80211_ref_node(struct ieee80211_node *ni);
7289 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7290 +
7291 +#define PASS_NODE(_ni) \
7292 +	ieee80211_pass_node(&_ni)
7293 +
7294 +static __inline struct ieee80211_node *
7295 +ieee80211_pass_node(struct ieee80211_node **pni) {
7296 +	struct ieee80211_node *tmp = *pni;
7297 +	*pni = NULL;
7298 +	return (tmp);
7299 +}
7300 +
7301 +/* Decrement ieee80211_node* refcount, and relinquish the pointer. */
7302 +#ifdef IEEE80211_DEBUG_REFCNT
7303 +#define ieee80211_unref_node(_pni) \
7304 +	ieee80211_unref_node_debug(_pni, __func__, __LINE__)
7305 +void
7306 +ieee80211_unref_node_debug(struct ieee80211_node **pni, const char *func, int line);
7307 +#else
7308 +void
7309 +ieee80211_unref_node(struct ieee80211_node **pni);
7310 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7311 +
7312 +/* Increments reference count of ieee80211_node *ni */
7313 +#ifdef IEEE80211_DEBUG_REFCNT
7314 +#define ieee80211_add_wds_addr(_table, _node, _mac, _static) \
7315 +	ieee80211_add_wds_addr_debug(_table, _node, _mac, _static, __func__, __LINE__)
7316 +int ieee80211_add_wds_addr_debug(struct ieee80211_node_table *, struct ieee80211_node *,
7317 +	const u_int8_t *, u_int8_t, const char* func, int line);
7318 +#else
7319 +int ieee80211_add_wds_addr(struct ieee80211_node_table *, struct ieee80211_node *,
7320 +	const u_int8_t *, u_int8_t);
7321 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7322 +
7323 +/* Decrements reference count of ieee80211_node *ni */
7324 +#ifdef IEEE80211_DEBUG_REFCNT
7325 +#define ieee80211_remove_wds_addr(_table, _mac) \
7326 +	ieee80211_remove_wds_addr_debug(_table, _mac, __func__, __LINE__)
7327 +void ieee80211_remove_wds_addr_debug(struct ieee80211_node_table *, const u_int8_t *,
7328 +			       const char* func, int line);
7329 +#else
7330 +void ieee80211_remove_wds_addr(struct ieee80211_node_table *, const u_int8_t *);
7331 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7332 +
7333 +/* Decrements reference count of node, if found */
7334 +#ifdef IEEE80211_DEBUG_REFCNT
7335 +#define ieee80211_del_wds_node(_table, _node) \
7336 +	ieee80211_del_wds_node_debug(_table, _node, __func__, __LINE__)
7337 +void ieee80211_del_wds_node_debug(struct ieee80211_node_table *, struct ieee80211_node *,
7338 +			    const char* func, int line);
7339 +#else
7340 +void ieee80211_del_wds_node(struct ieee80211_node_table *, struct ieee80211_node *);
7341 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7342 +
7343 +/* Increments reference count of node, if found */
7344 +#ifdef IEEE80211_DEBUG_REFCNT
7345 +#define ieee80211_find_wds_node(_table, _mac) \
7346 +	ieee80211_find_wds_node_debug(_table, _mac, __func__, __LINE__)
7347 +struct ieee80211_node *ieee80211_find_wds_node_debug(struct ieee80211_node_table *,
7348 +	const u_int8_t *, const char* func, int line);
7349 +#else
7350 +struct ieee80211_node *ieee80211_find_wds_node(struct ieee80211_node_table *,
7351 +	const u_int8_t *);
7352 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7353 +typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
7354 +void ieee80211_iterate_nodes(struct ieee80211_node_table *,
7355 +	ieee80211_iter_func *, void *);
7356 +void ieee80211_iterate_dev_nodes(struct net_device *,
7357 +	struct ieee80211_node_table *, ieee80211_iter_func *, void *);
7358 +void	ieee80211_dump_node(struct ieee80211_node_table *,
7359 +	struct ieee80211_node *);
7360 +void	ieee80211_dump_nodes(struct ieee80211_node_table *);
7361 +/* Returns a node with refcount of one.  Caller must release that reference */
7362 +#ifdef IEEE80211_DEBUG_REFCNT
7363 +#define ieee80211_fakeup_adhoc_node(_vap, _mac) \
7364 +	ieee80211_fakeup_adhoc_node_debug(_vap, _mac, __func__, __LINE__)
7365 +struct ieee80211_node *ieee80211_fakeup_adhoc_node_debug(struct ieee80211vap *,
7366 +	const u_int8_t macaddr[], const char*, int);
7367 +#else
7368 +struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
7369 +	const u_int8_t macaddr[]);
7370 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
7371 +struct ieee80211_scanparams;
7372 +/* Returns a node with refcount of one.  Caller must release that reference */
7373 +struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
7374 +	const struct ieee80211_frame *, const struct ieee80211_scanparams *);
7375 +/* Increments reference count of node */
7376 +void ieee80211_node_join(struct ieee80211_node *, int);
7377 +/* Decrements reference count of node */
7378 +void ieee80211_node_leave(struct ieee80211_node *);
7379 +u_int8_t ieee80211_getrssi(struct ieee80211com *);
7380 +int32_t ieee80211_get_node_count(struct ieee80211com *);
7381 +#endif /* _NET80211_IEEE80211_NODE_H_ */
7382 +
7383 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_power.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_power.h
7384 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_power.h	1970-01-01 01:00:00.000000000 +0100
7385 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_power.h	2008-06-19 17:34:17.000000000 +0200
7386 @@ -0,0 +1,53 @@
7387 +/*-
7388 + * Copyright (c) 2001 Atsushi Onoe
7389 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
7390 + * All rights reserved.
7391 + *
7392 + * Redistribution and use in source and binary forms, with or without
7393 + * modification, are permitted provided that the following conditions
7394 + * are met:
7395 + * 1. Redistributions of source code must retain the above copyright
7396 + *    notice, this list of conditions and the following disclaimer.
7397 + * 2. Redistributions in binary form must reproduce the above copyright
7398 + *    notice, this list of conditions and the following disclaimer in the
7399 + *    documentation and/or other materials provided with the distribution.
7400 + * 3. The name of the author may not be used to endorse or promote products
7401 + *    derived from this software without specific prior written permission.
7402 + *
7403 + * Alternatively, this software may be distributed under the terms of the
7404 + * GNU General Public License ("GPL") version 2 as published by the Free
7405 + * Software Foundation.
7406 + *
7407 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7408 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7409 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7410 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7411 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7412 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7413 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7414 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7415 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7416 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7417 + *
7418 + * $Id: ieee80211_power.h 3075 2007-12-23 20:11:05Z mentor $
7419 + */
7420 +#ifndef _NET80211_IEEE80211_POWER_H_
7421 +#define _NET80211_IEEE80211_POWER_H_
7422 +
7423 +struct ieee80211com;
7424 +struct ieee80211vap;
7425 +
7426 +void	ieee80211_power_attach(struct ieee80211com *);
7427 +void	ieee80211_power_detach(struct ieee80211com *);
7428 +void	ieee80211_power_vattach(struct ieee80211vap *);
7429 +void	ieee80211_power_latevattach(struct ieee80211vap *);
7430 +void	ieee80211_power_vdetach(struct ieee80211vap *);
7431 +
7432 +struct ieee80211_node;
7433 +
7434 +int	ieee80211_node_saveq_drain(struct ieee80211_node *);
7435 +int	ieee80211_node_saveq_age(struct ieee80211_node *);
7436 +int	ieee80211_pwrsave(struct sk_buff *);
7437 +void	ieee80211_node_pwrsave(struct ieee80211_node *, int);
7438 +void	ieee80211_sta_pwrsave(struct ieee80211vap *, int);
7439 +#endif /* _NET80211_IEEE80211_POWER_H_ */
7440 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_proto.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_proto.h
7441 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_proto.h	1970-01-01 01:00:00.000000000 +0100
7442 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_proto.h	2008-06-19 17:34:17.000000000 +0200
7443 @@ -0,0 +1,308 @@
7444 +/*-
7445 + * Copyright (c) 2001 Atsushi Onoe
7446 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
7447 + * All rights reserved.
7448 + *
7449 + * Redistribution and use in source and binary forms, with or without
7450 + * modification, are permitted provided that the following conditions
7451 + * are met:
7452 + * 1. Redistributions of source code must retain the above copyright
7453 + *    notice, this list of conditions and the following disclaimer.
7454 + * 2. Redistributions in binary form must reproduce the above copyright
7455 + *    notice, this list of conditions and the following disclaimer in the
7456 + *    documentation and/or other materials provided with the distribution.
7457 + * 3. The name of the author may not be used to endorse or promote products
7458 + *    derived from this software without specific prior written permission.
7459 + *
7460 + * Alternatively, this software may be distributed under the terms of the
7461 + * GNU General Public License ("GPL") version 2 as published by the Free
7462 + * Software Foundation.
7463 + *
7464 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7465 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7466 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7467 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7468 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7469 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7470 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7471 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7472 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7473 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7474 + *
7475 + * $Id: ieee80211_proto.h 3268 2008-01-26 20:48:11Z mtaylor $
7476 + */
7477 +#ifndef _NET80211_IEEE80211_PROTO_H_
7478 +#define _NET80211_IEEE80211_PROTO_H_
7479 +
7480 +/*
7481 + * 802.11 protocol implementation definitions.
7482 + */
7483 +
7484 +enum ieee80211_state {
7485 +	IEEE80211_S_INIT	= 0,	/* default state */
7486 +	IEEE80211_S_SCAN	= 1,	/* scanning */
7487 +	IEEE80211_S_AUTH	= 2,	/* try to authenticate */
7488 +	IEEE80211_S_ASSOC	= 3,	/* try to assoc */
7489 +	IEEE80211_S_RUN		= 4,	/* associated */
7490 +};
7491 +#define	IEEE80211_S_MAX		(IEEE80211_S_RUN + 1)
7492 +
7493 +#define	IEEE80211_SEND_MGMT(_ni,_type,_arg) \
7494 +	((*(_ni)->ni_ic->ic_send_mgmt)(_ni, _type, _arg))
7495 +
7496 +extern const char *ieee80211_mgt_subtype_name[];
7497 +extern const char *ieee80211_ctl_subtype_name[];
7498 +extern const char *ieee80211_state_name[IEEE80211_S_MAX];
7499 +extern const char *ieee80211_wme_acnames[];
7500 +extern const char *ieee80211_phymode_name[];
7501 +
7502 +void ieee80211_proto_attach(struct ieee80211com *);
7503 +void ieee80211_proto_detach(struct ieee80211com *);
7504 +void ieee80211_proto_vattach(struct ieee80211vap *);
7505 +void ieee80211_proto_vdetach(struct ieee80211vap *);
7506 +
7507 +struct ieee80211_node;
7508 +struct ieee80211_channel *ieee80211_doth_findchan(struct ieee80211vap *, u_int8_t);
7509 +int ieee80211_input(struct ieee80211vap *, struct ieee80211_node *, struct sk_buff *, int, u_int64_t);
7510 +int ieee80211_input_all(struct ieee80211com *, struct sk_buff *, int, u_int64_t);
7511 +int ieee80211_setup_rates(struct ieee80211_node *, const u_int8_t *,
7512 +	const u_int8_t *, int);
7513 +void ieee80211_saveie(u_int8_t **, const u_int8_t *);
7514 +void ieee80211_saveath(struct ieee80211_node *, u_int8_t *);
7515 +void ieee80211_recv_mgmt(struct ieee80211vap *, struct ieee80211_node *,
7516 +	struct sk_buff *, int, int, u_int64_t);
7517 +void ieee80211_sta_pwrsave(struct ieee80211vap *, int);
7518 +int ieee80211_hardstart(struct sk_buff *, struct net_device *);
7519 +void ieee80211_parent_queue_xmit(struct sk_buff *);
7520 +int ieee80211_send_nulldata(struct ieee80211_node *);
7521 +int ieee80211_send_qosnulldata(struct ieee80211_node *, int);
7522 +int ieee80211_send_mgmt(struct ieee80211_node *, int, int);
7523 +int ieee80211_send_probereq(struct ieee80211_node *,
7524 +	const u_int8_t sa[IEEE80211_ADDR_LEN],
7525 +	const u_int8_t da[IEEE80211_ADDR_LEN],
7526 +	const u_int8_t bssid[IEEE80211_ADDR_LEN],
7527 +	const u_int8_t *, size_t, const void *, size_t);
7528 +struct sk_buff *ieee80211_encap(struct ieee80211_node *, struct sk_buff *, int *);
7529 +
7530 +void ieee80211_reset_erp(struct ieee80211com *, enum ieee80211_phymode);
7531 +void ieee80211_set_shortslottime(struct ieee80211com *, int);
7532 +int ieee80211_iserp_rateset(struct ieee80211com *, struct ieee80211_rateset *);
7533 +void ieee80211_set11gbasicrates(struct ieee80211_rateset *, enum ieee80211_phymode);
7534 +enum ieee80211_phymode ieee80211_get11gbasicrates(struct ieee80211_rateset *);
7535 +void ieee80211_send_pspoll(struct ieee80211_node *);
7536 +void ieee80211_check_mic(struct ieee80211_node *, struct sk_buff *);
7537 +
7538 +/*
7539 + * Return the size of the 802.11 header for a management or data frame.
7540 + */
7541 +static __inline int
7542 +ieee80211_hdrsize(const void *data)
7543 +{
7544 +	const struct ieee80211_frame *wh = data;
7545 +	int size = sizeof(struct ieee80211_frame);
7546 +
7547 +	/* NB: we don't handle control frames */
7548 +	KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL,
7549 +		("%s: control frame", __func__));
7550 +	if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
7551 +		size += IEEE80211_ADDR_LEN;
7552 +	if (IEEE80211_QOS_HAS_SEQ(wh))
7553 +		size += sizeof(u_int16_t);
7554 +	return size;
7555 +}
7556 +
7557 +/*
7558 + * Like ieee80211_hdrsize, but handles any type of frame.
7559 + */
7560 +static __inline int
7561 +ieee80211_anyhdrsize(const void *data)
7562 +{
7563 +	const struct ieee80211_frame *wh = data;
7564 +
7565 +	if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
7566 +		switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
7567 +		case IEEE80211_FC0_SUBTYPE_CTS:
7568 +		case IEEE80211_FC0_SUBTYPE_ACK:
7569 +			return sizeof(struct ieee80211_frame_ack);
7570 +			break;
7571 +		default:
7572 +			return sizeof(struct ieee80211_frame_min);
7573 +			break;
7574 +		}
7575 +	} else
7576 +		return ieee80211_hdrsize(data);
7577 +}
7578 +
7579 +/*
7580 + * Template for an in-kernel authenticator.  Authenticators
7581 + * register with the protocol code and are typically loaded
7582 + * as separate modules as needed.
7583 + */
7584 +struct ieee80211_authenticator {
7585 +	const char *ia_name;		/* printable name */
7586 +	int (*ia_attach)(struct ieee80211vap *);
7587 +	void (*ia_detach)(struct ieee80211vap *);
7588 +	void (*ia_node_join)(struct ieee80211_node *);
7589 +	void (*ia_node_leave)(struct ieee80211_node *);
7590 +};
7591 +void ieee80211_authenticator_register(int, const struct ieee80211_authenticator *);
7592 +void ieee80211_authenticator_unregister(int);
7593 +const struct ieee80211_authenticator *ieee80211_authenticator_get(int);
7594 +
7595 +struct eapolcom;
7596 +/*
7597 + * Template for an in-kernel authenticator backend.  Backends
7598 + * register with the protocol code and are typically loaded
7599 + * as separate modules as needed.
7600 + */
7601 +struct ieee80211_authenticator_backend {
7602 +	const char *iab_name;		/* printable name */
7603 +	int (*iab_attach)(struct eapolcom *);
7604 +	void (*iab_detach)(struct eapolcom *);
7605 +};
7606 +void ieee80211_authenticator_backend_register(
7607 +	const struct ieee80211_authenticator_backend *);
7608 +void ieee80211_authenticator_backend_unregister(
7609 +	const struct ieee80211_authenticator_backend *);
7610 +const struct ieee80211_authenticator_backend *
7611 +	ieee80211_authenticator_backend_get(const char *);
7612 +
7613 +/*
7614 + * Template for an MAC ACL policy module.  Such modules
7615 + * register with the protocol code and are passed the sender's
7616 + * address of each received frame for validation.
7617 + */
7618 +struct ieee80211_aclator {
7619 +	const char *iac_name;		/* printable name */
7620 +	int (*iac_attach)(struct ieee80211vap *);
7621 +	void (*iac_detach)(struct ieee80211vap *);
7622 +	int (*iac_check)(struct ieee80211vap *,
7623 +		const u_int8_t mac[IEEE80211_ADDR_LEN]);
7624 +	int (*iac_add)(struct ieee80211vap *,
7625 +		const u_int8_t mac[IEEE80211_ADDR_LEN]);
7626 +	int (*iac_remove)(struct ieee80211vap *,
7627 +		const u_int8_t mac[IEEE80211_ADDR_LEN]);
7628 +	int (*iac_flush)(struct ieee80211vap *);
7629 +	int (*iac_setpolicy)(struct ieee80211vap *, int);
7630 +	int (*iac_getpolicy)(struct ieee80211vap *);
7631 +};
7632 +void ieee80211_aclator_register(const struct ieee80211_aclator *);
7633 +void ieee80211_aclator_unregister(const struct ieee80211_aclator *);
7634 +const struct ieee80211_aclator *ieee80211_aclator_get(const char *name);
7635 +
7636 +/* flags for ieee80211_fix_rate() */
7637 +#define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
7638 +#define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
7639 +#define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
7640 +#define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
7641 +int	ieee80211_fix_rate(struct ieee80211_node *, int);
7642 +
7643 +struct wmeParams {
7644 +	u_int8_t wmep_acm;		/* ACM parameter */
7645 +	u_int8_t wmep_aifsn;		/* AIFSN parameters */
7646 +	u_int8_t wmep_logcwmin;		/* cwmin in exponential form */
7647 +	u_int8_t wmep_logcwmax;		/* cwmax in exponential form */
7648 +	u_int16_t wmep_txopLimit;	/* txopLimit */
7649 +	u_int8_t wmep_noackPolicy;	/* No-Ack Policy: 0=ack, 1=no-ack */
7650 +};
7651 +
7652 +#define IEEE80211_EXPONENT_TO_VALUE(_exp) (1 << (u_int32_t)(_exp)) - 1
7653 +#define IEEE80211_TXOP_TO_US(_txop)	(u_int32_t)(_txop) << 5
7654 +#define IEEE80211_US_TO_TXOP(_us)	(u_int16_t)((u_int32_t)(_us)) >> 5
7655 +
7656 +struct chanAccParams{
7657 +	/* XXX: is there any reason to have multiple instances of cap_info_count??? */
7658 +	u_int8_t cap_info_count;		 	/* ver. of the current param set */
7659 +	struct wmeParams cap_wmeParams[WME_NUM_AC];	/* WME params for each access class */
7660 +};
7661 +
7662 +struct ieee80211_wme_state {
7663 +	u_int32_t wme_flags;
7664 +#define	WME_F_AGGRMODE	0x00000001	/* STATUS: WME aggressive mode */
7665 +
7666 +	u_int wme_hipri_traffic;		/* VI/VO frames in beacon interval */
7667 +	u_int wme_hipri_switch_thresh;		/* aggressive mode switch threshold */
7668 +	u_int wme_hipri_switch_hysteresis;	/* aggressive mode switch hysteresis */
7669 +
7670 +	struct chanAccParams wme_wmeChanParams;	/* configured WME parameters applied to itself*/
7671 +	struct chanAccParams wme_wmeBssChanParams; /* configured WME parameters broadcasted to STAs*/
7672 +	struct chanAccParams wme_chanParams;	/* channel parameters applied to itself*/
7673 +	struct chanAccParams wme_bssChanParams;	/* channel parameters broadcasted to STAs*/
7674 +	u_int8_t wme_nonAggressiveMode;   	/* don't use aggressive params and use WME params */
7675 +
7676 +	/* update hardware tx params after wme state change */
7677 +	int (*wme_update)(struct ieee80211com *);
7678 +};
7679 +
7680 +void ieee80211_wme_initparams(struct ieee80211vap *);
7681 +void ieee80211_wme_initparams_locked(struct ieee80211vap *);
7682 +void ieee80211_wme_updateparams(struct ieee80211vap *);
7683 +void ieee80211_wme_updateparams_locked(struct ieee80211vap *);
7684 +
7685 +int ieee80211_open(struct net_device *);
7686 +int ieee80211_init(struct net_device *, int);
7687 +void ieee80211_start_running(struct ieee80211com *);
7688 +int ieee80211_stop(struct net_device *);
7689 +void ieee80211_stop_running(struct ieee80211com *);
7690 +void ieee80211_beacon_miss(struct ieee80211com *);
7691 +#ifdef ATH_SUPERG_DYNTURBO
7692 +void ieee80211_dturbo_switch(struct ieee80211com *, int);
7693 +#endif
7694 +int ieee80211_new_state(struct ieee80211vap *, enum ieee80211_state, int);
7695 +void ieee80211_print_essid(const u_int8_t *, int);
7696 +#ifdef IEEE80211_DEBUG
7697 +void ieee80211_dump_pkt(struct ieee80211com *, const u_int8_t *, int, int, int);
7698 +#else
7699 +#define ieee80211_dump_pkt(...)
7700 +#endif
7701 +struct sk_buff *ieee80211_getcfframe(struct ieee80211vap *, int);
7702 +
7703 +/*
7704 + * Beacon frames constructed by ieee80211_beacon_alloc
7705 + * have the following structure filled in so drivers
7706 + * can update the frame later w/ minimal overhead.
7707 + */
7708 +struct ieee80211_beacon_offsets {
7709 +	__le16 *bo_caps;		/* capabilities */
7710 +	u_int8_t *bo_tim;		/* start of atim/dtim */
7711 +	u_int8_t *bo_wme;		/* start of WME parameters */
7712 +	u_int8_t *bo_tim_trailer;	/* start of fixed-size tim trailer */
7713 +	u_int16_t bo_tim_len;		/* atim/dtim length in bytes */
7714 +	u_int16_t bo_tim_trailerlen;	/* trailer length in bytes */
7715 +	u_int8_t *bo_chanswitch;		/* where channel switch IE will go */
7716 +	u_int8_t *bo_ath_caps;		/* where ath caps is */
7717 +	u_int8_t *bo_xr;			/* start of xr element */
7718 +	u_int8_t *bo_erp;		/* start of ERP element */
7719 +	u_int8_t *bo_appie_buf;		/* start of APP IE buf */
7720 +	u_int16_t bo_appie_buf_len;	/* APP IE buf length in bytes */
7721 +	u_int16_t bo_chanswitch_trailerlen;
7722 +};
7723 +struct sk_buff *ieee80211_beacon_alloc(struct ieee80211_node *,
7724 +	struct ieee80211_beacon_offsets *);
7725 +int ieee80211_beacon_update(struct ieee80211_node *,
7726 +	struct ieee80211_beacon_offsets *, struct sk_buff *, int);
7727 +
7728 +/* XXX exposed due to of beacon code botch */
7729 +u_int8_t *ieee80211_add_rates(u_int8_t *, const struct ieee80211_rateset *);
7730 +u_int8_t *ieee80211_add_xrates(u_int8_t *, const struct ieee80211_rateset *);
7731 +u_int8_t *ieee80211_add_wpa(u_int8_t *, struct ieee80211vap *);
7732 +u_int8_t *ieee80211_add_erp(u_int8_t *, struct ieee80211com *);
7733 +u_int8_t *ieee80211_add_athAdvCap(u_int8_t *, u_int8_t, u_int16_t);
7734 +u_int8_t *ieee80211_add_xr_param(u_int8_t *, struct ieee80211vap *);
7735 +u_int8_t *ieee80211_add_xr_param(u_int8_t *, struct ieee80211vap *);
7736 +u_int8_t *ieee80211_add_wme_param(u_int8_t *, struct ieee80211_wme_state *, int);
7737 +u_int8_t *ieee80211_add_country(u_int8_t *, struct ieee80211com *);
7738 +u_int8_t *ieee80211_add_pwrcnstr(u_int8_t *frm, struct ieee80211com *ic);
7739 +u_int8_t *ieee80211_add_athAdvCap(u_int8_t *, u_int8_t, u_int16_t);
7740 +
7741 +/*
7742 + * Notification methods called from the 802.11 state machine.
7743 + * Note that while these are defined here, their implementation
7744 + * is OS-specific.
7745 + */
7746 +void ieee80211_notify_node_join(struct ieee80211_node *, int);
7747 +void ieee80211_notify_node_leave(struct ieee80211_node *);
7748 +void ieee80211_notify_scan_done(struct ieee80211vap *);
7749 +void ieee80211_notify_sta_stats(struct ieee80211_node *ni);
7750 +
7751 +#endif /* _NET80211_IEEE80211_PROTO_H_ */
7752 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_radiotap.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_radiotap.h
7753 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_radiotap.h	1970-01-01 01:00:00.000000000 +0100
7754 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_radiotap.h	2008-06-19 17:34:17.000000000 +0200
7755 @@ -0,0 +1,258 @@
7756 +/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
7757 +/* $NetBSD: ieee80211_radiotap.h,v 1.17 2007/03/26 04:32:14 dyoung Exp $ */
7758 +
7759 +/*-
7760 + * Copyright (c) 2003, 2004 David Young.  All rights reserved.
7761 + *
7762 + * Redistribution and use in source and binary forms, with or without
7763 + * modification, are permitted provided that the following conditions
7764 + * are met:
7765 + * 1. Redistributions of source code must retain the above copyright
7766 + *    notice, this list of conditions and the following disclaimer.
7767 + * 2. Redistributions in binary form must reproduce the above copyright
7768 + *    notice, this list of conditions and the following disclaimer in the
7769 + *    documentation and/or other materials provided with the distribution.
7770 + * 3. The name of David Young may not be used to endorse or promote
7771 + *    products derived from this software without specific prior
7772 + *    written permission.
7773 + *
7774 + * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
7775 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
7776 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
7777 + * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DAVID
7778 + * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
7779 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
7780 + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7781 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7782 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7783 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7784 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
7785 + * OF SUCH DAMAGE.
7786 + *
7787 + * $Id: ieee80211_radiotap.h 2220 2007-03-26 11:56:18Z scottr $
7788 + */
7789 +#ifndef _NET_IF_IEEE80211RADIOTAP_H_
7790 +#define _NET_IF_IEEE80211RADIOTAP_H_
7791 +
7792 +/* A generic radio capture format is desirable. There is one for
7793 + * Linux, but it is neither rigidly defined (there were not even
7794 + * units given for some fields) nor easily extensible.
7795 + *
7796 + * I suggest the following extensible radio capture format. It is
7797 + * based on a bitmap indicating which fields are present.
7798 + *
7799 + * I am trying to describe precisely what the application programmer
7800 + * should expect in the following, and for that reason I tell the
7801 + * units and origin of each measurement (where it applies), or else I
7802 + * use sufficiently weaselly language ("is a monotonically nondecreasing
7803 + * function of...") that I cannot set false expectations for lawyerly
7804 + * readers.
7805 + */
7806 +#if defined(__KERNEL__) || defined(_KERNEL)
7807 +#ifndef DLT_IEEE802_11_RADIO
7808 +#define	DLT_IEEE802_11_RADIO	127	/* 802.11 plus WLAN header */
7809 +#endif
7810 +#endif /* defined(__KERNEL__) || defined(_KERNEL) */
7811 +
7812 +/* The radio capture header precedes the 802.11 header. */
7813 +struct ieee80211_radiotap_header {
7814 +	u_int8_t it_version;		/* Version 0. Only increases
7815 +					 * for drastic changes,
7816 +					 * introduction of compatible
7817 +					 * new fields does not count.
7818 +					 */
7819 +	u_int8_t it_pad;
7820 +	__le16 it_len;			/* length of the whole
7821 +					 * header in bytes, including
7822 +					 * it_version, it_pad,
7823 +					 * it_len, and data fields.
7824 +					 */
7825 +	__le32 it_present;		/* A bitmap telling which
7826 +					 * fields are present. Set bit 31
7827 +					 * (0x80000000) to extend the
7828 +					 * bitmap by another 32 bits.
7829 +					 * Additional extensions are made
7830 +					 * by setting bit 31.
7831 +					 */
7832 +} __attribute__((__packed__));
7833 +
7834 +/* Name                                 Data type       Units
7835 + * ----                                 ---------       -----
7836 + *
7837 + * IEEE80211_RADIOTAP_TSFT              u_int64_t       microseconds
7838 + *
7839 + *      Value in microseconds of the MAC's 64-bit 802.11 Time
7840 + *      Synchronization Function timer when the first bit of the
7841 + *      MPDU arrived at the MAC. For received frames, only.
7842 + *
7843 + * IEEE80211_RADIOTAP_CHANNEL           2 x u_int16_t   MHz, bitmap
7844 + *
7845 + *      Tx/Rx frequency in MHz, followed by flags (see below).
7846 + *
7847 + * IEEE80211_RADIOTAP_FHSS              u_int16_t       see below
7848 + *
7849 + *      For frequency-hopping radios, the hop set (first byte)
7850 + *      and pattern (second byte).
7851 + *
7852 + * IEEE80211_RADIOTAP_RATE              u_int8_t        500kb/s
7853 + *
7854 + *      Tx/Rx data rate
7855 + *
7856 + * IEEE80211_RADIOTAP_DBM_ANTSIGNAL     int8_t          decibels from
7857 + *                                                      one milliwatt (dBm)
7858 + *
7859 + *      RF signal power at the antenna, decibel difference from
7860 + *      one milliwatt.
7861 + *
7862 + * IEEE80211_RADIOTAP_DBM_ANTNOISE      int8_t          decibels from
7863 + *                                                      one milliwatt (dBm)
7864 + *
7865 + *      RF noise power at the antenna, decibel difference from one
7866 + *      milliwatt.
7867 + *
7868 + * IEEE80211_RADIOTAP_DB_ANTSIGNAL      u_int8_t        decibel (dB)
7869 + *
7870 + *      RF signal power at the antenna, decibel difference from an
7871 + *      arbitrary, fixed reference.
7872 + *
7873 + * IEEE80211_RADIOTAP_DB_ANTNOISE       u_int8_t        decibel (dB)
7874 + *
7875 + *      RF noise power at the antenna, decibel difference from an
7876 + *      arbitrary, fixed reference point.
7877 + *
7878 + * IEEE80211_RADIOTAP_BARKER_CODE_LOCK  u_int16_t       unitless
7879 + *
7880 + *      Quality of Barker code lock. Unitless. Monotonically
7881 + *      nondecreasing with "better" lock strength. Called "Signal
7882 + *      Quality" in datasheets.  (Is there a standard way to measure
7883 + *      this?)
7884 + *
7885 + * IEEE80211_RADIOTAP_TX_ATTENUATION    u_int16_t       unitless
7886 + *
7887 + *      Transmit power expressed as unitless distance from max
7888 + *      power set at factory calibration.  0 is max power.
7889 + *      Monotonically nondecreasing with lower power levels.
7890 + *
7891 + * IEEE80211_RADIOTAP_DB_TX_ATTENUATION u_int16_t       decibels (dB)
7892 + *
7893 + *      Transmit power expressed as decibel distance from max power
7894 + *      set at factory calibration.  0 is max power.  Monotonically
7895 + *      nondecreasing with lower power levels.
7896 + *
7897 + * IEEE80211_RADIOTAP_DBM_TX_POWER      int8_t          decibels from
7898 + *                                                      one milliwatt (dBm)
7899 + *
7900 + *      Transmit power expressed as dBm (decibels from a 1 milliwatt
7901 + *      reference). This is the absolute power level measured at
7902 + *      the antenna port.
7903 + *
7904 + * IEEE80211_RADIOTAP_FLAGS             u_int8_t        bitmap
7905 + *
7906 + *      Properties of transmitted and received frames. See flags
7907 + *      defined below.
7908 + *
7909 + * IEEE80211_RADIOTAP_ANTENNA           u_int8_t        antenna index
7910 + *
7911 + *      Unitless indication of the Rx/Tx antenna for this packet.
7912 + *      The first antenna is antenna 0.
7913 + *
7914 + * IEEE80211_RADIOTAP_RX_FLAGS          u_int16_t       bitmap
7915 + *
7916 + *     Properties of received frames. See flags defined below.
7917 + *
7918 + * IEEE80211_RADIOTAP_TX_FLAGS          u_int16_t       bitmap
7919 + *
7920 + *     Properties of transmitted frames. See flags defined below.
7921 + *
7922 + * IEEE80211_RADIOTAP_RTS_RETRIES       u_int8_t        data
7923 + *
7924 + *     Number of rts retries a transmitted frame used.
7925 + *
7926 + * IEEE80211_RADIOTAP_DATA_RETRIES      u_int8_t        data
7927 + *
7928 + *     Number of unicast retries a transmitted frame used.
7929 + */
7930 +enum ieee80211_radiotap_type {
7931 +	IEEE80211_RADIOTAP_TSFT = 0,
7932 +	IEEE80211_RADIOTAP_FLAGS = 1,
7933 +	IEEE80211_RADIOTAP_RATE = 2,
7934 +	IEEE80211_RADIOTAP_CHANNEL = 3,
7935 +	IEEE80211_RADIOTAP_FHSS = 4,
7936 +	IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
7937 +	IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
7938 +	IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
7939 +	IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
7940 +	IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
7941 +	IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
7942 +	IEEE80211_RADIOTAP_ANTENNA = 11,
7943 +	IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
7944 +	IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
7945 +	IEEE80211_RADIOTAP_RX_FLAGS = 14,
7946 +	IEEE80211_RADIOTAP_TX_FLAGS = 15,
7947 +	IEEE80211_RADIOTAP_RTS_RETRIES = 16,
7948 +	IEEE80211_RADIOTAP_DATA_RETRIES = 17,
7949 +	IEEE80211_RADIOTAP_EXT = 31,
7950 +};
7951 +
7952 +#ifndef _KERNEL
7953 +/* Channel flags. */
7954 +#define IEEE80211_CHAN_TURBO    0x0010  /* Turbo channel */
7955 +#define IEEE80211_CHAN_CCK      0x0020  /* CCK channel */
7956 +#define IEEE80211_CHAN_OFDM     0x0040  /* OFDM channel */
7957 +#define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
7958 +#define IEEE80211_CHAN_5GHZ     0x0100  /* 5 GHz spectrum channel */
7959 +#define IEEE80211_CHAN_PASSIVE  0x0200  /* Only passive scan allowed */
7960 +#define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
7961 +#define	IEEE80211_CHAN_GFSK	0x0800	/* GFSK channel (FHSS PHY) */
7962 +
7963 +/* Useful combinations of channel characteristics, borrowed from Ethereal */
7964 +#define IEEE80211_CHAN_A \
7965 +	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
7966 +#define IEEE80211_CHAN_B \
7967 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
7968 +#define IEEE80211_CHAN_G \
7969 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
7970 +#define IEEE80211_CHAN_TA \
7971 +	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
7972 +#define IEEE80211_CHAN_TG \
7973 +	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN  | IEEE80211_CHAN_TURBO)
7974 +
7975 +#endif /* !_KERNEL */
7976 +
7977 +/* For IEEE80211_RADIOTAP_FLAGS */
7978 +#define	IEEE80211_RADIOTAP_F_CFP	0x01	/* sent/received
7979 +						 * during CFP
7980 +						 */
7981 +#define	IEEE80211_RADIOTAP_F_SHORTPRE	0x02	/* sent/received
7982 +						 * with short
7983 +						 * preamble
7984 +						 */
7985 +#define	IEEE80211_RADIOTAP_F_WEP	0x04	/* sent/received
7986 +						 * with WEP encryption
7987 +						 */
7988 +#define	IEEE80211_RADIOTAP_F_FRAG	0x08	/* sent/received
7989 +						 * with fragmentation
7990 +						 */
7991 +#define	IEEE80211_RADIOTAP_F_FCS	0x10	/* frame includes FCS */
7992 +#define	IEEE80211_RADIOTAP_F_DATAPAD	0x20	/* frame has padding between
7993 +						 * 802.11 header and payload
7994 +						 * (to 32-bit boundary)
7995 +						 */
7996 +#define	IEEE80211_RADIOTAP_F_BADFCS	0x40	/* does not pass FCS check */
7997 +
7998 +/* For IEEE80211_RADIOTAP_RX_FLAGS */
7999 +#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001  /* Frame failed CRC check.
8000 +						*
8001 +						* Deprecated: use the flag
8002 +						* IEEE80211_RADIOTAP_F_FCS in
8003 +						* the IEEE80211_RADIOTAP_FLAGS
8004 +						* field, instead.
8005 +						*/
8006 +
8007 +/* For IEEE80211_RADIOTAP_TX_FLAGS */
8008 +#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001  /* failed due to excessive
8009 +						* retries
8010 +						*/
8011 +#define IEEE80211_RADIOTAP_F_TX_CTS    0x0002  /* used cts 'protection' */
8012 +#define IEEE80211_RADIOTAP_F_TX_RTS    0x0004  /* used rts/cts handshake */
8013 +#endif /* _NET_IF_IEEE80211RADIOTAP_H_ */
8014 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_rate.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_rate.h
8015 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_rate.h	1970-01-01 01:00:00.000000000 +0100
8016 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_rate.h	2008-06-19 17:34:17.000000000 +0200
8017 @@ -0,0 +1,159 @@
8018 +/*-
8019 + * Copyright (c) 2004 Sam Leffler, Errno Consulting
8020 + * Copyright (c) 2004 Video54 Technologies, Inc.
8021 + * All rights reserved.
8022 + *
8023 + * Redistribution and use in source and binary forms, with or without
8024 + * modification, are permitted provided that the following conditions
8025 + * are met:
8026 + * 1. Redistributions of source code must retain the above copyright
8027 + *    notice, this list of conditions and the following disclaimer,
8028 +	without modification.
8029 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
8030 + *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
8031 + *    redistribution must be conditioned upon including a substantially
8032 + *    similar Disclaimer requirement for further binary redistribution.
8033 + * 3. Neither the names of the above-listed copyright holders nor the names
8034 + *    of any contributors may be used to endorse or promote products derived
8035 + *    from this software without specific prior written permission.
8036 + *
8037 + * Alternatively, this software may be distributed under the terms of the
8038 + * GNU General Public License ("GPL") version 2 as published by the Free
8039 + * Software Foundation.
8040 + *
8041 + * NO WARRANTY
8042 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8043 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8044 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
8045 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
8046 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
8047 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8048 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8049 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
8050 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8051 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
8052 + * THE POSSIBILITY OF SUCH DAMAGES.
8053 + *
8054 + * $Id: if_athrate.h 1667 2006-07-04 10:23:35Z kelmo $
8055 + */
8056 +#ifndef _ATH_RATECTRL_H_
8057 +#define _ATH_RATECTRL_H_
8058 +
8059 +/*
8060 + * Interface definitions for transmit rate control modules for the
8061 + * Atheros driver.
8062 + *
8063 + * A rate control module is responsible for choosing the transmit rate
8064 + * for each data frame.  Management+control frames are always sent at
8065 + * a fixed rate.
8066 + *
8067 + * An instance of the rate control module is attached to each device
8068 + * at attach time and detached when the device is destroyed.  The module
8069 + * may associate data with each device and each node (station).  Both
8070 + * sets of storage are opaque except for the size of the per-node storage
8071 + * which must be provided when the module is attached.
8072 + *
8073 + * The rate control module is notified for each state transition and
8074 + * station association/reassociation.  Otherwise it is queried for a
8075 + * rate for each outgoing frame and provided status from each transmitted
8076 + * frame.  Any ancillary processing is the responsibility of the module
8077 + * (e.g. if periodic processing is required then the module should setup
8078 + * its own timer).
8079 + *
8080 + * In addition to the transmit rate for each frame, the module must also
8081 + * indicate the number of attempts to make at the specified rate.  If this
8082 + * number is != ATH_TXMAXTRY, an additional callback is made to request
8083 + * 3 additional rate/retry pairs.
8084 + */
8085 +
8086 +enum {
8087 +	IEEE80211_RATE_AMRR,
8088 +	IEEE80211_RATE_MINSTREL,
8089 +	IEEE80211_RATE_ONOE,
8090 +	IEEE80211_RATE_SAMPLE,
8091 +	IEEE80211_RATE_MAX
8092 +};
8093 +
8094 +struct ath_softc;
8095 +struct ath_node;
8096 +struct ath_buf;
8097 +struct ieee80211vap;
8098 +
8099 +/* Multi-rare retry: 3 additional rate/retry pairs */
8100 +struct ieee80211_mrr {
8101 +	int rate1;
8102 +	int retries1;
8103 +	int rate2;
8104 +	int retries2;
8105 +	int rate3;
8106 +	int retries3;
8107 +	int privflags;
8108 +};
8109 +
8110 +struct ieee80211_rate_ops {
8111 +	int ratectl_id;
8112 +
8113 +	/* Attach/detach a rate control module */
8114 +	struct ath_ratectrl *(*attach)(struct ath_softc *sc);
8115 +	void (*detach)(struct ath_ratectrl *arc);
8116 +
8117 +	/* Register proc entries with a VAP */
8118 +	void (*dynamic_proc_register)(struct ieee80211vap *vap);
8119 +
8120 +	/* *** State storage handling *** */
8121 +
8122 +	/* Initialize per-node state already allocated for the specified
8123 +	 * node; this space can be assumed initialized to zero */
8124 +	void (*node_init)(struct ath_softc *sc, struct ath_node *an);
8125 +
8126 +	/* Cleanup any per-node state prior to the node being reclaimed */
8127 +	void (*node_cleanup)(struct ath_softc *sc, struct ath_node *an);
8128 +
8129 +	/* Update rate control state on station associate/reassociate 
8130 +	 * (when operating as an ap or for nodes discovered when operating
8131 +	 * in ibss mode) */
8132 +	void (*newassoc)(struct ath_softc *sc, struct ath_node *an,
8133 +			 int isnew);
8134 +
8135 +	/* Update/reset rate control state for 802.11 state transitions.
8136 +	 * Important mostly as the analog to newassoc when operating
8137 +	 * in station mode */
8138 +	void (*newstate)(struct ieee80211vap *vap,
8139 +			 enum ieee80211_state state);
8140 +
8141 +	/* *** Transmit handling *** */
8142 +
8143 +	/* Return the transmit info for a data packet.  If multi-rate state
8144 +	 * is to be setup then try0 should contain a value other than ATH_TXMAXTRY
8145 +	 * and setupxtxdesc will be called after deciding if the frame
8146 +	 * can be transmitted with multi-rate retry. */
8147 +	void (*findrate)(struct ath_softc *sc, struct ath_node *an,
8148 +			 int shortPreamble, size_t frameLen,
8149 +			 u_int8_t *rix, unsigned int *try0, u_int8_t *txrate);
8150 +
8151 +	/* Return 3 more rates to try and corresponding number of retries.
8152 +	 * The rate index returned by findrate is passed back in. */
8153 +	void (*get_mrr)(struct ath_softc *sc, struct ath_node *an,
8154 +			int shortPreamble, size_t frame_size, u_int8_t rix,
8155 +			struct ieee80211_mrr *mrr);
8156 +
8157 +	/* Update rate control state for a packet associated with the
8158 +	 * supplied transmit descriptor.  The routine is invoked both
8159 +	 * for packets that were successfully sent and for those that
8160 +	 * failed (consult the descriptor for details). */
8161 +	void (*tx_complete)(struct ath_softc *sc, struct ath_node *an,
8162 +			    const struct ath_buf *bf);
8163 +};
8164 +
8165 +struct ath_ratectrl {
8166 +	struct ieee80211_rate_ops *ops;
8167 +	size_t arc_space;	/* space required for per-node state */
8168 +	size_t arc_vap_space;	/* space required for per-vap state */
8169 +};
8170 +
8171 +int ieee80211_rate_register(struct ieee80211_rate_ops *ops);
8172 +void ieee80211_rate_unregister(struct ieee80211_rate_ops *ops);
8173 +
8174 +struct ath_ratectrl *ieee80211_rate_attach(struct ath_softc *sc, const char *name);
8175 +void ieee80211_rate_detach(struct ath_ratectrl *);
8176 +#endif /* _ATH_RATECTRL_H_ */
8177 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_scan.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_scan.h
8178 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_scan.h	1970-01-01 01:00:00.000000000 +0100
8179 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_scan.h	2008-06-19 17:34:17.000000000 +0200
8180 @@ -0,0 +1,225 @@
8181 +/*-
8182 + * Copyright (c) 2005 Sam Leffler, Errno Consulting
8183 + * All rights reserved.
8184 + *
8185 + * Redistribution and use in source and binary forms, with or without
8186 + * modification, are permitted provided that the following conditions
8187 + * are met:
8188 + * 1. Redistributions of source code must retain the above copyright
8189 + *    notice, this list of conditions and the following disclaimer.
8190 + * 2. Redistributions in binary form must reproduce the above copyright
8191 + *    notice, this list of conditions and the following disclaimer in the
8192 + *    documentation and/or other materials provided with the distribution.
8193 + * 3. The name of the author may not be used to endorse or promote products
8194 + *    derived from this software without specific prior written permission.
8195 + *
8196 + * Alternatively, this software may be distributed under the terms of the
8197 + * GNU General Public License ("GPL") version 2 as published by the Free
8198 + * Software Foundation.
8199 + *
8200 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8201 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8202 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8203 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
8204 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
8205 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8206 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8207 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8208 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8209 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8210 + *
8211 + * $Id: ieee80211_scan.h 2513 2007-06-25 03:48:07Z mentor $
8212 + */
8213 +#ifndef _NET80211_IEEE80211_SCAN_H_
8214 +#define _NET80211_IEEE80211_SCAN_H_
8215 +
8216 +#define	IEEE80211_SCAN_MAX	IEEE80211_CHAN_MAX
8217 +
8218 +struct ieee80211_scanner;
8219 +struct ieee80211_scan_entry;
8220 +
8221 +struct ieee80211_scan_ssid {
8222 +	int len;				/* length in bytes */
8223 +	u_int8_t ssid[IEEE80211_NWID_LEN];	/* ssid contents */
8224 +};
8225 +#define	IEEE80211_SCAN_MAX_SSID	1
8226 +
8227 +struct ieee80211_scan_state {
8228 +	struct ieee80211vap *ss_vap;
8229 +	const struct ieee80211_scanner *ss_ops;	/* policy hookup, see below */
8230 +	void *ss_priv;				/* scanner private state */
8231 +	u_int16_t ss_flags;
8232 +#define	IEEE80211_SCAN_NOPICK	0x0001		/* scan only, no selection */
8233 +#define	IEEE80211_SCAN_ACTIVE	0x0002		/* active scan (probe req) */
8234 +#define	IEEE80211_SCAN_PICK1ST	0x0004		/* ``hey sailor'' mode */
8235 +#define	IEEE80211_SCAN_BGSCAN	0x0008		/* bg scan, exit ps at end */
8236 +#define	IEEE80211_SCAN_ONCE	0x0010		/* do one complete pass */
8237 +#define	IEEE80211_SCAN_GOTPICK	0x1000		/* got candidate, can stop */
8238 +
8239 +	u_int8_t	ss_nssid;			/* # SSIDs to probe/match */
8240 +	struct ieee80211_scan_ssid ss_ssid[IEEE80211_SCAN_MAX_SSID];
8241 +						/* SSIDs to probe/match */
8242 +						/* ordered channel set */
8243 +	struct ieee80211_channel *ss_chans[IEEE80211_SCAN_MAX];
8244 +	u_int16_t ss_next;			/* ix of next chan to scan */
8245 +	u_int16_t ss_last;			/* ix + 1 of last chan to scan */
8246 +	unsigned long ss_mindwell;		/* min dwell on channel */
8247 +	unsigned long ss_maxdwell;		/* max dwell on channel */
8248 +	u_int ss_duration;			/* used for calling ieee80211_start_scan() */
8249 +};
8250 +
8251 +/*
8252 + * The upper 16 bits of the flags word is used to communicate
8253 + * information to the scanning code that is NOT recorded in
8254 + * ss_flags.  It might be better to split this stuff out into
8255 + * a separate variable to avoid confusion.
8256 + */
8257 +#define	IEEE80211_SCAN_FLUSH	0x10000		/* flush candidate table */
8258 +#define	IEEE80211_SCAN_NOSSID	0x20000		/* don't update ssid list */
8259 +#define	IEEE80211_SCAN_USECACHE	0x40000		/* Must use a result from the cache */
8260 +#define	IEEE80211_SCAN_KEEPMODE	0x80000		/* Must keep the same wireless mode (11a, 11g, or 11at, etc) */
8261 +
8262 +struct ieee80211com;
8263 +void ieee80211_scan_attach(struct ieee80211com *);
8264 +void ieee80211_scan_detach(struct ieee80211com *);
8265 +void ieee80211_scan_vattach(struct ieee80211vap *);
8266 +void ieee80211_scan_vdetach(struct ieee80211vap *);
8267 +
8268 +void ieee80211_scan_dump_channels(const struct ieee80211_scan_state *);
8269 +
8270 +#define	IEEE80211_SCAN_FOREVER	0x7fffffff
8271 +int ieee80211_start_scan(struct ieee80211vap *, int, u_int, u_int,
8272 +	const struct ieee80211_scan_ssid ssids[]);
8273 +int ieee80211_check_scan(struct ieee80211vap *, int, u_int, u_int,
8274 +	const struct ieee80211_scan_ssid ssids[],
8275 +	int (*action)(struct ieee80211vap *, const struct ieee80211_scan_entry *));
8276 +int ieee80211_bg_scan(struct ieee80211vap *);
8277 +void ieee80211_cancel_scan(struct ieee80211vap *);
8278 +
8279 +int ieee80211_scan_dfs_action(struct ieee80211vap *, const struct ieee80211_scan_entry *);
8280 +
8281 +struct ieee80211_scanparams;
8282 +void ieee80211_add_scan(struct ieee80211vap *, const struct ieee80211_scanparams *,
8283 +	const struct ieee80211_frame *, int, int, u_int64_t);
8284 +void ieee80211_scan_timeout(struct ieee80211com *);
8285 +
8286 +void ieee80211_scan_assoc_success(struct ieee80211com *,
8287 +	const u_int8_t mac[IEEE80211_ADDR_LEN]);
8288 +enum {
8289 +	IEEE80211_SCAN_FAIL_TIMEOUT	= 1,	/* no response to mgmt frame */
8290 +	IEEE80211_SCAN_FAIL_STATUS	= 2	/* negative response to " " */
8291 +};
8292 +void ieee80211_scan_assoc_fail(struct ieee80211com *,
8293 +	const u_int8_t mac[IEEE80211_ADDR_LEN], int);
8294 +void ieee80211_scan_flush(struct ieee80211com *);
8295 +
8296 +struct ieee80211_scan_entry;
8297 +typedef int ieee80211_scan_iter_func(void *, const struct ieee80211_scan_entry *);
8298 +int ieee80211_scan_iterate(struct ieee80211com *, ieee80211_scan_iter_func *, void *);
8299 +
8300 +/*
8301 + * Parameters supplied when adding/updating an entry in a
8302 + * scan cache.  Pointer variables should be set to NULL
8303 + * if no data is available.  Pointer references can be to
8304 + * local data; any information that is saved will be copied.
8305 + * All multi-byte values must be in host byte order.
8306 + */
8307 +struct ieee80211_scanparams {
8308 +	u_int16_t capinfo;	/* 802.11 capabilities */
8309 +	u_int16_t fhdwell;	/* FHSS dwell interval */
8310 +	u_int8_t chan;		/* */
8311 +	u_int8_t bchan;
8312 +	u_int8_t fhindex;
8313 +	u_int8_t erp;
8314 +	u_int16_t bintval;
8315 +	u_int8_t timoff;
8316 +	u_int8_t *tim;
8317 +	u_int8_t *tstamp;
8318 +	u_int8_t *country;
8319 +	u_int8_t *ssid;
8320 +	u_int8_t *rates;
8321 +	u_int8_t *xrates;
8322 +	u_int8_t *csa;
8323 +	u_int8_t *wpa;
8324 +	u_int8_t *rsn;
8325 +	u_int8_t *wme;
8326 +	u_int8_t *ath;
8327 +};
8328 +
8329 +/*
8330 + * Scan cache entry format used when exporting data from a policy
8331 + * module; this data may be represented some other way internally.
8332 + */
8333 +struct ieee80211_scan_entry {
8334 +	u_int8_t se_macaddr[IEEE80211_ADDR_LEN];
8335 +	u_int8_t se_bssid[IEEE80211_ADDR_LEN];
8336 +	u_int8_t se_ssid[2 + IEEE80211_NWID_LEN];
8337 +	u_int8_t se_rates[2 + IEEE80211_RATE_MAXSIZE];
8338 +	u_int8_t se_xrates[2 + IEEE80211_RATE_MAXSIZE];
8339 +	u_int64_t se_rtsf;		/* recv timestamp */
8340 +	union {
8341 +		u_int8_t data[8];
8342 +		__le64 tsf;
8343 +	} se_tstamp;			/* from last rcv'd beacon */
8344 +	u_int16_t se_intval;		/* beacon interval (host byte order) */
8345 +	u_int16_t se_capinfo;		/* capabilities (host byte order) */
8346 +	struct ieee80211_channel *se_chan;/* channel where sta found */
8347 +	u_int16_t se_timoff;		/* byte offset to TIM ie */
8348 +	u_int16_t se_fhdwell;		/* FH only (host byte order) */
8349 +	u_int8_t se_fhindex;		/* FH only */
8350 +	u_int8_t se_erp;			/* ERP from beacon/probe resp */
8351 +	int8_t se_rssi;			/* avg'd recv ssi */
8352 +	u_int8_t se_dtimperiod;		/* DTIM period */
8353 +	u_int8_t *se_wpa_ie;		/* captured WPA ie */
8354 +	u_int8_t *se_rsn_ie;		/* captured RSN ie */
8355 +	u_int8_t *se_wme_ie;		/* captured WME ie */
8356 +	u_int8_t *se_ath_ie;		/* captured Atheros ie */
8357 +	u_int se_age;			/* age of entry (0 on create) */
8358 +};
8359 +
8360 +/*
8361 + * Template for an in-kernel scan policy module.
8362 + * Modules register with the scanning code and are
8363 + * typically loaded as needed.
8364 + */
8365 +struct ieee80211_scanner {
8366 +	const char *scan_name;		/* printable name */
8367 +	int (*scan_attach)(struct ieee80211_scan_state *);
8368 +	int (*scan_detach)(struct ieee80211_scan_state *);
8369 +	int (*scan_start)(struct ieee80211_scan_state *, struct ieee80211vap *);
8370 +	int (*scan_restart)(struct ieee80211_scan_state *, struct ieee80211vap *);
8371 +	int (*scan_cancel)(struct ieee80211_scan_state *, struct ieee80211vap *);
8372 +	int (*scan_end)(struct ieee80211_scan_state *, struct ieee80211vap *,
8373 +		int (*action)(struct ieee80211vap *, const struct ieee80211_scan_entry *),
8374 +		u_int32_t);
8375 +	int (*scan_flush)(struct ieee80211_scan_state *);
8376 +	/* add an entry to the cache */
8377 +	int (*scan_add)(struct ieee80211_scan_state *,
8378 +		const struct ieee80211_scanparams *,
8379 +		const struct ieee80211_frame *, int, int, u_int64_t);
8380 +	/* age and/or purge entries in the cache */
8381 +	void (*scan_age)(struct ieee80211_scan_state *);
8382 +	/* note that association failed for an entry */
8383 +	void (*scan_assoc_fail)(struct ieee80211_scan_state *,
8384 +		const u_int8_t macaddr[IEEE80211_ADDR_LEN], int);
8385 +	/* note that association succeed for an entry */
8386 +	void (*scan_assoc_success)(struct ieee80211_scan_state *,
8387 +		const u_int8_t macaddr[IEEE80211_ADDR_LEN]);
8388 +	/* iterate over entries in the scan cache */
8389 +	int (*scan_iterate)(struct ieee80211_scan_state *,
8390 +		ieee80211_scan_iter_func *, void *);
8391 +	/* default action to take when found scan match */
8392 +	int (*scan_default)(struct ieee80211vap *,
8393 +		const struct ieee80211_scan_entry *);
8394 +};
8395 +const struct ieee80211_scanner *ieee80211_scanner_get(enum ieee80211_opmode,
8396 +	int);
8397 +void ieee80211_scanner_register(enum ieee80211_opmode,
8398 +	const struct ieee80211_scanner *);
8399 +void ieee80211_scanner_unregister(enum ieee80211_opmode,
8400 +	const struct ieee80211_scanner *);
8401 +void ieee80211_scanner_unregister_all(const struct ieee80211_scanner *);
8402 +void ieee80211_scan_add_channels(struct ieee80211com *ic,
8403 +	struct ieee80211_scan_state *ss,
8404 +	enum ieee80211_phymode mode);
8405 +#endif /* _NET80211_IEEE80211_SCAN_H_ */
8406 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_skb.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_skb.h
8407 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_skb.h	1970-01-01 01:00:00.000000000 +0100
8408 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_skb.h	2008-06-19 17:34:17.000000000 +0200
8409 @@ -0,0 +1,204 @@
8410 +/*-
8411 + * Copyright (c) 2007 Michael Taylor, Apprion
8412 + * All rights reserved.
8413 + *
8414 + * Redistribution and use in source and binary forms, with or without
8415 + * modification, are permitted provided that the following conditions
8416 + * are met:
8417 + * 1. Redistributions of source code must retain the above copyright
8418 + *    notice, this list of conditions and the following disclaimer.
8419 + * 2. Redistributions in binary form must reproduce the above copyright
8420 + *    notice, this list of conditions and the following disclaimer in the
8421 + *    documentation and/or other materials provided with the distribution.
8422 + * 3. The name of the author may not be used to endorse or promote products
8423 + *    derived from this software without specific prior written permission.
8424 + *
8425 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8426 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8427 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8428 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
8429 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
8430 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8431 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8432 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8433 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8434 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8435 + *
8436 + * $Id: ieee80211_skb.h 2647 2007-08-09 08:43:58Z mtaylor $
8437 + */
8438 +#ifndef _NET80211_IEEE80211_SKB_H_
8439 +#define _NET80211_IEEE80211_SKB_H_
8440 +
8441 +/*******************************************************************************
8442 + * Globals
8443 + ******************************************************************************/
8444 +
8445 +#ifdef IEEE80211_DEBUG_REFCNT
8446 +
8447 +/* Count of currently tracked skbs */
8448 +extern atomic_t skb_total_counter;
8449 +/* Count of currently tracked skbs' references */
8450 +extern atomic_t skb_refs_counter;
8451 +
8452 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
8453 +
8454 +/*******************************************************************************
8455 + * Public API
8456 + ******************************************************************************/
8457 +
8458 +/* ieee80211_dev_kfree_skb will release one reference from SKB.
8459 + * If SKB refcount is going to zero:
8460 + *  - Free the node reference and set it to null.
8461 + *  - Break the linked list, clearing next skb's prev pointer if possible. */
8462 +#ifdef IEEE80211_DEBUG_REFCNT
8463 +#define ieee80211_dev_kfree_skb(_pskb) \
8464 +	ieee80211_dev_kfree_skb_debug(_pskb, __func__, __LINE__)
8465 +void ieee80211_dev_kfree_skb_debug(struct sk_buff** pskb, const char* func, int line);
8466 +#else
8467 +void ieee80211_dev_kfree_skb(struct sk_buff** pskb);
8468 +#endif
8469 +
8470 +static inline void ieee80211_skb_copy_noderef(struct sk_buff *src, 
8471 +		struct sk_buff *dst)
8472 +{
8473 +	if (SKB_CB(src)->ni != NULL)
8474 +		SKB_CB(dst)->ni = ieee80211_ref_node(SKB_CB(src)->ni);
8475 +}
8476 +
8477 +/*
8478 + * ieee80211_dev_kfree_skb_list will invoke ieee80211_dev_kfree_skb on each node in
8479 + * a list of skbs, starting with the first.
8480 +*/
8481 +#ifdef IEEE80211_DEBUG_REFCNT
8482 +#define ieee80211_dev_kfree_skb_list(_pskb) \
8483 +	ieee80211_dev_kfree_skb_list_debug(_pskb, __func__, __LINE__)
8484 +void ieee80211_dev_kfree_skb_list_debug(struct sk_buff** pskb, const char* func, int line);
8485 +#else
8486 +void ieee80211_dev_kfree_skb_list(struct sk_buff** pskb);
8487 +#endif
8488 +
8489 +#ifdef IEEE80211_DEBUG_REFCNT
8490 +#define ieee80211_dev_alloc_skb(_size) \
8491 +	ieee80211_dev_alloc_skb_debug(_size, __func__, __LINE__)
8492 +struct sk_buff* ieee80211_dev_alloc_skb_debug(int size, const char* func, int line);
8493 +#else
8494 +struct sk_buff* ieee80211_dev_alloc_skb(int size);
8495 +#endif
8496 +
8497 +#ifdef IEEE80211_DEBUG_REFCNT
8498 +#define ieee80211_skb_track(_skb) \
8499 +	ieee80211_skb_track_debug(_skb, __func__, __LINE__)
8500 +#define ieee80211_skb_untrack(_skb) \
8501 +	ieee80211_skb_untrack_debug(_skb, __func__, __LINE__)
8502 +void ieee80211_skb_track_debug(struct sk_buff *skb, 
8503 +					       const char* func, int line);
8504 +void ieee80211_skb_untrack_debug(struct sk_buff *skb, 
8505 +					       const char* func, int line);
8506 +#else
8507 +void ieee80211_skb_track(struct sk_buff *skb);
8508 +void ieee80211_skb_untrack(struct sk_buff *skb);
8509 +#endif
8510 +
8511 +#ifdef IEEE80211_DEBUG_REFCNT
8512 +int ieee80211_skb_counter(void);
8513 +int ieee80211_skb_references(void);
8514 +#else
8515 +#define ieee80211_skb_counter() (0)
8516 +#define ieee80211_skb_references() (0)
8517 +#endif
8518 +
8519 +/*******************************************************************************
8520 + * skbuff leak/refcount debugging Replacement Functions
8521 + ******************************************************************************/
8522 +
8523 +#ifdef IEEE80211_DEBUG_REFCNT
8524 +
8525 +int  vlan_hwaccel_receive_skb_debug(struct sk_buff *skb, 
8526 +				    struct vlan_group *grp, unsigned short vlan_tag, 
8527 +				    const char* func, int line);
8528 +int netif_receive_skb_debug(struct sk_buff *skb, const char* func, int line);
8529 +struct sk_buff * alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
8530 +				 const char *func, int line);
8531 +struct sk_buff * dev_alloc_skb_debug(unsigned int length,
8532 +				     const char *func, int line);
8533 +struct sk_buff * skb_clone_debug(struct sk_buff *skb, gfp_t pri, 
8534 +				 const char *func, int line);
8535 +struct sk_buff * skb_copy_debug(struct sk_buff *skb, gfp_t pri, 
8536 +				const char *func, int line);
8537 +struct sk_buff * skb_get_debug(struct sk_buff *skb, 
8538 +			       const char *func, int line);
8539 +struct sk_buff * skb_realloc_headroom_debug(struct sk_buff *skb, unsigned int headroom, 
8540 +					    const char *func, int line);
8541 +struct sk_buff * pskb_copy_debug(struct sk_buff *skb, gfp_t pri,
8542 +				 const char *func, int line);
8543 +int dev_queue_xmit_debug(struct sk_buff *skb,
8544 +			 const char *func, int line);
8545 +struct sk_buff * skb_share_check_debug(struct sk_buff *skb, gfp_t pri,
8546 +				       const char *func, int line);
8547 +void  kfree_skb_fast_debug(struct sk_buff *skb, 
8548 +			   const char* func, int line);
8549 +struct sk_buff *  skb_unshare_debug(struct sk_buff *skb, gfp_t pri,
8550 +				    const char *func, int line);
8551 +struct sk_buff * skb_copy_expand_debug(const struct sk_buff *skb, int newheadroom, 
8552 +				       int newtailroom, gfp_t gfp_mask, 
8553 +				       const char *func, int line);
8554 +
8555 +#undef alloc_skb
8556 +#undef dev_alloc_skb
8557 +#undef dev_kfree_skb
8558 +#undef dev_kfree_skb_any
8559 +#undef dev_kfree_skb_irq
8560 +#undef dev_queue_xmit
8561 +#undef kfree_skb
8562 +#undef kfree_skb_fast
8563 +#undef netif_receive_skb
8564 +#undef pskb_copy
8565 +#undef skb_clone
8566 +#undef skb_copy
8567 +#undef skb_copy_expand
8568 +#undef skb_get
8569 +#undef skb_realloc_headroom
8570 +#undef skb_share_check
8571 +#undef skb_unshare
8572 +#undef vlan_hwaccel_receive_skb
8573 +
8574 +#define skb_unshare(_skb, _pri) \
8575 +	skb_unshare_debug(_skb, _pri, __func__, __LINE__)
8576 +#define skb_copy_expand(_skb, _newheadroom, _newtailroom, _gfp_mask) \
8577 +	skb_copy_expand_debug(_skb, _newheadroom, _newtailroom, _gfp_mask, __func__, __LINE__)
8578 +#define vlan_hwaccel_receive_skb(_skb, _grp, _tag) \
8579 +	vlan_hwaccel_receive_skb_debug(_skb, _grp, _tag, __func__, __LINE__)
8580 +#define netif_receive_skb(_skb) \
8581 +	netif_receive_skb_debug(_skb, __func__, __LINE__)
8582 +#define	alloc_skb(_length, _gfp_mask) \
8583 +	alloc_skb_debug(_length, _gfp_mask, __func__, __LINE__)
8584 +#define	dev_alloc_skb(_length) \
8585 +	dev_alloc_skb_debug(_length, __func__, __LINE__)
8586 +#define	dev_kfree_skb_irq(_skb) \
8587 +	unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB_IRQ, __func__, __LINE__)
8588 +#define	dev_kfree_skb_any(_skb) \
8589 +	unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB_ANY, __func__, __LINE__)
8590 +#define	dev_kfree_skb(_skb) \
8591 +	unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB, __func__, __LINE__)
8592 +#define	kfree_skb(_skb) \
8593 +	unref_skb(_skb, UNREF_USE_KFREE_SKB, __func__, __LINE__)
8594 +#define skb_clone(_skb, _pri) \
8595 +	skb_clone_debug(_skb, _pri, __func__, __LINE__)
8596 +#define skb_share_check(_skb, _pri) \
8597 +	skb_share_check_debug(_skb, _pri, __func__, __LINE__)
8598 +#define kfree_skb_fast(_skb) \
8599 +	kfree_skb_fast_debug(_skb, __func__, __LINE__)
8600 +#define skb_realloc_headroom(_skb, _headroom) \
8601 +	skb_realloc_headroom_debug(_skb, _headroom, __func__, __LINE__)
8602 +#define pskb_copy(_skb, _pri) \
8603 +	pskb_copy_debug(_skb, _pri, __func__, __LINE__)
8604 +#define skb_get(_skb) \
8605 +	skb_get_debug(_skb, __func__, __LINE__)
8606 +#define skb_copy(_skb, _pri) \
8607 +	skb_copy_debug(_skb, _pri, __func__, __LINE__)
8608 +#define dev_queue_xmit(_skb) \
8609 +	dev_queue_xmit_debug(_skb, __func__, __LINE__)
8610 +#endif /* #ifdef IEEE80211_DEBUG_REFCNT */
8611 +
8612 +#endif /* _NET80211_IEEE80211_SKB_H_ */
8613 +
8614 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_var.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_var.h
8615 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_var.h	1970-01-01 01:00:00.000000000 +0100
8616 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/ieee80211_var.h	2008-06-19 17:34:17.000000000 +0200
8617 @@ -0,0 +1,784 @@
8618 +/*-
8619 + * Copyright (c) 2001 Atsushi Onoe
8620 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
8621 + * All rights reserved.
8622 + *
8623 + * Redistribution and use in source and binary forms, with or without
8624 + * modification, are permitted provided that the following conditions
8625 + * are met:
8626 + * 1. Redistributions of source code must retain the above copyright
8627 + *    notice, this list of conditions and the following disclaimer.
8628 + * 2. Redistributions in binary form must reproduce the above copyright
8629 + *    notice, this list of conditions and the following disclaimer in the
8630 + *    documentation and/or other materials provided with the distribution.
8631 + * 3. The name of the author may not be used to endorse or promote products
8632 + *    derived from this software without specific prior written permission.
8633 + *
8634 + * Alternatively, this software may be distributed under the terms of the
8635 + * GNU General Public License ("GPL") version 2 as published by the Free
8636 + * Software Foundation.
8637 + *
8638 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8639 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8640 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8641 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
8642 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
8643 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8644 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8645 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8646 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8647 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8648 + *
8649 + * $Id: ieee80211_var.h 3314 2008-01-30 23:50:16Z mtaylor $
8650 + */
8651 +
8652 +#ifndef _NET80211_IEEE80211_VAR_H_
8653 +#define _NET80211_IEEE80211_VAR_H_
8654 +
8655 +/* Definitions for IEEE 802.11 drivers. */
8656 +#include <net80211/ieee80211_linux.h>
8657 +
8658 +#include <sys/queue.h>
8659 +
8660 +#include <net80211/_ieee80211.h>
8661 +#include <net80211/ieee80211.h>
8662 +#include <net80211/ieee80211_crypto.h>
8663 +#include <net80211/ieee80211_ioctl.h>		/* for ieee80211_stats */
8664 +#include <net80211/ieee80211_power.h>
8665 +#include <net80211/ieee80211_proto.h>
8666 +#include <net80211/ieee80211_scan.h>
8667 +
8668 +/* NB: 
8669 + * - Atheros chips use 6 bits when power is specified in whole dBm units, with 
8670 + *   a value range from 0 to 63.
8671 + * - Atheros chips use 7 bits when power is specified in half dBm units, with 
8672 + *   a value range from 0 to 127.
8673 + */
8674 +#define	IEEE80211_TXPOWER_MAX		127	/* .5 dBm units */
8675 +#define	IEEE80211_TXPOWER_MIN		0	/* kill radio */
8676 +
8677 +#define	IEEE80211_DTIM_MAX		15	/* max DTIM period */
8678 +#define	IEEE80211_DTIM_MIN		1	/* min DTIM period */
8679 +#define	IEEE80211_DTIM_DEFAULT		1	/* default DTIM period */
8680 +
8681 +#define	IEEE80211_BINTVAL_MAX		1000	/* max beacon interval (TUs) */
8682 +#define	IEEE80211_BINTVAL_MIN		25	/* min beacon interval (TUs) */
8683 +#define	IEEE80211_BINTVAL_DEFAULT 	100	/* default beacon interval (TUs) */
8684 +#define IEEE80211_BINTVAL_VALID(_bi) \
8685 +	((IEEE80211_BINTVAL_MIN <= (_bi)) && \
8686 +	 ((_bi) <= IEEE80211_BINTVAL_MAX))
8687 +#define IEEE80211_BINTVAL_SANITISE(_bi) \
8688 +	(IEEE80211_BINTVAL_VALID(_bi) ? \
8689 +	 (_bi) : IEEE80211_BINTVAL_DEFAULT)
8690 +
8691 +#define IEEE80211_BMISSTHRESH_BMIN	2	/* min bmiss threshold (beacons) */
8692 +/* Default beacon miss threshold is set to roundup from 850ms 
8693 + * This is halfway between the 10@100ms default from prior hardcoded setting for
8694 + * software beacon miss timers, and the 7@100ms default from prior hardcoded 
8695 + * timer value for hardware beacon miss timer.
8696 + * Based upon emperical evidence and practices of commercial vendors, I believe
8697 + * this should really be 2500ms by default. */
8698 +#define IEEE80211_BMISSTHRESH_DEFAULT_MS 850
8699 +
8700 +#define IEEE80211_BMISSTHRESH_VALID(_bmt) \
8701 +	(IEEE80211_BMISSTHRESH_BMIN <= (_bmt))
8702 +#define IEEE80211_BMISSTHRESH_SANITISE(_bmt) \
8703 +	((IEEE80211_BMISSTHRESH_BMIN > (_bmt)) ? \
8704 +	 IEEE80211_BMISSTHRESH_BMIN : (_bmt))
8705 +
8706 +#define	IEEE80211_BGSCAN_INTVAL_MIN	15	/* min bg scan intvl (secs) */
8707 +#define	IEEE80211_BGSCAN_INTVAL_DEFAULT	(5*60)	/* default bg scan intvl */
8708 +
8709 +#define	IEEE80211_BGSCAN_IDLE_MIN	100	/* min idle time (ms) */
8710 +#define	IEEE80211_BGSCAN_IDLE_DEFAULT	250	/* default idle time (ms) */
8711 +
8712 +#define IEEE80211_COVERAGE_CLASS_MAX	31	/* max coverage class */
8713 +#define IEEE80211_REGCLASSIDS_MAX	10	/* max regclass id list */
8714 +
8715 +#define	IEEE80211_PS_SLEEP	0x1		/* STA is in power saving mode */
8716 +#define	IEEE80211_PS_MAX_QUEUE	50		/* maximum saved packets */
8717 +
8718 +#define	IEEE80211_XR_BEACON_FACTOR	3	/* factor between xr Beacon interval and normal beacon interval */
8719 +#define	IEEE80211_XR_DEFAULT_RATE_INDEX	0
8720 +#define	IEEE80211_XR_FRAG_THRESHOLD	540
8721 +
8722 +#define	IEEE80211_FIXED_RATE_NONE	-1
8723 +
8724 +#define DEV_NAME(_d) \
8725 +	 ((NULL == _d || NULL == _d->name || 0 == strncmp(_d->name, "wifi%d", 6)) ? \
8726 +	  "MadWifi" : \
8727 +	  _d->name)
8728 +#define VAP_DEV_NAME(_v) \
8729 +	 ((NULL == _v) ? \
8730 +	  "MadWifi" : \
8731 +	  DEV_NAME(_v->iv_dev))
8732 +#define SC_DEV_NAME(_sc) \
8733 +	 ((NULL == _sc) ? \
8734 +	  "MadWifi" : \
8735 +	  DEV_NAME(_sc->sc_dev))
8736 +#define VAP_IC_DEV_NAME(_v) \
8737 +	 ((NULL == _v || NULL == _v->iv_ic) ? \
8738 +	  "MadWifi" : \
8739 +	  DEV_NAME(_v->iv_ic->ic_dev))
8740 +
8741 +#define	IEEE80211_MS_TO_TU(x)	(((x) * 1000) / 1024)
8742 +#define	IEEE80211_TU_TO_MS(x)	(((x) * 1024) / 1000)
8743 +#define	IEEE80211_TU_TO_JIFFIES(x) ((IEEE80211_TU_TO_MS(x) * HZ) / 1000)
8744 +#define	IEEE80211_JIFFIES_TO_TU(x) IEEE80211_MS_TO_TU((x) * 1000 / HZ)
8745 +
8746 +#define	IEEE80211_APPIE_MAX	1024
8747 +
8748 +#define IEEE80211_PROTMODE_RSSITHR	15	/* default rssi threshold for protection mode trigger */
8749 +#define IEEE80211_PROTMODE_TIMEOUT	30	/* timeout for keeping protection mode alive */
8750 +
8751 +#define IEEE80211_PWRCONSTRAINT_VAL(ic) \
8752 +	(((ic)->ic_bsschan->ic_maxregpower > (ic)->ic_curchanmaxpwr) ? \
8753 +	    (ic)->ic_bsschan->ic_maxregpower - (ic)->ic_curchanmaxpwr : 0)
8754 +
8755 +/* 802.11 control state is split into a common portion that maps
8756 + * 1-1 to a physical device and one or more "Virtual APs" (VAP)
8757 + * that are bound to an ieee80211com instance and share a single
8758 + * underlying device.  Each VAP has a corresponding OS device
8759 + * entity through which traffic flows and that applications use
8760 + * for issuing ioctls, etc.
8761 + */
8762 +
8763 +/* Data common to one or more virtual APs.  State shared by
8764 + * the underlying device and the net80211 layer is exposed here;
8765 + * e.g. device-specific callbacks.
8766 + */
8767 +
8768 +struct ieee80211com;
8769 +struct ieee80211_proc_entry;
8770 +struct vlan_group;
8771 +struct eapolcom;
8772 +struct ieee80211_aclator;
8773 +
8774 +struct ieee80211_nsparams {
8775 +	enum ieee80211_state newstate;
8776 +	int arg;
8777 +	int result;
8778 +};
8779 +
8780 +#define IW_MAX_SPY 8
8781 +struct ieee80211_spy {
8782 +	u_int8_t mac[IW_MAX_SPY * IEEE80211_ADDR_LEN];
8783 +	u_int64_t ts_rssi[IW_MAX_SPY];		/* ts of rssi value from last read */
8784 +	u_int8_t thr_low;			/* 1 byte rssi value, 0 = threshold is off */
8785 +	u_int8_t thr_high;			/* 1 byte rssi value */
8786 +	u_int8_t num;
8787 +};
8788 +
8789 +struct ieee80211_app_ie {
8790 +	u_int32_t		length;		/* buffer length */
8791 +	struct ieee80211_ie    *ie;		/* buffer containing one or more IEs */
8792 +};
8793 +
8794 +struct ieee80211vap {
8795 +	struct net_device *iv_dev;			/* associated device */
8796 +	struct net_device_stats	iv_devstats;		/* interface statistics */
8797 +	struct ifmedia iv_media;			/* interface media config */
8798 +	struct iw_statistics iv_iwstats;		/* wireless statistics block */
8799 +	struct ctl_table_header	*iv_sysctl_header;
8800 +	struct ctl_table *iv_sysctls;
8801 +	struct proc_dir_entry *iv_proc;
8802 +	struct ieee80211_proc_entry *iv_proc_entries;
8803 +	struct vlan_group *iv_vlgrp;			/* vlan group state */
8804 +
8805 +	TAILQ_ENTRY(ieee80211vap) iv_next;		/* list of vap instances */
8806 +	struct ieee80211com *iv_ic;			/* back ptr to common state */
8807 +	u_int32_t iv_debug;				/* debug msg flags */
8808 +	struct ieee80211_stats iv_stats;		/* statistics */
8809 +
8810 +	int iv_monitor_nods_only;			/* in monitor mode only nods traffic */
8811 +	int iv_monitor_txf_len;				/* in monitor mode, truncate tx packets */
8812 +	int iv_monitor_phy_errors;			/* in monitor mode, accept phy errors */
8813 +	int iv_monitor_crc_errors;			/* in monitor mode, accept crc errors */
8814 +
8815 +	int (*iv_newstate)(struct ieee80211vap *, enum ieee80211_state, int);
8816 +	u_int8_t iv_myaddr[IEEE80211_ADDR_LEN];
8817 +	u_int32_t iv_flags;				/* state flags */
8818 +	u_int32_t iv_flags_ext;				/* extension of state flags */
8819 +	u_int32_t iv_caps;				/* capabilities */
8820 +	u_int8_t iv_ath_cap;				/* Atheros adv. capabilities */
8821 +	enum ieee80211_opmode iv_opmode;		/* operation mode */
8822 +	enum ieee80211_state iv_state;			/* state machine state */
8823 +	struct timer_list iv_mgtsend;			/* mgmt frame response timer */
8824 +							/* inactivity timer settings */
8825 +	int iv_inact_init;				/* setting for new station */
8826 +	int iv_inact_auth;				/* auth but not assoc setting */
8827 +	int iv_inact_run;				/* authorized setting */
8828 +	int iv_inact_probe;				/* inactive probe time */
8829 +
8830 +	int iv_des_nssid;				/* # desired ssids */
8831 +	struct ieee80211_scan_ssid iv_des_ssid[1];	/* desired ssid table */
8832 +	u_int8_t iv_des_bssid[IEEE80211_ADDR_LEN];
8833 +	struct ieee80211_channel *iv_des_chan;		/* desired channel */
8834 +	u_int16_t iv_des_mode;				/* desired mode */
8835 +	int iv_nicknamelen;				/* XXX junk */
8836 +	u_int8_t iv_nickname[IEEE80211_NWID_LEN];
8837 +	u_int iv_bgscanidle;				/* bg scan idle threshold */
8838 +	u_int iv_bgscanintvl;				/* bg scan min interval */
8839 +	u_int iv_scanvalid;				/* scan cache valid threshold */
8840 +	struct ieee80211_roam iv_roam;			/* sta-mode roaming state */
8841 +
8842 +	u_int32_t iv_csa_jiffies;			/* last csa recv jiffies */
8843 +	u_int8_t iv_csa_count;				/* last csa count */
8844 +	struct ieee80211_channel *iv_csa_chan;		/* last csa channel */
8845 +	u_int8_t iv_csa_mode;				/* last csa mode */
8846 +	struct timer_list iv_csa_timer;			/* csa timer */
8847 +	u_int32_t *iv_aid_bitmap;			/* association id map */
8848 +	u_int16_t iv_max_aid;
8849 +	u_int16_t iv_sta_assoc;				/* stations associated */
8850 +	u_int16_t iv_ps_sta;				/* stations in power save */
8851 +	u_int16_t iv_ps_pending;			/* PS STAs w/ pending frames */
8852 +	u_int8_t *iv_tim_bitmap;			/* power-save stations w/ data*/
8853 +	u_int16_t iv_tim_len;				/* ic_tim_bitmap size (bytes) */
8854 +	u_int8_t iv_dtim_period;			/* DTIM period */
8855 +	u_int8_t iv_dtim_count;				/* DTIM count from last bcn */
8856 +							/* set/unset aid pwrsav state */
8857 +	void (*iv_set_tim)(struct ieee80211_node *, int);
8858 +	u_int8_t iv_uapsdinfo;				/* sta mode QoS Info flags */
8859 +	struct ieee80211_node *iv_bss;			/* information for this node */
8860 +
8861 +	u_int8_t iv_bssid[IEEE80211_ADDR_LEN];
8862 +
8863 +	int iv_fixed_rate;				/* 802.11 rate or IEEE80211_FIXED_RATE_NONE */
8864 +	u_int16_t iv_rtsthreshold;
8865 +	u_int16_t iv_fragthreshold;
8866 +	u_int16_t iv_txmin;				/* min tx retry count */
8867 +	u_int16_t iv_txmax;				/* max tx retry count */
8868 +	u_int16_t iv_txlifetime;			/* tx lifetime */
8869 +	int iv_inact_timer;				/* inactivity timer wait */
8870 +	void *iv_opt_ie;				/* user-specified IEs */
8871 +	u_int16_t iv_opt_ie_len;			/* length of ni_opt_ie */
8872 +	ieee80211_keyix_t iv_def_txkey;			/* default/group TX key index */
8873 +	struct ieee80211_key iv_nw_keys[IEEE80211_WEP_NKID];
8874 +	ieee80211_keyix_t (*iv_key_alloc)(struct ieee80211vap *, const struct ieee80211_key *);
8875 +	int (*iv_key_delete)(struct ieee80211vap *, const struct ieee80211_key *,
8876 +		struct ieee80211_node *);
8877 +	int (*iv_key_set)(struct ieee80211vap *, const struct ieee80211_key *,
8878 +		const u_int8_t mac[IEEE80211_ADDR_LEN]);
8879 +	void (*iv_key_update_begin)(struct ieee80211vap *);
8880 +	void (*iv_key_update_end)(struct ieee80211vap *);
8881 +#ifdef ATH_SUPERG_COMP
8882 +	void (*iv_comp_set)(struct ieee80211vap *, struct ieee80211_node *, int);
8883 +#endif
8884 +	const struct ieee80211_authenticator *iv_auth;	/* authenticator glue */
8885 +	void *iv_ec;					/* private auth state */
8886 +	struct ieee80211vap *iv_xrvap;			/* pointer to XR VAP , if XR is enabled */
8887 +	u_int16_t iv_xrbcnwait;				/* SWBA count incremented until it reaches XR_BECON_FACTOR */
8888 +	struct timer_list iv_xrvapstart;		/* timer to start xr */
8889 +	u_int8_t iv_chanchange_count; 			/* 11h counter for channel change */
8890 +	int iv_mcast_rate; 				/* Multicast rate (Kbps) */
8891 +
8892 +	const struct ieee80211_aclator *iv_acl;		/* aclator glue */
8893 +	void *iv_as;					/* private aclator state */
8894 +
8895 +	struct timer_list iv_swbmiss;			/* software beacon miss timer */
8896 +	u_int16_t iv_swbmiss_period; 			/* software beacon miss timer period */
8897 +	struct ieee80211_nsparams iv_nsparams;		/* new state parameters for tasklet for stajoin1 */
8898 +	struct IEEE80211_TQ_STRUCT iv_stajoin1tq; 	/* tasklet for newstate action called from stajoin1tq */
8899 +	unsigned int iv_nsdone;				/* Done with scheduled newstate tasklet */
8900 +	uint8_t	wds_mac[IEEE80211_ADDR_LEN];
8901 +	struct ieee80211_spy iv_spy;         		/* IWSPY support */
8902 +	struct ieee80211_app_ie app_ie[IEEE80211_APPIE_NUM_OF_FRAME]; /* app-specified IEs by frame type */
8903 +	u_int32_t app_filter;				/* filters which management frames are forwarded to app */
8904 +	int iv_maxrateindex;
8905 +	int iv_minrateindex;
8906 +};
8907 +
8908 +/* Debug functions need the defintion of struct ieee80211vap because iv_debug 
8909 + * is used at runtime to determine if we should log an event
8910 + */
8911 +#include <net80211/ieee80211_debug.h>
8912 +#include <net80211/ieee80211_node.h>
8913 +#include <net80211/ieee80211_skb.h>
8914 +
8915 +struct ieee80211com {
8916 +	struct net_device *ic_dev;		/* associated device */
8917 +	ieee80211com_lock_t ic_comlock;		/* state update lock */
8918 +	ieee80211com_lock_t ic_vapslock; 	/* vap state machine lock */
8919 +	TAILQ_HEAD(, ieee80211vap) ic_vaps;	/* list of vap instances */
8920 +	enum ieee80211_phytype ic_phytype;	/* XXX wrong for multi-mode */
8921 +	enum ieee80211_opmode ic_opmode;	/* operation mode */
8922 +	struct ifmedia ic_media;		/* interface media config */
8923 +	u_int8_t ic_myaddr[IEEE80211_ADDR_LEN];
8924 +	struct timer_list ic_inact;		/* mgmt/inactivity timer */
8925 +
8926 +	u_int32_t ic_flags;			/* state flags */
8927 +	u_int32_t ic_flags_ext;			/* extension of state flags */
8928 +	u_int32_t ic_caps;			/* capabilities */
8929 +	u_int8_t ic_ath_cap;			/* Atheros adv. capabilities */
8930 +	u_int8_t ic_promisc;			/* VAPs needing promisc mode */
8931 +	u_int8_t ic_allmulti;			/* VAPs needing all multicast*/
8932 +	u_int8_t ic_nopened;			/* VAPs been opened */
8933 +	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
8934 +	struct ieee80211_rateset ic_sup_xr_rates;
8935 +	struct ieee80211_rateset ic_sup_half_rates;
8936 +	struct ieee80211_rateset ic_sup_quarter_rates;
8937 +	u_int16_t ic_modecaps;			/* set of mode capabilities */
8938 +	u_int16_t ic_curmode;			/* current mode */
8939 +	u_int16_t ic_lintval;			/* beacon interval */
8940 +	u_int16_t ic_holdover;			/* PM hold over duration */
8941 +	u_int16_t ic_bmissthreshold;		/* beacon miss threshold (# beacons) */
8942 +	unsigned long ic_bmiss_guard;		/* when to cease ignoring bmiss (jiffies) */
8943 +	u_int16_t ic_txpowlimit; 		/* global tx power limit (in 0.5 dBm) */
8944 +	u_int16_t ic_newtxpowlimit; 		/* tx power limit to change to (in 0.5 dBm) */
8945 +	u_int16_t ic_uapsdmaxtriggers; 		/* max triggers that could arrive */
8946 +	u_int8_t ic_coverageclass; 		/* coverage class */
8947 +	u_int8_t ic_protmode_rssi;			/* rssi threshold for protection mode */
8948 +	u_int64_t ic_protmode_lasttrig;		/* last trigger for protection mode */
8949 +	u_int16_t ic_protmode_timeout;		/* protection mode timeout */
8950 +
8951 +	/* Channel state:
8952 +	 *
8953 +	 * ic_channels is the set of available channels for the device;
8954 +	 *    it is setup by the driver
8955 +	 * ic_nchans is the number of valid entries in ic_channels
8956 +	 * ic_chan_avail is a bit vector of these channels used to check
8957 +	 *    whether a channel is available w/o searching the channel table.
8958 +	 * ic_chan_active is a (potentially) constrained subset of
8959 +	 *    ic_chan_avail that reflects any mode setting or user-specified
8960 +	 *    limit on the set of channels to use/scan
8961 +	 * ic_curchan is the current channel the device is set to; it may
8962 +	 *    be different from ic_bsschan when we are off-channel scanning
8963 +	 *    or otherwise doing background work
8964 +	 * ic_bsschan is the channel selected for operation; it may
8965 +	 *    be undefined (IEEE80211_CHAN_ANYC)
8966 +	 */
8967 +	int ic_nchans;				/* # entries in ic_channels */
8968 +	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
8969 +	struct timeval ic_chan_non_occupy[IEEE80211_CHAN_MAX];
8970 +	u_int8_t ic_chan_avail[IEEE80211_CHAN_BYTES];
8971 +	u_int8_t ic_chan_active[IEEE80211_CHAN_BYTES];
8972 +	struct ieee80211_channel *ic_curchan;	/* current channel */
8973 +	struct ieee80211_channel *ic_bsschan;	/* bss channel */
8974 +	int16_t ic_channoise;			/* current channel noise in dBm */
8975 +	struct timer_list ic_dfs_excl_timer;
8976 +	/*
8977 +	 * Spectrum management (IEEE 802.11h-2003):
8978 +	 *
8979 +	 * ic_chan_nodes is an array of numbers of nodes that provide
8980 +	 *    ni_suppchans with the given channel reported as supported. Index
8981 +	 *    of the array is an IEEE channel number (ic_ieee)
8982 +	 * ic_cn_total is the number of nodes counted in ic_chan_nodes
8983 +	 *    (provided ni_suppchans and are associated)
8984 +	 * ic_sc_mincom is the desired minimum number of common channels, the
8985 +	 *    parameter used by SC_TIGHT and SC_STRICT algorithms
8986 +	 * ic_sc_algorithm is the algorithm for (re)association based on
8987 +	 *    supported channels
8988 +	 * ic_sc_slcg is the permil of Stations Lost per Channel Gained, the
8989 +	 *    parameter used by SC_TIGHT and SC_STRICT algorithms. If due to
8990 +	 *    association of the STA and disassociation of x other STAs (out of
8991 +	 *    y associated STAs in total), the number of common channel
8992 +	 *    increases by z, then such an action is performed if
8993 +	 *    1000*x/y < z*ic_sc_slcg
8994 +	 * ic_sc_sldg is the permil of Stations Lost per rssi Db Gained, the
8995 +	 *    parameter used by SC_LOOSE algorithm. If due to the switch,
8996 +	 *    the maximum RSSI of received packets on the current channel would
8997 +	 *    decrease by z decibels and x stations from the set of y stations
8998 +	 *    would be lost, then such a switch will be performed if
8999 +	 *    1000*x/y < z*ic_sc_sldg
9000 +	 * ic_sc_ie is the Supported Channels IE that is about to be sent along
9001 +	 *    with (re)assoc requests (STA mode)
9002 +	 */
9003 +	u_int16_t ic_chan_nodes[IEEE80211_CHAN_MAX+1];
9004 +	u_int16_t ic_cn_total;                  /* # nodes counted in ic_chan nodes */
9005 +	u_int16_t ic_sc_mincom;                 /* minimum number of common channels */
9006 +	enum ieee80211_sc_algorithm ic_sc_algorithm;
9007 +	u_int16_t ic_sc_slcg;                   /* permil of Stations Lost per Channel Gained */
9008 +	u_int16_t ic_sc_sldg;                   /* permil of Stations Lost per rssi Db Gained */
9009 +	struct ieee80211_ie_sc ic_sc_ie;        /* Supported Channels IE */
9010 +
9011 +	/* Regulatory class ids */
9012 +	u_int ic_nregclass;			/* # entries in ic_regclassids */
9013 +	u_int8_t ic_regclassids[IEEE80211_REGCLASSIDS_MAX];
9014 +
9015 +	/* Scan-related state */
9016 +	struct ieee80211_scan_state *ic_scan;	/* scan state */
9017 +	enum ieee80211_roamingmode ic_roaming;	/* roaming mode */
9018 +	unsigned long ic_lastdata;		/* time of last data frame */
9019 +	unsigned long ic_lastscan;		/* time last scan completed */
9020 +
9021 +	/* NB: this is the union of all vap stations/neighbors */
9022 +	struct ieee80211_node_table ic_sta;	/* stations/neighbors */
9023 +
9024 +	/* XXX Multi-BSS: split out common/VAP parts? */
9025 +	struct ieee80211_wme_state ic_wme;	/* WME/WMM state */
9026 +
9027 +	/* XXX Multi-BSS: can per-VAP be done/make sense? */
9028 +	enum ieee80211_protmode	ic_protmode;	/* 802.11g protection mode */
9029 +	u_int16_t ic_nonerpsta;			/* # non-ERP stations */
9030 +	u_int16_t ic_longslotsta;		/* # long slot time stations */
9031 +	u_int16_t ic_sta_assoc;			/* stations associated */
9032 +	u_int16_t ic_dt_sta_assoc;		/* dturbo capable stations */
9033 +	u_int16_t ic_xr_sta_assoc;		/* XR stations associated */
9034 +
9035 +	/* Spectrum management. */
9036 +	u_int16_t ic_country_code;
9037 +	int ic_country_outdoor;
9038 +	struct ieee80211_ie_country ic_country_ie; /* country info element */
9039 +
9040 +	/* current channel max power, used to compute Power Constraint IE.
9041 +	 *
9042 +	 * NB: local power constraint depends on the channel, but assuming it must
9043 +	 *     be detected dynamically, we cannot maintain a table (i.e., will not
9044 +	 *     know value until change to channel and detect).
9045 +	 */
9046 +	u_int8_t ic_curchanmaxpwr;
9047 +	u_int8_t ic_chanchange_tbtt;
9048 +	u_int8_t ic_chanchange_chan;
9049 +
9050 +	/* Global debug flags applicable to all VAPs */
9051 +	int ic_debug;
9052 +	/* used for reference tracking/counting.  Nodes are shared between VAPs,
9053 +	 * so we put this here. */
9054 +	atomic_t ic_node_counter;
9055 +	/* Virtual AP create/delete */
9056 +	struct ieee80211vap *(*ic_vap_create)(struct ieee80211com *,
9057 +		const char *, int, int, struct net_device *);
9058 +	void (*ic_vap_delete)(struct ieee80211vap *);
9059 +
9060 +	/* Send/recv 802.11 management frame */
9061 +	int (*ic_send_mgmt)(struct ieee80211_node *, int, int);
9062 +	void (*ic_recv_mgmt)(struct ieee80211vap *, struct ieee80211_node *,
9063 +		struct sk_buff *, int, int, u_int64_t);
9064 +
9065 +	/* Send management frame to driver (like hardstart) */
9066 +	int (*ic_mgtstart)(struct ieee80211com *, struct sk_buff *);
9067 +
9068 +	/* Reset device state after 802.11 parameter/state change */
9069 +	int (*ic_init)(struct net_device *);
9070 +	int (*ic_reset)(struct net_device *);
9071 +
9072 +	/* Update device state for 802.11 slot time change */
9073 +	void (*ic_updateslot)(struct net_device *);
9074 +
9075 +	/* New station association callback/notification */
9076 +	void (*ic_newassoc)(struct ieee80211_node *, int);
9077 +
9078 +	/* Node state management */
9079 +	int32_t (*ic_node_count)(struct ieee80211com *);
9080 +#ifdef IEEE80211_DEBUG_REFCNT
9081 +	struct ieee80211_node *(*ic_node_alloc_debug)(struct ieee80211vap *, 
9082 +			const char* func, int line);
9083 +	void (*ic_node_cleanup_debug)(struct ieee80211_node *, 
9084 +			const char* func, int line);
9085 +	void (*ic_node_free_debug)(struct ieee80211_node *, 
9086 +			const char* func, int line);
9087 +#else
9088 +	struct ieee80211_node *(*ic_node_alloc)(struct ieee80211vap *);
9089 +	void (*ic_node_cleanup)(struct ieee80211_node *);
9090 +	void (*ic_node_free)(struct ieee80211_node *);
9091 +#endif
9092 +
9093 +	u_int8_t (*ic_node_getrssi)(const struct ieee80211_node *);
9094 +	u_int8_t (*ic_node_move_data)(const struct ieee80211_node *);
9095 +
9096 +	/* Scanning support */
9097 +	void (*ic_scan_start)(struct ieee80211com *);
9098 +	void (*ic_scan_end)(struct ieee80211com *);
9099 +	void (*ic_set_channel)(struct ieee80211com *);
9100 +
9101 +	/* U-APSD support */
9102 +	void (*ic_uapsd_flush)(struct ieee80211_node *);
9103 +
9104 +	/* continuous transmission support */
9105 +	void (*ic_set_txcont)(struct ieee80211com *, int);
9106 +	int (*ic_get_txcont)(struct ieee80211com *);
9107 +	void (*ic_set_txcont_power)(struct ieee80211com *, u_int);
9108 +	int (*ic_get_txcont_power)(struct ieee80211com *);
9109 +	void (*ic_set_txcont_rate)(struct ieee80211com *, u_int);
9110 +	u_int (*ic_get_txcont_rate)(struct ieee80211com *);
9111 +
9112 +	/* DFS test mode prevents marking channel interference and channel 
9113 +	 * switching during detection probability tests */
9114 +	void (*ic_set_dfs_testmode)(struct ieee80211com *, int);
9115 +	int (*ic_get_dfs_testmode)(struct ieee80211com *);
9116 +
9117 +	/* inject a fake radar signal -- used while on a 802.11h DFS channels */
9118 +	unsigned int (*ic_test_radar)(struct ieee80211com *);
9119 +
9120 +#ifdef AR_DEBUG
9121 +	/* dump HAL */
9122 +	unsigned int (*ic_dump_hal_map)(struct ieee80211com *);
9123 +#endif
9124 +	/* DFS channel availability check time (in seconds) */
9125 +	void (*ic_set_dfs_cac_time)(struct ieee80211com *, unsigned int);
9126 +	unsigned int (*ic_get_dfs_cac_time)(struct ieee80211com *);
9127 +
9128 +	/* DFS non-occupancy period (in seconds) */
9129 +	void (*ic_set_dfs_excl_period)(struct ieee80211com *, unsigned int);
9130 +	unsigned int (*ic_get_dfs_excl_period)(struct ieee80211com *);
9131 +
9132 +	/* Set coverage class */
9133 +	void (*ic_set_coverageclass)(struct ieee80211com *);
9134 +
9135 +	/* MHz to IEEE channel conversion */
9136 +	u_int (*ic_mhz2ieee)(struct ieee80211com *, u_int, u_int);
9137 +
9138 +#ifdef ATH_REVERSE_ENGINEERING
9139 +	/* debug and reverse engineering hooks */
9140 +	void (*ic_registers_dump)(struct ieee80211com *);
9141 +	void (*ic_registers_mark)(struct ieee80211com *);
9142 +	void (*ic_registers_dump_delta)(struct ieee80211com *);
9143 +	unsigned int (*ic_write_register)(struct ieee80211com *, unsigned int, unsigned int);
9144 +	unsigned int (*ic_read_register)(struct ieee80211com *, unsigned int, unsigned int*);
9145 +#endif /* #ifdef ATH_REVERSE_ENGINEERING */
9146 +};
9147 +
9148 +#define MAX_PROC_IEEE80211_SIZE 16383
9149 +#define PROC_IEEE80211_PERM 0644
9150 +
9151 +struct proc_ieee80211_priv {
9152 +	int rlen;
9153 +	int max_rlen;
9154 +	char *rbuf;
9155 +
9156 +	int wlen;
9157 +	int max_wlen;
9158 +	char *wbuf;
9159 +};
9160 +
9161 +struct ieee80211_proc_entry {
9162 +	char *name;
9163 +	struct file_operations *fileops;
9164 +	struct proc_dir_entry *entry;
9165 +	struct ieee80211_proc_entry *next;
9166 +};
9167 +
9168 +MALLOC_DECLARE(M_80211_VAP);
9169 +
9170 +#define	IEEE80211_ADDR_NULL(a1)		(memcmp(a1, "\x00\x00\x00\x00\x00\x00", \
9171 +					 IEEE80211_ADDR_LEN) == 0)
9172 +#define	IEEE80211_ADDR_EQ(a1, a2)	(memcmp(a1, a2, IEEE80211_ADDR_LEN) == 0)
9173 +#define	IEEE80211_ADDR_COPY(dst, src)	memcpy(dst, src, IEEE80211_ADDR_LEN)
9174 +#define	IEEE80211_ADDR_SET_NULL(dst)	memset(dst, 0, IEEE80211_ADDR_LEN)
9175 +
9176 +/* ic_flags */
9177 +#define	IEEE80211_F_FF		0x00000001		/* CONF: ATH FF enabled */
9178 +#define	IEEE80211_F_TURBOP	0x00000002		/* CONF: ATH Turbo enabled*/
9179 +#define	IEEE80211_F_PROMISC	0x00000004		/* STATUS: promiscuous mode */
9180 +#define	IEEE80211_F_ALLMULTI	0x00000008		/* STATUS: all multicast mode */
9181 +/* NB: this is intentionally setup to be IEEE80211_CAPINFO_PRIVACY */
9182 +#define	IEEE80211_F_PRIVACY	0x00000010		/* CONF: privacy enabled */
9183 +#define	IEEE80211_F_PUREG	0x00000020		/* CONF: 11g w/o 11b STAs */
9184 +#define	IEEE80211_F_XRUPDATE	0x00000040		/* CONF: update beacon XR element*/
9185 +#define	IEEE80211_F_SCAN	0x00000080		/* STATUS: scanning */
9186 +#define	IEEE80211_F_XR		0x00000100		/* CONF: operate in XR mode */
9187 +#define	IEEE80211_F_SIBSS	0x00000200		/* STATUS: start IBSS */
9188 +/* NB: this is intentionally setup to be IEEE80211_CAPINFO_SHORT_SLOTTIME */
9189 +#define	IEEE80211_F_SHSLOT	0x00000400		/* STATUS: use short slot time*/
9190 +#define	IEEE80211_F_PMGTON	0x00000800		/* CONF: Power mgmt enable */
9191 +#define	IEEE80211_F_DESBSSID	0x00001000		/* CONF: des_bssid is set */
9192 +#define	IEEE80211_F_WME		0x00002000		/* CONF: enable WME use */
9193 +#define	IEEE80211_F_BGSCAN	0x00004000		/* CONF: bg scan enabled */
9194 +#define	IEEE80211_F_SWRETRY	0x00008000		/* CONF: sw tx retry enabled */
9195 +#define IEEE80211_F_TXPOW_FIXED	0x00010000		/* TX Power: fixed rate */
9196 +#define	IEEE80211_F_IBSSON	0x00020000		/* CONF: IBSS creation enable */
9197 +#define	IEEE80211_F_SHPREAMBLE	0x00040000		/* STATUS: use short preamble */
9198 +#define	IEEE80211_F_DATAPAD	0x00080000		/* CONF: do alignment pad */
9199 +#define	IEEE80211_F_USEPROT	0x00100000		/* STATUS: protection enabled */
9200 +#define	IEEE80211_F_USEBARKER	0x00200000		/* STATUS: use barker preamble*/
9201 +#define	IEEE80211_F_TIMUPDATE	0x00400000		/* STATUS: update beacon tim */
9202 +#define	IEEE80211_F_WPA1	0x00800000		/* CONF: WPA enabled */
9203 +#define	IEEE80211_F_WPA2	0x01000000		/* CONF: WPA2 enabled */
9204 +#define	IEEE80211_F_WPA		0x01800000		/* CONF: WPA/WPA2 enabled */
9205 +#define	IEEE80211_F_DROPUNENC	0x02000000		/* CONF: drop unencrypted */
9206 +#define	IEEE80211_F_COUNTERM	0x04000000		/* CONF: TKIP countermeasures */
9207 +#define	IEEE80211_F_HIDESSID	0x08000000		/* CONF: hide SSID in beacon */
9208 +#define IEEE80211_F_NOBRIDGE    0x10000000		/* CONF: disable internal bridge */
9209 +
9210 +#define	IEEE80211_F_WMEUPDATE	0x20000000		/* STATUS: update beacon wme */
9211 +#define IEEE80211_F_DOTH	0x40000000		/* enable 11.h */
9212 +#define IEEE80211_F_CHANSWITCH	0x80000000		/* force chanswitch */
9213 +
9214 +/* ic_flags_ext */
9215 +#define	IEEE80211_FEXT_WDS		0x00000001	/* CONF: 4 addr allowed */
9216 +#define IEEE80211_FEXT_COUNTRYIE	0x00000002	/* CONF: enable country IE */
9217 +#define IEEE80211_FEXT_SCAN_PENDING	0x00000004	/* STATE: scan pending */
9218 +#define	IEEE80211_FEXT_BGSCAN		0x00000008	/* STATE: enable full bgscan completion */
9219 +#define IEEE80211_FEXT_UAPSD		0x00000010	/* CONF: enable U-APSD */
9220 +#define IEEE80211_FEXT_SLEEP		0x00000020	/* STATUS: sleeping */
9221 +#define IEEE80211_FEXT_EOSPDROP		0x00000040	/* drop uapsd EOSP frames for test */
9222 +#define	IEEE80211_FEXT_MARKDFS		0x00000080	/* Enable marking of dfs interference */
9223 +#define IEEE80211_FEXT_REGCLASS		0x00000100	/* CONF: send regclassids in country ie */
9224 +#define IEEE80211_FEXT_ERPUPDATE	0x00000200	/* STATUS: update ERP element */
9225 +#define IEEE80211_FEXT_SWBMISS		0x00000400	/* CONF: use software beacon timer */
9226 +#define IEEE80211_FEXT_DROPUNENC_EAPOL	0x00000800	/* CONF: drop unencrypted eapol frames */
9227 +#define IEEE80211_FEXT_APPIE_UPDATE	0x00001000	/* STATE: beacon APP IE updated */
9228 +
9229 +#define IEEE80211_COM_UAPSD_ENABLE(_ic)		((_ic)->ic_flags_ext |= IEEE80211_FEXT_UAPSD)
9230 +#define IEEE80211_COM_UAPSD_DISABLE(_ic)	((_ic)->ic_flags_ext &= ~IEEE80211_FEXT_UAPSD)
9231 +#define IEEE80211_COM_UAPSD_ENABLED(_ic)	((_ic)->ic_flags_ext & IEEE80211_FEXT_UAPSD)
9232 +#define IEEE80211_COM_GOTOSLEEP(_ic)		((_ic)->ic_flags_ext |= IEEE80211_FEXT_GOTOSLEEP)
9233 +#define IEEE80211_COM_WAKEUP(_ic)		((_ic)->ic_flags_ext &= ~IEEE80211_FEXT_SLEEP)
9234 +#define IEEE80211_COM_IS_SLEEPING(_ic)		((_ic)->ic_flags_ext & IEEE80211_FEXT_SLEEP)
9235 +
9236 +#define IEEE80211_VAP_UAPSD_ENABLE(_v)		((_v)->iv_flags_ext |= IEEE80211_FEXT_UAPSD)
9237 +#define IEEE80211_VAP_UAPSD_DISABLE(_v)		((_v)->iv_flags_ext &= ~IEEE80211_FEXT_UAPSD)
9238 +#define IEEE80211_VAP_UAPSD_ENABLED(_v)		((_v)->iv_flags_ext & IEEE80211_FEXT_UAPSD)
9239 +#define IEEE80211_VAP_GOTOSLEEP(_v)		((_v)->iv_flags_ext |= IEEE80211_FEXT_SLEEP)
9240 +#define IEEE80211_VAP_WAKEUP(_v)		((_v)->iv_flags_ext &= ~IEEE80211_FEXT_SLEEP)
9241 +#define IEEE80211_VAP_IS_SLEEPING(_v)		((_v)->iv_flags_ext & IEEE80211_FEXT_SLEEP)
9242 +#define IEEE80211_VAP_EOSPDROP_ENABLE(_v)  	((_v)->iv_flags_ext |= IEEE80211_FEXT_EOSPDROP)
9243 +#define IEEE80211_VAP_EOSPDROP_DISABLE(_v) 	((_v)->iv_flags_ext &= ~IEEE80211_FEXT_EOSPDROP)
9244 +#define IEEE80211_VAP_EOSPDROP_ENABLED(_v) 	((_v)->iv_flags_ext & IEEE80211_FEXT_EOSPDROP)
9245 +#define IEEE80211_VAP_DROPUNENC_EAPOL_ENABLE(_v) \
9246 +						((_v)->iv_flags_ext |= IEEE80211_FEXT_DROPUNENC_EAPOL)
9247 +#define IEEE80211_VAP_DROPUNENC_EAPOL_DISABLE(_v) \
9248 +						((_v)->iv_flags_ext &= ~IEEE80211_FEXT_DROPUNENC_EAPOL)
9249 +#define IEEE80211_VAP_DROPUNENC_EAPOL(_v) 	((_v)->iv_flags_ext & IEEE80211_FEXT_DROPUNENC_EAPOL)
9250 +
9251 +
9252 +/* ic_caps */
9253 +#define	IEEE80211_C_WEP		0x00000001	/* CAPABILITY: WEP available */
9254 +#define	IEEE80211_C_TKIP	0x00000002	/* CAPABILITY: TKIP available */
9255 +#define	IEEE80211_C_AES		0x00000004	/* CAPABILITY: AES OCB avail */
9256 +#define	IEEE80211_C_AES_CCM	0x00000008	/* CAPABILITY: AES CCM avail */
9257 +#define	IEEE80211_C_CKIP	0x00000020	/* CAPABILITY: CKIP available */
9258 +#define	IEEE80211_C_FF		0x00000040	/* CAPABILITY: ATH FF avail */
9259 +#define	IEEE80211_C_TURBOP	0x00000080	/* CAPABILITY: ATH Turbo avail*/
9260 +#define	IEEE80211_C_IBSS	0x00000100	/* CAPABILITY: IBSS available */
9261 +#define	IEEE80211_C_PMGT	0x00000200	/* CAPABILITY: Power mgmt */
9262 +#define	IEEE80211_C_HOSTAP	0x00000400	/* CAPABILITY: HOSTAP avail */
9263 +#define	IEEE80211_C_AHDEMO	0x00000800	/* CAPABILITY: Old Adhoc Demo */
9264 +#define	IEEE80211_C_SWRETRY	0x00001000	/* CAPABILITY: sw tx retry */
9265 +#define	IEEE80211_C_TXPMGT	0x00002000	/* CAPABILITY: tx power mgmt */
9266 +#define	IEEE80211_C_SHSLOT	0x00004000	/* CAPABILITY: short slottime */
9267 +#define	IEEE80211_C_SHPREAMBLE	0x00008000	/* CAPABILITY: short preamble */
9268 +#define	IEEE80211_C_MONITOR	0x00010000	/* CAPABILITY: monitor mode */
9269 +#define	IEEE80211_C_TKIPMIC	0x00020000	/* CAPABILITY: TKIP MIC avail */
9270 +#define	IEEE80211_C_WPA1	0x00800000	/* CAPABILITY: WPA1 avail */
9271 +#define	IEEE80211_C_WPA2	0x01000000	/* CAPABILITY: WPA2 avail */
9272 +#define	IEEE80211_C_WPA		0x01800000	/* CAPABILITY: WPA1+WPA2 avail*/
9273 +#define	IEEE80211_C_BURST	0x02000000	/* CAPABILITY: frame bursting */
9274 +#define	IEEE80211_C_WME		0x04000000	/* CAPABILITY: WME avail */
9275 +#define	IEEE80211_C_WDS		0x08000000	/* CAPABILITY: 4-addr support */
9276 +#define IEEE80211_C_WME_TKIPMIC	0x10000000	/* CAPABILITY: TKIP MIC for QoS frame */
9277 +#define	IEEE80211_C_BGSCAN	0x20000000	/* CAPABILITY: bg scanning */
9278 +#define	IEEE80211_C_UAPSD	0x40000000	/* CAPABILITY: UAPSD */
9279 +/* XXX protection/barker? */
9280 +
9281 +#define	IEEE80211_C_CRYPTO	0x0000002f	/* CAPABILITY: crypto alg's */
9282 +
9283 +/* Atheros ABOLT definitions */
9284 +#define IEEE80211_ABOLT_TURBO_G		0x01	/* Legacy Turbo G */
9285 +#define IEEE80211_ABOLT_TURBO_PRIME	0x02	/* Turbo Prime */
9286 +#define IEEE80211_ABOLT_COMPRESSION	0x04	/* Compression */
9287 +#define IEEE80211_ABOLT_FAST_FRAME	0x08	/* Fast Frames */
9288 +#define IEEE80211_ABOLT_BURST		0x10	/* Bursting */
9289 +#define IEEE80211_ABOLT_WME_ELE		0x20	/* WME based cwmin/max/burst tuning */
9290 +#define IEEE80211_ABOLT_XR		0x40	/* XR */
9291 +#define IEEE80211_ABOLT_AR		0x80	/* AR switches out based on adjaced non-turbo traffic */
9292 +
9293 +/* Atheros Advanced Capabilities ABOLT definition */
9294 +#define IEEE80211_ABOLT_ADVCAP	(IEEE80211_ABOLT_TURBO_PRIME | \
9295 +				 IEEE80211_ABOLT_COMPRESSION | \
9296 +				 IEEE80211_ABOLT_FAST_FRAME | \
9297 +				 IEEE80211_ABOLT_XR | \
9298 +				 IEEE80211_ABOLT_AR | \
9299 +				 IEEE80211_ABOLT_BURST | \
9300 +				 IEEE80211_ABOLT_WME_ELE)
9301 +
9302 +/* check if a capability was negotiated for use */
9303 +#define	IEEE80211_ATH_CAP(vap, ni, bit) \
9304 +	((ni)->ni_ath_flags & (vap)->iv_ath_cap & (bit))
9305 +
9306 +/* flags to VAP create function */
9307 +#define IEEE80211_VAP_XR		0x10000	/* create a XR VAP without registering net device with OS */
9308 +
9309 +int ieee80211_ifattach(struct ieee80211com *);
9310 +void ieee80211_ifdetach(struct ieee80211com *);
9311 +int ieee80211_vap_setup(struct ieee80211com *, struct net_device *,
9312 +	const char *, int, int);
9313 +int ieee80211_vap_attach(struct ieee80211vap *, ifm_change_cb_t, ifm_stat_cb_t);
9314 +void ieee80211_vap_detach(struct ieee80211vap *);
9315 +void ieee80211_mark_dfs(struct ieee80211com *, struct ieee80211_channel *);
9316 +void ieee80211_dfs_test_return(struct ieee80211com *, u_int8_t);
9317 +void ieee80211_announce(struct ieee80211com *);
9318 +void ieee80211_announce_channels(struct ieee80211com *);
9319 +int ieee80211_media_change(struct net_device *);
9320 +void ieee80211_media_status(struct net_device *, struct ifmediareq *);
9321 +int ieee80211_rate2media(struct ieee80211com*, int, enum ieee80211_phymode);
9322 +int ieee80211_media2rate(int);
9323 +u_int ieee80211_mhz2ieee(u_int, u_int);
9324 +u_int ieee80211_chan2ieee(struct ieee80211com *,	const struct ieee80211_channel *);
9325 +u_int ieee80211_ieee2mhz(u_int, u_int);
9326 +struct ieee80211_channel *ieee80211_find_channel(struct ieee80211com *, int, int);
9327 +int ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
9328 +void ieee80211_reset_erp(struct ieee80211com *, enum ieee80211_phymode);
9329 +enum ieee80211_phymode ieee80211_chan2mode(const struct ieee80211_channel *);
9330 +void ieee80211_build_countryie(struct ieee80211com *);
9331 +int ieee80211_media_setup(struct ieee80211com *, struct ifmedia *, u_int32_t,
9332 +	ifm_change_cb_t, ifm_stat_cb_t);
9333 +void ieee80211_build_sc_ie(struct ieee80211com *);
9334 +void ieee80211_dfs_action(struct ieee80211com *);
9335 +void ieee80211_expire_channel_excl_restrictions(struct ieee80211com *);
9336 +void ieee80211_setpuregbasicrates(struct ieee80211_rateset *rs);
9337 +
9338 +/*
9339 + * Iterate through ic_channels to enumerate all distinct ic_ieee channel numbers.
9340 + * It relies on the assumption that ic_ieee cannot be 0 and that all the
9341 + * duplicates in ic_channels occur subsequently.
9342 + *
9343 + * _i and _prevchan are temporary variables
9344 + */
9345 +#define CHANNEL_FOREACH(_chan, _ic, _i, _prevchan)			\
9346 +	for ((_i) = 0, (_prevchan) = 0;					\
9347 +	     (_i) < (_ic)->ic_nchans && ((_chan) =			\
9348 +		     (_ic)->ic_channels[(_i)].ic_ieee);			\
9349 +	     (_prevchan) = (_chan), (_i)++				\
9350 +	    ) if ((_chan) != (_prevchan))
9351 +
9352 +/* Key update synchronization methods.  XXX should not be visible. */
9353 +static __inline void
9354 +ieee80211_key_update_begin(struct ieee80211vap *vap)
9355 +{
9356 +	vap->iv_key_update_begin(vap);
9357 +}
9358 +static __inline void
9359 +ieee80211_key_update_end(struct ieee80211vap *vap)
9360 +{
9361 +	vap->iv_key_update_end(vap);
9362 +}
9363 +
9364 +/* XXX these need to be here for IEEE80211_F_DATAPAD */
9365 +
9366 +/*
9367 + * Return the space occupied by the 802.11 header and any
9368 + * padding required by the driver.  This works for a
9369 + * management or data frame.
9370 + */
9371 +static __inline int
9372 +ieee80211_hdrspace(struct ieee80211com *ic, const void *data)
9373 +{
9374 +	int size = ieee80211_hdrsize(data);
9375 +	if (ic->ic_flags & IEEE80211_F_DATAPAD)
9376 +		size = roundup(size, sizeof(u_int32_t));
9377 +	return size;
9378 +}
9379 +
9380 +/* Like ieee80211_hdrspace, but handles any type of frame. */
9381 +static __inline int
9382 +ieee80211_anyhdrspace(struct ieee80211com *ic, const void *data)
9383 +{
9384 +	int size = ieee80211_anyhdrsize(data);
9385 +	if (ic->ic_flags & IEEE80211_F_DATAPAD)
9386 +		size = roundup(size, sizeof(u_int32_t));
9387 +	return size;
9388 +}
9389 +
9390 +/* Macros to print MAC address used in 802.11 headers */
9391 +
9392 +#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
9393 +#define MAC_ADDR(addr) \
9394 +  ((unsigned char *)(addr)) [0], \
9395 +  ((unsigned char *)(addr)) [1], \
9396 +  ((unsigned char *)(addr)) [2], \
9397 +  ((unsigned char *)(addr)) [3], \
9398 +  ((unsigned char *)(addr)) [4], \
9399 +  ((unsigned char *)(addr)) [5]
9400 +
9401 +#endif /* _NET80211_IEEE80211_VAR_H_ */
9402 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_athproto.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_athproto.h
9403 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_athproto.h	1970-01-01 01:00:00.000000000 +0100
9404 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_athproto.h	2008-06-19 17:34:17.000000000 +0200
9405 @@ -0,0 +1,102 @@
9406 +/*
9407 + * Copyright (c) 2004 Atheros Communications Inc.  All rights reserved.
9408 + *
9409 + * $Id: if_athproto.h 2888 2007-11-21 10:45:58Z mtaylor $
9410 + */
9411 +
9412 +#ifndef _NET_IF_ATH_PROTO_H_
9413 +#define _NET_IF_ATH_PROTO_H_
9414 +
9415 +/*
9416 + * Atheros proprietary protocol info.
9417 + */
9418 +
9419 +/*
9420 + * Atheros RSSI, Signal, Noise, etc.
9421 + */
9422 +
9423 +#define ATH_DEFAULT_NOISE	-95	/* dBm */
9424 +
9425 +/*
9426 + * Atheros proprietary SuperG defines.
9427 + */
9428 +
9429 +#define ATH_ETH_TYPE  		0x88bd
9430 +#define ATH_SNAP_ORGCODE_0	0x00
9431 +#define ATH_SNAP_ORGCODE_1	0x03
9432 +#define ATH_SNAP_ORGCODE_2	0x7f
9433 +
9434 +struct athl2p_tunnel_hdr {
9435 +#if (_BYTE_ORDER == _LITTLE_ENDIAN)
9436 +	u_int32_t offset:11,
9437 +	seqNum:11,
9438 +	optHdrLen32:2,
9439 +	frameType:2,
9440 +	proto:6;
9441 +#else /* big endian */
9442 +	u_int32_t proto:6,
9443 +	frameType:2,
9444 +	optHdrLen32:2,
9445 +	seqNum:11,
9446 +	offset:11;
9447 +#endif
9448 +} __packed;
9449 +
9450 +/*
9451 + * The following defines control compiling Atheros-specific features
9452 + * (see BuildCaps.inc):
9453 + *
9454 + *   ATH_SUPERG_FF 
9455 + *      set to 1 for fast-frame
9456 + */
9457 +
9458 +#define ATH_L2TUNNEL_PROTO_FF 0
9459 +/* FF max payload: 
9460 + * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500:
9461 + *   8   +   4   +  4   +   14  +   8   + 1500 +  6   +   14  +   8   + 1500
9462 + * = 3066
9463 + */
9464 +#define ATH_FF_MAX_HDR_PAD	4
9465 +#define ATH_FF_MAX_SEP_PAD	6
9466 +#define ATH_FF_MAX_HDR		30
9467 +#define ATH_FF_MAX_PAYLOAD 	3066
9468 +#define ATH_FF_MAX_LEN (ATH_FF_MAX_PAYLOAD + IEEE80211_CRC_LEN + \
9469 +	(IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
9470 +
9471 +/*
9472 + * Store a magic number in skb->cb[] area to indicate FF within driver.
9473 + * Offset of 8B into cb[] is used to preserve vlan tag info.
9474 + */
9475 +#define ATH_FF_MAGIC_PUT(_skb) \
9476 +	(SKB_CB(_skb)->flags |= M_FF)
9477 +#define ATH_FF_MAGIC_CLR(_skb) \
9478 +	(SKB_CB(_skb)->flags &= ~M_FF)
9479 +#define ATH_FF_MAGIC_PRESENT(_skb) \
9480 +	((SKB_CB(_skb)->flags & M_FF) != 0)
9481 +#define ATH_FF_NEXTSKB_PUT(_skb, _next) \
9482 +	(SKB_CB(_skb)->next = _next)
9483 +#define ATH_FF_NEXTSKB_GET(_skb) \
9484 +	(SKB_CB(_skb)->next)
9485 +
9486 +/*
9487 + * default value for the minimum txq depth required for an ath_buf to be
9488 + * placed on the FF staging queue. this value should be >=3 due to interaction
9489 + * with HW compression.
9490 + */
9491 +#define ATH_FF_TXQMIN		3
9492 +
9493 +/* 
9494 + * default maximum age an ath_buf is allowed to remain on the staging queue.
9495 + * When this number of ath_bufs have been queued on the txq, after an ath_buf
9496 + * was placed on the staging queue, that ath_buf on the staging queue will be
9497 + * flushed.
9498 + */
9499 +#define ATH_FF_STAGEQAGEMAX	5
9500 +
9501 +/*
9502 + * Reserve enough buffer header length to avoid reallocation on fast-frame
9503 + * rx and tx.
9504 + */
9505 +#define USE_HEADERLEN_RESV	1
9506 +
9507 +#endif /* _NET_IF_ATH_PROTO_H_ */
9508 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_ethersubr.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_ethersubr.h
9509 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_ethersubr.h	1970-01-01 01:00:00.000000000 +0100
9510 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_ethersubr.h	2008-06-19 17:34:17.000000000 +0200
9511 @@ -0,0 +1,79 @@
9512 +/*-
9513 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
9514 + * All rights reserved.
9515 + *
9516 + * Redistribution and use in source and binary forms, with or without
9517 + * modification, are permitted provided that the following conditions
9518 + * are met:
9519 + * 1. Redistributions of source code must retain the above copyright
9520 + *    notice, this list of conditions and the following disclaimer,
9521 + *    without modification.
9522 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
9523 + *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
9524 + *    redistribution must be conditioned upon including a substantially
9525 + *    similar Disclaimer requirement for further binary redistribution.
9526 + * 3. Neither the names of the above-listed copyright holders nor the names
9527 + *    of any contributors may be used to endorse or promote products derived
9528 + *    from this software without specific prior written permission.
9529 + *
9530 + * Alternatively, this software may be distributed under the terms of the
9531 + * GNU General Public License ("GPL") version 2 as published by the Free
9532 + * Software Foundation.
9533 + *
9534 + * NO WARRANTY
9535 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9536 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9537 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
9538 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
9539 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
9540 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
9541 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
9542 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
9543 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
9544 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
9545 + * THE POSSIBILITY OF SUCH DAMAGES.
9546 + *
9547 + * $Id: if_ethersubr.h 2028 2007-01-30 03:51:52Z proski $
9548 + */
9549 +
9550 +#ifndef _NET_IF_ETHERSUBR_H_
9551 +#define _NET_IF_ETHERSUBR_H_
9552 +
9553 +#define	ETHER_ADDR_LEN		6	/* length of an Ethernet address */
9554 +#define	ETHER_TYPE_LEN		2	/* length of the Ethernet type field */
9555 +#define	ETHER_CRC_LEN		4	/* length of the Ethernet CRC */
9556 +#define	ETHER_HDR_LEN		(ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
9557 +#define	ETHER_MAX_LEN		1518
9558 +
9559 +#define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
9560 +
9561 +/*
9562 + * Structure of a 10Mb/s Ethernet header.
9563 + */
9564 +struct	ether_header {
9565 +	u_char ether_dhost[ETHER_ADDR_LEN];
9566 +	u_char ether_shost[ETHER_ADDR_LEN];
9567 +	__be16 ether_type;
9568 +} __packed;
9569 +
9570 +#ifndef ETHERTYPE_PAE
9571 +#define	ETHERTYPE_PAE	0x888e		/* EAPOL PAE/802.1x */
9572 +#endif
9573 +#ifndef ETHERTYPE_IP
9574 +#define	ETHERTYPE_IP	0x0800		/* IP protocol */
9575 +#endif
9576 +
9577 +/*
9578 + * Structure of a 48-bit Ethernet address.
9579 + */
9580 +struct	ether_addr {
9581 +	u_char octet[ETHER_ADDR_LEN];
9582 +} __packed;
9583 +
9584 +#define	ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
9585 +
9586 +#define VLAN_PRI_SHIFT	13		/* Shift to find VLAN user priority */
9587 +#define VLAN_PRI_MASK	7		/* Mask for user priority bits in VLAN */
9588 +
9589 +
9590 +#endif /* _NET_IF_ETHERSUBR_H_ */
9591 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_llc.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_llc.h
9592 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_llc.h	1970-01-01 01:00:00.000000000 +0100
9593 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_llc.h	2008-06-19 17:34:17.000000000 +0200
9594 @@ -0,0 +1,193 @@
9595 +/*-
9596 + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
9597 + * All rights reserved.
9598 + *
9599 + * Redistribution and use in source and binary forms, with or without
9600 + * modification, are permitted provided that the following conditions
9601 + * are met:
9602 + * 1. Redistributions of source code must retain the above copyright
9603 + *    notice, this list of conditions and the following disclaimer,
9604 + *    without modification.
9605 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
9606 + *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
9607 + *    redistribution must be conditioned upon including a substantially
9608 + *    similar Disclaimer requirement for further binary redistribution.
9609 + * 3. Neither the names of the above-listed copyright holders nor the names
9610 + *    of any contributors may be used to endorse or promote products derived
9611 + *    from this software without specific prior written permission.
9612 + *
9613 + * Alternatively, this software may be distributed under the terms of the
9614 + * GNU General Public License ("GPL") version 2 as published by the Free
9615 + * Software Foundation.
9616 + *
9617 + * NO WARRANTY
9618 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9619 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9620 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
9621 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
9622 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
9623 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
9624 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
9625 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
9626 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
9627 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
9628 + * THE POSSIBILITY OF SUCH DAMAGES.
9629 + *
9630 + * $Id: if_llc.h 2028 2007-01-30 03:51:52Z proski $
9631 + */
9632 +
9633 +/*
9634 + * Copyright (c) 1988, 1993
9635 + *	The Regents of the University of California.  All rights reserved.
9636 + *
9637 + * Redistribution and use in source and binary forms, with or without
9638 + * modification, are permitted provided that the following conditions
9639 + * are met:
9640 + * 1. Redistributions of source code must retain the above copyright
9641 + *    notice, this list of conditions and the following disclaimer.
9642 + * 2. Redistributions in binary form must reproduce the above copyright
9643 + *    notice, this list of conditions and the following disclaimer in the
9644 + *    documentation and/or other materials provided with the distribution.
9645 + * 3. All advertising materials mentioning features or use of this software
9646 + *    must display the following acknowledgement:
9647 + *	This product includes software developed by the University of
9648 + *	California, Berkeley and its contributors.
9649 + * 4. Neither the name of the University nor the names of its contributors
9650 + *    may be used to endorse or promote products derived from this software
9651 + *    without specific prior written permission.
9652 + *
9653 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
9654 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9655 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9656 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
9657 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9658 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
9659 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
9660 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9661 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9662 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9663 + * SUCH DAMAGE.
9664 + */
9665 +
9666 +#ifndef _NET_IF_LLC_H_
9667 +#define _NET_IF_LLC_H_
9668 +
9669 +/*
9670 + * IEEE 802.2 Link Level Control headers, for use in conjunction with
9671 + * 802.{3,4,5} media access control methods.
9672 + *
9673 + * Headers here do not use bit fields due to shortcomings in many
9674 + * compilers.
9675 + */
9676 +
9677 +struct llc {
9678 +	u_int8_t llc_dsap;
9679 +	u_int8_t llc_ssap;
9680 +	union {
9681 +	    struct {
9682 +		u_int8_t control;
9683 +		u_int8_t format_id;
9684 +		u_int8_t class;
9685 +		u_int8_t window_x2;
9686 +	    } __packed type_u;
9687 +	    struct {
9688 +		u_int8_t num_snd_x2;
9689 +		u_int8_t num_rcv_x2;
9690 +	    } __packed type_i;
9691 +	    struct {
9692 +		u_int8_t control;
9693 +		u_int8_t num_rcv_x2;
9694 +	    } __packed type_s;
9695 +	    struct {
9696 +	        u_int8_t control;
9697 +		/*
9698 +		 * We cannot put the following fields in a structure because
9699 +		 * the structure rounding might cause padding.
9700 +		 */
9701 +		u_int8_t frmr_rej_pdu0;
9702 +		u_int8_t frmr_rej_pdu1;
9703 +		u_int8_t frmr_control;
9704 +		u_int8_t frmr_control_ext;
9705 +		u_int8_t frmr_cause;
9706 +	    } __packed type_frmr;
9707 +	    struct {
9708 +		u_int8_t control;
9709 +		u_int8_t org_code[3];
9710 +		__be16 ether_type;
9711 +	    } __packed type_snap;
9712 +	    struct {
9713 +		u_int8_t control;
9714 +		u_int8_t control_ext;
9715 +	    } __packed type_raw;
9716 +	} llc_un /* XXX __packed ??? */;
9717 +} __packed;
9718 +
9719 +struct frmrinfo {
9720 +	u_int8_t frmr_rej_pdu0;
9721 +	u_int8_t frmr_rej_pdu1;
9722 +	u_int8_t frmr_control;
9723 +	u_int8_t frmr_control_ext;
9724 +	u_int8_t frmr_cause;
9725 +} __packed;
9726 +
9727 +#define	llc_control		llc_un.type_u.control
9728 +#define	llc_control_ext		llc_un.type_raw.control_ext
9729 +#define	llc_fid			llc_un.type_u.format_id
9730 +#define	llc_class		llc_un.type_u.class
9731 +#define	llc_window		llc_un.type_u.window_x2
9732 +#define	llc_frmrinfo 		llc_un.type_frmr.frmr_rej_pdu0
9733 +#define	llc_frmr_pdu0		llc_un.type_frmr.frmr_rej_pdu0
9734 +#define	llc_frmr_pdu1		llc_un.type_frmr.frmr_rej_pdu1
9735 +#define	llc_frmr_control	llc_un.type_frmr.frmr_control
9736 +#define	llc_frmr_control_ext	llc_un.type_frmr.frmr_control_ext
9737 +#define	llc_frmr_cause		llc_un.type_frmr.frmr_cause
9738 +#define	llc_snap		llc_un.type_snap
9739 +
9740 +/*
9741 + * Don't use sizeof(struct llc_un) for LLC header sizes
9742 + */
9743 +#define LLC_ISFRAMELEN 4
9744 +#define LLC_UFRAMELEN  3
9745 +#define LLC_FRMRLEN    7
9746 +#define LLC_SNAPFRAMELEN 8
9747 +
9748 +/*
9749 + * Unnumbered LLC format commands
9750 + */
9751 +#define LLC_UI		0x3
9752 +#define LLC_UI_P	0x13
9753 +#define LLC_DISC	0x43
9754 +#define	LLC_DISC_P	0x53
9755 +#define LLC_UA		0x63
9756 +#define LLC_UA_P	0x73
9757 +#define LLC_TEST	0xe3
9758 +#define LLC_TEST_P	0xf3
9759 +#define LLC_FRMR	0x87
9760 +#define	LLC_FRMR_P	0x97
9761 +#define LLC_DM		0x0f
9762 +#define	LLC_DM_P	0x1f
9763 +#define LLC_XID		0xaf
9764 +#define LLC_XID_P	0xbf
9765 +#define LLC_SABME	0x6f
9766 +#define LLC_SABME_P	0x7f
9767 +
9768 +/*
9769 + * Supervisory LLC commands
9770 + */
9771 +#define	LLC_RR		0x01
9772 +#define	LLC_RNR		0x05
9773 +#define	LLC_REJ		0x09
9774 +
9775 +/*
9776 + * Info format - dummy only
9777 + */
9778 +#define	LLC_INFO	0x00
9779 +
9780 +/*
9781 + * ISO PDTR 10178 contains among others
9782 + */
9783 +#define LLC_X25_LSAP	0x7e
9784 +#define LLC_SNAP_LSAP	0xaa
9785 +#define LLC_ISO_LSAP	0xfe
9786 +
9787 +#endif /* _NET_IF_LLC_H_ */
9788 diff -Nur kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_media.h kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_media.h
9789 --- kamikaze_7.09.orig/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_media.h	1970-01-01 01:00:00.000000000 +0100
9790 +++ kamikaze_7.09/package/madwifi/kmod-madwifi/usr/include/madwifi/net80211/if_media.h	2008-06-19 17:34:17.000000000 +0200
9791 @@ -0,0 +1,497 @@
9792 +/*	$NetBSD: if_media.h,v 1.3 1997/03/26 01:19:27 thorpej Exp $	*/
9793 +/* $FreeBSD: src/sys/net/if_media.h,v 1.18 2002/07/14 21:58:19 kbyanc Exp $ */
9794 +/*	$Id: if_media.h 2864 2007-11-20 17:18:36Z proski $	*/
9795 +
9796 +/*
9797 + * Copyright (c) 1997
9798 + *	Jonathan Stone and Jason R. Thorpe.  All rights reserved.
9799 + *
9800 + * This software is derived from information provided by Matt Thomas.
9801 + *
9802 + * Redistribution and use in source and binary forms, with or without
9803 + * modification, are permitted provided that the following conditions
9804 + * are met:
9805 + * 1. Redistributions of source code must retain the above copyright
9806 + *    notice, this list of conditions and the following disclaimer.
9807 + * 2. Redistributions in binary form must reproduce the above copyright
9808 + *    notice, this list of conditions and the following disclaimer in the
9809 + *    documentation and/or other materials provided with the distribution.
9810 + * 3. All advertising materials mentioning features or use of this software
9811 + *    must display the following acknowledgement:
9812 + *	This product includes software developed by Jonathan Stone
9813 + *	and Jason R. Thorpe for the NetBSD Project.
9814 + * 4. The names of the authors may not be used to endorse or promote products
9815 + *    derived from this software without specific prior written permission.
9816 + *
9817 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
9818 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9819 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9820 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
9821 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
9822 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
9823 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
9824 + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
9825 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9826 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9827 + * SUCH DAMAGE.
9828 + *
9829 + * $Id: if_media.h 2864 2007-11-20 17:18:36Z proski $
9830 + */
9831 +
9832 +#ifndef _NET_IF_MEDIA_H_
9833 +#define _NET_IF_MEDIA_H_
9834 +
9835 +#include <net80211/ieee80211_linux.h>
9836 +
9837 +/*
9838 + * Prototypes and definitions for BSD/OS-compatible network interface
9839 + * media selection.
9840 + *
9841 + * Where it is safe to do so, this code strays slightly from the BSD/OS
9842 + * design.  Software which uses the API (device drivers, basically)
9843 + * shouldn't notice any difference.
9844 + *
9845 + * Many thanks to Matt Thomas for providing the information necessary
9846 + * to implement this interface.
9847 + */
9848 +
9849 +struct ifmediareq {
9850 +	char ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
9851 +	int ifm_current;			/* current media options */
9852 +	int ifm_mask;			/* don't care mask */
9853 +	int ifm_status;			/* media status */
9854 +	int ifm_active;			/* active options */
9855 +	int ifm_count;			/* # entries in ifm_ulist array */
9856 +	int __user *ifm_ulist;		/* media words */
9857 +};
9858 +#define	SIOCSIFMEDIA	_IOWR('i', 55, struct ifreq)	/* set net media */
9859 +#define	SIOCGIFMEDIA	_IOWR('i', 56, struct ifmediareq) /* get net media */
9860 +
9861 +#ifdef __KERNEL__
9862 +
9863 +#include <sys/queue.h>
9864 +
9865 +/*
9866 + * Driver callbacks for media status and change requests.
9867 + */
9868 +struct net_device;
9869 +typedef	int (*ifm_change_cb_t)(struct net_device *);
9870 +typedef	void (*ifm_stat_cb_t)(struct net_device *, struct ifmediareq *);
9871 +
9872 +/*
9873 + * In-kernel representation of a single supported media type.
9874 + */
9875 +struct ifmedia_entry {
9876 +	LIST_ENTRY(ifmedia_entry) ifm_list;
9877 +	int ifm_media;		/* description of this media attachment */
9878 +	int ifm_data;		/* for driver-specific use */
9879 +	void *ifm_aux;		/* for driver-specific use */
9880 +};
9881 +
9882 +/*
9883 + * One of these goes into a network interface's softc structure.
9884 + * It is used to keep general media state.
9885 + */
9886 +struct ifmedia {
9887 +	int ifm_mask;			/* mask of changes we don't care about */
9888 +	int ifm_media;			/* current user-set media word */
9889 +	struct ifmedia_entry *ifm_cur;	/* currently selected media */
9890 +	ATH_LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
9891 +	ifm_change_cb_t	ifm_change;	/* media change driver callback */
9892 +	ifm_stat_cb_t ifm_status;	/* media status driver callback */
9893 +};
9894 +
9895 +/* Initialize an interface's struct if_media field. */
9896 +void ifmedia_init(struct ifmedia *, int, ifm_change_cb_t, ifm_stat_cb_t);
9897 +
9898 +/* Remove all mediums from a struct ifmedia.  */
9899 +void ifmedia_removeall(struct ifmedia *);
9900 +
9901 +/* Add one supported medium to a struct ifmedia. */
9902 +void ifmedia_add(struct ifmedia *, int, int, void *);
9903 +
9904 +/* Add an array (of ifmedia_entry) media to a struct ifmedia. */
9905 +void ifmedia_list_add(struct ifmedia *, struct ifmedia_entry *, int);
9906 +
9907 +/* Set default media type on initialization. */
9908 +void ifmedia_set(struct ifmedia *, int);
9909 +
9910 +/* Common ioctl function for getting/setting media, called by driver. */
9911 +int ifmedia_ioctl(struct net_device *, struct ifreq *, struct ifmedia *, u_long);
9912 +
9913 +#endif /*_KERNEL */
9914 +
9915 +/*
9916 + * if_media Options word:
9917 + *	Bits	Use
9918 + *	----	-------
9919 + *	0-4	Media variant
9920 + *	5-7	Media type
9921 + *	8-15	Type specific options
9922 + *	16-18	Mode (for multi-mode devices)
9923 + *	19	RFU
9924 + *	20-27	Shared (global) options
9925 + *	28-31	Instance
9926 + */
9927 +
9928 +/*
9929 + * Ethernet
9930 + */
9931 +#define	IFM_ETHER	0x00000020
9932 +#define	IFM_10_T	3		/* 10BaseT - RJ45 */
9933 +#define	IFM_10_2	4		/* 10Base2 - Thinnet */
9934 +#define	IFM_10_5	5		/* 10Base5 - AUI */
9935 +#define	IFM_100_TX	6		/* 100BaseTX - RJ45 */
9936 +#define	IFM_100_FX	7		/* 100BaseFX - Fiber */
9937 +#define	IFM_100_T4	8		/* 100BaseT4 - 4 pair cat 3 */
9938 +#define	IFM_100_VG	9		/* 100VG-AnyLAN */
9939 +#define	IFM_100_T2	10		/* 100BaseT2 */
9940 +#define	IFM_1000_SX	11		/* 1000BaseSX - multi-mode fiber */
9941 +#define	IFM_10_STP	12		/* 10BaseT over shielded TP */
9942 +#define	IFM_10_FL	13		/* 10BaseFL - Fiber */
9943 +#define	IFM_1000_LX	14		/* 1000baseLX - single-mode fiber */
9944 +#define	IFM_1000_CX	15		/* 1000baseCX - 150ohm STP */
9945 +#define	IFM_1000_T	16		/* 1000baseT - 4 pair cat 5 */
9946 +#define	IFM_HPNA_1	17		/* HomePNA 1.0 (1Mb/s) */
9947 +/* note 31 is the max! */
9948 +
9949 +#define	IFM_ETH_MASTER	0x00000100	/* master mode (1000baseT) */
9950 +
9951 +/*
9952 + * Token ring
9953 + */
9954 +#define	IFM_TOKEN	0x00000040
9955 +#define	IFM_TOK_STP4	3		/* Shielded twisted pair 4m - DB9 */
9956 +#define	IFM_TOK_STP16	4		/* Shielded twisted pair 16m - DB9 */
9957 +#define	IFM_TOK_UTP4	5		/* Unshielded twisted pair 4m - RJ45 */
9958 +#define	IFM_TOK_UTP16	6		/* Unshielded twisted pair 16m - RJ45 */
9959 +#define	IFM_TOK_STP100  7		/* Shielded twisted pair 100m - DB9 */
9960 +#define	IFM_TOK_UTP100  8		/* Unshielded twisted pair 100m - RJ45 */
9961 +#define	IFM_TOK_ETR	0x00000200	/* Early token release */
9962 +#define	IFM_TOK_SRCRT	0x00000400	/* Enable source routing features */
9963 +#define	IFM_TOK_ALLR	0x00000800	/* All routes / Single route bcast */
9964 +#define	IFM_TOK_DTR	0x00002000	/* Dedicated token ring */
9965 +#define	IFM_TOK_CLASSIC	0x00004000	/* Classic token ring */
9966 +#define	IFM_TOK_AUTO	0x00008000	/* Automatic Dedicate/Classic token ring */
9967 +
9968 +/*
9969 + * FDDI
9970 + */
9971 +#define	IFM_FDDI	0x00000060
9972 +#define	IFM_FDDI_SMF	3		/* Single-mode fiber */
9973 +#define	IFM_FDDI_MMF	4		/* Multi-mode fiber */
9974 +#define	IFM_FDDI_UTP	5		/* CDDI / UTP */
9975 +#define	IFM_FDDI_DA	0x00000100	/* Dual attach / single attach */
9976 +
9977 +/*
9978 + * IEEE 802.11 Wireless
9979 + */
9980 +#define	IFM_IEEE80211	0x00000080
9981 +/* NB: 0,1,2 are auto, manual, none defined below */
9982 +#define	IFM_IEEE80211_FH1	3	/* Frequency Hopping 1Mbps */
9983 +#define	IFM_IEEE80211_FH2	4	/* Frequency Hopping 2Mbps */
9984 +#define	IFM_IEEE80211_DS1	5	/* Direct Sequence 1Mbps */
9985 +#define	IFM_IEEE80211_DS2	6	/* Direct Sequence 2Mbps */
9986 +#define	IFM_IEEE80211_DS5	7	/* Direct Sequence 5.5Mbps */
9987 +#define	IFM_IEEE80211_DS11	8	/* Direct Sequence 11Mbps */
9988 +#define	IFM_IEEE80211_DS22	9	/* Direct Sequence 22Mbps */
9989 +#define IFM_IEEE80211_OFDM1_50  10      /* OFDM 1.5Mbps */
9990 +#define IFM_IEEE80211_OFDM2_25  11      /* OFDM 2.25Mbps */
9991 +#define IFM_IEEE80211_OFDM3     12      /* OFDM 3Mbps */
9992 +#define IFM_IEEE80211_OFDM4_50  13      /* OFDM 4.5Mbps */
9993 +#define IFM_IEEE80211_OFDM6     14      /* OFDM 6Mbps */
9994 +#define IFM_IEEE80211_OFDM9     15      /* OFDM 9Mbps */
9995 +#define IFM_IEEE80211_OFDM12    16      /* OFDM 12Mbps */
9996 +#define IFM_IEEE80211_OFDM13_5  17      /* OFDM 13.5Mpbs */
9997 +#define IFM_IEEE80211_OFDM18    18      /* OFDM 18Mbps */
9998 +#define IFM_IEEE80211_OFDM24    19      /* OFDM 24Mbps */
9999 +#define IFM_IEEE80211_OFDM27    20      /* OFDM 27Mbps */
10000 +#define IFM_IEEE80211_OFDM36    21      /* OFDM 36Mbps */
10001 +#define IFM_IEEE80211_OFDM48    22      /* OFDM 48Mbps */
10002 +#define IFM_IEEE80211_OFDM54    23      /* OFDM 54Mbps */
10003 +#define IFM_IEEE80211_OFDM72    24      /* OFDM 72Mbps */
10004 +
10005 +#define	IFM_IEEE80211_ADHOC	0x00000100	/* Operate in Adhoc mode */
10006 +#define	IFM_IEEE80211_HOSTAP	0x00000200	/* Operate in Host AP mode */
10007 +#define	IFM_IEEE80211_IBSS	0x00000400	/* Operate in IBSS mode */
10008 +#define	IFM_IEEE80211_WDS	0x00000800	/* Operate in WDS mode */
10009 +#define	IFM_IEEE80211_TURBO	0x00001000	/* Operate in turbo mode */
10010 +#define	IFM_IEEE80211_MONITOR	0x00002000	/* Operate in monitor mode */
10011 +
10012 +/* operating mode for multi-mode devices */
10013 +#define	IFM_IEEE80211_11A	0x00010000	/* 5Ghz, OFDM mode */
10014 +#define	IFM_IEEE80211_11B	0x00020000	/* Direct Sequence mode */
10015 +#define	IFM_IEEE80211_11G	0x00030000	/* 2Ghz, CCK mode */
10016 +#define	IFM_IEEE80211_FH	0x00040000	/* 2Ghz, GFSK mode */
10017 +
10018 +/*
10019 + * Shared media sub-types
10020 + */
10021 +#define	IFM_AUTO	0		/* Autoselect best media */
10022 +#define	IFM_MANUAL	1		/* Jumper/dipswitch selects media */
10023 +#define	IFM_NONE	2		/* Deselect all media */
10024 +
10025 +/*
10026 + * Shared options
10027 + */
10028 +#define	IFM_FDX		0x00100000	/* Force full duplex */
10029 +#define	IFM_HDX		0x00200000	/* Force half duplex */
10030 +#define	IFM_FLAG0	0x01000000	/* Driver defined flag */
10031 +#define	IFM_FLAG1	0x02000000	/* Driver defined flag */
10032 +#define	IFM_FLAG2	0x04000000	/* Driver defined flag */
10033 +#define	IFM_LOOP	0x08000000	/* Put hardware in loopback */
10034 +
10035 +/*
10036 + * Masks
10037 + */
10038 +#define	IFM_NMASK	0x000000e0	/* Network type */
10039 +#define	IFM_TMASK	0x0000001f	/* Media sub-type */
10040 +#define	IFM_IMASK	0xf0000000	/* Instance */
10041 +#define	IFM_ISHIFT	28		/* Instance shift */
10042 +#define	IFM_OMASK	0x0000ff00	/* Type specific options */
10043 +#define	IFM_MMASK	0x00070000	/* Mode */
10044 +#define	IFM_MSHIFT	16		/* Mode shift */
10045 +#define	IFM_GMASK	0x0ff00000	/* Global options */
10046 +
10047 +/*
10048 + * Status bits
10049 + */
10050 +#define	IFM_AVALID	0x00000001	/* Active bit valid */
10051 +#define	IFM_ACTIVE	0x00000002	/* Interface attached to working net */
10052 +
10053 +/*
10054 + * Macros to extract various bits of information from the media word.
10055 + */
10056 +#define	IFM_TYPE(x)		((x) & IFM_NMASK)
10057 +#define	IFM_SUBTYPE(x)		((x) & IFM_TMASK)
10058 +#define	IFM_TYPE_OPTIONS(x)	((x) & IFM_OMASK)
10059 +#define	IFM_INST(x)		(((x) & IFM_IMASK) >> IFM_ISHIFT)
10060 +#define	IFM_OPTIONS(x)		((x) & (IFM_OMASK|IFM_GMASK))
10061 +#define	IFM_MODE(x)		((x) & IFM_MMASK)
10062 +
10063 +#define	IFM_INST_MAX		IFM_INST(IFM_IMASK)
10064 +
10065 +/*
10066 + * Macro to create a media word.
10067 + */
10068 +#define	IFM_MAKEWORD(type, subtype, options, instance)			\
10069 +	((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
10070 +#define	IFM_MAKEMODE(mode) \
10071 +	(((mode) << IFM_MSHIFT) & IFM_MMASK)
10072 +
10073 +/*
10074 + * NetBSD extension not defined in the BSDI API.  This is used in various
10075 + * places to get the canonical description for a given type/subtype.
10076 + *
10077 + * NOTE: all but the top-level type descriptions must contain NO whitespace!
10078 + * Otherwise, parsing these in ifconfig(8) would be a nightmare.
10079 + */
10080 +struct ifmedia_description {
10081 +	int	ifmt_word;		/* word value; may be masked */
10082 +	const char *ifmt_string;	/* description */
10083 +};
10084 +
10085 +#define	IFM_TYPE_DESCRIPTIONS {						\
10086 +	{ IFM_ETHER,		"Ethernet" },				\
10087 +	{ IFM_TOKEN,		"Token ring" },				\
10088 +	{ IFM_FDDI,		"FDDI" },				\
10089 +	{ IFM_IEEE80211,	"IEEE 802.11 Wireless Ethernet" },	\
10090 +	{ 0, NULL },							\
10091 +}
10092 +
10093 +#define	IFM_SUBTYPE_ETHERNET_DESCRIPTIONS {				\
10094 +	{ IFM_10_T,	"10baseT/UTP" },				\
10095 +	{ IFM_10_2,	"10base2/BNC" },				\
10096 +	{ IFM_10_5,	"10base5/AUI" },				\
10097 +	{ IFM_100_TX,	"100baseTX" },					\
10098 +	{ IFM_100_FX,	"100baseFX" },					\
10099 +	{ IFM_100_T4,	"100baseT4" },					\
10100 +	{ IFM_100_VG,	"100baseVG" },					\
10101 +	{ IFM_100_T2,	"100baseT2" },					\
10102 +	{ IFM_10_STP,	"10baseSTP" },					\
10103 +	{ IFM_10_FL,	"10baseFL" },					\
10104 +	{ IFM_1000_SX,	"1000baseSX" },					\
10105 +	{ IFM_1000_LX,	"1000baseLX" },					\
10106 +	{ IFM_1000_CX,	"1000baseCX" },					\
10107 +	{ IFM_1000_T,	"1000baseTX" },					\
10108 +	{ IFM_1000_T,	"1000baseT" },					\
10109 +	{ IFM_HPNA_1,	"homePNA" },					\
10110 +	{ 0, NULL },							\
10111 +}
10112 +
10113 +#define	IFM_SUBTYPE_ETHERNET_ALIASES {					\
10114 +	{ IFM_10_T,	"UTP" },					\
10115 +	{ IFM_10_T,	"10UTP" },					\
10116 +	{ IFM_10_2,	"BNC" },					\
10117 +	{ IFM_10_2,	"10BNC" },					\
10118 +	{ IFM_10_5,	"AUI" },					\
10119 +	{ IFM_10_5,	"10AUI" },					\
10120 +	{ IFM_100_TX,	"100TX" },					\
10121 +	{ IFM_100_T4,	"100T4" },					\
10122 +	{ IFM_100_VG,	"100VG" },					\
10123 +	{ IFM_100_T2,	"100T2" },					\
10124 +	{ IFM_10_STP,	"10STP" },					\
10125 +	{ IFM_10_FL,	"10FL" },					\
10126 +	{ IFM_1000_SX,	"1000SX" },					\
10127 +	{ IFM_1000_LX,	"1000LX" },					\
10128 +	{ IFM_1000_CX,	"1000CX" },					\
10129 +	{ IFM_1000_T,	"1000TX" },					\
10130 +	{ IFM_1000_T,	"1000T" },					\
10131 +	{ 0, NULL },							\
10132 +}
10133 +
10134 +#define	IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS {			\
10135 +	{ 0, NULL },							\
10136 +}
10137 +
10138 +#define	IFM_SUBTYPE_TOKENRING_DESCRIPTIONS {				\
10139 +	{ IFM_TOK_STP4,	"DB9/4Mbit" },					\
10140 +	{ IFM_TOK_STP16, "DB9/16Mbit" },				\
10141 +	{ IFM_TOK_UTP4,	"UTP/4Mbit" },					\
10142 +	{ IFM_TOK_UTP16, "UTP/16Mbit" },				\
10143 +	{ IFM_TOK_STP100, "STP/100Mbit" },				\
10144 +	{ IFM_TOK_UTP100, "UTP/100Mbit" },				\
10145 +	{ 0, NULL },							\
10146 +}
10147 +
10148 +#define	IFM_SUBTYPE_TOKENRING_ALIASES {					\
10149 +	{ IFM_TOK_STP4,	"4STP" },					\
10150 +	{ IFM_TOK_STP16, "16STP" },					\
10151 +	{ IFM_TOK_UTP4,	"4UTP" },					\
10152 +	{ IFM_TOK_UTP16, "16UTP" },					\
10153 +	{ IFM_TOK_STP100, "100STP" },					\
10154 +	{ IFM_TOK_UTP100, "100UTP" },					\
10155 +	{ 0, NULL },							\
10156 +}
10157 +
10158 +#define	IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS {			\
10159 +	{ IFM_TOK_ETR,	"EarlyTokenRelease" },				\
10160 +	{ IFM_TOK_SRCRT, "SourceRouting" },				\
10161 +	{ IFM_TOK_ALLR,	 "AllRoutes" },					\
10162 +	{ IFM_TOK_DTR,	 "Dedicated" },					\
10163 +	{ IFM_TOK_CLASSIC, "Classic" },					\
10164 +	{ IFM_TOK_AUTO,	" " },						\
10165 +	{ 0, NULL },							\
10166 +}
10167 +
10168 +#define	IFM_SUBTYPE_FDDI_DESCRIPTIONS {					\
10169 +	{ IFM_FDDI_SMF, "Single-mode" },				\
10170 +	{ IFM_FDDI_MMF, "Multi-mode" },					\
10171 +	{ IFM_FDDI_UTP, "UTP" },					\
10172 +	{ 0, NULL },							\
10173 +}
10174 +
10175 +#define	IFM_SUBTYPE_FDDI_ALIASES {					\
10176 +	{ IFM_FDDI_SMF,	"SMF" },					\
10177 +	{ IFM_FDDI_MMF,	"MMF" },					\
10178 +	{ IFM_FDDI_UTP,	"CDDI" },					\
10179 +	{ 0, NULL },							\
10180 +}
10181 +
10182 +#define	IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS {				\
10183 +	{ IFM_FDDI_DA, "Dual-attach" },					\
10184 +	{ 0, NULL },							\
10185 +}
10186 +
10187 +#define	IFM_SUBTYPE_IEEE80211_DESCRIPTIONS {				\
10188 +	{ IFM_IEEE80211_FH1, "FH/1Mbps" },				\
10189 +	{ IFM_IEEE80211_FH2, "FH/2Mbps" },				\
10190 +	{ IFM_IEEE80211_DS1, "DS/1Mbps" },				\
10191 +	{ IFM_IEEE80211_DS2, "DS/2Mbps" },				\
10192 +	{ IFM_IEEE80211_DS5, "DS/5.5Mbps" },				\
10193 +	{ IFM_IEEE80211_DS11, "DS/11Mbps" },				\
10194 +	{ IFM_IEEE80211_DS22, "DS/22Mbps" },				\
10195 +	{ IFM_IEEE80211_OFDM1_50, "OFDM/1.50Mbps" },			\
10196 +	{ IFM_IEEE80211_OFDM2_25, "OFDM/2.25Mbps" },			\
10197 +	{ IFM_IEEE80211_OFDM3, "OFDM/3Mbps" },				\
10198 +	{ IFM_IEEE80211_OFDM4_50, "OFDM/4.5Mbps" },			\
10199 +	{ IFM_IEEE80211_OFDM6, "OFDM/6Mbps" },				\
10200 +	{ IFM_IEEE80211_OFDM9, "OFDM/9Mbps" },				\
10201 +	{ IFM_IEEE80211_OFDM12, "OFDM/12Mbps" },			\
10202 +	{ IFM_IEEE80211_OFDM13_5, "OFDM/13.5Mbps" },			\
10203 +	{ IFM_IEEE80211_OFDM18, "OFDM/18Mbps" },			\
10204 +	{ IFM_IEEE80211_OFDM24, "OFDM/24Mbps" },			\
10205 +	{ IFM_IEEE80211_OFDM27, "OFDM/27Mbps" },			\
10206 +	{ IFM_IEEE80211_OFDM36, "OFDM/36Mbps" },			\
10207 +	{ IFM_IEEE80211_OFDM48, "OFDM/48Mbps" },			\
10208 +	{ IFM_IEEE80211_OFDM54, "OFDM/54Mbps" },			\
10209 +	{ IFM_IEEE80211_OFDM72, "OFDM/72Mbps" },			\
10210 +	{ 0, NULL },							\
10211 +}
10212 +
10213 +#define	IFM_SUBTYPE_IEEE80211_ALIASES {					\
10214 +	{ IFM_IEEE80211_FH1, "FH1" },					\
10215 +	{ IFM_IEEE80211_FH2, "FH2" },					\
10216 +	{ IFM_IEEE80211_FH1, "FrequencyHopping/1Mbps" },		\
10217 +	{ IFM_IEEE80211_FH2, "FrequencyHopping/2Mbps" },		\
10218 +	{ IFM_IEEE80211_DS1, "DS1" },					\
10219 +	{ IFM_IEEE80211_DS2, "DS2" },					\
10220 +	{ IFM_IEEE80211_DS5, "DS5.5" },					\
10221 +	{ IFM_IEEE80211_DS11, "DS11" },					\
10222 +	{ IFM_IEEE80211_DS22, "DS22" },					\
10223 +	{ IFM_IEEE80211_DS1, "DirectSequence/1Mbps" },			\
10224 +	{ IFM_IEEE80211_DS2, "DirectSequence/2Mbps" },			\
10225 +	{ IFM_IEEE80211_DS5, "DirectSequence/5.5Mbps" },		\
10226 +	{ IFM_IEEE80211_DS11, "DirectSequence/11Mbps" },		\
10227 +	{ IFM_IEEE80211_DS22, "DirectSequence/22Mbps" },		\
10228 +	{ IFM_IEEE80211_OFDM1_50, "OFDM1.50Mpbs" },			\
10229 +	{ IFM_IEEE80211_OFDM2_25, "OFDM2.25Mbps" },			\
10230 +	{ IFM_IEEE80211_OFDM3, "OFDM3Mbps" },				\
10231 +	{ IFM_IEEE80211_OFDM4_50, "OFDM4.5Mbps" },			\
10232 +	{ IFM_IEEE80211_OFDM6, "OFDM6" },				\
10233 +	{ IFM_IEEE80211_OFDM9, "OFDM9" },				\
10234 +	{ IFM_IEEE80211_OFDM12, "OFDM12" },				\
10235 +	{ IFM_IEEE80211_OFDM13_5, "OFDM13.5Mbps" },			\
10236 +	{ IFM_IEEE80211_OFDM18, "OFDM18" },				\
10237 +	{ IFM_IEEE80211_OFDM24, "OFDM24" },				\
10238 +	{ IFM_IEEE80211_OFDM27, "OFDM27" },				\
10239 +	{ IFM_IEEE80211_OFDM36, "OFDM36" },				\
10240 +	{ IFM_IEEE80211_OFDM48, "OFDM48" },				\
10241 +	{ IFM_IEEE80211_OFDM54, "OFDM54" },				\
10242 +	{ IFM_IEEE80211_OFDM72, "OFDM72" },				\
10243 +	{ IFM_IEEE80211_DS1, "CCK1" },					\
10244 +	{ IFM_IEEE80211_DS2, "CCK2" },					\
10245 +	{ IFM_IEEE80211_DS5, "CCK5.5" },				\
10246 +	{ IFM_IEEE80211_DS11, "CCK11" },				\
10247 +	{ 0, NULL },							\
10248 +}
10249 +
10250 +#define	IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS {			\
10251 +	{ IFM_IEEE80211_ADHOC, "adhoc" },				\
10252 +	{ IFM_IEEE80211_HOSTAP, "hostap" },				\
10253 +	{ IFM_IEEE80211_IBSS, "ibss" },					\
10254 +	{ IFM_IEEE80211_WDS, "wds" },					\
10255 +	{ IFM_IEEE80211_TURBO, "turbo" },				\
10256 +	{ 0, NULL },							\
10257 +}
10258 +
10259 +#define	IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS {			\
10260 +	{ IFM_IEEE80211_11A, "11a" },					\
10261 +	{ IFM_IEEE80211_11B, "11b" },					\
10262 +	{ IFM_IEEE80211_11G, "11g" },					\
10263 +	{ 0, NULL },							\
10264 +}
10265 +
10266 +#define	IFM_SUBTYPE_SHARED_DESCRIPTIONS {				\
10267 +	{ IFM_AUTO,	"autoselect" },					\
10268 +	{ IFM_MANUAL,	"manual" },					\
10269 +	{ IFM_NONE,	"none" },					\
10270 +	{ 0, NULL },							\
10271 +}
10272 +
10273 +#define	IFM_SUBTYPE_SHARED_ALIASES {					\
10274 +	{ IFM_AUTO,	"auto" },					\
10275 +	{ 0, NULL },							\
10276 +}
10277 +
10278 +#define	IFM_SHARED_OPTION_DESCRIPTIONS {				\
10279 +	{ IFM_FDX,	"full-duplex" },				\
10280 +	{ IFM_HDX,	"half-duplex" },				\
10281 +	{ IFM_FLAG0,	"flag0" },					\
10282 +	{ IFM_FLAG1,	"flag1" },					\
10283 +	{ IFM_FLAG2,	"flag2" },					\
10284 +	{ IFM_LOOP,	"hw-loopback" },				\
10285 +	{ 0, NULL },							\
10286 +}
10287 +
10288 +#endif	/* _NET_IF_MEDIA_H_ */
10289 diff -Nur kamikaze_7.09.orig/package/madwifi/Makefile kamikaze_7.09/package/madwifi/Makefile
10290 --- kamikaze_7.09.orig/package/madwifi/Makefile	2007-09-20 10:54:59.000000000 +0200
10291 +++ kamikaze_7.09/package/madwifi/Makefile	2008-06-19 17:34:17.000000000 +0200
10292 @@ -1,27 +1,42 @@
10293  # 
10294 -# Copyright (C) 2006 OpenWrt.org
10295 +# Copyright (C) 2006-2008 OpenWrt.org
10296  #
10297  # This is free software, licensed under the GNU General Public License v2.
10298  # See /LICENSE for more information.
10299  #
10300 -# $Id: Makefile 8682 2007-09-07 20:57:08Z nbd $
10301 +# $Id: Makefile 11352 2008-06-04 13:51:17Z kaloz $
10302  
10303  include $(TOPDIR)/rules.mk
10304  include $(INCLUDE_DIR)/kernel.mk
10305  
10306  PKG_NAME:=madwifi
10307 -PKG_VERSION:=r2568-20070710
10308 -PKG_BRANCH:=madwifi-ng
10309 -PKG_RELEASE:=2
10310 -
10311 -PKG_SOURCE:=$(PKG_BRANCH)-$(PKG_VERSION).tar.gz
10312 -PKG_SOURCE_URL:=http://snapshots.madwifi.org/$(PKG_BRANCH)
10313 -PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_BRANCH)-$(PKG_VERSION)
10314 -PKG_MD5SUM:=fe5d41acd085d2c46934be3f8839e694
10315 +PKG_REV:=3314
10316 +PKG_VERSION:=r$(PKG_REV)
10317 +# PKG_BRANCH:=madwifi-dfs
10318 +PKG_RELEASE:=1
10319 +
10320 +PKG_SOURCE_PROTO:=svn
10321 +PKG_SOURCE_VERSION:=$(PKG_REV)
10322 +PKG_SOURCE_SUBDIR:=$(if $(PKG_BRANCH),$(PKG_BRANCH),madwifi-trunk)-$(PKG_VERSION)
10323 +PKG_SOURCE_URL:=http://svn.madwifi.org/madwifi/$(if $(PKG_BRANCH),branches/$(PKG_BRANCH),trunk)
10324 +PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz
10325 +
10326 +PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(if $(PKG_BRANCH),$(PKG_BRANCH),madwifi-trunk)-$(PKG_VERSION)
10327  
10328  include $(INCLUDE_DIR)/package.mk
10329  
10330 -RATE_CONTROL:=minstrel
10331 +ifneq ($(CONFIG_TARGET_atheros),)
10332 +  BUS:=AHB
10333 +else
10334 +  ifneq ($(CONFIG_PCI_SUPPORT),)
10335 +    BUS:=PCI
10336 +  endif
10337 +endif
10338 +
10339 +# XXX: remove this check later when we have PCI support properly detected on all targets
10340 +ifneq ($(CONFIG_TARGET_ar7)$(CONFIG_TARGET_uml),)
10341 +  BUS:=
10342 +endif
10343  
10344  ifeq ($(ARCH),mips)
10345    HAL_TARGET:=mips-be-elf
10346 @@ -32,30 +47,58 @@
10347  ifeq ($(ARCH),i386)
10348    HAL_TARGET:=i386-elf
10349  endif
10350 -ifeq ($(ARCH),armeb)
10351 +ifeq ($(ARCH),i686)
10352 +  HAL_TARGET:=i386-elf
10353 +endif
10354 +ifeq ($(BOARD),ixp4xx)
10355    HAL_TARGET:=xscale-be-elf
10356  endif
10357 -ifeq ($(ARCH),arm)
10358 +ifeq ($(BOARD),iop32x)
10359 +  HAL_TARGET:=xscale-le-elf
10360 +endif
10361 +ifeq ($(BOARD),orion)
10362    HAL_TARGET:=xscale-le-elf
10363  endif
10364  ifeq ($(ARCH),powerpc)
10365    HAL_TARGET:=powerpc-be-elf
10366  endif
10367 +ifeq ($(BOARD),storm)
10368 +  HAL_TARGET:=armv4-le-elf
10369 +endif
10370 +ifneq ($(CONFIG_TARGET_atheros),)
10371 +  HAL_TARGET:=wisoc
10372 +endif
10373  
10374 -BUS:=PCI
10375 -ifneq ($(CONFIG_LINUX_2_6_ATHEROS),)
10376 -  BUS:=AHB
10377 -  HAL_TARGET:=ap51
10378 +RATE_CONTROL:=minstrel
10379 +
10380 +ifdef CONFIG_MADWIFI_RCA_MINSTREL
10381 +  RATE_CONTROL:=minstrel
10382  endif
10383  
10384 -BUS_MODULES:=
10385 -ifeq ($(findstring AHB,$(BUS)),AHB)
10386 -  BUS_MODULES+=$(PKG_BUILD_DIR)/ath/ath_ahb.$(LINUX_KMOD_SUFFIX)
10387 +ifdef CONFIG_MADWIFI_RCA_ONOE
10388 +  RATE_CONTROL:=onoe
10389  endif
10390 -ifeq ($(findstring PCI,$(BUS)),PCI)
10391 -  BUS_MODULES+=$(PKG_BUILD_DIR)/ath/ath_pci.$(LINUX_KMOD_SUFFIX)
10392 +
10393 +ifdef CONFIG_MADWIFI_RCA_AMRR
10394 +  RATE_CONTROL:=amrr
10395 +endif
10396 +
10397 +ifdef CONFIG_MADWIFI_RCA_SAMPLERATE
10398 +  RATE_CONTROL:=sample
10399  endif
10400  
10401 +MADWIFI_FILES:= \
10402 +	$(PKG_BUILD_DIR)/net80211/wlan.$(LINUX_KMOD_SUFFIX) \
10403 +	$(PKG_BUILD_DIR)/net80211/wlan_scan_ap.$(LINUX_KMOD_SUFFIX) \
10404 +	$(PKG_BUILD_DIR)/net80211/wlan_scan_sta.$(LINUX_KMOD_SUFFIX) \
10405 +	$(PKG_BUILD_DIR)/ath_hal/ath_hal.$(LINUX_KMOD_SUFFIX) \
10406 +	$(PKG_BUILD_DIR)/ath_rate/$(RATE_CONTROL)/ath_rate_$(RATE_CONTROL).$(LINUX_KMOD_SUFFIX) \
10407 +	$(PKG_BUILD_DIR)/net80211/wlan_acl.$(LINUX_KMOD_SUFFIX) \
10408 +	$(PKG_BUILD_DIR)/net80211/wlan_ccmp.$(LINUX_KMOD_SUFFIX) \
10409 +	$(PKG_BUILD_DIR)/net80211/wlan_tkip.$(LINUX_KMOD_SUFFIX) \
10410 +	$(PKG_BUILD_DIR)/net80211/wlan_wep.$(LINUX_KMOD_SUFFIX) \
10411 +	$(PKG_BUILD_DIR)/net80211/wlan_xauth.$(LINUX_KMOD_SUFFIX) \
10412 +
10413  MADWIFI_AUTOLOAD:= \
10414  	wlan \
10415  	wlan_scan_ap \
10416 @@ -66,26 +109,29 @@
10417  	wlan_ccmp \
10418  	wlan_tkip \
10419  	wlan_wep \
10420 -	wlan_xauth
10421 +	wlan_xauth \
10422  
10423  ifeq ($(findstring AHB,$(BUS)),AHB)
10424 -	MADWIFI_AUTOLOAD += ath_ahb
10425 +  MADWIFI_FILES+= $(PKG_BUILD_DIR)/ath/ath_ahb.$(LINUX_KMOD_SUFFIX)
10426 +  MADWIFI_AUTOLOAD+= ath_ahb/countrycode=40/outdoor=1/tpc=1
10427  endif
10428  ifeq ($(findstring PCI,$(BUS)),PCI)
10429 -	MADWIFI_AUTOLOAD += ath_pci
10430 +  MADWIFI_FILES+= $(PKG_BUILD_DIR)/ath/ath_pci.$(LINUX_KMOD_SUFFIX)
10431 +  MADWIFI_AUTOLOAD+= ath_pci/countrycode=40/outdoor=1/tpc=1
10432 +endif
10433 +
10434 +MADWIFI_APPLETS:=80211stats,athchans,athctrl,athkey,athstats,wlanconfig
10435 +ifdef CONFIG_MADWIFI_DEBUG
10436 +  MADWIFI_APPLETS:=$(strip $(MADWIFI_APPLETS)),athdebug,80211debug
10437  endif
10438  
10439 +
10440  define KernelPackage/madwifi
10441    SUBMENU:=Wireless Drivers
10442    TITLE:=Driver for Atheros wireless chipsets
10443 -  DEPENDS:=+wireless-tools @!LINUX_2_6_AVR32
10444    URL:=http://madwifi.org/
10445 -  VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(BOARD)-$(PKG_RELEASE)
10446 -  FILES:= \
10447 -		$(PKG_BUILD_DIR)/ath_hal/ath_hal.$(LINUX_KMOD_SUFFIX) \
10448 -		$(BUS_MODULES) \
10449 -		$(PKG_BUILD_DIR)/ath_rate/$(RATE_CONTROL)/ath_rate_$(RATE_CONTROL).$(LINUX_KMOD_SUFFIX) \
10450 -		$(PKG_BUILD_DIR)/net80211/wlan*.$(LINUX_KMOD_SUFFIX)
10451 +  DEPENDS:=+wireless-tools @PCI_SUPPORT||TARGET_atheros @!TARGET_ar7 @!TARGET_avr32 @!TARGET_etrax @!TARGET_uml
10452 +  FILES:=$(MADWIFI_FILES)
10453    AUTOLOAD:=$(call AutoLoad,50,$(MADWIFI_AUTOLOAD))
10454  endef
10455  
10456 @@ -93,28 +139,57 @@
10457   This package contains a driver for Atheros 802.11a/b/g chipsets.
10458  endef
10459  
10460 -MADWIFI_MAKEOPTS= -C $(PKG_BUILD_DIR) \
10461 -		PATH="$(TARGET_PATH)" \
10462 -		ARCH="$(LINUX_KARCH)" \
10463 -		CROSS_COMPILE="$(TARGET_CROSS)" \
10464 -		TARGET="$(HAL_TARGET)" \
10465 -		TOOLPREFIX="$(KERNEL_CROSS)" \
10466 -		TOOLPATH="$(KERNEL_CROSS)" \
10467 -		KERNELPATH="$(LINUX_DIR)" \
10468 -		LDOPTS="--no-warn-mismatch " \
10469 -		ATH_RATE="ath_rate/$(RATE_CONTROL)" \
10470 -		WARNINGS="" \
10471 -		DOMULTI=1
10472 +define KernelPackage/madwifi/config
10473 +	source "$(SOURCE)/Config.in"
10474 +endef
10475 +
10476 +MAKE_ARGS:= \
10477 +	PATH="$(TARGET_PATH)" \
10478 +	ARCH="$(LINUX_KARCH)" \
10479 +	CROSS_COMPILE="$(TARGET_CROSS)" \
10480 +	TARGET="$(HAL_TARGET)" \
10481 +	TOOLPREFIX="$(KERNEL_CROSS)" \
10482 +	TOOLPATH="$(KERNEL_CROSS)" \
10483 +	KERNELPATH="$(LINUX_DIR)" \
10484 +	LDOPTS="--no-warn-mismatch " \
10485 +	ATH_RATE="ath_rate/$(RATE_CONTROL)" \
10486 +	WARNINGS="-Wno-unused" \
10487 +	$(if $(CONFIG_MADWIFI_DEBUG),,DEBUG="") \
10488 +	DO_MULTI=1
10489 +
10490 +MAKE_VARS:= \
10491 +	COPTS="-DCONFIG_ATHEROS_RATE_DEFAULT='\"$(RATE_CONTROL)\"' -DATH_REVERSE_ENGINEERING=1" \
10492 +
10493 +HALFILE:=$(lastword $(sort $(wildcard ./ath_hal-*.tgz)))
10494 +ifneq ($(HALFILE),)
10495 +  define Build/Prepare
10496 +	$(call Build/Prepare/Default)
10497 +	rm -rf $(PKG_BUILD_DIR)/tmp
10498 +	mkdir -p $(PKG_BUILD_DIR)/tmp
10499 +	tar xvzf $(HALFILE) -C $(PKG_BUILD_DIR)/tmp
10500 +	$(CP) $(PKG_BUILD_DIR)/tmp/ath_hal*/* $(PKG_BUILD_DIR)/hal/
10501 +	rm -rf $(PKG_BUILD_DIR)/tmp
10502 +	# patch cflags
10503 +	$(SED) 's, -E[LB],,' \
10504 +		-e 's, -mips2,,' \
10505 +		-e 's, -mapcs-32,,' \
10506 +		$(PKG_BUILD_DIR)/hal/public/*.inc
10507 +	$(SED) 's,march=armv4,march=armv5te,' \
10508 +		$(PKG_BUILD_DIR)/hal/public/xscale*.inc
10509 +  endef
10510 +endif
10511  
10512  ifeq ($(findstring AHB,$(BUS)),AHB)
10513    define Build/Compile/ahb
10514 -	COPTS="-DCONFIG_ATHEROS_RATE_DEFAULT='\"$(RATE_CONTROL)\"'" $(MAKE) $(MADWIFI_MAKEOPTS) BUS="AHB" modules
10515 +	$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_ARGS) BUS="AHB" modules
10516 +	$(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_ARGS) CFLAGS="$(TARGET_CFLAGS)" tools
10517    endef
10518  endif
10519  
10520  ifeq ($(findstring PCI,$(BUS)),PCI)
10521    define Build/Compile/pci
10522 -	COPTS="-DCONFIG_ATHEROS_RATE_DEFAULT='\"$(RATE_CONTROL)\"'" $(MAKE) $(MADWIFI_MAKEOPTS) BUS="PCI" modules
10523 +	$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_ARGS) BUS="PCI" modules
10524 +	$(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_ARGS) CFLAGS="$(TARGET_CFLAGS)" tools
10525    endef
10526  endif
10527  
10528 @@ -125,27 +200,20 @@
10529  define Build/Compile
10530  	$(call Build/Compile/ahb)
10531  	$(call Build/Compile/pci)
10532 -	$(MAKE) $(MADWIFI_MAKEOPTS) \
10533 -		CFLAGS="$(TARGET_CFLAGS)" \
10534 -		tools
10535  endef
10536  
10537  define Build/InstallDev
10538 -	mkdir -p $(STAGING_DIR)/usr/include/madwifi
10539 -	$(CP) $(PKG_BUILD_DIR)/include $(STAGING_DIR)/usr/include/madwifi/
10540 -	mkdir -p $(STAGING_DIR)/usr/include/madwifi/net80211
10541 -	$(CP) $(PKG_BUILD_DIR)/net80211/*.h $(STAGING_DIR)/usr/include/madwifi/net80211/
10542 -endef
10543 -
10544 -define Build/UninstallDev
10545 -	rm -rf	$(STAGING_DIR)/usr/include/madwifi
10546 +	mkdir -p $(1)/usr/include/madwifi
10547 +	$(CP) $(PKG_BUILD_DIR)/include $(1)/usr/include/madwifi/
10548 +	mkdir -p $(1)/usr/include/madwifi/net80211
10549 +	$(CP) $(PKG_BUILD_DIR)/net80211/*.h $(1)/usr/include/madwifi/net80211/
10550  endef
10551  
10552  define KernelPackage/madwifi/install
10553  	$(INSTALL_DIR) $(1)/lib/wifi
10554  	$(INSTALL_DATA) ./files/lib/wifi/madwifi.sh $(1)/lib/wifi
10555  	$(INSTALL_DIR) $(1)/usr/sbin
10556 -	$(CP) $(PKG_BUILD_DIR)/tools/{madwifi_multi,80211stats,athchans,athctrl,athkey,athstats,wlanconfig} $(1)/usr/sbin/
10557 +	$(CP) $(PKG_BUILD_DIR)/tools/{madwifi_multi,$(MADWIFI_APPLETS)} $(1)/usr/sbin/
10558  endef
10559  
10560  $(eval $(call KernelPackage,madwifi))
10561 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/100-kernel_cflags.patch kamikaze_7.09/package/madwifi/patches/100-kernel_cflags.patch
10562 --- kamikaze_7.09.orig/package/madwifi/patches/100-kernel_cflags.patch	2007-09-20 10:54:59.000000000 +0200
10563 +++ kamikaze_7.09/package/madwifi/patches/100-kernel_cflags.patch	1970-01-01 01:00:00.000000000 +0100
10564 @@ -1,33 +0,0 @@
10565 -Index: madwifi-ng-r2568-20070710/hal/public/mips-be-elf.inc
10566 -===================================================================
10567 ---- madwifi-ng-r2568-20070710.orig/hal/public/mips-be-elf.inc	2007-07-23 01:48:38.974201182 +0200
10568 -+++ madwifi-ng-r2568-20070710/hal/public/mips-be-elf.inc	2007-07-23 01:48:39.166212125 +0200
10569 -@@ -71,5 +71,5 @@
10570 - 
10571 - LDOPTS=	-EB
10572 - COPTS+=	-DAH_BYTE_ORDER=AH_BIG_ENDIAN
10573 --COPTS+=	-G 0 -EB -mno-abicalls -fno-pic -mips2 -Wa,--trap \
10574 -+COPTS+=	-G 0 -mno-abicalls -fno-pic -mips32 -Wa,--trap \
10575 - 	-fno-strict-aliasing -fno-common -fomit-frame-pointer -mlong-calls
10576 -Index: madwifi-ng-r2568-20070710/hal/public/mips-le-elf.inc
10577 -===================================================================
10578 ---- madwifi-ng-r2568-20070710.orig/hal/public/mips-le-elf.inc	2007-07-23 01:48:38.982201640 +0200
10579 -+++ madwifi-ng-r2568-20070710/hal/public/mips-le-elf.inc	2007-07-23 01:48:39.170212355 +0200
10580 -@@ -68,5 +68,5 @@
10581 - 
10582 - LDOPTS=	-EL
10583 - COPTS+=	-DAH_BYTE_ORDER=AH_LITTLE_ENDIAN
10584 --COPTS+=	-G 0 -EL -mno-abicalls -fno-pic -mips2 -Wa,--trap \
10585 -+COPTS+=	-G 0 -mno-abicalls -fno-pic -mips32 -Wa,--trap \
10586 - 	-fno-strict-aliasing -fno-common -fomit-frame-pointer -mlong-calls
10587 -Index: madwifi-ng-r2568-20070710/hal/public/xscale-be-elf.inc
10588 -===================================================================
10589 ---- madwifi-ng-r2568-20070710.orig/hal/public/xscale-be-elf.inc	2007-07-23 01:48:38.990202093 +0200
10590 -+++ madwifi-ng-r2568-20070710/hal/public/xscale-be-elf.inc	2007-07-23 01:48:39.194213721 +0200
10591 -@@ -77,5 +77,5 @@
10592 - 
10593 - LDOPTS=	-EB
10594 - COPTS+=	-DAH_BYTE_ORDER=AH_BIG_ENDIAN
10595 --COPTS+= -march=armv4 -mbig-endian -fno-strict-aliasing -fno-common -mapcs-32 \
10596 -+COPTS+= -march=armv5te -mbig-endian -fno-strict-aliasing -fno-common  \
10597 - 	-mtune=xscale  -mshort-load-bytes
10598 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/102-multicall_binary.patch kamikaze_7.09/package/madwifi/patches/102-multicall_binary.patch
10599 --- kamikaze_7.09.orig/package/madwifi/patches/102-multicall_binary.patch	2007-09-20 10:54:59.000000000 +0200
10600 +++ kamikaze_7.09/package/madwifi/patches/102-multicall_binary.patch	2008-06-19 17:34:17.000000000 +0200
10601 @@ -1,256 +1,142 @@
10602 -Index: madwifi-ng-r2568-20070710/tools/80211debug.c
10603 -===================================================================
10604 ---- madwifi-ng-r2568-20070710.orig/tools/80211debug.c	2007-07-23 01:48:38.846193887 +0200
10605 -+++ madwifi-ng-r2568-20070710/tools/80211debug.c	2007-07-23 01:48:39.578235605 +0200
10606 -@@ -49,6 +49,10 @@
10607 +--- a/tools/80211debug.c
10608 ++++ b/tools/80211debug.c
10609 +@@ -48,6 +48,7 @@
10610 + #include <ctype.h>
10611   #include <getopt.h>
10612   #include <err.h>
10613 - 
10614 -+#ifdef DOMULTI
10615  +#include "do_multi.h"
10616 -+#endif
10617 -+
10618 - #define	N(a)	(sizeof(a)/sizeof(a[0]))
10619   
10620 - const char *progname;
10621 -@@ -180,9 +184,19 @@
10622 - }
10623 + #undef ARRAY_SIZE
10624 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
10625 +@@ -185,7 +186,7 @@
10626   #endif /* __linux__ */
10627   
10628 -+#ifdef DOMULTI
10629 -+
10630 -+int
10631 -+a80211debug_init(int argc, char *argv[])
10632 -+{
10633 -+
10634 -+#else
10635 -+
10636   int
10637 - main(int argc, char *argv[])
10638 +-main(int argc, char *argv[])
10639 ++CMD(a80211debug)(int argc, char *argv[])
10640   {
10641 -+
10642 -+#endif
10643   	const char *ifname = "ath0";
10644   	const char *cp, *tp;
10645 - 	const char *sep;
10646 -Index: madwifi-ng-r2568-20070710/tools/80211stats.c
10647 -===================================================================
10648 ---- madwifi-ng-r2568-20070710.orig/tools/80211stats.c	2007-07-23 01:48:38.854194346 +0200
10649 -+++ madwifi-ng-r2568-20070710/tools/80211stats.c	2007-07-23 01:48:39.578235605 +0200
10650 -@@ -60,6 +60,10 @@
10651 +--- a/tools/80211stats.c
10652 ++++ b/tools/80211stats.c
10653 +@@ -59,6 +59,7 @@
10654 + #include "net80211/ieee80211.h"
10655   #include "net80211/ieee80211_crypto.h"
10656   #include "net80211/ieee80211_ioctl.h"
10657 - 
10658 -+#ifdef DOMULTI
10659  +#include "do_multi.h"
10660 -+#endif
10661 -+
10662 + 
10663   #ifndef SIOCG80211STATS
10664   #define	SIOCG80211STATS	(SIOCDEVPRIVATE + 2)
10665 - #endif
10666 -@@ -243,9 +247,19 @@
10667 - #undef STAT
10668 +@@ -240,7 +241,7 @@
10669   }
10670   
10671 -+#ifdef DOMULTI
10672 -+
10673 -+int
10674 -+a80211stats_init(int argc, char *argv[])
10675 -+{
10676 -+
10677 -+#else
10678 -+
10679   int
10680 - main(int argc, char *argv[])
10681 +-main(int argc, char *argv[])
10682 ++CMD(a80211stats)(int argc, char *argv[])
10683   {
10684 -+
10685 -+#endif
10686   	int c, len;
10687   	struct ieee80211req_sta_info *si;
10688 - 	u_int8_t buf[24*1024], *cp;
10689 -Index: madwifi-ng-r2568-20070710/tools/athchans.c
10690 -===================================================================
10691 ---- madwifi-ng-r2568-20070710.orig/tools/athchans.c	2007-07-23 01:48:38.858194572 +0200
10692 -+++ madwifi-ng-r2568-20070710/tools/athchans.c	2007-07-23 01:48:39.598236745 +0200
10693 -@@ -59,6 +59,10 @@
10694 +--- a/tools/athchans.c
10695 ++++ b/tools/athchans.c
10696 +@@ -58,6 +58,7 @@
10697 + #include "net80211/ieee80211.h"
10698   #include "net80211/ieee80211_crypto.h"
10699   #include "net80211/ieee80211_ioctl.h"
10700 - 
10701 -+#ifdef DOMULTI
10702  +#include "do_multi.h"
10703 -+#endif
10704 -+
10705 - static	int s = -1;
10706 - const char *progname;
10707   
10708 -@@ -138,9 +142,20 @@
10709 + static	int s = -1;
10710 + static const char *progname;
10711 +@@ -140,8 +141,9 @@
10712   }
10713   
10714   #define	MAXCHAN	((int)(sizeof(struct ieee80211req_chanlist) * NBBY))
10715  +
10716 -+#ifdef DOMULTI
10717 -+
10718 -+int
10719 -+athchans_init(int argc, char *argv[])
10720 -+{
10721 -+
10722 -+#else
10723 -+
10724   int
10725 - main(int argc, char *argv[])
10726 +-main(int argc, char *argv[])
10727 ++CMD(athchans)(int argc, char *argv[])
10728   {
10729 -+
10730 -+#endif
10731   	const char *ifname = "wifi0";
10732   	struct ieee80211req_chanlist chanlist;
10733 - 	int c;
10734 -Index: madwifi-ng-r2568-20070710/tools/athctrl.c
10735 -===================================================================
10736 ---- madwifi-ng-r2568-20070710.orig/tools/athctrl.c	2007-07-23 01:48:38.866195027 +0200
10737 -+++ madwifi-ng-r2568-20070710/tools/athctrl.c	2007-07-23 01:48:39.626238340 +0200
10738 -@@ -53,6 +53,10 @@
10739 +--- a/tools/athctrl.c
10740 ++++ b/tools/athctrl.c
10741 +@@ -52,6 +52,7 @@
10742 + #include <err.h>
10743   
10744   #include <net/if.h>
10745 - 
10746 -+#ifdef DOMULTI
10747  +#include "do_multi.h"
10748 -+#endif
10749 -+
10750 + 
10751   static int
10752   setsysctrl(const char *dev, const char *control , u_long value)
10753 - {
10754 -@@ -87,9 +91,19 @@
10755 - 	exit(1);
10756 +@@ -88,7 +89,7 @@
10757   }
10758   
10759 -+#ifdef DOMULTI
10760 -+
10761 -+int
10762 -+athctrl_init(int argc, char *argv[])
10763 -+{
10764 -+
10765 -+#else
10766 -+
10767   int
10768 - main(int argc, char *argv[])
10769 +-main(int argc, char *argv[])
10770 ++CMD(athctrl)(int argc, char *argv[])
10771   {
10772 -+
10773 -+#endif
10774   	char device[IFNAMSIZ + 1];
10775   	int distance = -1;
10776 - 	int c;
10777 -Index: madwifi-ng-r2568-20070710/tools/athdebug.c
10778 -===================================================================
10779 ---- madwifi-ng-r2568-20070710.orig/tools/athdebug.c	2007-07-23 01:48:38.874195486 +0200
10780 -+++ madwifi-ng-r2568-20070710/tools/athdebug.c	2007-07-23 01:48:39.650239706 +0200
10781 -@@ -52,6 +52,10 @@
10782 +--- a/tools/athdebug.c
10783 ++++ b/tools/athdebug.c
10784 +@@ -51,6 +51,7 @@
10785 + #include <ctype.h>
10786   #include <getopt.h>
10787   #include <err.h>
10788 - 
10789 -+#ifdef DOMULTI
10790  +#include "do_multi.h"
10791 -+#endif
10792 -+
10793 - #define	N(a)	(sizeof(a)/sizeof(a[0]))
10794   
10795 - const char *progname;
10796 -@@ -179,9 +183,20 @@
10797 - }
10798 + #undef ARRAY_SIZE
10799 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
10800 +@@ -194,7 +195,7 @@
10801   #endif /* __linux__ */
10802   
10803 -+#ifdef DOMULTI
10804 -+
10805 -+int
10806 -+athdebug_init(int argc, char *argv[])
10807 -+{
10808 -+
10809 -+#else
10810 -+
10811   int
10812 - main(int argc, char *argv[])
10813 +-main(int argc, char *argv[])
10814 ++CMD(athdebug)(int argc, char *argv[])
10815   {
10816 -+
10817 -+#endif
10818 -+
10819   #ifdef __linux__
10820   	const char *ifname = "wifi0";
10821 - #else
10822 -Index: madwifi-ng-r2568-20070710/tools/athkey.c
10823 -===================================================================
10824 ---- madwifi-ng-r2568-20070710.orig/tools/athkey.c	2007-07-23 01:48:38.878195712 +0200
10825 -+++ madwifi-ng-r2568-20070710/tools/athkey.c	2007-07-23 01:48:39.698242443 +0200
10826 -@@ -59,6 +59,10 @@
10827 +--- a/tools/athkey.c
10828 ++++ b/tools/athkey.c
10829 +@@ -58,6 +58,7 @@
10830 + #include "net80211/ieee80211.h"
10831   #include "net80211/ieee80211_crypto.h"
10832   #include "net80211/ieee80211_ioctl.h"
10833 - 
10834 -+#ifdef DOMULTI
10835  +#include "do_multi.h"
10836 -+#endif
10837 -+
10838 - static int s = -1;
10839 - const char *progname;
10840   
10841 -@@ -211,9 +215,19 @@
10842 + static int s = -1;
10843 + static const char *progname;
10844 +@@ -213,8 +214,7 @@
10845   	exit(-1);
10846   }
10847   
10848 -+#ifdef DOMULTI
10849 -+
10850 -+int
10851 -+athkey_init(int argc, char *argv[])
10852 -+{
10853 -+
10854 -+#else
10855 -+
10856 - int
10857 - main(int argc, char *argv[])
10858 +-int
10859 +-main(int argc, char *argv[])
10860 ++int CMD(athkey)(int argc, char *argv[])
10861   {
10862 -+
10863 -+#endif
10864   	const char *ifname = "wifi0";
10865   	struct ieee80211req_key setkey;
10866 - 	struct ieee80211req_del_key delkey;
10867 -Index: madwifi-ng-r2568-20070710/tools/athstats.c
10868 -===================================================================
10869 ---- madwifi-ng-r2568-20070710.orig/tools/athstats.c	2007-07-23 01:48:38.886196167 +0200
10870 -+++ madwifi-ng-r2568-20070710/tools/athstats.c	2007-07-23 01:48:39.726244040 +0200
10871 -@@ -63,6 +63,10 @@
10872 - #include "wireless_copy.h"
10873 - #include "if_athioctl.h"
10874 +--- a/tools/athstats.c
10875 ++++ b/tools/athstats.c
10876 +@@ -65,6 +65,7 @@
10877   
10878 -+#ifdef DOMULTI
10879 + #undef ARRAY_SIZE
10880 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
10881  +#include "do_multi.h"
10882 -+#endif
10883 -+
10884 + 
10885   static const struct {
10886   	u_int		phyerr;
10887 - 	const char*	desc;
10888 -@@ -226,9 +230,20 @@
10889 - 	signalled = 1;
10890 +@@ -228,7 +229,7 @@
10891   }
10892   
10893 -+#ifdef DOMULTI
10894 -+
10895 -+int
10896 -+athstats_init(int argc, char *argv[])
10897 -+{
10898 -+
10899 -+#else
10900 -+
10901   int
10902 - main(int argc, char *argv[])
10903 +-main(int argc, char *argv[])
10904 ++CMD(athstats)(int argc, char *argv[])
10905   {
10906 -+
10907 -+#endif
10908 -+
10909   #ifdef __linux__
10910   	const char *ifname = "wifi0";
10911 - #else
10912 -Index: madwifi-ng-r2568-20070710/tools/do_multi.c
10913 -===================================================================
10914 ---- /dev/null	1970-01-01 00:00:00.000000000 +0000
10915 -+++ madwifi-ng-r2568-20070710/tools/do_multi.c	2007-07-23 01:48:39.754245634 +0200
10916 -@@ -0,0 +1,30 @@
10917 +--- /dev/null
10918 ++++ b/tools/do_multi.c
10919 +@@ -0,0 +1,32 @@
10920  +#include <string.h>
10921  +#include "do_multi.h"
10922  +
10923 @@ -278,15 +164,15 @@
10924  +	ret =  athstats_init(argc, argv);
10925  +    if(strcmp(progname, "wlanconfig") == 0)
10926  +	ret =  wlanconfig_init(argc, argv);
10927 ++    if(strcmp(progname, "ath_info") == 0)
10928 ++	ret =  athinfo_init(argc, argv);
10929  +
10930  +    return ret;
10931  +}
10932 -Index: madwifi-ng-r2568-20070710/tools/do_multi.h
10933 -===================================================================
10934 ---- /dev/null	1970-01-01 00:00:00.000000000 +0000
10935 -+++ madwifi-ng-r2568-20070710/tools/do_multi.h	2007-07-23 01:48:39.778247001 +0200
10936 -@@ -0,0 +1,9 @@
10937 -+
10938 +--- /dev/null
10939 ++++ b/tools/do_multi.h
10940 +@@ -0,0 +1,15 @@
10941 ++#ifdef DO_MULTI
10942  +int a80211debug_init(int argc, char *argv[]);
10943  +int a80211stats_init(int argc, char *argv[]);
10944  +int athchans_init(int argc, char *argv[]);
10945 @@ -295,86 +181,134 @@
10946  +int athkey_init(int argc, char *argv[]);
10947  +int athstats_init(int argc, char *argv[]);
10948  +int wlanconfig_init(int argc, char *argv[]);
10949 -Index: madwifi-ng-r2568-20070710/tools/Makefile
10950 -===================================================================
10951 ---- madwifi-ng-r2568-20070710.orig/tools/Makefile	2007-07-23 01:48:38.902197078 +0200
10952 -+++ madwifi-ng-r2568-20070710/tools/Makefile	2007-07-23 01:48:39.798248141 +0200
10953 -@@ -49,6 +49,12 @@
10954 - 
10955 - ALL=	athstats 80211stats athkey athchans athctrl \
10956 - 	athdebug 80211debug wlanconfig
10957 -+	
10958 -+ifdef DOMULTI
10959 -+OBJS=	do_multi.o athstats.o 80211stats.o athkey.o athchans.o athctrl.o \
10960 -+	athdebug.o 80211debug.o wlanconfig.o
10961 -+ALL=	${OBJS} madwifi_multi
10962 ++int athinfo_init(int argc, char *argv[]);
10963 ++
10964 ++#define CMD(name) name##_init
10965 ++#else
10966 ++#define CMD(name) main
10967 ++#endif
10968 +--- a/tools/Makefile
10969 ++++ b/tools/Makefile
10970 +@@ -46,56 +46,55 @@
10971 + HAL=   $(TOP)/hal
10972 + endif
10973 + 
10974 ++all: compile
10975 + 
10976 +-ALL=	athstats 80211stats athkey athchans athctrl \
10977 ++ALLPROGS=	athstats 80211stats athkey athchans athctrl \
10978 + 	athdebug 80211debug wlanconfig ath_info
10979 + 
10980 +-all:	$(ALL)
10981 ++OBJS=	$(patsubst %,%.o,$(ALLPROGS))
10982 + 
10983 +-INCS=	-I. -I$(HAL) -I$(TOP) -I$(ATH_HAL)
10984 ++INCS=	-I. -I../ath -I$(HAL) -I$(TOP) -I$(ATH_HAL)
10985 + CFLAGS=	-g -O2 -Wall
10986 + ALL_CFLAGS= $(CFLAGS) $(INCS)
10987 + LDFLAGS=
10988 + 
10989 +-all:	$(ALL)
10990 + 
10991 +-athstats: athstats.c
10992 +-	$(CC) -o athstats $(ALL_CFLAGS) -I$(TOP)/ath $(LDFLAGS) athstats.c
10993 +-80211stats: 80211stats.c
10994 +-	$(CC) -o 80211stats $(ALL_CFLAGS) $(LDFLAGS) 80211stats.c
10995 +-athkey: athkey.c
10996 +-	$(CC) -o athkey $(ALL_CFLAGS) $(LDFLAGS) athkey.c
10997 +-athchans: athchans.c
10998 +-	$(CC) -o athchans $(ALL_CFLAGS) $(LDFLAGS) athchans.c
10999 +-athctrl: athctrl.c
11000 +-	$(CC) -o athctrl $(ALL_CFLAGS) $(LDFLAGS) athctrl.c
11001 +-athdebug: athdebug.c
11002 +-	$(CC) -o athdebug $(ALL_CFLAGS) $(LDFLAGS) athdebug.c
11003 +-wlanconfig: wlanconfig.c
11004 +-	$(CC) -o wlanconfig $(ALL_CFLAGS) $(LDFLAGS) wlanconfig.c
11005 +-80211debug: 80211debug.c
11006 +-	$(CC) -o 80211debug $(ALL_CFLAGS) $(LDFLAGS) 80211debug.c
11007 +-ath_info: ath_info.c
11008 +-	$(CC) -o ath_info $(CFLAGS) ath_info.c
11009 ++ifneq ($(DO_MULTI),)
11010 ++ALL_CFLAGS += -DDO_MULTI=1
11011 ++%.o: %.c
11012 ++	${CC} $(ALL_CFLAGS) -c -o $@  $<
11013 ++
11014 ++madwifi_multi: $(OBJS) do_multi.o
11015 ++	$(CC) -o $@ $^
11016 ++
11017 ++compile: madwifi_multi
11018 ++	for i in $(ALLPROGS); do \
11019 ++		ln -s -f madwifi_multi $$i; \
11020 ++	done
11021 ++else
11022 ++$(ALLPROGS):
11023 ++	$(CC) $(ALL_CFLAGS) -o $@ $@.c
11024 ++
11025 ++compile: $(ALLPROGS)
11026  +endif
11027   
11028 - all:	$(ALL)
11029 - 
11030 -@@ -59,6 +65,30 @@
11031 - 
11032 - all:	$(ALL)
11033   
11034 -+athstats.o: athstats.c
11035 -+	${CC} -c -o athstats.o -DDOMULTI=1 ${ALL_CFLAGS} -I../ath athstats.c
11036 -+80211stats.o: 80211stats.c
11037 -+	${CC} -c -o 80211stats.o -DDOMULTI=1 ${ALL_CFLAGS} 80211stats.c
11038 -+athkey.o: athkey.c
11039 -+	${CC} -c -o athkey.o -DDOMULTI=1 ${ALL_CFLAGS} athkey.c
11040 -+athchans.o: athchans.c
11041 -+	${CC} -c -o athchans.o -DDOMULTI=1 ${ALL_CFLAGS} athchans.c
11042 -+athctrl.o: athctrl.c
11043 -+	${CC} -c -o athctrl.o -DDOMULTI=1 ${ALL_CFLAGS} athctrl.c
11044 -+athdebug.o: athdebug.c
11045 -+	${CC} -c -o athdebug.o -DDOMULTI=1 ${ALL_CFLAGS} athdebug.c
11046 -+wlanconfig.o: wlanconfig.c
11047 -+	${CC} -c -o wlanconfig.o -DDOMULTI=1 ${ALL_CFLAGS} wlanconfig.c
11048 -+80211debug.o: 80211debug.c
11049 -+	${CC} -c -o 80211debug.o -DDOMULTI=1 ${ALL_CFLAGS} 80211debug.c
11050 -+do_multi.o: do_multi.c
11051 -+	${CC} -c -o do_multi.o -DDOMULTI=1 ${ALL_CFLAGS} do_multi.c
11052 -+madwifi_multi:
11053 -+	${CC} -o madwifi_multi ${LDFLAGS} ${OBJS}
11054 -+	for i in athstats 80211stats athkey athchans athctrl athdebug wlanconfig 80211debug; do \
11055 -+	ln -s -f madwifi_multi $$i; \
11056 -+	done
11057 -+
11058 - athstats: athstats.c
11059 - 	$(CC) -o athstats $(ALL_CFLAGS) -I$(TOP)/ath $(LDFLAGS) athstats.c
11060 - 80211stats: 80211stats.c
11061 -Index: madwifi-ng-r2568-20070710/tools/wlanconfig.c
11062 -===================================================================
11063 ---- madwifi-ng-r2568-20070710.orig/tools/wlanconfig.c	2007-07-23 01:48:38.910197536 +0200
11064 -+++ madwifi-ng-r2568-20070710/tools/wlanconfig.c	2007-07-23 01:48:39.850251108 +0200
11065 -@@ -62,6 +62,10 @@
11066 + install: $(ALL) 
11067 + 	install -d $(DESTDIR)$(BINDIR)
11068 +-	for i in $(ALL); do \
11069 ++	for i in $(ALLPROGS) $(if $(DO_MULTI),madwifi_multi); do \
11070 + 		install $$i $(DESTDIR)$(BINDIR)/$$i; \
11071 +-		$(STRIP) $(DESTDIR)$(BINDIR)/$$i; \
11072 + 	done
11073 + 	install -d $(DESTDIR)$(MANDIR)/man8
11074 + 	install -m 0644 man/*.8 $(DESTDIR)$(MANDIR)/man8
11075 + 	install $(TOP)/scripts/madwifi-unload $(DESTDIR)$(BINDIR)/madwifi-unload
11076 + 
11077 + uninstall:
11078 +-	for i in $(ALL); do \
11079 ++	for i in $(ALLPROGS) $(if $(DO_MULTI),madwifi_multi); do \
11080 + 		rm -f $(DESTDIR)$(BINDIR)/$$i; \
11081 + 	done
11082 +-	for i in $(ALL:=.8); do \
11083 +-		rm -f $(DESTDIR)$(MANDIR)/man8/$$i; \
11084 ++	for i in $(ALLPROGS); do \
11085 ++		rm -f $(DESTDIR)$(MANDIR)/man8/$$i.8; \
11086 + 	done
11087 + 
11088 + clean:
11089 +-	rm -f $(ALL) core a.out
11090 ++	rm -f $(ALLPROGS) madwifi_multi *.o core a.out
11091 +--- a/tools/wlanconfig.c
11092 ++++ b/tools/wlanconfig.c
11093 +@@ -61,6 +61,7 @@
11094 + #include "net80211/ieee80211.h"
11095   #include "net80211/ieee80211_crypto.h"
11096   #include "net80211/ieee80211_ioctl.h"
11097 - 
11098 -+#ifdef DOMULTI
11099  +#include "do_multi.h"
11100 -+#endif
11101 -+
11102 + 
11103   /*
11104    * These are taken from ieee80211_node.h
11105 -  */
11106 -@@ -96,9 +100,19 @@
11107 - 
11108 - int verbose = 0;
11109 +@@ -100,7 +101,7 @@
11110 + static int verbose = 0;
11111   
11112 -+#ifdef DOMULTI
11113 -+
11114 -+int
11115 -+wlanconfig_init(int argc, char *argv[])
11116 -+{
11117 -+
11118 -+#else
11119 -+
11120   int
11121 - main(int argc, char *argv[])
11122 +-main(int argc, char *argv[])
11123 ++CMD(wlanconfig)(int argc, char *argv[])
11124   {
11125 -+
11126 -+#endif
11127   	const char *ifname, *cmd;
11128   	unsigned char bnounit = 0;
11129 - 	char *if_base = NULL;
11130 +--- a/tools/ath_info.c
11131 ++++ b/tools/ath_info.c
11132 +@@ -98,6 +98,7 @@
11133 + #include <sys/mman.h>
11134 + #include <endian.h>
11135 + #include <byteswap.h>
11136 ++#include "do_multi.h"
11137 + 
11138 + #undef ARRAY_SIZE
11139 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
11140 +@@ -738,7 +739,8 @@
11141 + 		"unlawful radio transmissions!\n\n");
11142 + }
11143 + 
11144 +-int main(int argc, char *argv[])
11145 ++int
11146 ++CMD(athinfo)(int argc, char *argv[])
11147 + {
11148 + 	u_int32_t dev_addr;
11149 + 	u_int16_t eeprom_header, srev, phy_rev_5ghz, phy_rev_2ghz;
11150 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/104-autocreate_none.patch kamikaze_7.09/package/madwifi/patches/104-autocreate_none.patch
11151 --- kamikaze_7.09.orig/package/madwifi/patches/104-autocreate_none.patch	2007-09-20 10:54:59.000000000 +0200
11152 +++ kamikaze_7.09/package/madwifi/patches/104-autocreate_none.patch	2008-06-19 17:34:17.000000000 +0200
11153 @@ -1,8 +1,6 @@
11154 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
11155 -===================================================================
11156 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:38.770189557 +0200
11157 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:40.226272533 +0200
11158 -@@ -427,7 +427,7 @@
11159 +--- a/ath/if_ath.c
11160 ++++ b/ath/if_ath.c
11161 +@@ -516,7 +516,7 @@
11162   	HAL_STATUS status;
11163   	int error = 0;
11164   	unsigned int i;
11165 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/105-ratectl_attach.patch kamikaze_7.09/package/madwifi/patches/105-ratectl_attach.patch
11166 --- kamikaze_7.09.orig/package/madwifi/patches/105-ratectl_attach.patch	2007-09-20 10:54:59.000000000 +0200
11167 +++ kamikaze_7.09/package/madwifi/patches/105-ratectl_attach.patch	2008-06-19 17:34:17.000000000 +0200
11168 @@ -1,7 +1,5 @@
11169 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_rate.c
11170 -===================================================================
11171 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_rate.c	2007-07-23 01:48:38.694185224 +0200
11172 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_rate.c	2007-07-23 01:48:40.474286668 +0200
11173 +--- a/net80211/ieee80211_rate.c
11174 ++++ b/net80211/ieee80211_rate.c
11175  @@ -100,8 +100,18 @@
11176   		ieee80211_load_module(buf);
11177   
11178 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/110-init_fix_PR_914.patch kamikaze_7.09/package/madwifi/patches/110-init_fix_PR_914.patch
11179 --- kamikaze_7.09.orig/package/madwifi/patches/110-init_fix_PR_914.patch	2007-09-20 10:54:59.000000000 +0200
11180 +++ kamikaze_7.09/package/madwifi/patches/110-init_fix_PR_914.patch	1970-01-01 01:00:00.000000000 +0100
11181 @@ -1,15 +0,0 @@
11182 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
11183 -===================================================================
11184 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:40.226272533 +0200
11185 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:40.726301028 +0200
11186 -@@ -1988,7 +1988,10 @@
11187 - 		ath_draintxq(sc);
11188 - 		if (!sc->sc_invalid) {
11189 - 			ath_stoprecv(sc);
11190 -+
11191 -+			/* XXX: this helps to avoid crashes on ifconfig down/up
11192 - 			ath_hal_phydisable(ah);
11193 -+			 */
11194 - 		} else
11195 - 			sc->sc_rxlink = NULL;
11196 - 		ath_beacon_free(sc);		/* XXX needed? */
11197 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/111-minstrel_crash.patch kamikaze_7.09/package/madwifi/patches/111-minstrel_crash.patch
11198 --- kamikaze_7.09.orig/package/madwifi/patches/111-minstrel_crash.patch	2007-09-20 10:54:59.000000000 +0200
11199 +++ kamikaze_7.09/package/madwifi/patches/111-minstrel_crash.patch	2008-06-19 17:34:17.000000000 +0200
11200 @@ -1,8 +1,6 @@
11201 -Index: madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c
11202 -===================================================================
11203 ---- madwifi-ng-r2568-20070710.orig/ath_rate/minstrel/minstrel.c	2007-07-23 01:48:38.542176563 +0200
11204 -+++ madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c	2007-07-23 01:48:40.974315165 +0200
11205 -@@ -388,6 +388,9 @@
11206 +--- a/ath_rate/minstrel/minstrel.c
11207 ++++ b/ath_rate/minstrel/minstrel.c
11208 +@@ -393,6 +393,9 @@
11209   		struct minstrel_node *sn = ATH_NODE_MINSTREL(an);
11210   		int rc1, rc2, rc3;         /* Index into the rate table, so for example, it is  0..11 */
11211   
11212 @@ -10,5 +8,5 @@
11213  +			return;
11214  +
11215   		if (sn->is_sampling) {
11216 - 			rc1 = sn->max_tp_rate;
11217   			sn->is_sampling = 0;
11218 + 			if (sn->rs_sample_rate_slower)
11219 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/112-keycache_PR_962.patch kamikaze_7.09/package/madwifi/patches/112-keycache_PR_962.patch
11220 --- kamikaze_7.09.orig/package/madwifi/patches/112-keycache_PR_962.patch	2007-09-20 10:54:59.000000000 +0200
11221 +++ kamikaze_7.09/package/madwifi/patches/112-keycache_PR_962.patch	1970-01-01 01:00:00.000000000 +0100
11222 @@ -1,61 +0,0 @@
11223 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
11224 -===================================================================
11225 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:40.726301028 +0200
11226 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:41.230329754 +0200
11227 -@@ -5732,7 +5732,8 @@
11228 - 		 * frame; it'll be dropped where it's not wanted.
11229 - 		 */
11230 - 		if (rs->rs_keyix != HAL_RXKEYIX_INVALID &&
11231 --		    (ni = sc->sc_keyixmap[rs->rs_keyix]) != NULL) {
11232 -+		    ((ni = sc->sc_keyixmap[rs->rs_keyix]) != NULL) &&
11233 -+			ieee80211_check_rxnode(ni, (const struct ieee80211_frame_min *) skb->data)) {
11234 - 			struct ath_node *an;
11235 - 			/*
11236 - 			 * Fast path: node is present in the key map;
11237 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
11238 -===================================================================
11239 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-23 01:48:38.458171774 +0200
11240 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-23 01:48:41.230329754 +0200
11241 -@@ -1271,8 +1271,6 @@
11242 - 	IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
11243 - 
11244 - 	return ni;
11245 --#undef IS_PSPOLL
11246 --#undef IS_CTL
11247 - }
11248 - #ifdef IEEE80211_DEBUG_REFCNT
11249 - EXPORT_SYMBOL(ieee80211_find_rxnode_debug);
11250 -@@ -1280,6 +1278,20 @@
11251 - EXPORT_SYMBOL(ieee80211_find_rxnode);
11252 - #endif
11253 - 
11254 -+int
11255 -+ieee80211_check_rxnode(struct ieee80211_node *ni,
11256 -+	const struct ieee80211_frame_min *wh)
11257 -+{
11258 -+	if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
11259 -+		return IEEE80211_ADDR_EQ(ni->ni_macaddr, wh->i_addr1);
11260 -+	else
11261 -+		return IEEE80211_ADDR_EQ(ni->ni_macaddr, wh->i_addr2);
11262 -+}
11263 -+
11264 -+EXPORT_SYMBOL(ieee80211_check_rxnode);
11265 -+#undef IS_PSPOLL
11266 -+#undef IS_CTL
11267 -+
11268 - /*
11269 -  * Return a reference to the appropriate node for sending
11270 -  * a data frame.  This handles node discovery in adhoc networks.
11271 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.h
11272 -===================================================================
11273 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.h	2007-07-23 01:48:38.466172232 +0200
11274 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.h	2007-07-23 01:48:41.254331120 +0200
11275 -@@ -328,6 +328,8 @@
11276 - 	*pni = NULL;			/* guard against use */
11277 - }
11278 - 
11279 -+int ieee80211_check_rxnode(struct ieee80211_node *ni,
11280 -+	const struct ieee80211_frame_min *wh);
11281 - int ieee80211_add_wds_addr(struct ieee80211_node_table *, struct ieee80211_node *,
11282 - 	const u_int8_t *, u_int8_t);
11283 - void ieee80211_remove_wds_addr(struct ieee80211_node_table *, const u_int8_t *);
11284 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/113-no_ibss_pwrsave.patch kamikaze_7.09/package/madwifi/patches/113-no_ibss_pwrsave.patch
11285 --- kamikaze_7.09.orig/package/madwifi/patches/113-no_ibss_pwrsave.patch	2007-09-20 10:54:59.000000000 +0200
11286 +++ kamikaze_7.09/package/madwifi/patches/113-no_ibss_pwrsave.patch	2008-06-19 17:34:17.000000000 +0200
11287 @@ -1,7 +1,5 @@
11288 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_scan.c
11289 -===================================================================
11290 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_scan.c	2007-07-23 01:48:38.374166989 +0200
11291 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_scan.c	2007-07-23 01:48:41.534347075 +0200
11292 +--- a/net80211/ieee80211_scan.c
11293 ++++ b/net80211/ieee80211_scan.c
11294  @@ -291,7 +291,8 @@
11295   	struct ieee80211com *ic = vap->iv_ic;
11296   	int delay;
11297 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/116-adhoc_beacon_PR_1033.patch kamikaze_7.09/package/madwifi/patches/116-adhoc_beacon_PR_1033.patch
11298 --- kamikaze_7.09.orig/package/madwifi/patches/116-adhoc_beacon_PR_1033.patch	2007-09-20 10:54:59.000000000 +0200
11299 +++ kamikaze_7.09/package/madwifi/patches/116-adhoc_beacon_PR_1033.patch	1970-01-01 01:00:00.000000000 +0100
11300 @@ -1,197 +0,0 @@
11301 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
11302 -===================================================================
11303 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:41.230329754 +0200
11304 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:41.758359843 +0200
11305 -@@ -4426,16 +4426,31 @@
11306 - 	struct ieee80211com *ic = &sc->sc_ic;
11307 - 	struct ath_hal *ah = sc->sc_ah;
11308 - 	struct ieee80211_node *ni;
11309 --	u_int32_t nexttbtt, intval;
11310 -+	u_int32_t nexttbtt = 0;
11311 -+	u_int32_t intval;
11312 -+	u_int64_t tsf, hw_tsf;
11313 -+	u_int32_t tsftu, hw_tsftu;
11314 -+	int should_reset_tsf = 0;
11315 - 
11316 - 	if (vap == NULL)
11317 - 		vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */
11318 - 
11319 - 	ni = vap->iv_bss;
11320 - 
11321 --	/* extract tstamp from last beacon and convert to TU */
11322 --	nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4),
11323 --			     LE_READ_4(ni->ni_tstamp.data));
11324 -+	hw_tsf = ath_hal_gettsf64(ah);
11325 -+	tsf = le64_to_cpu(ni->ni_tstamp.tsf);
11326 -+	hw_tsftu = hw_tsf >> 10;
11327 -+	tsftu = tsf >> 10;
11328 -+
11329 -+	/* we should reset hw TSF only once, so we increment
11330 -+	   ni_tstamp.tsf to avoid resetting the hw TSF multiple
11331 -+	   times */
11332 -+
11333 -+	if (tsf == 0) {
11334 -+		should_reset_tsf = 1;
11335 -+		ni->ni_tstamp.tsf = cpu_to_le64(1);
11336 -+	}
11337 -+
11338 - 	/* XXX conditionalize multi-bss support? */
11339 - 	if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
11340 - 		/*
11341 -@@ -4449,20 +4464,61 @@
11342 - 		if (sc->sc_stagbeacons)
11343 - 			intval /= ATH_BCBUF;	/* for staggered beacons */
11344 - 		if ((sc->sc_nostabeacons) &&
11345 --		    (vap->iv_opmode == IEEE80211_M_HOSTAP))
11346 --			nexttbtt = 0;
11347 -+			(vap->iv_opmode == IEEE80211_M_HOSTAP))
11348 -+			should_reset_tsf = 1;
11349 - 	} else
11350 - 		intval = ni->ni_intval & HAL_BEACON_PERIOD;
11351 --	if (nexttbtt == 0)		/* e.g. for ap mode */
11352 -+
11353 -+#define	FUDGE	2
11354 -+	sc->sc_syncbeacon = 0;
11355 -+	if (should_reset_tsf) {
11356 -+
11357 -+		/* We just created the interface and TSF will be reset to
11358 -+		   zero, so next beacon will be sent at the next intval
11359 -+		   time */
11360 -+
11361 - 		nexttbtt = intval;
11362 --	else if (intval)		/* NB: can be 0 for monitor mode */
11363 --		nexttbtt = roundup(nexttbtt, intval);
11364 --	DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt %u intval %u (%u)\n",
11365 --		__func__, nexttbtt, intval, ni->ni_intval);
11366 -+	} else if (intval) {	/* NB: can be 0 for monitor mode */
11367 -+		if (tsf == 1) {
11368 -+ 	
11369 -+			/* We do not receive any beacons or probe response. Since
11370 -+			   a beacon should be sent every 'intval' ms, we compute
11371 -+			   the next beacon timestamp using the hardware TSF. We
11372 -+			   ensure that it is at least FUDGE ms ahead of the
11373 -+			   current TSF. Otherwise, we use the next beacon
11374 -+			   timestamp again */
11375 -+
11376 -+			nexttbtt = roundup(hw_tsftu +1, intval);
11377 -+			while (nexttbtt <= hw_tsftu + FUDGE) {
11378 -+				nexttbtt += intval;
11379 -+			}
11380 -+		} else {
11381 -+			if (tsf > hw_tsf) {
11382 -+
11383 -+			/* We do receive a beacon from someone else in the past,
11384 -+			   but the hw TSF has not been updated (otherwise we
11385 -+			   would have tsf >= hw_tsf). Since we cannot use the
11386 -+			   hardware TSF, we will do nothing and wait for the
11387 -+			   next beacon. In order to do so, we set sc->syncbeacon
11388 -+			   again */
11389 -+
11390 -+				sc->sc_syncbeacon = 1;
11391 -+				goto ath_beacon_config_debug;
11392 -+			} else {
11393 -+				/* We do receive a beacon in the past, normal case. We
11394 -+				   make sure that the timestamp is at least FUDGE ms
11395 -+				   ahead of the hardware TSF */
11396 -+
11397 -+				nexttbtt = tsftu + intval;
11398 -+				while (nexttbtt <= hw_tsftu + FUDGE) {
11399 -+					nexttbtt += intval;
11400 -+				}
11401 -+			}
11402 -+		}
11403 -+	}
11404 -+
11405 - 	if (ic->ic_opmode == IEEE80211_M_STA &&	!(sc->sc_nostabeacons)) {
11406 - 		HAL_BEACON_STATE bs;
11407 --		u_int64_t tsf;
11408 --		u_int32_t tsftu;
11409 - 		int dtimperiod, dtimcount;
11410 - 		int cfpperiod, cfpcount;
11411 - 
11412 -@@ -4478,13 +4534,13 @@
11413 - 			dtimcount = 0;		/* XXX? */
11414 - 		cfpperiod = 1;			/* NB: no PCF support yet */
11415 - 		cfpcount = 0;
11416 --#define	FUDGE	2
11417 - 		/*
11418 - 		 * Pull nexttbtt forward to reflect the current
11419 - 		 * TSF and calculate dtim+cfp state for the result.
11420 - 		 */
11421 --		tsf = ath_hal_gettsf64(ah);
11422 --		tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
11423 -+		nexttbtt = tsftu;
11424 -+		if (nexttbtt == 0)		/* e.g. for ap mode */
11425 -+			nexttbtt = intval;
11426 - 		do {
11427 - 			nexttbtt += intval;
11428 - 			if (--dtimcount < 0) {
11429 -@@ -4492,7 +4548,7 @@
11430 - 				if (--cfpcount < 0)
11431 - 					cfpcount = cfpperiod - 1;
11432 - 			}
11433 --		} while (nexttbtt < tsftu);
11434 -+		} while (nexttbtt < hw_tsftu + FUDGE);
11435 - #undef FUDGE
11436 - 		memset(&bs, 0, sizeof(bs));
11437 - 		bs.bs_intval = intval;
11438 -@@ -4544,7 +4600,7 @@
11439 - 		DPRINTF(sc, ATH_DEBUG_BEACON,
11440 - 			"%s: tsf %llu tsf:tu %u intval %u nexttbtt %u dtim %u nextdtim %u bmiss %u sleep %u cfp:period %u maxdur %u next %u timoffset %u\n",
11441 - 			__func__,
11442 --			(unsigned long long) tsf, tsftu,
11443 -+			(unsigned long long) hw_tsf, hw_tsftu,
11444 - 			bs.bs_intval,
11445 - 			bs.bs_nexttbtt,
11446 - 			bs.bs_dtimperiod,
11447 -@@ -4566,7 +4622,7 @@
11448 - 		ath_hal_intrset(ah, sc->sc_imask);
11449 - 	} else {
11450 - 		ath_hal_intrset(ah, 0);
11451 --		if (nexttbtt == intval)
11452 -+		if (should_reset_tsf)
11453 - 			intval |= HAL_BEACON_RESET_TSF;
11454 - 		if (ic->ic_opmode == IEEE80211_M_IBSS) {
11455 - 			/*
11456 -@@ -4603,8 +4659,40 @@
11457 - 		if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol)
11458 - 			ath_beacon_start_adhoc(sc, vap);
11459 - 	}
11460 --	sc->sc_syncbeacon = 0;
11461 - #undef TSF_TO_TU
11462 -+
11463 -+	ath_beacon_config_debug:
11464 -+
11465 -+	/* we print all debug messages here, in order to preserve the
11466 -+	   time critical aspect of this function */
11467 -+
11468 -+	DPRINTF(sc, ATH_DEBUG_BEACON,
11469 -+		"%s: ni=%p tsf=%llu hw_tsf=%llu tsftu=%u hw_tsftu=%u\n",
11470 -+		__func__, ni, tsf, hw_tsf, tsftu, hw_tsftu);
11471 -+
11472 -+	if (should_reset_tsf) {
11473 -+		/* we just created the interface */
11474 -+		DPRINTF(sc, ATH_DEBUG_BEACON, "%s: first beacon\n",__func__);
11475 -+	} else {
11476 -+		if (tsf == 1) {
11477 -+			/* we do not receive any beacons or probe response */
11478 -+			DPRINTF(sc, ATH_DEBUG_BEACON,
11479 -+				"%s: no beacon received...\n",__func__);
11480 -+		} else {
11481 -+			if (tsf > hw_tsf) {
11482 -+				/* we do receive a beacon and the hw TSF has not been updated */
11483 -+				DPRINTF(sc, ATH_DEBUG_BEACON,
11484 -+					"%s: beacon received, but TSF is incorrect\n",__func__);
11485 -+			} else {
11486 -+				/* we do receive a beacon in the past, normal case */
11487 -+				DPRINTF(sc, ATH_DEBUG_BEACON,
11488 -+					"%s: beacon received, TSF is correct\n",__func__);
11489 -+			}
11490 -+		}
11491 -+	}
11492 -+
11493 -+	DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt=%u intval=%u\n",
11494 -+		__func__,nexttbtt, intval & HAL_BEACON_PERIOD);
11495 - }
11496 - 
11497 - static int
11498 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/120-soc_fix.patch kamikaze_7.09/package/madwifi/patches/120-soc_fix.patch
11499 --- kamikaze_7.09.orig/package/madwifi/patches/120-soc_fix.patch	2007-09-20 10:54:59.000000000 +0200
11500 +++ kamikaze_7.09/package/madwifi/patches/120-soc_fix.patch	1970-01-01 01:00:00.000000000 +0100
11501 @@ -1,46 +0,0 @@
11502 -Index: madwifi-ng-r2568-20070710/ath/if_ath_ahb.c
11503 -===================================================================
11504 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath_ahb.c	2007-07-23 01:48:38.098151260 +0200
11505 -+++ madwifi-ng-r2568-20070710/ath/if_ath_ahb.c	2007-07-23 01:48:41.998373519 +0200
11506 -@@ -275,11 +275,10 @@
11507 - 
11508 - 
11509 - static int
11510 --exit_ath_wmac(u_int16_t wlanNum)
11511 -+exit_ath_wmac(u_int16_t wlanNum, struct ar531x_config *config)
11512 - {
11513 - 	struct ath_ahb_softc *sc = sclist[wlanNum];
11514 - 	struct net_device *dev;
11515 --	const char *sysType;
11516 - 	u_int16_t devid;
11517 - 
11518 - 	if (sc == NULL)
11519 -@@ -289,13 +288,17 @@
11520 - 	ath_detach(dev);
11521 - 	if (dev->irq)
11522 - 		free_irq(dev->irq, dev);
11523 --	sysType = get_system_type();
11524 --	if (!strcmp(sysType, "Atheros AR5315"))
11525 -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
11526 -+	devid = sc->aps_sc.devid;
11527 -+	config->tag = (unsigned long) devid;
11528 -+#else
11529 -+	if (!strcmp(get_system_type(), "Atheros AR5315"))
11530 - 		devid = (u_int16_t) (sysRegRead(AR5315_SREV) &
11531 - 			(AR5315_REV_MAJ_M | AR5315_REV_MIN_M));
11532 - 	else
11533 - 		devid = (u_int16_t) ((sysRegRead(AR531X_REV) >> 8) &
11534 - 			(AR531X_REV_MAJ | AR531X_REV_MIN));
11535 -+#endif
11536 - 
11537 - 	ahb_disable_wmac(devid, wlanNum);
11538 - 	free_netdev(dev);
11539 -@@ -401,7 +404,7 @@
11540 - 
11541 - static int ahb_wmac_remove(struct platform_device *pdev)
11542 - {
11543 --	exit_ath_wmac(pdev->id);
11544 -+	exit_ath_wmac(pdev->id, (struct ar531x_config *) pdev->dev.platform_data);
11545 - 
11546 - 	return 0;
11547 - }
11548 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/121-ibss_hostap.patch kamikaze_7.09/package/madwifi/patches/121-ibss_hostap.patch
11549 --- kamikaze_7.09.orig/package/madwifi/patches/121-ibss_hostap.patch	2007-09-20 10:54:59.000000000 +0200
11550 +++ kamikaze_7.09/package/madwifi/patches/121-ibss_hostap.patch	1970-01-01 01:00:00.000000000 +0100
11551 @@ -1,250 +0,0 @@
11552 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
11553 -===================================================================
11554 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:41.758359843 +0200
11555 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:42.258388337 +0200
11556 -@@ -410,7 +410,6 @@
11557 -  * and use the next two bits as the index of the VAP.
11558 -  */
11559 - #define ATH_SET_VAP_BSSID_MASK(bssid_mask)      ((bssid_mask)[0] &= ~(((ATH_BCBUF-1)<<2)|0x02))
11560 --#define ATH_GET_VAP_ID(bssid)                   ((bssid)[0] >> 2)
11561 - #define ATH_SET_VAP_BSSID(bssid, id) \
11562 - 		do { \
11563 - 			if (id) \
11564 -@@ -1055,9 +1054,12 @@
11565 - 			ic_opmode = opmode;
11566 - 		break;
11567 - 	case IEEE80211_M_IBSS:
11568 --		if (sc->sc_nvaps != 0)		/* only one */
11569 --			return NULL;
11570 --		ic_opmode = opmode;
11571 -+		if (sc->sc_nvaps == 0)		/* only one */
11572 -+			ic_opmode = opmode;
11573 -+		else
11574 -+			ic_opmode = IEEE80211_M_HOSTAP;
11575 -+
11576 -+		sc->sc_nibssvaps++;
11577 - 		break;
11578 - 	case IEEE80211_M_AHDEMO:
11579 - 	case IEEE80211_M_MONITOR:
11580 -@@ -1087,7 +1089,7 @@
11581 - 		return NULL;
11582 - 	}
11583 - 
11584 --	if (sc->sc_nvaps >= ATH_BCBUF) {
11585 -+	if (sc->sc_nvaps + sc->sc_nibssvaps >= ATH_BCBUF) {
11586 - 		printk(KERN_WARNING "too many virtual APs (already got %d)\n", sc->sc_nvaps);
11587 - 		return NULL;
11588 - 	}
11589 -@@ -1123,6 +1125,7 @@
11590 - 	if (opmode == IEEE80211_M_MONITOR)
11591 - 		dev->type = ARPHRD_IEEE80211_RADIOTAP;
11592 - 
11593 -+	avp->av_bslot = -1;
11594 - 	if ((flags & IEEE80211_CLONE_BSSID) &&
11595 - 	    opmode != IEEE80211_M_WDS && sc->sc_hasbmask) {
11596 - 		struct ieee80211vap *v;
11597 -@@ -1137,18 +1140,22 @@
11598 - 
11599 - 		/* do a full search to mark all the allocated VAPs */
11600 - 		id_mask = 0;
11601 --		TAILQ_FOREACH(v, &ic->ic_vaps, iv_next)
11602 --			id_mask |= (1 << ATH_GET_VAP_ID(v->iv_myaddr));
11603 -+		TAILQ_FOREACH(v, &ic->ic_vaps, iv_next) {
11604 -+			struct ath_vap *a = (struct ath_vap *) v->iv_dev->priv;
11605 -+			if (a->av_bslot >= 0)
11606 -+				id_mask |= (1 << a->av_bslot);
11607 -+		}
11608 - 
11609 --		for (id = 1; id < ATH_BCBUF; id++) {
11610 -+		/* IBSS mode has local always set, so don't hand out beacon slot 0 to an IBSS vap */
11611 -+		for (id = (opmode == IEEE80211_M_IBSS ? 1 : 0); id < ATH_BCBUF; id++) {
11612 - 			/* get the first available slot */
11613 - 			if ((id_mask & (1 << id)) == 0) {
11614 - 				ATH_SET_VAP_BSSID(vap->iv_myaddr, id);
11615 -+				avp->av_bslot = id;
11616 - 				break;
11617 - 			}
11618 - 		}
11619 - 	}
11620 --	avp->av_bslot = -1;
11621 - 	STAILQ_INIT(&avp->av_mcastq.axq_q);
11622 - 	ATH_TXQ_LOCK_INIT(&avp->av_mcastq);
11623 - 	if (opmode == IEEE80211_M_HOSTAP || opmode == IEEE80211_M_IBSS) {
11624 -@@ -1158,33 +1165,14 @@
11625 - 		 */
11626 - 		avp->av_bcbuf = STAILQ_FIRST(&sc->sc_bbuf);
11627 - 		STAILQ_REMOVE_HEAD(&sc->sc_bbuf, bf_list);
11628 --		if (opmode == IEEE80211_M_HOSTAP || !sc->sc_hasveol) {
11629 -+		if ((opmode == IEEE80211_M_IBSS) || (opmode == IEEE80211_M_HOSTAP) || !sc->sc_hasveol) {
11630 - 			unsigned int slot;
11631 --			/*
11632 --			 * Assign the VAP to a beacon xmit slot.  As
11633 --			 * above, this cannot fail to find one.
11634 --			 */
11635 --			avp->av_bslot = 0;
11636 --			for (slot = 0; slot < ATH_BCBUF; slot++)
11637 --				if (sc->sc_bslot[slot] == NULL) {
11638 --					/*
11639 --					 * XXX hack, space out slots to better
11640 --					 * deal with misses
11641 --					 */
11642 --					if (slot + 1 < ATH_BCBUF &&
11643 --					    sc->sc_bslot[slot+1] == NULL) {
11644 --						avp->av_bslot = slot + 1;
11645 --						break;
11646 --					}
11647 --					avp->av_bslot = slot;
11648 --					/* NB: keep looking for a double slot */
11649 --				}
11650 - 			KASSERT(sc->sc_bslot[avp->av_bslot] == NULL,
11651 - 				("beacon slot %u not empty?", avp->av_bslot));
11652 - 			sc->sc_bslot[avp->av_bslot] = vap;
11653 - 			sc->sc_nbcnvaps++;
11654 - 		}
11655 --		if ((opmode == IEEE80211_M_HOSTAP) && (sc->sc_hastsfadd)) {
11656 -+		if ((sc->sc_opmode == IEEE80211_M_HOSTAP) && (sc->sc_hastsfadd)) {
11657 - 			/*
11658 - 			 * Multiple VAPs are to transmit beacons and we
11659 - 			 * have h/w support for TSF adjusting; enable use
11660 -@@ -1294,7 +1282,9 @@
11661 - 			sc->sc_stagbeacons = 0;
11662 - 	}
11663 - 
11664 --	if (vap->iv_opmode == IEEE80211_M_STA) {
11665 -+	if (vap->iv_opmode == IEEE80211_M_IBSS) {
11666 -+		sc->sc_nibssvaps--;
11667 -+	} else if (vap->iv_opmode == IEEE80211_M_STA) {
11668 - 		sc->sc_nstavaps--;
11669 - 		sc->sc_nostabeacons = 0;
11670 - 	} else if (vap->iv_opmode == IEEE80211_M_MONITOR)
11671 -@@ -3383,7 +3373,7 @@
11672 - 	    sc->sc_opmode == HAL_M_IBSS ||	/* NB: AHDEMO too */
11673 - 	    (sc->sc_nostabeacons) || sc->sc_scanning)
11674 - 		rfilt |= HAL_RX_FILTER_BEACON;
11675 --	if (sc->sc_nmonvaps > 0)
11676 -+	if ((sc->sc_nmonvaps > 0) || ((sc->sc_nvaps > 0) && (sc->sc_nibssvaps > 0)))
11677 - 		rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
11678 - 			  HAL_RX_FILTER_PROBEREQ | HAL_RX_FILTER_PROM);
11679 - 	return rfilt;
11680 -@@ -5832,12 +5822,20 @@
11681 - 			type = ieee80211_input(ni, skb, rs->rs_rssi, rs_tsf);
11682 - 			ieee80211_unref_node(&ni);
11683 - 		} else {
11684 -+			const struct ieee80211_frame_min *wh = (const struct ieee80211_frame_min *) skb->data;
11685 - 			/*
11686 - 			 * No key index or no entry, do a lookup and
11687 - 			 * add the node to the mapping table if possible.
11688 - 			 */
11689 --			ni = ieee80211_find_rxnode(ic,
11690 --				(const struct ieee80211_frame_min *) skb->data);
11691 -+			if (((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PROBE_REQ) &&
11692 -+					(sc->sc_nibssvaps > 0))
11693 -+				/* if this is a probe request, send it to all vaps
11694 -+				 * when looking up nodes, hostap will be preferred over ibss,
11695 -+				 * because ibss will catch all nodes */
11696 -+				ni = NULL;
11697 -+			else
11698 -+				ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
11699 -+
11700 - 			if (ni != NULL) {
11701 - 				struct ath_node *an = ATH_NODE(ni);
11702 - 				ieee80211_keyix_t keyix;
11703 -Index: madwifi-ng-r2568-20070710/ath/if_athvar.h
11704 -===================================================================
11705 ---- madwifi-ng-r2568-20070710.orig/ath/if_athvar.h	2007-07-23 01:48:38.006146018 +0200
11706 -+++ madwifi-ng-r2568-20070710/ath/if_athvar.h	2007-07-23 01:48:42.262388566 +0200
11707 -@@ -204,7 +204,7 @@
11708 - #define	ATH_RXBUF	40		/* number of RX buffers */
11709 - #define	ATH_TXBUF	200		/* number of TX buffers */
11710 - 
11711 --#define	ATH_BCBUF	4		/* number of beacon buffers */
11712 -+#define	ATH_BCBUF	8		/* number of beacon buffers */
11713 - 
11714 - /* free buffer threshold to restart net dev */
11715 - #define	ATH_TXBUF_FREE_THRESHOLD  (ATH_TXBUF / 20)
11716 -@@ -603,6 +603,7 @@
11717 - 	u_int16_t sc_nvaps;			/* # of active virtual APs */
11718 - 	u_int8_t sc_nstavaps;			/* # of active station VAPs */
11719 - 	u_int8_t sc_nmonvaps;			/* # of monitor VAPs */
11720 -+	u_int8_t sc_nibssvaps;			/* # of active ibss vaps */
11721 - 	u_int8_t sc_nbcnvaps;			/* # of vaps sending beacons */
11722 - 	u_int sc_fftxqmin;			/* aggregation threshold */
11723 - 	HAL_INT sc_imask;			/* interrupt mask copy */
11724 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_beacon.c
11725 -===================================================================
11726 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_beacon.c	2007-07-23 01:48:38.010146245 +0200
11727 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_beacon.c	2007-07-23 01:48:42.278389477 +0200
11728 -@@ -111,7 +111,7 @@
11729 - 	bo->bo_tim = frm;
11730 - 
11731 - 	/* IBSS/TIM */
11732 --	if (vap->iv_opmode == IEEE80211_M_IBSS) {
11733 -+	if (ic->ic_opmode == IEEE80211_M_IBSS) {
11734 - 		*frm++ = IEEE80211_ELEMID_IBSSPARMS;
11735 - 		*frm++ = 2;
11736 - 		*frm++ = 0; *frm++ = 0;		/* TODO: ATIM window */
11737 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
11738 -===================================================================
11739 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-23 01:48:38.018146699 +0200
11740 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-23 01:48:42.282389707 +0200
11741 -@@ -2981,7 +2981,13 @@
11742 - 			return;
11743 - 		}
11744 - 		if (ni == vap->iv_bss) {
11745 --			if (vap->iv_opmode == IEEE80211_M_IBSS) {
11746 -+			/* this probe request may have been sent to all vaps
11747 -+			 * to give each a chance of creating a node for this.
11748 -+			 * important for hostap+ibss mode */
11749 -+			ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
11750 -+			if (ni) {
11751 -+				allocbs = 0;
11752 -+			} else if (vap->iv_opmode == IEEE80211_M_IBSS) {
11753 - 				/*
11754 - 				 * XXX Cannot tell if the sender is operating
11755 - 				 * in ibss mode.  But we need a new node to
11756 -@@ -2990,12 +2996,13 @@
11757 - 				 */
11758 - 				ni = ieee80211_fakeup_adhoc_node(vap,
11759 - 					wh->i_addr2);
11760 -+				allocbs = 1;
11761 - 			} else {
11762 - 				ni = ieee80211_dup_bss(vap, wh->i_addr2, 1);
11763 -+				allocbs = 1;
11764 - 			}
11765 - 			if (ni == NULL)
11766 - 				return;
11767 --			allocbs = 1;
11768 - 		}
11769 - 
11770 - 		IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
11771 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
11772 -===================================================================
11773 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-23 01:48:41.230329754 +0200
11774 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-23 01:48:42.330392441 +0200
11775 -@@ -1084,8 +1084,25 @@
11776 - 	IEEE80211_NODE_TABLE_LOCK_ASSERT(nt);
11777 - 
11778 - 	hash = IEEE80211_NODE_HASH(macaddr);
11779 -+
11780 -+	/* look for non-ibss nodes first */
11781 -+	LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
11782 -+		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_vap->iv_opmode != IEEE80211_M_IBSS) {
11783 -+			ieee80211_ref_node(ni);	/* mark referenced */
11784 -+#ifdef IEEE80211_DEBUG_REFCNT
11785 -+			IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
11786 -+				"%s (%s:%u) %p<%s> refcnt %d\n", __func__,
11787 -+				func, line,
11788 -+				ni, ether_sprintf(ni->ni_macaddr),
11789 -+				ieee80211_node_refcnt(ni));
11790 -+#endif
11791 -+			return ni;
11792 -+		}
11793 -+	}
11794 -+
11795 -+	/* now look for ibss nodes */
11796 - 	LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
11797 --		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
11798 -+		if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_vap->iv_opmode == IEEE80211_M_IBSS) {
11799 - 			ieee80211_ref_node(ni);	/* mark referenced */
11800 - #ifdef IEEE80211_DEBUG_REFCNT
11801 - 			IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
11802 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/122-replayfail_workaround.patch kamikaze_7.09/package/madwifi/patches/122-replayfail_workaround.patch
11803 --- kamikaze_7.09.orig/package/madwifi/patches/122-replayfail_workaround.patch	2007-09-20 10:54:59.000000000 +0200
11804 +++ kamikaze_7.09/package/madwifi/patches/122-replayfail_workaround.patch	2008-06-19 17:34:17.000000000 +0200
11805 @@ -1,14 +1,12 @@
11806 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_linux.c
11807 -===================================================================
11808 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_linux.c	2007-07-23 01:48:37.914140773 +0200
11809 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_linux.c	2007-07-23 01:48:42.626409310 +0200
11810 -@@ -285,6 +285,9 @@
11811 +--- a/net80211/ieee80211_linux.c
11812 ++++ b/net80211/ieee80211_linux.c
11813 +@@ -331,6 +331,9 @@
11814   		k->wk_cipher->ic_name, k->wk_keyix,
11815 - 		(unsigned long long)rsc );
11816 + 		(unsigned long long)rsc);
11817   
11818  +	/* disabled for now due to bogus events for unknown reasons */
11819  +	return;
11820  +
11821   	/* TODO: needed parameters: count, keyid, key type, src address, TSC */
11822 - 	snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=%s)", tag,
11823 + 	snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=" MAC_FMT ")", tag,
11824   		k->wk_keyix,
11825 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/123-ccmp_checks.patch kamikaze_7.09/package/madwifi/patches/123-ccmp_checks.patch
11826 --- kamikaze_7.09.orig/package/madwifi/patches/123-ccmp_checks.patch	2007-09-20 10:54:59.000000000 +0200
11827 +++ kamikaze_7.09/package/madwifi/patches/123-ccmp_checks.patch	2008-06-19 17:34:17.000000000 +0200
11828 @@ -1,7 +1,5 @@
11829 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_ccmp.c
11830 -===================================================================
11831 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto_ccmp.c	2007-07-23 01:48:37.830135985 +0200
11832 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_ccmp.c	2007-07-23 01:48:42.870423216 +0200
11833 +--- a/net80211/ieee80211_crypto_ccmp.c
11834 ++++ b/net80211/ieee80211_crypto_ccmp.c
11835  @@ -475,6 +475,9 @@
11836   	uint8_t *mic, *pos;
11837   	u_int space;
11838 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/124-linux24_compat.patch kamikaze_7.09/package/madwifi/patches/124-linux24_compat.patch
11839 --- kamikaze_7.09.orig/package/madwifi/patches/124-linux24_compat.patch	2007-09-20 10:54:59.000000000 +0200
11840 +++ kamikaze_7.09/package/madwifi/patches/124-linux24_compat.patch	2008-06-19 17:34:17.000000000 +0200
11841 @@ -1,9 +1,7 @@
11842 -Index: madwifi-ng-r2568-20070710/ath/if_athvar.h
11843 -===================================================================
11844 ---- madwifi-ng-r2568-20070710.orig/ath/if_athvar.h	2007-07-23 01:48:42.262388566 +0200
11845 -+++ madwifi-ng-r2568-20070710/ath/if_athvar.h	2007-07-23 01:48:43.126437804 +0200
11846 -@@ -123,6 +123,11 @@
11847 - #define	NETDEV_TX_BUSY	1
11848 +--- a/ath/if_athvar.h
11849 ++++ b/ath/if_athvar.h
11850 +@@ -126,6 +126,11 @@
11851 + #define ATH_GET_NETDEV_DEV(ndev)	((ndev)->class_dev.dev)
11852   #endif
11853   
11854  +#ifndef NETDEV_TX_OK
11855 @@ -14,3 +12,191 @@
11856   #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23)
11857   static inline struct net_device *_alloc_netdev(int sizeof_priv, const char *mask,
11858   					       void (*setup)(struct net_device *))
11859 +--- a/ath/if_ath_radar.c
11860 ++++ b/ath/if_ath_radar.c
11861 +@@ -92,6 +92,13 @@
11862 + #define nofloat_pct(_value, _pct) \
11863 + 	( (_value * (1000 + _pct)) / 1000 )
11864 + 
11865 ++#ifndef list_for_each_entry_reverse
11866 ++#define list_for_each_entry_reverse(pos, head, member)			\
11867 ++	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
11868 ++	     prefetch(pos->member.prev), &pos->member != (head); 	\
11869 ++	     pos = list_entry(pos->member.prev, typeof(*pos), member))
11870 ++#endif
11871 ++
11872 + struct radar_pattern_specification {
11873 + 	/* The name of the rule/specification (i.e. what did we detect) */
11874 + 	const char *name;
11875 +--- a/ath/if_ath.c
11876 ++++ b/ath/if_ath.c
11877 +@@ -4705,6 +4705,46 @@
11878 + #undef USE_SHPREAMBLE
11879 + }
11880 + 
11881 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
11882 ++static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11883 ++{
11884 ++	int ret;
11885 ++	unsigned long flags;
11886 ++
11887 ++	local_irq_save(flags);
11888 ++	ret = v->counter;
11889 ++	if (likely(ret == old))
11890 ++		v->counter = new;
11891 ++	local_irq_restore(flags);
11892 ++
11893 ++	return ret;
11894 ++}
11895 ++
11896 ++/**
11897 ++ * atomic_add_unless - add unless the number is a given value
11898 ++ * @v: pointer of type atomic_t
11899 ++ * @a: the amount to add to v...
11900 ++ * @u: ...unless v is equal to u.
11901 ++ *
11902 ++ * Atomically adds @a to @v, so long as it was not @u.
11903 ++ * Returns non-zero if @v was not @u, and zero otherwise.
11904 ++ */
11905 ++static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
11906 ++{
11907 ++	int c, old;
11908 ++	c = atomic_read(v);
11909 ++	for (;;) {
11910 ++		if (unlikely(c == (u)))
11911 ++			break;
11912 ++		old = atomic_cmpxchg((v), c, c + (a));
11913 ++		if (likely(old == c))
11914 ++			break;
11915 ++		c = old;
11916 ++	}
11917 ++	return c != (u);
11918 ++}
11919 ++#endif
11920 ++
11921 + /*
11922 +  * Generate beacon frame and queue cab data for a VAP.
11923 +  */
11924 +--- /dev/null
11925 ++++ b/net80211/sort.c
11926 +@@ -0,0 +1,120 @@
11927 ++/*
11928 ++ * A fast, small, non-recursive O(nlog n) sort for the Linux kernel
11929 ++ *
11930 ++ * Jan 23 2005  Matt Mackall <mpm@selenic.com>
11931 ++ */
11932 ++
11933 ++#include <linux/kernel.h>
11934 ++#include <linux/module.h>
11935 ++#include <linux/slab.h>
11936 ++
11937 ++static void u32_swap(void *a, void *b, int size)
11938 ++{
11939 ++	u32 t = *(u32 *)a;
11940 ++	*(u32 *)a = *(u32 *)b;
11941 ++	*(u32 *)b = t;
11942 ++}
11943 ++
11944 ++static void generic_swap(void *a, void *b, int size)
11945 ++{
11946 ++	char t;
11947 ++
11948 ++	do {
11949 ++		t = *(char *)a;
11950 ++		*(char *)a++ = *(char *)b;
11951 ++		*(char *)b++ = t;
11952 ++	} while (--size > 0);
11953 ++}
11954 ++
11955 ++/**
11956 ++ * sort - sort an array of elements
11957 ++ * @base: pointer to data to sort
11958 ++ * @num: number of elements
11959 ++ * @size: size of each element
11960 ++ * @cmp: pointer to comparison function
11961 ++ * @swap: pointer to swap function or NULL
11962 ++ *
11963 ++ * This function does a heapsort on the given array. You may provide a
11964 ++ * swap function optimized to your element type.
11965 ++ *
11966 ++ * Sorting time is O(n log n) both on average and worst-case. While
11967 ++ * qsort is about 20% faster on average, it suffers from exploitable
11968 ++ * O(n*n) worst-case behavior and extra memory requirements that make
11969 ++ * it less suitable for kernel use.
11970 ++ */
11971 ++
11972 ++static void sort(void *base, size_t num, size_t size,
11973 ++	  int (*cmp)(const void *, const void *),
11974 ++	  void (*swap)(void *, void *, int size))
11975 ++{
11976 ++	/* pre-scale counters for performance */
11977 ++	int i = (num/2 - 1) * size, n = num * size, c, r;
11978 ++
11979 ++	if (!swap)
11980 ++		swap = (size == 4 ? u32_swap : generic_swap);
11981 ++
11982 ++	/* heapify */
11983 ++	for ( ; i >= 0; i -= size) {
11984 ++		for (r = i; r * 2 + size < n; r  = c) {
11985 ++			c = r * 2 + size;
11986 ++			if (c < n - size && cmp(base + c, base + c + size) < 0)
11987 ++				c += size;
11988 ++			if (cmp(base + r, base + c) >= 0)
11989 ++				break;
11990 ++			swap(base + r, base + c, size);
11991 ++		}
11992 ++	}
11993 ++
11994 ++	/* sort */
11995 ++	for (i = n - size; i >= 0; i -= size) {
11996 ++		swap(base, base + i, size);
11997 ++		for (r = 0; r * 2 + size < i; r = c) {
11998 ++			c = r * 2 + size;
11999 ++			if (c < i - size && cmp(base + c, base + c + size) < 0)
12000 ++				c += size;
12001 ++			if (cmp(base + r, base + c) >= 0)
12002 ++				break;
12003 ++			swap(base + r, base + c, size);
12004 ++		}
12005 ++	}
12006 ++}
12007 ++
12008 ++EXPORT_SYMBOL(sort);
12009 ++
12010 ++#if 0
12011 ++/* a simple boot-time regression test */
12012 ++
12013 ++int cmpint(const void *a, const void *b)
12014 ++{
12015 ++	return *(int *)a - *(int *)b;
12016 ++}
12017 ++
12018 ++static int sort_test(void)
12019 ++{
12020 ++	int *a, i, r = 1;
12021 ++
12022 ++	a = kmalloc(1000 * sizeof(int), GFP_KERNEL);
12023 ++	BUG_ON(!a);
12024 ++
12025 ++	printk("testing sort()\n");
12026 ++
12027 ++	for (i = 0; i < 1000; i++) {
12028 ++		r = (r * 725861) % 6599;
12029 ++		a[i] = r;
12030 ++	}
12031 ++
12032 ++	sort(a, 1000, sizeof(int), cmpint, NULL);
12033 ++
12034 ++	for (i = 0; i < 999; i++)
12035 ++		if (a[i] > a[i+1]) {
12036 ++			printk("sort() failed!\n");
12037 ++			break;
12038 ++		}
12039 ++
12040 ++	kfree(a);
12041 ++
12042 ++	return 0;
12043 ++}
12044 ++
12045 ++module_init(sort_test);
12046 ++#endif
12047 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/125-tpc_PR_1435.patch kamikaze_7.09/package/madwifi/patches/125-tpc_PR_1435.patch
12048 --- kamikaze_7.09.orig/package/madwifi/patches/125-tpc_PR_1435.patch	2007-09-20 10:54:59.000000000 +0200
12049 +++ kamikaze_7.09/package/madwifi/patches/125-tpc_PR_1435.patch	1970-01-01 01:00:00.000000000 +0100
12050 @@ -1,100 +0,0 @@
12051 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12052 -===================================================================
12053 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:42.258388337 +0200
12054 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:43.370451713 +0200
12055 -@@ -273,9 +273,7 @@
12056 - static char *autocreate = NULL;
12057 - static char *ratectl = DEF_RATE_CTL;
12058 - static int rfkill = 0;
12059 --#ifdef ATH_CAP_TPC
12060 - static int tpc = 0;
12061 --#endif
12062 - static int countrycode = -1;
12063 - static int outdoor = -1;
12064 - static int xchanmode = -1;
12065 -@@ -533,12 +531,6 @@
12066 - 		rfkill ? "on" : "off");
12067 - 	ath_hal_setrfsilent(ah, rfkill);
12068 - 
12069 --#ifdef ATH_CAP_TPC
12070 --	printk(KERN_INFO "ath_pci: ath_pci: switching per-packet transmit power control %s\n",
12071 --		tpc ? "on" : "off");
12072 --	ath_hal_settpc(ah, tpc);
12073 --#endif
12074 --
12075 - 	/*
12076 - 	 * Setup rate tables for all potential media types.
12077 - 	 */
12078 -@@ -818,11 +810,18 @@
12079 - 	 */
12080 - #ifdef ATH_CAP_TPC
12081 - 	sc->sc_hastpc = ath_hal_hastpc(ah);
12082 --	if (sc->sc_hastpc || ath_hal_hastxpowlimit(ah))
12083 -+	if(tpc && !sc->sc_hastpc) {
12084 -+		printk(KERN_WARNING "ath_pci: WARNING: per-packet transmit power control was requested, but is not supported by the hardware.\n");
12085 -+		tpc = 0;
12086 -+	}
12087 -+	printk(KERN_INFO "ath_pci: switching per-packet transmit power control %s\n",
12088 -+		tpc ? "on" : "off");
12089 -+	ath_hal_settpc(ah, tpc);
12090 - #else
12091 - 	sc->sc_hastpc = 0;
12092 --	if (ath_hal_hastxpowlimit(ah))
12093 -+	tpc = 0; /* TPC is always zero, when compiled without ATH_CAP_TPC */
12094 - #endif
12095 -+	if (sc->sc_hastpc || ath_hal_hastxpowlimit(ah))
12096 - 		ic->ic_caps |= IEEE80211_C_TXPMGT;
12097 - 
12098 - 	/*
12099 -@@ -1836,7 +1835,7 @@
12100 - 	ath_stop_locked(dev);
12101 - 
12102 - #ifdef ATH_CAP_TPC
12103 --	/* Re-enable after suspend (?) */
12104 -+	/* Re-enable after suspend */
12105 - 	ath_hal_settpc(ah, tpc);
12106 - #endif
12107 - 
12108 -@@ -8787,26 +8786,16 @@
12109 - 	 * Search for the VAP that needs a txpow change, if any
12110 - 	 */
12111 - 	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
12112 --#ifdef ATH_CAP_TPC
12113 --		if (ic->ic_newtxpowlimit == vap->iv_bss->ni_txpower) {
12114 -+		if (!tpc || ic->ic_newtxpowlimit >= vap->iv_bss->ni_txpower) {
12115 - 			vap->iv_bss->ni_txpower = clamped_txpow;
12116 - 			ieee80211_iterate_nodes(&vap->iv_ic->ic_sta, set_node_txpower, &clamped_txpow);
12117 - 		}
12118 --#else
12119 --		vap->iv_bss->ni_txpower = clamped_txpow;
12120 --		ieee80211_iterate_nodes(&vap->iv_ic->ic_sta, set_node_txpower, &clamped_txpow);
12121 --#endif
12122 - 	}
12123 - 
12124 --	ic->ic_newtxpowlimit = sc->sc_curtxpow = clamped_txpow;
12125 -+	sc->sc_curtxpow = clamped_txpow;
12126 - 
12127 --#ifdef ATH_CAP_TPC
12128 --	if (ic->ic_newtxpowlimit >= txpowlimit)
12129 --		ath_hal_settxpowlimit(ah, ic->ic_newtxpowlimit);
12130 --#else
12131 --	if (ic->ic_newtxpowlimit != txpowlimit)
12132 --		ath_hal_settxpowlimit(ah, ic->ic_newtxpowlimit);
12133 --#endif
12134 -+	if (clamped_txpow != txpowlimit)
12135 -+		ath_hal_settxpowlimit(ah, clamped_txpow);
12136 - }
12137 - 
12138 - 
12139 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_wireless.c
12140 -===================================================================
12141 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_wireless.c	2007-07-23 01:48:37.670126869 +0200
12142 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_wireless.c	2007-07-23 01:48:43.374451939 +0200
12143 -@@ -1403,6 +1403,7 @@
12144 - 	} else {
12145 - 		if (!fixed)		/* no change */
12146 - 			return 0;
12147 -+		ic->ic_newtxpowlimit = IEEE80211_TXPOWER_MAX;
12148 - 		ic->ic_flags &= ~IEEE80211_F_TXPOW_FIXED;
12149 - 	}
12150 - done:
12151 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/126-rxerr_frames.patch kamikaze_7.09/package/madwifi/patches/126-rxerr_frames.patch
12152 --- kamikaze_7.09.orig/package/madwifi/patches/126-rxerr_frames.patch	2007-09-20 10:54:59.000000000 +0200
12153 +++ kamikaze_7.09/package/madwifi/patches/126-rxerr_frames.patch	2008-06-19 17:34:17.000000000 +0200
12154 @@ -1,10 +1,8 @@
12155 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12156 -===================================================================
12157 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:43.370451713 +0200
12158 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:43.690469948 +0200
12159 -@@ -5711,8 +5711,9 @@
12160 +--- a/ath/if_ath.c
12161 ++++ b/ath/if_ath.c
12162 +@@ -6474,8 +6474,9 @@
12163   			/*
12164 - 			 * Reject error frames if we have no vaps that 
12165 + 			 * Reject error frames if we have no vaps that
12166   			 * are operating in monitor mode.
12167  +			 * Reject empty frames as well
12168   			 */
12169 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/127-beacon_node.patch kamikaze_7.09/package/madwifi/patches/127-beacon_node.patch
12170 --- kamikaze_7.09.orig/package/madwifi/patches/127-beacon_node.patch	2007-09-20 10:54:59.000000000 +0200
12171 +++ kamikaze_7.09/package/madwifi/patches/127-beacon_node.patch	1970-01-01 01:00:00.000000000 +0100
12172 @@ -1,13 +0,0 @@
12173 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12174 -===================================================================
12175 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:43.690469948 +0200
12176 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:43.942484311 +0200
12177 -@@ -4027,6 +4027,8 @@
12178 - 	}
12179 - 	bf = avp->av_bcbuf;
12180 - 	ni = bf->bf_node;
12181 -+	if (!ni)
12182 -+		return NULL;
12183 - 
12184 - #ifdef ATH_SUPERG_DYNTURBO
12185 - 	/* 
12186 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/128-adhoc_memleak.patch kamikaze_7.09/package/madwifi/patches/128-adhoc_memleak.patch
12187 --- kamikaze_7.09.orig/package/madwifi/patches/128-adhoc_memleak.patch	2007-09-20 10:54:59.000000000 +0200
12188 +++ kamikaze_7.09/package/madwifi/patches/128-adhoc_memleak.patch	1970-01-01 01:00:00.000000000 +0100
12189 @@ -1,26 +0,0 @@
12190 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
12191 -===================================================================
12192 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-24 00:01:54.068861828 +0200
12193 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-24 00:02:44.035709278 +0200
12194 -@@ -2875,7 +2875,7 @@
12195 - 		}
12196 - 		if ((vap->iv_opmode == IEEE80211_M_IBSS) && 
12197 - 				(scan.capinfo & IEEE80211_CAPINFO_IBSS)) {
12198 --			if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
12199 -+			if (ni == vap->iv_bss) {
12200 - 				/* Create a new entry in the neighbor table. */
12201 - 				ni = ieee80211_add_neighbor(vap, wh, &scan);
12202 - 			} else {
12203 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
12204 -===================================================================
12205 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-24 00:02:51.284122342 +0200
12206 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-24 00:03:04.540877800 +0200
12207 -@@ -1205,7 +1205,7 @@
12208 - 	struct ieee80211com *ic = vap->iv_ic;
12209 - 	struct ieee80211_node *ni;
12210 - 
12211 --	ni = ieee80211_dup_bss(vap, wh->i_addr2, 1);
12212 -+	ni = ieee80211_dup_bss(vap, wh->i_addr2, 0);
12213 - 	if (ni != NULL) {
12214 - 		ni->ni_esslen = sp->ssid[1];
12215 - 		memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]);
12216 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/129-rxant_r2591.patch kamikaze_7.09/package/madwifi/patches/129-rxant_r2591.patch
12217 --- kamikaze_7.09.orig/package/madwifi/patches/129-rxant_r2591.patch	2007-09-20 10:54:59.000000000 +0200
12218 +++ kamikaze_7.09/package/madwifi/patches/129-rxant_r2591.patch	1970-01-01 01:00:00.000000000 +0100
12219 @@ -1,14 +0,0 @@
12220 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12221 -===================================================================
12222 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-25 16:02:49.730126121 +0200
12223 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-25 16:03:20.355871384 +0200
12224 -@@ -1882,6 +1882,9 @@
12225 - 	 */
12226 - 	ath_update_txpow(sc);
12227 - 
12228 -+	/* Set the default RX antenna; it may get lost on reset. */
12229 -+	ath_setdefantenna(sc, sc->sc_defant);
12230 -+
12231 - 	/*
12232 - 	 * Setup the hardware after reset: the key cache
12233 - 	 * is filled as needed and the receive engine is
12234 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/131-minstrel_rateidx.patch kamikaze_7.09/package/madwifi/patches/131-minstrel_rateidx.patch
12235 --- kamikaze_7.09.orig/package/madwifi/patches/131-minstrel_rateidx.patch	2007-09-20 10:54:59.000000000 +0200
12236 +++ kamikaze_7.09/package/madwifi/patches/131-minstrel_rateidx.patch	1970-01-01 01:00:00.000000000 +0100
12237 @@ -1,17 +0,0 @@
12238 -Index: madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c
12239 -===================================================================
12240 ---- madwifi-ng-r2568-20070710.orig/ath_rate/minstrel/minstrel.c	2007-08-11 02:08:15.931956005 +0200
12241 -+++ madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c	2007-08-11 02:09:37.572608440 +0200
12242 -@@ -675,6 +675,12 @@
12243 - 		}
12244 - 
12245 - 		for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
12246 -+			if (sn->rates[x].rix == 0xff) {
12247 -+				DPRINTF(sc, "%s: %s ignore bogus rix at %d\n",
12248 -+					dev_info, __func__, x);
12249 -+				continue;
12250 -+			}
12251 -+
12252 - 			sn->rs_rateattempts	[x] = 0;
12253 - 			sn->rs_thisprob		[x] = 0;
12254 - 			sn->rs_ratesuccess 	[x] = 0;
12255 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/200-no_debug.patch kamikaze_7.09/package/madwifi/patches/200-no_debug.patch
12256 --- kamikaze_7.09.orig/package/madwifi/patches/200-no_debug.patch	2007-09-20 10:54:59.000000000 +0200
12257 +++ kamikaze_7.09/package/madwifi/patches/200-no_debug.patch	2008-06-19 17:34:17.000000000 +0200
12258 @@ -1,112 +1,160 @@
12259 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12260 -===================================================================
12261 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:43.942484311 +0200
12262 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:44.466514171 +0200
12263 -@@ -75,7 +75,7 @@
12264 - #include <net80211/if_llc.h>
12265 - #endif
12266 - 
12267 +--- a/ath/if_ath.c
12268 ++++ b/ath/if_ath.c
12269 +@@ -42,7 +42,6 @@
12270 +  * This software is derived from work of Atsushi Onoe; his contribution
12271 +  * is greatly appreciated.
12272 +  */
12273  -#define	AR_DEBUG
12274 -+#undef	AR_DEBUG
12275 + #include "if_ath_debug.h"
12276 + #include "opt_ah.h"
12277   
12278 - #include "net80211/if_athproto.h"
12279 - #include "if_athvar.h"
12280 -Index: madwifi-ng-r2568-20070710/ath_rate/amrr/amrr.c
12281 -===================================================================
12282 ---- madwifi-ng-r2568-20070710.orig/ath_rate/amrr/amrr.c	2007-07-23 01:48:37.298105667 +0200
12283 -+++ madwifi-ng-r2568-20070710/ath_rate/amrr/amrr.c	2007-07-23 01:48:44.470514400 +0200
12284 -@@ -70,7 +70,7 @@
12285 +@@ -368,8 +367,10 @@
12286 + static void ath_set_dfs_cac_time(struct ieee80211com *, unsigned int seconds);
12287 + 
12288 + static unsigned int ath_test_radar(struct ieee80211com *);
12289 +-static unsigned int ath_dump_hal_map(struct ieee80211com *ic);
12290 ++#ifdef AR_DEBUG
12291 + 
12292 ++static unsigned int ath_dump_hal_map(struct ieee80211com *ic);
12293 ++#endif
12294 + static u_int32_t ath_get_clamped_maxtxpower(struct ath_softc *sc);
12295 + static u_int32_t ath_set_clamped_maxtxpower(struct ath_softc *sc, 
12296 + 		u_int32_t new_clamped_maxtxpower);
12297 +@@ -520,9 +521,11 @@
12298 + 	u_int8_t csz;
12299 + 
12300 + 	sc->devid = devid;
12301 ++#ifdef AR_DEBUG
12302 + 	ath_debug_global = (ath_debug & ATH_DEBUG_GLOBAL);
12303 + 	sc->sc_debug 	 = (ath_debug & ~ATH_DEBUG_GLOBAL);
12304 + 	DPRINTF(sc, ATH_DEBUG_ANY, "%s: devid 0x%x\n", __func__, devid);
12305 ++#endif
12306 + 
12307 + 	/* Allocate space for dynamically determined maximum VAP count */
12308 + 	sc->sc_bslot = 
12309 +@@ -1038,8 +1041,9 @@
12310 + 	ic->ic_vap_delete = ath_vap_delete;
12311 + 
12312 + 	ic->ic_test_radar           = ath_test_radar;
12313 ++#ifdef AR_DEBUG
12314 + 	ic->ic_dump_hal_map	    = ath_dump_hal_map;
12315 +-
12316 ++#endif
12317 + 	ic->ic_set_dfs_testmode     = ath_set_dfs_testmode;
12318 + 	ic->ic_get_dfs_testmode     = ath_get_dfs_testmode;
12319 + 
12320 +@@ -1297,12 +1301,14 @@
12321 + 		/* If no default VAP debug flags are passed, allow a few to
12322 + 		 * transfer down from the driver to new VAPs so we can have load
12323 + 		 * time debugging for VAPs too. */
12324 ++#ifdef AR_DEBUG
12325 + 		vap->iv_debug = 0 |
12326 + 			((sc->sc_debug & ATH_DEBUG_RATE) ? IEEE80211_MSG_XRATE  : 0) | 
12327 + 			((sc->sc_debug & ATH_DEBUG_XMIT) ? IEEE80211_MSG_OUTPUT : 0) | 
12328 + 			((sc->sc_debug & ATH_DEBUG_RECV) ? IEEE80211_MSG_INPUT  : 0) |
12329 + 			0
12330 + 			;
12331 ++#endif
12332 + 	}
12333 + 	ic->ic_debug = (sc->sc_default_ieee80211_debug & IEEE80211_MSG_IC);
12334 + 
12335 +@@ -10496,9 +10502,11 @@
12336 + 				/* XXX validate? */
12337 + 				sc->sc_ledpin = val;
12338 + 				break;
12339 ++#ifdef AR_DEBUG
12340 + 			case ATH_DEBUG:
12341 + 				sc->sc_debug 	 = (val & ~ATH_DEBUG_GLOBAL);
12342 + 				ath_debug_global = (val &  ATH_DEBUG_GLOBAL);
12343 ++#endif
12344 + 				break;
12345 + 			case ATH_TXANTENNA:
12346 + 				/*
12347 +@@ -10918,9 +10926,11 @@
12348 + 	}
12349 + 
12350 + 	/* initialize values */
12351 ++#ifdef AR_DEBUG
12352 + 	ath_debug_global = (ath_debug & ATH_DEBUG_GLOBAL);
12353 + 	sc->sc_debug 	 = (ath_debug & ~ATH_DEBUG_GLOBAL);
12354 + 	sc->sc_default_ieee80211_debug = ieee80211_debug;
12355 ++#endif
12356 + 	sc->sc_txantenna = 0;		/* default to auto-selection */
12357 + 	sc->sc_txintrperiod = ATH_TXQ_INTR_PERIOD;
12358 + }
12359 +@@ -11762,6 +11772,7 @@
12360 + }
12361 + 
12362 + /* This is called by a private ioctl (iwpriv) to dump the HAL obfuscation table */
12363 ++#ifdef AR_DEBUG
12364 + static unsigned int
12365 + ath_dump_hal_map(struct ieee80211com *ic)
12366 + {
12367 +@@ -11770,7 +11781,7 @@
12368 + 	ath_hal_dump_map(sc->sc_ah);
12369 + 	return 0;
12370 + }
12371 +-
12372 ++#endif
12373 + /* If we are shutting down or blowing off the DFS channel availability check
12374 +  * then we call this to stop the behavior before we take the rest of the
12375 +  * necessary actions (such as a DFS reaction to radar). */
12376 +--- a/ath_rate/amrr/amrr.c
12377 ++++ b/ath_rate/amrr/amrr.c
12378 +@@ -70,7 +70,9 @@
12379   
12380   #include "amrr.h"
12381   
12382 --#define	AMRR_DEBUG
12383 -+#undef	AMRR_DEBUG
12384 ++#ifdef AR_DEBUG
12385 + #define	AMRR_DEBUG
12386 ++#endif
12387   #ifdef AMRR_DEBUG
12388   #define	DPRINTF(sc, _fmt, ...) do {					\
12389   	if (sc->sc_debug & 0x10)					\
12390 -Index: madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c
12391 -===================================================================
12392 ---- madwifi-ng-r2568-20070710.orig/ath_rate/minstrel/minstrel.c	2007-07-23 01:48:40.974315165 +0200
12393 -+++ madwifi-ng-r2568-20070710/ath_rate/minstrel/minstrel.c	2007-07-23 01:48:44.494515770 +0200
12394 -@@ -117,7 +117,7 @@
12395 +--- a/ath_rate/minstrel/minstrel.c
12396 ++++ b/ath_rate/minstrel/minstrel.c
12397 +@@ -117,7 +117,9 @@
12398   
12399   #include "minstrel.h"
12400   
12401 --#define	MINSTREL_DEBUG
12402 -+#undef	MINSTREL_DEBUG
12403 ++#ifdef AR_DEBUG
12404 + #define	MINSTREL_DEBUG
12405 ++#endif
12406   #ifdef MINSTREL_DEBUG
12407   enum {
12408   		ATH_DEBUG_RATE		= 0x00000010	/* rate control */
12409 -Index: madwifi-ng-r2568-20070710/ath_rate/onoe/onoe.c
12410 -===================================================================
12411 ---- madwifi-ng-r2568-20070710.orig/ath_rate/onoe/onoe.c	2007-07-23 01:48:37.314106578 +0200
12412 -+++ madwifi-ng-r2568-20070710/ath_rate/onoe/onoe.c	2007-07-23 01:48:44.518517136 +0200
12413 -@@ -66,7 +66,7 @@
12414 +--- a/ath_rate/onoe/onoe.c
12415 ++++ b/ath_rate/onoe/onoe.c
12416 +@@ -66,7 +66,9 @@
12417   
12418   #include "onoe.h"
12419   
12420 --#define	ONOE_DEBUG
12421 -+#undef	ONOE_DEBUG
12422 ++#ifdef AR_DEBUG
12423 + #define	ONOE_DEBUG
12424 ++#endif
12425   #ifdef ONOE_DEBUG
12426   enum {
12427   	ATH_DEBUG_RATE	= 0x00000010,	/* rate control */
12428 -Index: madwifi-ng-r2568-20070710/ath_rate/sample/sample.c
12429 -===================================================================
12430 ---- madwifi-ng-r2568-20070710.orig/ath_rate/sample/sample.c	2007-07-23 01:48:37.322107035 +0200
12431 -+++ madwifi-ng-r2568-20070710/ath_rate/sample/sample.c	2007-07-23 01:48:44.546518731 +0200
12432 -@@ -68,7 +68,7 @@
12433 +--- a/ath_rate/sample/sample.c
12434 ++++ b/ath_rate/sample/sample.c
12435 +@@ -68,7 +68,9 @@
12436   
12437   #include "sample.h"
12438   
12439  -#define	SAMPLE_DEBUG
12440 -+#undef	SAMPLE_DEBUG
12441 ++#ifdef AR_DEBUG
12442 ++#define SAMPLE_DEBUG
12443 ++#endif
12444   #ifdef SAMPLE_DEBUG
12445   enum {
12446 - 	ATH_DEBUG_NODE		= 0x00080000,	/* node management */
12447 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c
12448 -===================================================================
12449 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_proto.c	2007-07-23 01:48:37.330107492 +0200
12450 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c	2007-07-23 01:48:44.570520097 +0200
12451 -@@ -286,6 +286,7 @@
12452 - }
12453 - EXPORT_SYMBOL(ieee80211_aclator_get);
12454 - 
12455 -+#ifdef IEEE80211_DEBUG
12456 - void
12457 - ieee80211_print_essid(const u_int8_t *essid, int len)
12458 - {
12459 -@@ -312,7 +313,6 @@
12460 - }
12461 - EXPORT_SYMBOL(ieee80211_print_essid);
12462 - 
12463 --#ifdef IEEE80211_DEBUG
12464 - void
12465 - ieee80211_dump_pkt(struct ieee80211com *ic,
12466 - 	const u_int8_t *buf, int len, int rate, int rssi)
12467 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_var.h
12468 -===================================================================
12469 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_var.h	2007-07-23 01:48:37.338107946 +0200
12470 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_var.h	2007-07-23 01:48:44.622523064 +0200
12471 -@@ -35,8 +35,8 @@
12472 - #ifndef _NET80211_IEEE80211_VAR_H_
12473 - #define _NET80211_IEEE80211_VAR_H_
12474 - 
12475 --#define	IEEE80211_DEBUG
12476 --#define	IEEE80211_DEBUG_REFCNT			/* Node reference count debugging */
12477 -+#undef	IEEE80211_DEBUG
12478 -+#undef	IEEE80211_DEBUG_REFCNT			/* Node reference count debugging */
12479 - 
12480 - /* Definitions for IEEE 802.11 drivers. */
12481 - #include <net80211/ieee80211_linux.h>
12482 -Index: madwifi-ng-r2568-20070710/tools/do_multi.c
12483 -===================================================================
12484 ---- madwifi-ng-r2568-20070710.orig/tools/do_multi.c	2007-07-23 01:48:39.754245634 +0200
12485 -+++ madwifi-ng-r2568-20070710/tools/do_multi.c	2007-07-23 01:48:44.650524656 +0200
12486 + 	ATH_DEBUG_RATE		= 0x00000010,	/* rate control */
12487 +--- a/tools/do_multi.c
12488 ++++ b/tools/do_multi.c
12489  @@ -9,16 +9,20 @@
12490   
12491       progname = basename(argv[0]);
12492   
12493 -+#if 0
12494 ++#ifdef AR_DEBUG
12495       if(strcmp(progname, "80211debug") == 0)
12496   	ret = a80211debug_init(argc, argv);
12497  +#endif
12498 @@ -116,32 +164,199 @@
12499   	ret = athchans_init(argc, argv);
12500       if(strcmp(progname, "athctrl") == 0)
12501   	ret =  athctrl_init(argc, argv);
12502 -+#if 0
12503 ++#ifdef AR_DEBUG
12504       if(strcmp(progname, "athdebug") == 0)
12505   	ret =  athdebug_init(argc, argv);
12506  +#endif
12507       if(strcmp(progname, "athkey") == 0)
12508   	ret =  athkey_init(argc, argv);
12509       if(strcmp(progname, "athstats") == 0)
12510 -Index: madwifi-ng-r2568-20070710/tools/Makefile
12511 -===================================================================
12512 ---- madwifi-ng-r2568-20070710.orig/tools/Makefile	2007-07-23 01:48:39.798248141 +0200
12513 -+++ madwifi-ng-r2568-20070710/tools/Makefile	2007-07-23 01:48:44.670525796 +0200
12514 -@@ -52,7 +52,7 @@
12515 - 	
12516 - ifdef DOMULTI
12517 - OBJS=	do_multi.o athstats.o 80211stats.o athkey.o athchans.o athctrl.o \
12518 --	athdebug.o 80211debug.o wlanconfig.o
12519 -+	wlanconfig.o
12520 - ALL=	${OBJS} madwifi_multi
12521 - endif
12522 - 
12523 -@@ -85,7 +85,7 @@
12524 - 	${CC} -c -o do_multi.o -DDOMULTI=1 ${ALL_CFLAGS} do_multi.c
12525 - madwifi_multi:
12526 - 	${CC} -o madwifi_multi ${LDFLAGS} ${OBJS}
12527 --	for i in athstats 80211stats athkey athchans athctrl athdebug wlanconfig 80211debug; do \
12528 -+	for i in athstats 80211stats athkey athchans athctrl wlanconfig; do \
12529 - 	ln -s -f madwifi_multi $$i; \
12530 - 	done
12531 +--- a/tools/Makefile
12532 ++++ b/tools/Makefile
12533 +@@ -48,6 +48,8 @@
12534 + 
12535 + all: compile
12536 + 
12537 ++DEBUG = -DAR_DEBUG
12538 ++
12539 + ALLPROGS=	athstats 80211stats athkey athchans athctrl \
12540 + 	athdebug 80211debug wlanconfig ath_info
12541 + 
12542 +@@ -55,7 +57,7 @@
12543 + 
12544 + INCS=	-I. -I../ath -I$(HAL) -I$(TOP) -I$(ATH_HAL)
12545 + CFLAGS=	-g -O2 -Wall
12546 +-ALL_CFLAGS= $(CFLAGS) $(INCS)
12547 ++ALL_CFLAGS= $(CFLAGS) $(INCS) $(DEBUG)
12548 + LDFLAGS=
12549 + 
12550 + 
12551 +--- a/net80211/ieee80211_linux.h
12552 ++++ b/net80211/ieee80211_linux.h
12553 +@@ -29,8 +29,6 @@
12554 + #ifndef _NET80211_IEEE80211_LINUX_H_
12555 + #define _NET80211_IEEE80211_LINUX_H_
12556 + 
12557 +-#define	IEEE80211_DEBUG
12558 +-#define	IEEE80211_DEBUG_REFCNT			/* Node reference count debugging */
12559 + /* #define ATH_DEBUG_SPINLOCKS */		/* announce before spinlocking */
12560 + 
12561 + #include <linux/wireless.h>
12562 +--- a/Makefile.inc
12563 ++++ b/Makefile.inc
12564 +@@ -148,7 +148,8 @@
12565 + TOOLS=  $(TOP)/tools 
12566 + 
12567 + WARNINGS = -Werror
12568 +-COPTS+= $(WARNINGS)
12569 ++DEBUG = -DAR_DEBUG -DIEEE80211_DEBUG
12570 ++COPTS+= $(WARNINGS) $(DEBUG)
12571 + INCS=	-include $(TOP)/include/compat.h -I$(TOP)/include
12572 + 
12573 + # TARGET defines the target platform architecture. It must match one of
12574 +--- a/ath/if_ath_radar.c
12575 ++++ b/ath/if_ath_radar.c
12576 +@@ -19,8 +19,6 @@
12577 +  * $Id: if_ath_radar.c 2464 2007-06-15 22:51:56Z mtaylor $
12578 +  */
12579 + #include "opt_ah.h"
12580 +-
12581 +-#define	AR_DEBUG
12582 + #include "if_ath_debug.h"
12583 + 
12584 + #ifndef AUTOCONF_INCLUDED
12585 +@@ -56,8 +54,6 @@
12586 + #include <net80211/if_llc.h>
12587 + #endif
12588 + 
12589 +-#define	AR_DEBUG
12590 +-
12591 + #include "net80211/if_athproto.h"
12592 + #include "if_athvar.h"
12593 + 
12594 +--- a/ath/if_ath_hal.h
12595 ++++ b/ath/if_ath_hal.h
12596 +@@ -1081,6 +1081,7 @@
12597 + 
12598 +            tail -f /var/log/messages | sed -f hal_unmangle.sed 
12599 +  */
12600 ++#ifdef AR_DEBUG
12601 + static inline void ath_hal_dump_map(struct ath_hal *ah)
12602 + {
12603 + #ifdef CONFIG_KALLSYMS
12604 +@@ -1345,7 +1346,7 @@
12605 + #endif				/* #ifndef CONFIG_KALLSYMS */
12606 + 
12607 + }
12608 +-
12609 ++#endif
12610 + #include "if_ath_hal_wrappers.h"
12611 + 
12612 + #endif				/* #ifndef _IF_ATH_HAL_H_ */
12613 +--- a/net80211/ieee80211_var.h
12614 ++++ b/net80211/ieee80211_var.h
12615 +@@ -492,9 +492,10 @@
12616 + 	/* inject a fake radar signal -- used while on a 802.11h DFS channels */
12617 + 	unsigned int (*ic_test_radar)(struct ieee80211com *);
12618 + 
12619 ++#ifdef AR_DEBUG
12620 + 	/* dump HAL */
12621 + 	unsigned int (*ic_dump_hal_map)(struct ieee80211com *);
12622 +-
12623 ++#endif
12624 + 	/* DFS channel availability check time (in seconds) */
12625 + 	void (*ic_set_dfs_cac_time)(struct ieee80211com *, unsigned int);
12626 + 	unsigned int (*ic_get_dfs_cac_time)(struct ieee80211com *);
12627 +--- a/net80211/ieee80211_wireless.c
12628 ++++ b/net80211/ieee80211_wireless.c
12629 +@@ -1548,6 +1548,7 @@
12630 + 	return 0;
12631 + }
12632 + 
12633 ++#ifdef AR_DEBUG
12634 + static int 
12635 + ieee80211_ioctl_hal_map(struct net_device *dev, struct iw_request_info *info,
12636 +        void *w, char *extra)
12637 +@@ -1558,7 +1559,7 @@
12638 +        params[0] = ic->ic_dump_hal_map(ic);
12639 +        return 0;
12640 + }
12641 +-
12642 ++#endif
12643 + 
12644 + static int
12645 + ieee80211_ioctl_radar(struct net_device *dev, struct iw_request_info *info,
12646 +@@ -5258,8 +5259,10 @@
12647 + 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,   "getwmmparams" },
12648 + 	{ IEEE80211_IOCTL_RADAR,
12649 + 	  0, 0, "doth_radar" },
12650 ++#ifdef AR_DEBUG
12651 + 	{ IEEE80211_IOCTL_HALMAP,
12652 + 	  0, 0, "dump_hal_map" },
12653 ++#endif
12654 + 	/*
12655 + 	 * These depends on sub-ioctl support which added in version 12.
12656 + 	 */
12657 +@@ -5695,7 +5698,9 @@
12658 + 	set_priv(IEEE80211_IOCTL_SETMLME, ieee80211_ioctl_setmlme),
12659 + 	set_priv(IEEE80211_IOCTL_SETKEY, ieee80211_ioctl_setkey),
12660 + 	set_priv(IEEE80211_IOCTL_DELKEY, ieee80211_ioctl_delkey),
12661 ++#ifdef AR_DEBUG
12662 + 	set_priv(IEEE80211_IOCTL_HALMAP, ieee80211_ioctl_hal_map),
12663 ++#endif
12664 + 	set_priv(IEEE80211_IOCTL_ADDMAC, ieee80211_ioctl_addmac),
12665 + 	set_priv(IEEE80211_IOCTL_DELMAC, ieee80211_ioctl_delmac),
12666 + 	set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsmac),
12667 +--- a/ath/if_ath_debug.h
12668 ++++ b/ath/if_ath_debug.h
12669 +@@ -68,13 +68,6 @@
12670 + 		ath_keyprint((_sc), __func__, _ix, _hk, _mac);		\
12671 + } while (0)
12672 + 
12673 +-#else /* #ifdef AR_DEBUG */
12674 +-
12675 +-#define	DFLAG_ISSET(sc, _m)		0
12676 +-#define	DPRINTF(sc, _m, _fmt, ...)
12677 +-#define	KEYPRINTF(sc, k, ix, mac)
12678 +-
12679 +-#endif /* #ifdef AR_DEBUG */
12680 + 
12681 + #define	IFF_DUMPPKTS(_sc, _m)   DFLAG_ISSET((_sc), (_m))
12682 + 
12683 +@@ -89,5 +82,15 @@
12684 + #define	IPRINTF(_sc, _fmt, ...) \
12685 + 		printk(KERN_INFO "%s: %s: " _fmt, \
12686 + 			SC_DEV_NAME(_sc), __func__, ## __VA_ARGS__)
12687 ++#else
12688 ++#define	DFLAG_ISSET(sc, _m)		0
12689 ++#define	DPRINTF(sc, _m, _fmt, ...)
12690 ++#define	KEYPRINTF(sc, k, ix, mac)
12691 ++#define EPRINTF(...)
12692 ++#define WPRINTF(...)
12693 ++#define IPRINTF(...)
12694 ++#define IFF_DUMPPKTS(...) 0
12695 ++
12696 ++#endif
12697 + 
12698 + #endif /* #ifndef _IF_ATH_DEBUG_H_ */
12699 +--- a/net80211/ieee80211_node.c
12700 ++++ b/net80211/ieee80211_node.c
12701 +@@ -920,6 +920,9 @@
12702 + 	ni->ni_rxkeyoff = 0;
12703 + }
12704 + 
12705 ++#ifndef IEEE80211_DEBUG
12706 ++#define node_print_message(...) do {} while(0)
12707 ++#else
12708 + static void node_print_message(
12709 + 		u_int32_t flags,
12710 + 		int show_counter, 
12711 +@@ -972,7 +975,7 @@
12712 + 			adjusted_refcount);
12713 + 	va_end(args);
12714 + }
12715 +-EXPORT_SYMBOL(node_print_message);
12716 ++#endif
12717   
12718 + static void
12719 + #ifdef IEEE80211_DEBUG_REFCNT
12720 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/201-debug_fix.patch kamikaze_7.09/package/madwifi/patches/201-debug_fix.patch
12721 --- kamikaze_7.09.orig/package/madwifi/patches/201-debug_fix.patch	1970-01-01 01:00:00.000000000 +0100
12722 +++ kamikaze_7.09/package/madwifi/patches/201-debug_fix.patch	2008-06-19 17:34:17.000000000 +0200
12723 @@ -0,0 +1,20 @@
12724 +--- a/ath_hal/ah_os.c
12725 ++++ b/ath_hal/ah_os.c
12726 +@@ -65,7 +65,7 @@
12727 + #include <ah_os.h>
12728 + 
12729 + #ifdef AH_DEBUG
12730 +-static	int ath_hal_debug = 0;
12731 ++static	int ath_hal_debug = 99;
12732 + #endif
12733 + 
12734 + int	ath_hal_dma_beacon_response_time = 2;	/* in TUs */
12735 +@@ -327,6 +327,8 @@
12736 +  * useful for debugging and figuring out, which hal function sets which 
12737 +  * registers */
12738 + char *ath_hal_func = NULL;
12739 ++EXPORT_SYMBOL(ath_hal_func);
12740 ++
12741 + #endif
12742 + 
12743 + /*
12744 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/300-napi_polling.patch kamikaze_7.09/package/madwifi/patches/300-napi_polling.patch
12745 --- kamikaze_7.09.orig/package/madwifi/patches/300-napi_polling.patch	2007-09-20 10:54:59.000000000 +0200
12746 +++ kamikaze_7.09/package/madwifi/patches/300-napi_polling.patch	2008-06-19 17:34:17.000000000 +0200
12747 @@ -1,58 +1,83 @@
12748 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
12749 -===================================================================
12750 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:44.466514171 +0200
12751 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:45.030546315 +0200
12752 -@@ -170,7 +170,7 @@
12753 - 	int, u_int64_t);
12754 +--- a/ath/if_ath.c
12755 ++++ b/ath/if_ath.c
12756 +@@ -184,7 +184,11 @@
12757 + 	struct sk_buff *, int, int, u_int64_t);
12758   static void ath_setdefantenna(struct ath_softc *, u_int);
12759   static struct ath_txq *ath_txq_setup(struct ath_softc *, int, int);
12760  -static void ath_rx_tasklet(TQUEUE_ARG);
12761 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12762 ++static int ath_rx_poll(struct napi_struct *napi, int budget);
12763 ++#else
12764  +static int ath_rx_poll(struct net_device *dev, int *budget);
12765 ++#endif
12766   static int ath_hardstart(struct sk_buff *, struct net_device *);
12767   static int ath_mgtstart(struct ieee80211com *, struct sk_buff *);
12768   #ifdef ATH_SUPERG_COMP
12769 -@@ -444,7 +444,6 @@
12770 - 	ATH_TXBUF_LOCK_INIT(sc);
12771 - 	ATH_RXBUF_LOCK_INIT(sc);
12772 +@@ -376,6 +380,9 @@
12773 + 		u_int32_t new_clamped_maxtxpower);
12774 + static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
12775 + 
12776 ++static void ath_poll_disable(struct net_device *dev);
12777 ++static void ath_poll_enable(struct net_device *dev);
12778 ++
12779 + /* calibrate every 30 secs in steady state but check every second at first. */
12780 + static int ath_calinterval = ATH_SHORT_CALINTERVAL;
12781 + static int ath_countrycode = CTRY_DEFAULT;	/* country code */
12782 +@@ -547,7 +554,6 @@
12783 + 
12784 + 	atomic_set(&sc->sc_txbuf_counter, 0);
12785   
12786  -	ATH_INIT_TQUEUE(&sc->sc_rxtq,     ath_rx_tasklet,	dev);
12787   	ATH_INIT_TQUEUE(&sc->sc_txtq,	  ath_tx_tasklet,	dev);
12788   	ATH_INIT_TQUEUE(&sc->sc_bmisstq,  ath_bmiss_tasklet,	dev);
12789   	ATH_INIT_TQUEUE(&sc->sc_bstucktq, ath_bstuck_tasklet,	dev);
12790 -@@ -691,6 +690,8 @@
12791 +@@ -821,6 +827,12 @@
12792   	dev->set_mac_address = ath_set_mac_address;
12793 -  	dev->change_mtu = ath_change_mtu;
12794 - 	dev->tx_queue_len = ATH_TXBUF - 1;		/* 1 for mgmt frame */
12795 + 	dev->change_mtu = ath_change_mtu;
12796 + 	dev->tx_queue_len = ATH_TXBUF - ATH_TXBUF_MGT_RESERVED;
12797 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12798 ++	netif_napi_add(dev, &sc->sc_napi, ath_rx_poll, 64);
12799 ++#else
12800  +	dev->poll = ath_rx_poll;
12801  +	dev->weight = 64;
12802 ++#endif
12803   #ifdef USE_HEADERLEN_RESV
12804   	dev->hard_header_len += sizeof(struct ieee80211_qosframe) +
12805   				sizeof(struct llc) +
12806 -@@ -1667,6 +1668,7 @@
12807 - 	 */
12808 - 	ath_hal_getisr(ah, &status);		/* NB: clears ISR too */
12809 - 	DPRINTF(sc, ATH_DEBUG_INTR, "%s: status 0x%x\n", __func__, status);
12810 +@@ -2216,6 +2228,7 @@
12811 + 		(status & HAL_INT_GLOBAL)	? " HAL_INT_GLOBAL"	: ""
12812 + 		);
12813 + 
12814  +	sc->sc_isr = status;
12815   	status &= sc->sc_imask;			/* discard unasked for bits */
12816 - 	if (status & HAL_INT_FATAL) {
12817 - 		sc->sc_stats.ast_hardware++;
12818 -@@ -1702,7 +1704,14 @@
12819 - 		if (status & HAL_INT_RX) {
12820 - 			sc->sc_tsf = ath_hal_gettsf64(ah);
12821 - 			ath_uapsd_processtriggers(sc);
12822 + 	/* As soon as we know we have a real interrupt we intend to service, 
12823 + 	 * we will check to see if we need an initial hardware TSF reading. 
12824 +@@ -2273,7 +2286,23 @@
12825 + 		}
12826 + 		if (status & (HAL_INT_RX | HAL_INT_RXPHY)) {
12827 + 			ath_uapsd_processtriggers(sc, hw_tsf);
12828  -			ATH_SCHEDULE_TQUEUE(&sc->sc_rxtq, &needmark);
12829  +			sc->sc_isr &= ~HAL_INT_RX;
12830 -+			if (netif_rx_schedule_prep(dev)) {
12831 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12832 ++			if (netif_rx_schedule_prep(dev, &sc->sc_napi))
12833 ++#else
12834 ++			if (netif_rx_schedule_prep(dev))
12835 ++#endif
12836 ++			{
12837  +#ifndef ATH_PRECISE_TSF
12838  +				sc->sc_imask &= ~HAL_INT_RX;
12839  +				ath_hal_intrset(ah, sc->sc_imask);
12840  +#endif
12841 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12842 ++				__netif_rx_schedule(dev, &sc->sc_napi);
12843 ++#else
12844  +				__netif_rx_schedule(dev);
12845 ++#endif
12846  +			}
12847   		}
12848   		if (status & HAL_INT_TX) {
12849   #ifdef ATH_SUPERG_DYNTURBO
12850 -@@ -1728,6 +1737,11 @@
12851 +@@ -2299,6 +2328,11 @@
12852   				}
12853   			}
12854   #endif
12855 @@ -64,75 +89,149 @@
12856   			ATH_SCHEDULE_TQUEUE(&sc->sc_txtq, &needmark);
12857   		}
12858   		if (status & HAL_INT_BMISS) {
12859 -@@ -3315,10 +3329,10 @@
12860 - 	 *
12861 - 	 * XXX Using in_softirq is not right since we might
12862 - 	 * be called from other soft irq contexts than
12863 --	 * ath_rx_tasklet.
12864 +@@ -2511,6 +2545,7 @@
12865 + 	if (sc->sc_tx99 != NULL)
12866 + 		sc->sc_tx99->start(sc->sc_tx99);
12867 + #endif
12868 ++	ath_poll_enable(dev);
12869 + 
12870 + done:
12871 + 	ATH_UNLOCK(sc);
12872 +@@ -2551,6 +2586,9 @@
12873 + 		if (sc->sc_tx99 != NULL)
12874 + 			sc->sc_tx99->stop(sc->sc_tx99);
12875 + #endif
12876 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12877 ++		ath_poll_disable(dev);
12878 ++#endif
12879 + 		netif_stop_queue(dev);	/* XXX re-enabled by ath_newstate */
12880 + 		dev->flags &= ~IFF_RUNNING;	/* NB: avoid recursion */
12881 + 		ieee80211_stop_running(ic);	/* stop all VAPs */
12882 +@@ -4009,6 +4047,39 @@
12883 + 	return ath_keyset(sc, k, mac, vap->iv_bss);
12884 + }
12885 + 
12886 ++static void ath_poll_disable(struct net_device *dev)
12887 ++{
12888 ++	struct ath_softc *sc = dev->priv;
12889 ++
12890 ++	/*
12891 ++	 * XXX Using in_softirq is not right since we might
12892 ++	 * be called from other soft irq contexts than
12893  +	 * ath_rx_poll
12894 ++	 */
12895 ++	if (!in_softirq()) {
12896 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12897 ++		napi_disable(&sc->sc_napi);
12898 ++#else
12899 ++		netif_poll_disable(dev);
12900 ++#endif
12901 ++	}
12902 ++}
12903 ++
12904 ++static void ath_poll_enable(struct net_device *dev)
12905 ++{
12906 ++	struct ath_softc *sc = dev->priv;
12907 ++
12908 ++	/* NB: see above */
12909 ++	if (!in_softirq()) {
12910 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12911 ++		napi_enable(&sc->sc_napi);
12912 ++#else
12913 ++		netif_poll_enable(dev);
12914 ++#endif
12915 ++	}
12916 ++}
12917 ++
12918 ++
12919 + /*
12920 +  * Block/unblock tx+rx processing while a key change is done.
12921 +  * We assume the caller serializes key management operations
12922 +@@ -4026,13 +4097,7 @@
12923 + 	 * When called from the rx tasklet we cannot use
12924 + 	 * tasklet_disable because it will block waiting
12925 + 	 * for us to complete execution.
12926 +-	 *
12927 +-	 * XXX Using in_softirq is not right since we might
12928 +-	 * be called from other soft irq contexts than
12929 +-	 * ath_rx_tasklet.
12930   	 */
12931 - 	if (!in_softirq())
12932 +-	if (!in_softirq())
12933  -		tasklet_disable(&sc->sc_rxtq);
12934 -+		netif_poll_disable(dev);
12935   	netif_stop_queue(dev);
12936   }
12937   
12938 -@@ -3331,7 +3345,7 @@
12939 - 	DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s:\n", __func__);
12940 - 	netif_start_queue(dev);
12941 - 	if (!in_softirq())		/* NB: see above */
12942 +@@ -4043,9 +4108,9 @@
12943 + 	struct ath_softc *sc = dev->priv;
12944 + 
12945 + 	DPRINTF(sc, ATH_DEBUG_KEYCACHE, "End\n");
12946 +-	netif_wake_queue(dev);
12947 +-	if (!in_softirq())		/* NB: see above */
12948  -		tasklet_enable(&sc->sc_rxtq);
12949 -+		netif_poll_enable(dev);
12950 ++
12951 ++	if (dev->flags&IFF_RUNNING)
12952 ++		netif_wake_queue(dev);
12953   }
12954   
12955   /*
12956 -@@ -5586,13 +5600,12 @@
12957 +@@ -6350,15 +6415,25 @@
12958   	sc->sc_rxotherant = 0;
12959   }
12960   
12961  -static void
12962  -ath_rx_tasklet(TQUEUE_ARG data)
12963  +static int
12964 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12965 ++ath_rx_poll(struct napi_struct *napi, int budget)
12966 ++#else
12967  +ath_rx_poll(struct net_device *dev, int *budget)
12968 ++#endif
12969   {
12970   #define	PA2DESC(_sc, _pa) \
12971   	((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
12972   		((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
12973  -	struct net_device *dev = (struct net_device *)data;
12974 - 	struct ath_buf *bf;
12975 +-	struct ath_buf *bf;
12976 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
12977 ++	struct ath_softc *sc = container_of(napi, struct ath_softc, sc_napi);
12978 ++	struct net_device *dev = sc->sc_dev;
12979 ++	u_int rx_limit = budget;
12980 ++#else
12981   	struct ath_softc *sc = dev->priv;
12982 ++	u_int rx_limit = min(dev->quota, *budget);
12983 ++#endif
12984 ++	struct ath_buf *bf;
12985   	struct ieee80211com *ic = &sc->sc_ic;
12986 -@@ -5605,12 +5618,15 @@
12987 + 	struct ath_hal *ah = sc ? sc->sc_ah : NULL;
12988 + 	struct ath_desc *ds;
12989 +@@ -6368,8 +6443,10 @@
12990 + 	unsigned int len;
12991   	int type;
12992   	u_int phyerr;
12993 - 	u_int64_t rs_tsf;
12994  +	u_int processed = 0, early_stop = 0;
12995 -+	u_int rx_limit = dev->quota;
12996   
12997 - 	/* Let the 802.11 layer know about the new noise floor */
12998 - 	sc->sc_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));
12999 - 	ic->ic_channoise = sc->sc_channoise;
13000 - 
13001 - 	DPRINTF(sc, ATH_DEBUG_RX_PROC, "%s\n", __func__);
13002 + 	DPRINTF(sc, ATH_DEBUG_RX_PROC, "invoked\n");
13003  +process_rx_again:
13004   	do {
13005   		bf = STAILQ_FIRST(&sc->sc_rxbuf);
13006   		if (bf == NULL) {		/* XXX ??? can this happen */
13007 -@@ -5634,6 +5650,13 @@
13008 +@@ -6393,6 +6470,15 @@
13009   			/* NB: never process the self-linked entry at the end */
13010   			break;
13011   		}
13012  +
13013 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
13014  +		processed++;
13015 ++#endif
13016  +		if (rx_limit-- < 0) {
13017  +			early_stop = 1;
13018  +			break;
13019  +		}
13020  +
13021   		skb = bf->bf_skb;
13022 - 		if (skb == NULL) {		/* XXX ??? can this happen */
13023 - 			printk("%s: no skbuff (%s)\n", DEV_NAME(dev), __func__);
13024 -@@ -5672,6 +5695,7 @@
13025 + 		if (skb == NULL) {
13026 + 			EPRINTF(sc, "Dropping; buffer contains NULL skbuff.\n");
13027 +@@ -6440,6 +6526,7 @@
13028   				sc->sc_stats.ast_rx_phyerr++;
13029   				phyerr = rs->rs_phyerr & 0x1f;
13030   				sc->sc_stats.ast_rx_phy[phyerr]++;
13031 @@ -140,43 +239,55 @@
13032   			}
13033   			if (rs->rs_status & HAL_RXERR_DECRYPT) {
13034   				/*
13035 -@@ -5889,9 +5913,33 @@
13036 +@@ -6635,9 +6722,43 @@
13037   		STAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
13038   		ATH_RXBUF_UNLOCK_IRQ(sc);
13039   	} while (ath_rxbuf_init(sc, bf) == 0);
13040  +	if (!early_stop) {
13041 ++		unsigned long flags;
13042  +		/* Check if more data is received while we were
13043  +		 * processing the descriptor chain.
13044  +		 */
13045  +#ifndef ATH_PRECISE_TSF
13046 -+		ATH_DISABLE_INTR();
13047 ++		local_irq_save(flags);
13048  +		if (sc->sc_isr & HAL_INT_RX) {
13049 ++			u_int64_t hw_tsf = ath_hal_gettsf64(ah);
13050  +			sc->sc_isr &= ~HAL_INT_RX;
13051 -+			ATH_ENABLE_INTR();
13052 -+			ath_uapsd_processtriggers(sc);
13053 ++			local_irq_restore(flags);
13054 ++			ath_uapsd_processtriggers(sc, hw_tsf);
13055  +			goto process_rx_again;
13056  +		}
13057  +#endif
13058 -+		netif_rx_complete(dev);
13059 -+
13060  +#ifndef ATH_PRECISE_TSF
13061  +		sc->sc_imask |= HAL_INT_RX;
13062  +		ath_hal_intrset(ah, sc->sc_imask);
13063 -+		ATH_ENABLE_INTR();
13064 ++		local_irq_restore(flags);
13065  +#endif
13066  +	}
13067  +
13068 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
13069 ++	netif_rx_complete(dev, napi);
13070 ++#else
13071 ++	netif_rx_complete(dev);
13072  +	*budget -= processed;
13073 ++	dev->quota -= processed;
13074 ++#endif
13075   
13076   	/* rx signal state monitoring */
13077   	ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
13078 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
13079 ++	return processed;
13080 ++#else
13081  +	return early_stop;
13082 ++#endif
13083   #undef PA2DESC
13084   }
13085   
13086 -@@ -7514,11 +7562,22 @@
13087 +@@ -8288,12 +8409,24 @@
13088 + {
13089   	struct net_device *dev = (struct net_device *)data;
13090   	struct ath_softc *sc = dev->priv;
13091 ++	unsigned long flags;
13092   
13093  +process_tx_again:
13094   	if (txqactive(sc->sc_ah, 0))
13095 @@ -184,96 +295,89 @@
13096   	if (txqactive(sc->sc_ah, sc->sc_cabq->axq_qnum))
13097   		ath_tx_processq(sc, sc->sc_cabq);
13098   
13099 -+	ATH_DISABLE_INTR();
13100 ++	local_irq_save(flags);
13101  +	if (sc->sc_isr & HAL_INT_TX) {
13102  +		sc->sc_isr &= ~HAL_INT_TX;
13103 -+		ATH_ENABLE_INTR();
13104 ++		local_irq_restore(flags);
13105  +		goto process_tx_again;
13106  +	}
13107  +	sc->sc_imask |= HAL_INT_TX;
13108  +	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
13109 -+	ATH_ENABLE_INTR();
13110 ++	local_irq_restore(flags);
13111  +
13112   	netif_wake_queue(dev);
13113   
13114   	if (sc->sc_softled)
13115 -@@ -7535,6 +7594,7 @@
13116 +@@ -8309,7 +8442,9 @@
13117 + {
13118   	struct net_device *dev = (struct net_device *)data;
13119   	struct ath_softc *sc = dev->priv;
13120 ++	unsigned long flags;
13121   
13122  +process_tx_again:
13123   	/*
13124   	 * Process each active queue.
13125   	 */
13126 -@@ -7555,6 +7615,16 @@
13127 +@@ -8330,6 +8465,16 @@
13128   	if (sc->sc_uapsdq && txqactive(sc->sc_ah, sc->sc_uapsdq->axq_qnum))
13129   		ath_tx_processq(sc, sc->sc_uapsdq);
13130   
13131 -+	ATH_DISABLE_INTR();
13132 ++	local_irq_save(flags);
13133  +	if (sc->sc_isr & HAL_INT_TX) {
13134  +		sc->sc_isr &= ~HAL_INT_TX;
13135 -+		ATH_ENABLE_INTR();
13136 ++		local_irq_restore(flags);
13137  +		goto process_tx_again;
13138  +	}
13139  +	sc->sc_imask |= HAL_INT_TX;
13140  +	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
13141 -+	ATH_ENABLE_INTR();
13142 ++	local_irq_restore(flags);
13143  +
13144   	netif_wake_queue(dev);
13145   
13146   	if (sc->sc_softled)
13147 -@@ -7572,6 +7642,7 @@
13148 +@@ -8345,13 +8490,25 @@
13149 + 	struct net_device *dev = (struct net_device *)data;
13150 + 	struct ath_softc *sc = dev->priv;
13151   	unsigned int i;
13152 ++	unsigned long flags;
13153   
13154 - 	/* Process each active queue. */
13155 + 	/* Process each active queue. This includes sc_cabq, sc_xrtq and
13156 + 	 * sc_uapsdq */
13157  +process_tx_again:
13158   	for (i = 0; i < HAL_NUM_TX_QUEUES; i++)
13159   		if (ATH_TXQ_SETUP(sc, i) && txqactive(sc->sc_ah, i))
13160   			ath_tx_processq(sc, &sc->sc_txq[i]);
13161 -@@ -7580,6 +7651,16 @@
13162 - 		ath_tx_processq(sc, sc->sc_xrtxq);
13163 - #endif
13164   
13165 -+	ATH_DISABLE_INTR();
13166 ++	local_irq_save(flags);
13167  +	if (sc->sc_isr & HAL_INT_TX) {
13168  +		sc->sc_isr &= ~HAL_INT_TX;
13169 -+		ATH_ENABLE_INTR();
13170 ++		local_irq_restore(flags);
13171  +		goto process_tx_again;
13172  +	}
13173  +	sc->sc_imask |= HAL_INT_TX;
13174  +	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
13175 -+	ATH_ENABLE_INTR();
13176 ++	local_irq_restore(flags);
13177  +
13178   	netif_wake_queue(dev);
13179   
13180   	if (sc->sc_softled)
13181 -@@ -7678,6 +7759,7 @@
13182 - ath_draintxq(struct ath_softc *sc)
13183 - {
13184 - 	struct ath_hal *ah = sc->sc_ah;
13185 -+	int npend = 0;
13186 - 	unsigned int i;
13187 - 
13188 - 	/* XXX return value */
13189 -@@ -9186,9 +9268,9 @@
13190 +@@ -10284,9 +10441,9 @@
13191   	dev->mtu = mtu;
13192   	if ((dev->flags & IFF_RUNNING) && !sc->sc_invalid) {
13193   		/* NB: the rx buffers may need to be reallocated */
13194  -		tasklet_disable(&sc->sc_rxtq);
13195 -+		netif_poll_disable(dev);
13196 ++		ath_poll_disable(dev);
13197   		error = ath_reset(dev);
13198  -		tasklet_enable(&sc->sc_rxtq);
13199 -+		netif_poll_enable(dev);
13200 ++		ath_poll_enable(dev);
13201   	}
13202   	ATH_UNLOCK(sc);
13203   
13204 -Index: madwifi-ng-r2568-20070710/ath/if_athvar.h
13205 -===================================================================
13206 ---- madwifi-ng-r2568-20070710.orig/ath/if_athvar.h	2007-07-23 01:48:43.126437804 +0200
13207 -+++ madwifi-ng-r2568-20070710/ath/if_athvar.h	2007-07-23 01:48:45.030546315 +0200
13208 -@@ -49,6 +49,10 @@
13209 - #include "net80211/ieee80211.h"		/* XXX for WME_NUM_AC */
13210 - #include <asm/io.h>
13211 +--- a/ath/if_athvar.h
13212 ++++ b/ath/if_athvar.h
13213 +@@ -53,6 +53,10 @@
13214 + # include	<asm/bitops.h>
13215 + #endif
13216   
13217  +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
13218  +#define irqs_disabled()			0
13219 @@ -282,7 +386,17 @@
13220   /*
13221    * Deduce if tasklets are available.  If not then
13222    * fall back to using the immediate work queue.
13223 -@@ -635,7 +639,6 @@
13224 +@@ -616,6 +620,9 @@
13225 + struct ath_softc {
13226 + 	struct ieee80211com sc_ic;		/* NB: must be first */
13227 + 	struct net_device *sc_dev;
13228 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
13229 ++	struct napi_struct sc_napi;
13230 ++#endif
13231 + 	void __iomem *sc_iobase;		/* address of the device */
13232 + 	struct semaphore sc_lock;		/* dev-level lock */
13233 + 	struct net_device_stats	sc_devstats;	/* device statistics */
13234 +@@ -730,7 +737,6 @@
13235   	struct ath_buf *sc_rxbufcur;		/* current rx buffer */
13236   	u_int32_t *sc_rxlink;			/* link ptr in last RX desc */
13237   	spinlock_t sc_rxbuflock;
13238 @@ -290,7 +404,7 @@
13239   	struct ATH_TQ_STRUCT sc_rxorntq;	/* rxorn intr tasklet */
13240   	u_int8_t sc_defant;			/* current default antenna */
13241   	u_int8_t sc_rxotherant;			/* RXs on non-default antenna */
13242 -@@ -648,6 +651,7 @@
13243 +@@ -745,6 +751,7 @@
13244   	u_int sc_txintrperiod;			/* tx interrupt batching */
13245   	struct ath_txq sc_txq[HAL_NUM_TX_QUEUES];
13246   	struct ath_txq *sc_ac2q[WME_NUM_AC];	/* WME AC -> h/w qnum */
13247 @@ -298,28 +412,120 @@
13248   	struct ATH_TQ_STRUCT sc_txtq;		/* tx intr tasklet */
13249   	u_int8_t sc_grppoll_str[GRPPOLL_RATE_STR_LEN];
13250   	struct ath_descdma sc_bdma;		/* beacon descriptors */
13251 -@@ -720,6 +724,8 @@
13252 - #define	ATH_TXBUF_LOCK_ASSERT(_sc) \
13253 - 	KASSERT(spin_is_locked(&(_sc)->sc_txbuflock), ("txbuf not locked!"))
13254 +@@ -858,6 +865,8 @@
13255 + #define	ATH_TXBUF_LOCK_CHECK(_sc)
13256 + #endif
13257   
13258  +#define ATH_DISABLE_INTR		local_irq_disable
13259  +#define ATH_ENABLE_INTR 		local_irq_enable
13260   
13261   #define	ATH_RXBUF_LOCK_INIT(_sc)	spin_lock_init(&(_sc)->sc_rxbuflock)
13262   #define	ATH_RXBUF_LOCK_DESTROY(_sc)
13263 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
13264 -===================================================================
13265 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-23 01:48:44.214499810 +0200
13266 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-23 01:48:45.030546315 +0200
13267 -@@ -1128,8 +1128,9 @@
13268 - 		if (ni->ni_vlan != 0 && vap->iv_vlgrp != NULL) {
13269 +--- a/net80211/ieee80211_input.c
13270 ++++ b/net80211/ieee80211_input.c
13271 +@@ -1198,7 +1198,7 @@
13272   			/* attach vlan tag */
13273 - 			vlan_hwaccel_receive_skb(skb, vap->iv_vlgrp, ni->ni_vlan);
13274 --		} else
13275 --			netif_rx(skb);
13276 -+		} else {
13277 -+			netif_receive_skb(skb);
13278 -+		}
13279 - 		dev->last_rx = jiffies;
13280 - 	}
13281 + 			struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
13282 + 			if (vlan_hwaccel_receive_skb(skb, vap->iv_vlgrp, ni->ni_vlan) == NET_RX_DROP) {
13283 +-				/* If netif_rx dropped the packet because 
13284 ++				/* If netif_receive_skb dropped the packet because
13285 + 				 * device was too busy */
13286 + 				if (ni_tmp != NULL) {
13287 + 					/* node reference was leaked */
13288 +@@ -1209,8 +1209,8 @@
13289 + 			skb = NULL; /* SKB is no longer ours */
13290 + 		} else {
13291 + 			struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
13292 +-			if (netif_rx(skb) == NET_RX_DROP) {
13293 +-				/* If netif_rx dropped the packet because 
13294 ++			if (netif_receive_skb(skb) == NET_RX_DROP) {
13295 ++				/* If netif_receive_skb dropped the packet because
13296 + 				 * device was too busy */
13297 + 				if (ni_tmp != NULL) {
13298 + 					/* node reference was leaked */
13299 +@@ -2322,8 +2322,8 @@
13300 + 		skb1->protocol = __constant_htons(0x0019);  /* ETH_P_80211_RAW */
13301 + 
13302 + 		ni_tmp = SKB_CB(skb1)->ni;
13303 +-		if (netif_rx(skb1) == NET_RX_DROP) {
13304 +-			/* If netif_rx dropped the packet because 
13305 ++		if (netif_receive_skb(skb1) == NET_RX_DROP) {
13306 ++			/* If netif_receive_skb dropped the packet because
13307 + 			 * device was too busy */
13308 + 			if (ni_tmp != NULL) {
13309 + 				/* node reference was leaked */
13310 +--- a/net80211/ieee80211_monitor.c
13311 ++++ b/net80211/ieee80211_monitor.c
13312 +@@ -584,8 +584,8 @@
13313 + 			skb1->protocol = 
13314 + 				__constant_htons(0x0019); /* ETH_P_80211_RAW */
13315 + 
13316 +-			if (netif_rx(skb1) == NET_RX_DROP) {
13317 +-				/* If netif_rx dropped the packet because 
13318 ++			if (netif_receive_skb(skb1) == NET_RX_DROP) {
13319 ++				/* If netif_receive_skb dropped the packet because
13320 + 				 * device was too busy, reclaim the ref. in 
13321 + 				 * the skb. */
13322 + 				if (SKB_CB(skb1)->ni != NULL)
13323 +--- a/net80211/ieee80211_skb.c
13324 ++++ b/net80211/ieee80211_skb.c
13325 +@@ -73,7 +73,7 @@
13326 + #undef dev_queue_xmit
13327 + #undef kfree_skb
13328 + #undef kfree_skb_fast
13329 +-#undef netif_rx
13330 ++#undef netif_receive_skb
13331 + #undef pskb_copy
13332 + #undef skb_clone
13333 + #undef skb_copy
13334 +@@ -638,8 +638,8 @@
13335 + 		grp, vlan_tag);
13336 + }
13337 + 
13338 +-int netif_rx_debug(struct sk_buff *skb, const char* func, int line) {
13339 +-	return netif_rx(untrack_skb(skb, 0, func, line, __func__, __LINE__));
13340 ++int netif_receive_skb_debug(struct sk_buff *skb, const char* func, int line) {
13341 ++	return netif_receive_skb(untrack_skb(skb, 0, func, line, __func__, __LINE__));
13342   }
13343 + 
13344 + struct sk_buff * alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
13345 +@@ -760,7 +760,7 @@
13346 + }
13347 + 
13348 + EXPORT_SYMBOL(vlan_hwaccel_receive_skb_debug);
13349 +-EXPORT_SYMBOL(netif_rx_debug);
13350 ++EXPORT_SYMBOL(netif_receive_skb_debug);
13351 + EXPORT_SYMBOL(alloc_skb_debug);
13352 + EXPORT_SYMBOL(dev_alloc_skb_debug);
13353 + EXPORT_SYMBOL(skb_clone_debug);
13354 +--- a/net80211/ieee80211_skb.h
13355 ++++ b/net80211/ieee80211_skb.h
13356 +@@ -116,7 +116,7 @@
13357 + int  vlan_hwaccel_receive_skb_debug(struct sk_buff *skb, 
13358 + 				    struct vlan_group *grp, unsigned short vlan_tag, 
13359 + 				    const char* func, int line);
13360 +-int netif_rx_debug(struct sk_buff *skb, const char* func, int line);
13361 ++int netif_receive_skb_debug(struct sk_buff *skb, const char* func, int line);
13362 + struct sk_buff * alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
13363 + 				 const char *func, int line);
13364 + struct sk_buff * dev_alloc_skb_debug(unsigned int length,
13365 +@@ -151,7 +151,7 @@
13366 + #undef dev_queue_xmit
13367 + #undef kfree_skb
13368 + #undef kfree_skb_fast
13369 +-#undef netif_rx
13370 ++#undef netif_receive_skb
13371 + #undef pskb_copy
13372 + #undef skb_clone
13373 + #undef skb_copy
13374 +@@ -168,8 +168,8 @@
13375 + 	skb_copy_expand_debug(_skb, _newheadroom, _newtailroom, _gfp_mask, __func__, __LINE__)
13376 + #define vlan_hwaccel_receive_skb(_skb, _grp, _tag) \
13377 + 	vlan_hwaccel_receive_skb_debug(_skb, _grp, _tag, __func__, __LINE__)
13378 +-#define netif_rx(_skb) \
13379 +-	netif_rx_debug(_skb, __func__, __LINE__)
13380 ++#define netif_receive_skb(_skb) \
13381 ++	netif_receive_skb_debug(_skb, __func__, __LINE__)
13382 + #define	alloc_skb(_length, _gfp_mask) \
13383 + 	alloc_skb_debug(_length, _gfp_mask, __func__, __LINE__)
13384 + #define	dev_alloc_skb(_length) \
13385 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/301-tx_locking.patch kamikaze_7.09/package/madwifi/patches/301-tx_locking.patch
13386 --- kamikaze_7.09.orig/package/madwifi/patches/301-tx_locking.patch	2007-09-20 10:54:59.000000000 +0200
13387 +++ kamikaze_7.09/package/madwifi/patches/301-tx_locking.patch	1970-01-01 01:00:00.000000000 +0100
13388 @@ -1,77 +0,0 @@
13389 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
13390 -===================================================================
13391 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:45.030546315 +0200
13392 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:45.406567742 +0200
13393 -@@ -2558,7 +2558,7 @@
13394 - 	/* NB: use this lock to protect an->an_tx_ffbuf (and txq->axq_stageq)
13395 - 	 *	in athff_can_aggregate() call too.
13396 - 	 */
13397 --	ATH_TXQ_LOCK_IRQ(txq);
13398 -+	ATH_TXQ_LOCK_BH(txq);
13399 - 	if (athff_can_aggregate(sc, eh, an, skb, vap->iv_fragthreshold, &ff_flush)) {
13400 - 		if (an->an_tx_ffbuf[skb->priority]) { /* i.e., frame on the staging queue */
13401 - 			bf = an->an_tx_ffbuf[skb->priority];
13402 -@@ -2566,6 +2566,7 @@
13403 - 			/* get (and remove) the frame from staging queue */
13404 - 			TAILQ_REMOVE(&txq->axq_stageq, bf, bf_stagelist);
13405 - 			an->an_tx_ffbuf[skb->priority] = NULL;
13406 -+			ATH_TXQ_UNLOCK_BH(txq);
13407 - 
13408 - 			/*
13409 - 			 * chain skbs and add FF magic
13410 -@@ -2588,7 +2589,7 @@
13411 - 			 */
13412 - 			ATH_HARDSTART_GET_TX_BUF_WITH_LOCK;
13413 - 			if (bf == NULL) {
13414 --				ATH_TXQ_UNLOCK_IRQ_EARLY(txq);
13415 -+				ATH_TXQ_UNLOCK_BH(txq);
13416 - 				goto hardstart_fail;
13417 - 			}
13418 - 			DPRINTF(sc, ATH_DEBUG_XMIT | ATH_DEBUG_FF,
13419 -@@ -2600,8 +2601,7 @@
13420 - 			an->an_tx_ffbuf[skb->priority] = bf;
13421 - 
13422 - 			TAILQ_INSERT_HEAD(&txq->axq_stageq, bf, bf_stagelist);
13423 --
13424 --			ATH_TXQ_UNLOCK_IRQ_EARLY(txq);
13425 -+			ATH_TXQ_UNLOCK_BH(txq);
13426 - 
13427 - 			return NETDEV_TX_OK;
13428 - 		}
13429 -@@ -2614,7 +2614,7 @@
13430 - 			an->an_tx_ffbuf[skb->priority] = NULL;
13431 - 
13432 - 			/* NB: ath_tx_start -> ath_tx_txqaddbuf uses ATH_TXQ_LOCK too */
13433 --			ATH_TXQ_UNLOCK_IRQ_EARLY(txq);
13434 -+			ATH_TXQ_UNLOCK_BH(txq);
13435 - 
13436 - 			/* encap and xmit */
13437 - 			bf_ff->bf_skb = ieee80211_encap(ni, bf_ff->bf_skb, &framecnt);
13438 -@@ -2663,12 +2663,12 @@
13439 - 
13440 - 		ATH_HARDSTART_GET_TX_BUF_WITH_LOCK;
13441 - 		if (bf == NULL) {
13442 --			ATH_TXQ_UNLOCK_IRQ_EARLY(txq);
13443 -+			ATH_TXQ_UNLOCK_BH(txq);
13444 - 			goto hardstart_fail;
13445 - 		}
13446 -+		ATH_TXQ_UNLOCK_BH(txq);
13447 - 	}
13448 - 
13449 --	ATH_TXQ_UNLOCK_IRQ(txq);
13450 - 
13451 - ff_flush_done:
13452 - ff_bypass:
13453 -Index: madwifi-ng-r2568-20070710/ath/if_athvar.h
13454 -===================================================================
13455 ---- madwifi-ng-r2568-20070710.orig/ath/if_athvar.h	2007-07-23 01:48:45.030546315 +0200
13456 -+++ madwifi-ng-r2568-20070710/ath/if_athvar.h	2007-07-23 01:48:45.406567742 +0200
13457 -@@ -497,6 +497,8 @@
13458 - #define ATH_TXQ_INTR_PERIOD		5  /* axq_intrcnt period for intr gen */
13459 - #define	ATH_TXQ_LOCK_INIT(_tq)		spin_lock_init(&(_tq)->axq_lock)
13460 - #define	ATH_TXQ_LOCK_DESTROY(_tq)
13461 -+#define ATH_TXQ_LOCK_BH(_tq)		spin_lock_bh(&(_tq)->axq_lock);
13462 -+#define ATH_TXQ_UNLOCK_BH(_tq)		spin_unlock_bh(&(_tq)->axq_lock);
13463 - #define ATH_TXQ_LOCK_IRQ(_tq)		do {				\
13464 - 	unsigned long __axq_lockflags;					\
13465 - 	spin_lock_irqsave(&(_tq)->axq_lock, __axq_lockflags);
13466 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/305-pureg_fix.patch kamikaze_7.09/package/madwifi/patches/305-pureg_fix.patch
13467 --- kamikaze_7.09.orig/package/madwifi/patches/305-pureg_fix.patch	2007-09-20 10:54:59.000000000 +0200
13468 +++ kamikaze_7.09/package/madwifi/patches/305-pureg_fix.patch	2008-06-19 17:34:17.000000000 +0200
13469 @@ -1,8 +1,6 @@
13470 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
13471 -===================================================================
13472 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:45.406567742 +0200
13473 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:45.690583928 +0200
13474 -@@ -3384,7 +3384,9 @@
13475 +--- a/ath/if_ath.c
13476 ++++ b/ath/if_ath.c
13477 +@@ -4149,7 +4149,9 @@
13478   		rfilt |= HAL_RX_FILTER_PROM;
13479   	if (ic->ic_opmode == IEEE80211_M_STA ||
13480   	    sc->sc_opmode == HAL_M_IBSS ||	/* NB: AHDEMO too */
13481 @@ -11,47 +9,56 @@
13482  +		((ic->ic_opmode == IEEE80211_M_HOSTAP) &&
13483  +		 (ic->ic_protmode != IEEE80211_PROT_NONE)))
13484   		rfilt |= HAL_RX_FILTER_BEACON;
13485 - 	if ((sc->sc_nmonvaps > 0) || ((sc->sc_nvaps > 0) && (sc->sc_nibssvaps > 0)))
13486 + 	if (sc->sc_nmonvaps > 0)
13487   		rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
13488 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
13489 -===================================================================
13490 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-23 01:48:45.030546315 +0200
13491 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-23 01:48:45.690583928 +0200
13492 -@@ -321,11 +321,12 @@
13493 +--- a/net80211/ieee80211_input.c
13494 ++++ b/net80211/ieee80211_input.c
13495 +@@ -346,11 +346,12 @@
13496   				bssid = wh->i_addr3;
13497   			}
13498   			/*
13499  -			 * Validate the bssid.
13500  +			 * Validate the bssid. Let beacons get through though for 11g protection mode.
13501   			 */
13502 - #ifdef ATH_SUPERG_XR
13503 - 			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
13504 +-#ifdef ATH_SUPERG_XR
13505 + 			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bssid) &&
13506  -			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast)) {
13507  +			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast) &&
13508  +				(subtype != IEEE80211_FC0_SUBTYPE_BEACON)) {
13509 ++#ifdef ATH_SUPERG_XR
13510   				/*
13511   				 * allow MGT frames to vap->iv_xrvap.
13512   				 * this will allow roaming between  XR and normal vaps
13513 -@@ -344,7 +345,8 @@
13514 - 			}
13515 +@@ -366,18 +367,14 @@
13516 + 					vap->iv_stats.is_rx_wrongbss++;
13517 + 					goto out;
13518 + 				}
13519 +-			}
13520   #else
13521 - 			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
13522 +-			if (!IEEE80211_ADDR_EQ(bssid, vap->iv_bssid) &&
13523  -			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast)) {
13524 -+			    !IEEE80211_ADDR_EQ(bssid, dev->broadcast) &&
13525 -+				(subtype != IEEE80211_FC0_SUBTYPE_BEACON)) {
13526   				/* not interested in */
13527   				IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
13528   					bssid, NULL, "%s", "not to bss");
13529 -@@ -2541,7 +2543,7 @@
13530 + 				vap->iv_stats.is_rx_wrongbss++;
13531 + 				goto out;
13532 +-			}
13533 +-
13534 + #endif
13535 ++			}
13536 + 			break;
13537 + 		case IEEE80211_M_WDS:
13538 + 			if (skb->len < sizeof(struct ieee80211_frame_addr4)) {
13539 +@@ -3066,7 +3063,7 @@
13540   	u_int8_t *frm, *efrm;
13541 - 	u_int8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath;
13542 + 	u_int8_t *ssid, *rates, *xrates, *suppchan, *wpa, *rsn, *wme, *ath;
13543   	u_int8_t rate;
13544  -	int reassoc, resp, allocbs = 0;
13545  +	int reassoc, resp, allocbs = 0, has_erp = 0;
13546   	u_int8_t qosinfo;
13547   
13548 - 	wh = (struct ieee80211_frame *) skb->data;
13549 -@@ -2563,11 +2565,15 @@
13550 + 	if (ni_or_null == NULL)
13551 +@@ -3096,11 +3093,15 @@
13552   		 *    o station mode when associated (to collect state
13553   		 *      updates such as 802.11g slot time), or
13554   		 *    o adhoc mode (to discover neighbors)
13555 @@ -68,7 +75,7 @@
13556   			vap->iv_stats.is_rx_mgtdiscard++;
13557   			return;
13558   		}
13559 -@@ -2650,6 +2656,7 @@
13560 +@@ -3184,6 +3185,7 @@
13561   					break;
13562   				}
13563   				scan.erp = frm[2];
13564 @@ -76,7 +83,7 @@
13565   				break;
13566   			case IEEE80211_ELEMID_RSN:
13567   				scan.rsn = frm;
13568 -@@ -2867,6 +2874,20 @@
13569 +@@ -3421,6 +3423,20 @@
13570   				ieee80211_bg_scan(vap);
13571   			return;
13572   		}
13573 @@ -97,11 +104,9 @@
13574   		/*
13575   		 * If scanning, just pass information to the scan module.
13576   		 */
13577 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
13578 -===================================================================
13579 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-23 01:48:42.330392441 +0200
13580 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-23 01:48:45.694584154 +0200
13581 -@@ -332,10 +332,16 @@
13582 +--- a/net80211/ieee80211_node.c
13583 ++++ b/net80211/ieee80211_node.c
13584 +@@ -383,10 +383,16 @@
13585   	/* Update country ie information */
13586   	ieee80211_build_countryie(ic);
13587   
13588 @@ -120,11 +125,9 @@
13589   
13590   	(void) ieee80211_sta_join1(PASS_NODE(ni));
13591   }
13592 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c
13593 -===================================================================
13594 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_proto.c	2007-07-23 01:48:44.570520097 +0200
13595 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_proto.c	2007-07-23 01:48:45.718585522 +0200
13596 -@@ -586,6 +586,28 @@
13597 +--- a/net80211/ieee80211_proto.c
13598 ++++ b/net80211/ieee80211_proto.c
13599 +@@ -595,6 +595,28 @@
13600   	{ 4, { 2, 4, 11, 22 } },	/* IEEE80211_MODE_TURBO_G (mixed b/g) */
13601   };
13602   
13603 @@ -153,16 +156,13 @@
13604   /*
13605    * Mark the basic rates for the 11g rate table based on the
13606    * specified mode.  For 11b compatibility we mark only 11b
13607 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_var.h
13608 -===================================================================
13609 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_var.h	2007-07-23 01:48:44.622523064 +0200
13610 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_var.h	2007-07-23 01:48:45.734586433 +0200
13611 -@@ -592,6 +592,8 @@
13612 - void ieee80211_build_countryie(struct ieee80211com *);
13613 - int ieee80211_media_setup(struct ieee80211com *, struct ifmedia *, u_int32_t,
13614 - 	ifm_change_cb_t, ifm_stat_cb_t);
13615 +--- a/net80211/ieee80211_var.h
13616 ++++ b/net80211/ieee80211_var.h
13617 +@@ -708,6 +708,7 @@
13618 + void ieee80211_build_sc_ie(struct ieee80211com *);
13619 + void ieee80211_dfs_action(struct ieee80211com *);
13620 + void ieee80211_expire_channel_excl_restrictions(struct ieee80211com *);
13621  +void ieee80211_setpuregbasicrates(struct ieee80211_rateset *rs);
13622 -+
13623   
13624 - /* Key update synchronization methods.  XXX should not be visible. */
13625 - static __inline void
13626 + /*
13627 +  * Iterate through ic_channels to enumerate all distinct ic_ieee channel numbers.
13628 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/306-mib_intr_workaround.patch kamikaze_7.09/package/madwifi/patches/306-mib_intr_workaround.patch
13629 --- kamikaze_7.09.orig/package/madwifi/patches/306-mib_intr_workaround.patch	2007-09-20 10:54:59.000000000 +0200
13630 +++ kamikaze_7.09/package/madwifi/patches/306-mib_intr_workaround.patch	1970-01-01 01:00:00.000000000 +0100
13631 @@ -1,83 +0,0 @@
13632 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
13633 -===================================================================
13634 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-08-01 11:07:47.882943145 +0200
13635 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-08-01 11:41:11.781138794 +0200
13636 -@@ -203,6 +203,7 @@
13637 - static void ath_flushrecv(struct ath_softc *);
13638 - static void ath_chan_change(struct ath_softc *, struct ieee80211_channel *);
13639 - static void ath_calibrate(unsigned long);
13640 -+static void ath_mib_enable(unsigned long);
13641 - static int ath_newstate(struct ieee80211vap *, enum ieee80211_state, int);
13642 - 
13643 - static void ath_scan_start(struct ieee80211com *);
13644 -@@ -660,6 +661,10 @@
13645 - 	sc->sc_cal_ch.function = ath_calibrate;
13646 - 	sc->sc_cal_ch.data = (unsigned long) dev;
13647 - 
13648 -+	init_timer(&sc->sc_mib_enable);
13649 -+	sc->sc_mib_enable.function = ath_mib_enable;
13650 -+	sc->sc_mib_enable.data = (unsigned long) sc;
13651 -+
13652 - #ifdef ATH_SUPERG_DYNTURBO
13653 - 	init_timer(&sc->sc_dturbo_switch_mode);
13654 - 	sc->sc_dturbo_switch_mode.function = ath_turbo_switch_mode;
13655 -@@ -1751,16 +1756,19 @@
13656 - 		if (status & HAL_INT_MIB) {
13657 - 			sc->sc_stats.ast_mib++;
13658 - 			/*
13659 --			 * Disable interrupts until we service the MIB
13660 --			 * interrupt; otherwise it will continue to fire.
13661 --			 */
13662 --			ath_hal_intrset(ah, 0);
13663 --			/*
13664 --			 * Let the HAL handle the event.  We assume it will
13665 --			 * clear whatever condition caused the interrupt.
13666 -+			 * When the card receives lots of PHY errors, the MIB
13667 -+			 * interrupt will fire at a very rapid rate. We will use
13668 -+			 * a timer to enforce at least 1 jiffy delay between
13669 -+			 * MIB interrupts. This should be unproblematic, since
13670 -+			 * the hardware will continue to update the counters in the
13671 -+			 * mean time.
13672 - 			 */
13673 --			ath_hal_mibevent(ah, &sc->sc_halstats);
13674 -+			sc->sc_imask &= ~HAL_INT_MIB;
13675 - 			ath_hal_intrset(ah, sc->sc_imask);
13676 -+			mod_timer(&sc->sc_mib_enable, jiffies + 1);
13677 -+
13678 -+			/* Let the HAL handle the event. */
13679 -+			ath_hal_mibevent(ah, &sc->sc_halstats);
13680 - 		}
13681 - 	}
13682 - 	if (needmark)
13683 -@@ -8029,6 +8037,19 @@
13684 - }
13685 - 
13686 - /*
13687 -+ * Enable MIB interrupts again, after the ISR disabled them
13688 -+ * to slow down the rate of PHY error reporting.
13689 -+ */
13690 -+static void
13691 -+ath_mib_enable(unsigned long arg)
13692 -+{
13693 -+	struct ath_softc *sc = (struct ath_softc *) arg;
13694 -+
13695 -+	sc->sc_imask |= HAL_INT_MIB;
13696 -+	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
13697 -+}
13698 -+
13699 -+/*
13700 -  * Periodically recalibrate the PHY to account
13701 -  * for temperature/environment changes.
13702 -  */
13703 -Index: madwifi-ng-r2568-20070710/ath/if_athvar.h
13704 -===================================================================
13705 ---- madwifi-ng-r2568-20070710.orig/ath/if_athvar.h	2007-08-01 11:33:50.800008711 +0200
13706 -+++ madwifi-ng-r2568-20070710/ath/if_athvar.h	2007-08-01 11:34:33.202425088 +0200
13707 -@@ -687,6 +687,7 @@
13708 - 	struct ctl_table *sc_sysctls;
13709 - 
13710 - 	u_int16_t sc_reapcount;  		/* # of tx buffers reaped after net dev stopped */
13711 -+	struct timer_list sc_mib_enable;
13712 - 
13713 - #ifdef ATH_REVERSE_ENGINEERING
13714 - 	u_int8_t register_snapshot[MAX_REGISTER_ADDRESS];
13715 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/309-micfail_detect.patch kamikaze_7.09/package/madwifi/patches/309-micfail_detect.patch
13716 --- kamikaze_7.09.orig/package/madwifi/patches/309-micfail_detect.patch	2007-09-20 10:54:59.000000000 +0200
13717 +++ kamikaze_7.09/package/madwifi/patches/309-micfail_detect.patch	2008-06-19 17:34:17.000000000 +0200
13718 @@ -1,16 +1,14 @@
13719 -Index: madwifi-ng-r2568-20070710/ath/if_ath.c
13720 -===================================================================
13721 ---- madwifi-ng-r2568-20070710.orig/ath/if_ath.c	2007-07-23 01:48:46.026603077 +0200
13722 -+++ madwifi-ng-r2568-20070710/ath/if_ath.c	2007-07-23 01:48:46.310619260 +0200
13723 -@@ -5632,6 +5632,7 @@
13724 - 	u_int64_t rs_tsf;
13725 +--- a/ath/if_ath.c
13726 ++++ b/ath/if_ath.c
13727 +@@ -6446,6 +6446,7 @@
13728 + 	int type;
13729 + 	u_int phyerr;
13730   	u_int processed = 0, early_stop = 0;
13731 - 	u_int rx_limit = dev->quota;
13732  +	u_int mic_fail = 0;
13733   
13734 - 	/* Let the 802.11 layer know about the new noise floor */
13735 - 	sc->sc_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));
13736 -@@ -5726,25 +5727,7 @@
13737 + 	DPRINTF(sc, ATH_DEBUG_RX_PROC, "invoked\n");
13738 + process_rx_again:
13739 +@@ -6547,24 +6548,8 @@
13740   			}
13741   			if (rs->rs_status & HAL_RXERR_MIC) {
13742   				sc->sc_stats.ast_rx_badmic++;
13743 @@ -19,7 +17,6 @@
13744  -				 * the 802.11 header for notification.
13745  -				 */
13746  -				/* XXX frag's and QoS frames */
13747 --				len = rs->rs_datalen;
13748  -				if (len >= sizeof (struct ieee80211_frame)) {
13749  -					bus_dma_sync_single(sc->sc_bdev,
13750  -					    bf->bf_skbaddr, len,
13751 @@ -27,17 +24,18 @@
13752  -#if 0
13753  -/* XXX revalidate MIC, lookup ni to find VAP */
13754  -					ieee80211_notify_michael_failure(ic,
13755 --					    (struct ieee80211_frame *) skb->data,
13756 +-					    (struct ieee80211_frame *)skb->data,
13757  -					    sc->sc_splitmic ?
13758  -					        rs->rs_keyix - 32 : rs->rs_keyix
13759  -					);
13760  -#endif
13761  -				}
13762  +				mic_fail = 1;
13763 ++				goto rx_accept;
13764   			}
13765   			/*
13766 - 			 * Reject error frames if we have no vaps that 
13767 -@@ -5809,8 +5792,9 @@
13768 + 			 * Reject error frames if we have no vaps that
13769 +@@ -6603,8 +6588,9 @@
13770   		/*
13771   		 * Finished monitor mode handling, now reject
13772   		 * error frames before passing to other vaps
13773 @@ -45,14 +43,13 @@
13774   		 */
13775  -		if (rs->rs_status != 0) {
13776  +		if (rs->rs_status & ~(HAL_RXERR_MIC | HAL_RXERR_DECRYPT)) {
13777 - 			dev_kfree_skb(skb);
13778 - 			skb = NULL;
13779 + 			ieee80211_dev_kfree_skb(&skb);
13780   			goto rx_next;
13781 -@@ -5841,6 +5825,27 @@
13782 - 				   sc->sc_hwmap[rs->rs_rate].ieeerate,
13783 - 				   rs->rs_rssi);
13784 + 		}
13785 +@@ -6612,6 +6598,26 @@
13786 + 		/* remove the CRC */
13787 + 		skb_trim(skb, skb->len - IEEE80211_CRC_LEN);
13788   
13789 -+		/* MIC failure. Drop the packet in any case */
13790  +		if (mic_fail) {
13791  +			/* Ignore control frames which are reported with mic error */
13792  +		    if ((((struct ieee80211_frame *)skb->data)->i_fc[0] &
13793 @@ -71,15 +68,21 @@
13794  +			skb = NULL;
13795  +			mic_fail = 0;
13796  +			goto rx_next;
13797 -+ 		}
13798 ++		}
13799  +
13800   		/*
13801 - 		 * Locate the node for sender, track state, and then
13802 - 		 * pass the (referenced) node up to the 802.11 layer
13803 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_ccmp.c
13804 -===================================================================
13805 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto_ccmp.c	2007-07-23 01:48:42.870423216 +0200
13806 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_ccmp.c	2007-07-23 01:48:46.310619260 +0200
13807 + 		 * From this point on we assume the frame is at least
13808 + 		 * as large as ieee80211_frame_min; verify that.
13809 +@@ -6624,6 +6630,7 @@
13810 + 			goto rx_next;
13811 + 		}
13812 + 
13813 ++		/* MIC failure. Drop the packet in any case */
13814 + 		/*
13815 + 		 * Normal receive.
13816 + 		 */
13817 +--- a/net80211/ieee80211_crypto_ccmp.c
13818 ++++ b/net80211/ieee80211_crypto_ccmp.c
13819  @@ -73,7 +73,7 @@
13820   static int ccmp_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
13821   static int ccmp_decap(struct ieee80211_key *, struct sk_buff *, int);
13822 @@ -98,10 +101,8 @@
13823   {
13824   	return 1;
13825   }
13826 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto.h
13827 -===================================================================
13828 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto.h	2007-07-23 01:48:36.806077628 +0200
13829 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto.h	2007-07-23 01:48:46.326620171 +0200
13830 +--- a/net80211/ieee80211_crypto.h
13831 ++++ b/net80211/ieee80211_crypto.h
13832  @@ -145,7 +145,7 @@
13833   	int (*ic_encap)(struct ieee80211_key *, struct sk_buff *, u_int8_t);
13834   	int (*ic_decap)(struct ieee80211_key *, struct sk_buff *, int);
13835 @@ -124,10 +125,8 @@
13836   }
13837   
13838   /*
13839 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_none.c
13840 -===================================================================
13841 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto_none.c	2007-07-23 01:48:36.810077857 +0200
13842 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_none.c	2007-07-23 01:48:46.342621086 +0200
13843 +--- a/net80211/ieee80211_crypto_none.c
13844 ++++ b/net80211/ieee80211_crypto_none.c
13845  @@ -52,7 +52,7 @@
13846   static int none_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
13847   static int none_decap(struct ieee80211_key *, struct sk_buff *, int);
13848 @@ -146,10 +145,8 @@
13849   {
13850   	struct ieee80211vap *vap = k->wk_private;
13851   
13852 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_tkip.c
13853 -===================================================================
13854 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto_tkip.c	2007-07-23 01:48:36.818078312 +0200
13855 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_tkip.c	2007-07-23 01:48:46.362622225 +0200
13856 +--- a/net80211/ieee80211_crypto_tkip.c
13857 ++++ b/net80211/ieee80211_crypto_tkip.c
13858  @@ -57,7 +57,7 @@
13859   static int tkip_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
13860   static int tkip_enmic(struct ieee80211_key *, struct sk_buff *, int);
13861 @@ -177,10 +174,8 @@
13862   		struct ieee80211vap *vap = ctx->tc_vap;
13863   		u8 mic[IEEE80211_WEP_MICLEN];
13864   		u8 mic0[IEEE80211_WEP_MICLEN];
13865 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_wep.c
13866 -===================================================================
13867 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_crypto_wep.c	2007-07-23 01:48:36.826078768 +0200
13868 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_crypto_wep.c	2007-07-23 01:48:46.402624504 +0200
13869 +--- a/net80211/ieee80211_crypto_wep.c
13870 ++++ b/net80211/ieee80211_crypto_wep.c
13871  @@ -54,7 +54,7 @@
13872   static int wep_encap(struct ieee80211_key *, struct sk_buff *, u_int8_t);
13873   static int wep_decap(struct ieee80211_key *, struct sk_buff *, int);
13874 @@ -199,11 +194,9 @@
13875   {
13876   	return 1;
13877   }
13878 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_input.c
13879 -===================================================================
13880 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_input.c	2007-07-23 01:48:45.690583928 +0200
13881 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_input.c	2007-07-23 01:48:46.406624734 +0200
13882 -@@ -632,7 +632,7 @@
13883 +--- a/net80211/ieee80211_input.c
13884 ++++ b/net80211/ieee80211_input.c
13885 +@@ -669,7 +669,7 @@
13886   		 * Next strip any MSDU crypto bits.
13887   		 */
13888   		if (key != NULL &&
13889 @@ -212,7 +205,7 @@
13890   			IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
13891   				ni->ni_macaddr, "data", "%s", "demic error");
13892   			IEEE80211_NODE_STAT(ni, rx_demicfail);
13893 -@@ -3772,6 +3772,47 @@
13894 +@@ -4293,6 +4293,47 @@
13895   }
13896   #endif
13897   
13898 @@ -260,11 +253,9 @@
13899   #ifdef IEEE80211_DEBUG
13900   /*
13901    * Debugging support.
13902 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_proto.h
13903 -===================================================================
13904 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_proto.h	2007-07-23 01:48:36.838079452 +0200
13905 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_proto.h	2007-07-23 01:48:46.438626555 +0200
13906 -@@ -91,6 +91,7 @@
13907 +--- a/net80211/ieee80211_proto.h
13908 ++++ b/net80211/ieee80211_proto.h
13909 +@@ -90,6 +90,7 @@
13910   void ieee80211_set11gbasicrates(struct ieee80211_rateset *, enum ieee80211_phymode);
13911   enum ieee80211_phymode ieee80211_get11gbasicrates(struct ieee80211_rateset *);
13912   void ieee80211_send_pspoll(struct ieee80211_node *);
13913 @@ -272,26 +263,22 @@
13914   
13915   /*
13916    * Return the size of the 802.11 header for a management or data frame.
13917 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_linux.c
13918 -===================================================================
13919 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_linux.c	2007-07-23 01:48:42.626409310 +0200
13920 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_linux.c	2007-07-23 01:48:46.462627924 +0200
13921 -@@ -291,8 +291,8 @@
13922 +--- a/net80211/ieee80211_linux.c
13923 ++++ b/net80211/ieee80211_linux.c
13924 +@@ -337,8 +337,8 @@
13925   	/* TODO: needed parameters: count, keyid, key type, src address, TSC */
13926 - 	snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=%s)", tag,
13927 + 	snprintf(buf, sizeof(buf), "%s(keyid=%d %scast addr=" MAC_FMT ")", tag,
13928   		k->wk_keyix,
13929  -		IEEE80211_IS_MULTICAST(wh->i_addr1) ?  "broad" : "uni",
13930 --		ether_sprintf(wh->i_addr1));
13931 +-		MAC_ADDR(wh->i_addr1));
13932  +		IEEE80211_IS_MULTICAST(wh->i_addr2) ?  "broad" : "uni",
13933 -+		ether_sprintf(wh->i_addr2));
13934 ++		MAC_ADDR(wh->i_addr2));
13935   	memset(&wrqu, 0, sizeof(wrqu));
13936   	wrqu.data.length = strlen(buf);
13937   	wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
13938 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_output.c
13939 -===================================================================
13940 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_output.c	2007-07-23 01:48:36.854080363 +0200
13941 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_output.c	2007-07-23 01:48:46.466628154 +0200
13942 -@@ -1079,13 +1079,16 @@
13943 +--- a/net80211/ieee80211_output.c
13944 ++++ b/net80211/ieee80211_output.c
13945 +@@ -1074,13 +1074,16 @@
13946   			cip = (struct ieee80211_cipher *) key->wk_cipher;
13947   			ciphdrsize = cip->ic_header;
13948   			tailsize += (cip->ic_trailer + cip->ic_miclen);
13949 @@ -311,24 +298,22 @@
13950   
13951   		/*
13952   		 * Allocate sk_buff for each subsequent fragment; First fragment
13953 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_node.c
13954 -===================================================================
13955 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_node.c	2007-07-23 01:48:45.694584154 +0200
13956 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_node.c	2007-07-23 01:48:46.590635219 +0200
13957 -@@ -1891,11 +1891,13 @@
13958 +--- a/net80211/ieee80211_node.c
13959 ++++ b/net80211/ieee80211_node.c
13960 +@@ -2264,11 +2264,13 @@
13961   	/* From this point onwards we can no longer find the node,
13962   	 * so no more references are generated
13963   	 */
13964  -	ieee80211_remove_wds_addr(nt, ni->ni_macaddr);
13965  -	ieee80211_del_wds_node(nt, ni);
13966  -	IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
13967 --	_node_table_leave(nt, ni);
13968 +-	node_table_leave_locked(nt, ni);
13969  -	IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
13970  +	if (nt) {
13971  +		ieee80211_remove_wds_addr(nt, ni->ni_macaddr);
13972  +		ieee80211_del_wds_node(nt, ni);
13973  +		IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
13974 -+		_node_table_leave(nt, ni);
13975 ++		node_table_leave_locked(nt, ni);
13976  +		IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
13977  +	}
13978   
13979 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/310-erp_beacon_check.patch kamikaze_7.09/package/madwifi/patches/310-erp_beacon_check.patch
13980 --- kamikaze_7.09.orig/package/madwifi/patches/310-erp_beacon_check.patch	2007-09-20 10:54:59.000000000 +0200
13981 +++ kamikaze_7.09/package/madwifi/patches/310-erp_beacon_check.patch	1970-01-01 01:00:00.000000000 +0100
13982 @@ -1,13 +0,0 @@
13983 -Index: madwifi-ng-r2568-20070710/net80211/ieee80211_beacon.c
13984 -===================================================================
13985 ---- madwifi-ng-r2568-20070710.orig/net80211/ieee80211_beacon.c	2007-07-23 01:48:42.278389477 +0200
13986 -+++ madwifi-ng-r2568-20070710/net80211/ieee80211_beacon.c	2007-07-23 01:48:46.966656645 +0200
13987 -@@ -512,7 +512,7 @@
13988 - 			vap->iv_flags &= ~IEEE80211_F_XRUPDATE;
13989 - 		}
13990 - #endif
13991 --		if (ic->ic_flags_ext & IEEE80211_FEXT_ERPUPDATE) {
13992 -+		if ((ic->ic_flags_ext & IEEE80211_FEXT_ERPUPDATE) && (bo->bo_erp != NULL)) {
13993 - 			(void) ieee80211_add_erp(bo->bo_erp, ic);
13994 - 			ic->ic_flags_ext &= ~IEEE80211_FEXT_ERPUPDATE;
13995 - 		}
13996 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/310-noise_get.patch kamikaze_7.09/package/madwifi/patches/310-noise_get.patch
13997 --- kamikaze_7.09.orig/package/madwifi/patches/310-noise_get.patch	1970-01-01 01:00:00.000000000 +0100
13998 +++ kamikaze_7.09/package/madwifi/patches/310-noise_get.patch	2008-06-19 17:34:17.000000000 +0200
13999 @@ -0,0 +1,55 @@
14000 +--- a/ath/if_ath.c
14001 ++++ b/ath/if_ath.c
14002 +@@ -1695,8 +1695,6 @@
14003 + 	 * get to reality.  This value is used in monitor mode and by tools like
14004 + 	 * Wireshark and Kismet.
14005 + 	 */
14006 +-	ic->ic_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));
14007 +-
14008 + 	ATH_RXBUF_LOCK_IRQ(sc);
14009 + 	if (sc->sc_rxbufcur == NULL)
14010 + 		sc->sc_rxbufcur = STAILQ_FIRST(&sc->sc_rxbuf);
14011 +@@ -8966,6 +8964,7 @@
14012 + 			sc->sc_curchan.channel);
14013 + 		sc->sc_stats.ast_per_calfail++;
14014 + 	}
14015 ++	ic->ic_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));
14016 + 
14017 + 	ath_hal_process_noisefloor(ah);
14018 + 	if (isIQdone == AH_TRUE) {
14019 +@@ -9034,6 +9033,7 @@
14020 + 	struct ath_softc *sc = dev->priv;
14021 + 
14022 + 	(void) ath_chan_set(sc, ic->ic_curchan);
14023 ++	ic->ic_channoise = ath_hal_get_channel_noise(sc->sc_ah, &(sc->sc_curchan));
14024 + 	/*
14025 + 	 * If we are returning to our bss channel then mark state
14026 + 	 * so the next recv'd beacon's TSF will be used to sync the
14027 +@@ -9302,6 +9302,7 @@
14028 + 		}
14029 + 
14030 + 		ath_hal_process_noisefloor(ah);
14031 ++		ic->ic_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));
14032 + 		/*
14033 + 		 * Reset rssi stats; maybe not the best place...
14034 + 		 */
14035 +--- a/net80211/ieee80211_wireless.c
14036 ++++ b/net80211/ieee80211_wireless.c
14037 +@@ -4358,6 +4358,7 @@
14038 + 	si->isi_state = ni->ni_flags;
14039 + 	si->isi_authmode = ni->ni_authmode;
14040 + 	si->isi_rssi = ic->ic_node_getrssi(ni);
14041 ++	si->isi_noise = ic->ic_channoise;
14042 + 	si->isi_capinfo = ni->ni_capinfo;
14043 + 	si->isi_athflags = ni->ni_ath_flags;
14044 + 	si->isi_erp = ni->ni_erp;
14045 +--- a/net80211/ieee80211_ioctl.h
14046 ++++ b/net80211/ieee80211_ioctl.h
14047 +@@ -311,6 +311,7 @@
14048 + 	u_int16_t isi_state;		/* state flags */
14049 + 	u_int8_t isi_authmode;		/* authentication algorithm */
14050 + 	u_int8_t isi_rssi;
14051 ++	int8_t isi_noise;
14052 + 	u_int16_t isi_capinfo;		/* capabilities */
14053 + 	u_int8_t isi_athflags;		/* Atheros capabilities */
14054 + 	u_int8_t isi_erp;		/* ERP element */
14055 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/311-bssid_alloc.patch kamikaze_7.09/package/madwifi/patches/311-bssid_alloc.patch
14056 --- kamikaze_7.09.orig/package/madwifi/patches/311-bssid_alloc.patch	1970-01-01 01:00:00.000000000 +0100
14057 +++ kamikaze_7.09/package/madwifi/patches/311-bssid_alloc.patch	2008-06-19 17:34:17.000000000 +0200
14058 @@ -0,0 +1,11 @@
14059 +--- a/ath/if_ath.c
14060 ++++ b/ath/if_ath.c
14061 +@@ -1354,7 +1354,7 @@
14062 + 		TAILQ_FOREACH(v, &ic->ic_vaps, iv_next)
14063 + 			id_mask |= (1 << ATH_GET_VAP_ID(v->iv_myaddr));
14064 + 
14065 +-		for (id = 1; id < ath_maxvaps; id++) {
14066 ++		for (id = 0; id < ath_maxvaps; id++) {
14067 + 			/* get the first available slot */
14068 + 			if ((id_mask & (1 << id)) == 0) {
14069 + 				ATH_SET_VAP_BSSID(vap->iv_myaddr, id);
14070 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/312-erpupdate.patch kamikaze_7.09/package/madwifi/patches/312-erpupdate.patch
14071 --- kamikaze_7.09.orig/package/madwifi/patches/312-erpupdate.patch	1970-01-01 01:00:00.000000000 +0100
14072 +++ kamikaze_7.09/package/madwifi/patches/312-erpupdate.patch	2008-06-19 17:34:17.000000000 +0200
14073 @@ -0,0 +1,68 @@
14074 +--- a/net80211/ieee80211_beacon.c
14075 ++++ b/net80211/ieee80211_beacon.c
14076 +@@ -542,10 +542,10 @@
14077 + 			vap->iv_flags &= ~IEEE80211_F_XRUPDATE;
14078 + 		}
14079 + #endif
14080 +-		if ((ic->ic_flags_ext & IEEE80211_FEXT_ERPUPDATE) && 
14081 ++		if ((vap->iv_flags_ext & IEEE80211_FEXT_ERPUPDATE) &&
14082 + 				(bo->bo_erp != NULL)) {
14083 + 			(void)ieee80211_add_erp(bo->bo_erp, ic);
14084 +-			ic->ic_flags_ext &= ~IEEE80211_FEXT_ERPUPDATE;
14085 ++			vap->iv_flags_ext &= ~IEEE80211_FEXT_ERPUPDATE;
14086 + 		}
14087 + 	}
14088 + 	/* if it is a mode change beacon for dynamic turbo case */
14089 +--- a/net80211/ieee80211_input.c
14090 ++++ b/net80211/ieee80211_input.c
14091 +@@ -3431,9 +3431,12 @@
14092 + 			/* Assume no ERP IE == 11b AP */
14093 + 			if ((!has_erp || (has_erp && (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) &&
14094 + 				!(ic->ic_flags & IEEE80211_F_USEPROT)) {
14095 ++				struct ieee80211vap *tmpvap;
14096 + 
14097 + 				ic->ic_flags |= IEEE80211_F_USEPROT;
14098 +-				ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14099 ++				TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
14100 ++					tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14101 ++				}
14102 + 			}
14103 + 		}
14104 + 
14105 +--- a/net80211/ieee80211_node.c
14106 ++++ b/net80211/ieee80211_node.c
14107 +@@ -2025,8 +2025,12 @@
14108 + 		}
14109 + 
14110 + 		/* Update ERP element if this is first non ERP station */
14111 +-		if (ic->ic_nonerpsta == 1)
14112 +-			ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14113 ++		if (ic->ic_nonerpsta == 1) {
14114 ++			struct ieee80211vap *tmpvap;
14115 ++			TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
14116 ++				tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14117 ++			}
14118 ++		}
14119 + 	} else
14120 + 		ni->ni_flags |= IEEE80211_NODE_ERP;
14121 + }
14122 +@@ -2229,6 +2233,8 @@
14123 + 		IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
14124 + 			"non-ERP station leaves, count now %d", ic->ic_nonerpsta);
14125 + 		if (ic->ic_nonerpsta == 0) {
14126 ++			struct ieee80211vap *tmpvap;
14127 ++
14128 + 			IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
14129 + 				"%s: disable use of protection\n", __func__);
14130 + 			ic->ic_flags &= ~IEEE80211_F_USEPROT;
14131 +@@ -2240,7 +2246,9 @@
14132 + 				ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
14133 + 				ic->ic_flags &= ~IEEE80211_F_USEBARKER;
14134 + 			}
14135 +-			ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14136 ++			TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
14137 ++				tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
14138 ++			}
14139 + 		}
14140 + 	}
14141 + }
14142 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/317-bmask.patch kamikaze_7.09/package/madwifi/patches/317-bmask.patch
14143 --- kamikaze_7.09.orig/package/madwifi/patches/317-bmask.patch	1970-01-01 01:00:00.000000000 +0100
14144 +++ kamikaze_7.09/package/madwifi/patches/317-bmask.patch	2008-06-19 17:34:17.000000000 +0200
14145 @@ -0,0 +1,13 @@
14146 +--- a/ath/if_ath.c
14147 ++++ b/ath/if_ath.c
14148 +@@ -8680,6 +8680,10 @@
14149 + 
14150 + 	sc->sc_rxbufcur = NULL;
14151 + 
14152 ++	/* configure bssid mask */
14153 ++	if (sc->sc_hasbmask)
14154 ++		ath_hal_setbssidmask(ah, sc->sc_bssidmask);
14155 ++
14156 + 	bf = STAILQ_FIRST(&sc->sc_rxbuf);
14157 + 	ath_hal_putrxbuf(ah, bf->bf_daddr);
14158 + 	ath_hal_rxena(ah);		/* enable recv descriptors */
14159 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/323-dfs_optional.patch kamikaze_7.09/package/madwifi/patches/323-dfs_optional.patch
14160 --- kamikaze_7.09.orig/package/madwifi/patches/323-dfs_optional.patch	1970-01-01 01:00:00.000000000 +0100
14161 +++ kamikaze_7.09/package/madwifi/patches/323-dfs_optional.patch	2008-06-19 17:34:17.000000000 +0200
14162 @@ -0,0 +1,38 @@
14163 +--- a/ath/if_ath.c
14164 ++++ b/ath/if_ath.c
14165 +@@ -1774,17 +1774,14 @@
14166 + 			 * may have occurred in the intervening timeframe. */
14167 + 			bf->bf_channoise = ic->ic_channoise;
14168 + 
14169 +-			if (rs->rs_status) {
14170 +-				if ((HAL_RXERR_PHY == rs->rs_status) &&
14171 +-				    (HAL_PHYERR_RADAR ==
14172 +-				     (rs->rs_phyerr & 0x1f)) &&
14173 +-				    (0 == (bf->bf_status &
14174 +-					   ATH_BUFSTATUS_RADAR_DONE))) {
14175 +-					check_for_radar = 1;
14176 +-				}
14177 +-				/* Skip past the error now */
14178 ++			if ((HAL_RXERR_PHY == rs->rs_status) &&
14179 ++			    (HAL_PHYERR_RADAR == (rs->rs_phyerr & 0x1f)) &&
14180 ++			    (0 == (bf->bf_status & ATH_BUFSTATUS_RADAR_DONE)) &&
14181 ++			    (ic->ic_flags & IEEE80211_F_DOTH))
14182 ++				check_for_radar = 1;
14183 ++
14184 ++			if (rs->rs_status) /* Skip past the error now */
14185 + 				continue;
14186 +-			}
14187 + 
14188 + 			/* Prepare wireless header for examination */
14189 + 			bus_dma_sync_single(sc->sc_bdev, bf->bf_skbaddr,
14190 +--- a/ath/if_ath_radar.c
14191 ++++ b/ath/if_ath_radar.c
14192 +@@ -261,7 +261,7 @@
14193 + 		unsigned int new_rxfilt = old_rxfilt;
14194 + 
14195 + 		ath_hal_intrset(ah, old_ier & ~HAL_INT_GLOBAL);
14196 +-		if (required) {
14197 ++		if ((required) && (ic->ic_flags & IEEE80211_F_DOTH)) {
14198 + 			new_radar |= AR5K_PHY_RADAR_ENABLE;
14199 + 			new_filter |= AR5K_AR5212_PHY_ERR_FIL_RADAR;
14200 + 			new_rxfilt |= (HAL_RX_FILTER_PHYERR | 
14201 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/324-alignment.patch kamikaze_7.09/package/madwifi/patches/324-alignment.patch
14202 --- kamikaze_7.09.orig/package/madwifi/patches/324-alignment.patch	1970-01-01 01:00:00.000000000 +0100
14203 +++ kamikaze_7.09/package/madwifi/patches/324-alignment.patch	2008-06-19 17:34:17.000000000 +0200
14204 @@ -0,0 +1,19 @@
14205 +--- a/net80211/ieee80211_input.c
14206 ++++ b/net80211/ieee80211_input.c
14207 +@@ -1275,14 +1275,8 @@
14208 + 		eh->ether_type = ether_type;
14209 + 
14210 + 	if (!ALIGNED_POINTER(skb->data + sizeof(*eh), u_int32_t)) {
14211 +-		struct sk_buff *tskb;
14212 +-
14213 +-		/* XXX: does this always work? */
14214 +-		tskb = skb_copy(skb, GFP_ATOMIC);
14215 +-		if (tskb)
14216 +-			ieee80211_skb_copy_noderef(skb, tskb);
14217 +-		ieee80211_dev_kfree_skb(&skb);
14218 +-		skb = tskb;
14219 ++		memmove(skb->data - 2, skb->data, skb->len);
14220 ++		skb->data -= 2;
14221 + 	}
14222 + 	return skb;
14223 + }
14224 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/325-channel_spam.patch kamikaze_7.09/package/madwifi/patches/325-channel_spam.patch
14225 --- kamikaze_7.09.orig/package/madwifi/patches/325-channel_spam.patch	1970-01-01 01:00:00.000000000 +0100
14226 +++ kamikaze_7.09/package/madwifi/patches/325-channel_spam.patch	2008-06-19 17:34:17.000000000 +0200
14227 @@ -0,0 +1,28 @@
14228 +--- a/ath/if_ath.c
14229 ++++ b/ath/if_ath.c
14230 +@@ -9783,7 +9783,9 @@
14231 + 	/*
14232 + 	 * Convert HAL channels to ieee80211 ones.
14233 + 	 */
14234 ++#ifdef AR_DEBUG
14235 + 	IPRINTF(sc, "HAL returned %d channels.\n", nchan);
14236 ++#endif
14237 + 	for (i = 0; i < nchan; i++) {
14238 + 		HAL_CHANNEL *c = &chans[i];
14239 + 		struct ieee80211_channel *ichan = &ic->ic_channels[i];
14240 +@@ -9810,6 +9812,7 @@
14241 + 		ic->ic_chan_non_occupy[i].tv_sec  = 0;
14242 + 		ic->ic_chan_non_occupy[i].tv_usec = 0;
14243 + 
14244 ++#ifdef AR_DEBUG
14245 + 		IPRINTF(sc, "Channel %3d (%4d MHz) Max Tx Power %d dBm%s "
14246 + 				"[%d hw %d reg] Flags%s%s%s%s%s%s%s%s%s%s%s%s%"
14247 + 				"s%s%s%s%s%s%s%s%s%s%s%s\n",
14248 +@@ -9898,6 +9901,7 @@
14249 + 				(c->privFlags & 0x0080 ? 
14250 + 				 " PF & (1 << 7)" : "")
14251 + 				);
14252 ++#endif
14253 + 	}
14254 + 	ic->ic_nchans = nchan;
14255 + 	kfree(chans);
14256 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/327-queue.patch kamikaze_7.09/package/madwifi/patches/327-queue.patch
14257 --- kamikaze_7.09.orig/package/madwifi/patches/327-queue.patch	1970-01-01 01:00:00.000000000 +0100
14258 +++ kamikaze_7.09/package/madwifi/patches/327-queue.patch	2008-06-19 17:34:17.000000000 +0200
14259 @@ -0,0 +1,40 @@
14260 +--- a/ath/if_ath.c
14261 ++++ b/ath/if_ath.c
14262 +@@ -8431,8 +8431,6 @@
14263 + 	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
14264 + 	local_irq_restore(flags);
14265 + 
14266 +-	netif_wake_queue(dev);
14267 +-
14268 + 	if (sc->sc_softled)
14269 + 		ath_led_event(sc, ATH_LED_TX);
14270 + }
14271 +@@ -8479,8 +8477,6 @@
14272 + 	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
14273 + 	local_irq_restore(flags);
14274 + 
14275 +-	netif_wake_queue(dev);
14276 +-
14277 + 	if (sc->sc_softled)
14278 + 		ath_led_event(sc, ATH_LED_TX);
14279 + }
14280 +@@ -8513,8 +8509,6 @@
14281 + 	ath_hal_intrset(sc->sc_ah, sc->sc_imask);
14282 + 	local_irq_restore(flags);
14283 + 
14284 +-	netif_wake_queue(dev);
14285 +-
14286 + 	if (sc->sc_softled)
14287 + 		ath_led_event(sc, ATH_LED_TX);
14288 + }
14289 +--- a/net80211/ieee80211_input.c
14290 ++++ b/net80211/ieee80211_input.c
14291 +@@ -1132,7 +1132,7 @@
14292 + 	    (vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0) {
14293 + 		struct sk_buff *skb1 = NULL;
14294 + 
14295 +-		if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
14296 ++		if (ETHER_IS_MULTICAST(eh->ether_dhost) && !netif_queue_stopped(dev)) {
14297 + 			/* Create a SKB for the BSS to send out. */
14298 + 			skb1 = skb_copy(skb, GFP_ATOMIC);
14299 + 			if (skb1)
14300 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/330-beaconcal.patch kamikaze_7.09/package/madwifi/patches/330-beaconcal.patch
14301 --- kamikaze_7.09.orig/package/madwifi/patches/330-beaconcal.patch	1970-01-01 01:00:00.000000000 +0100
14302 +++ kamikaze_7.09/package/madwifi/patches/330-beaconcal.patch	2008-06-19 17:34:17.000000000 +0200
14303 @@ -0,0 +1,164 @@
14304 +--- a/ath/if_ath.c
14305 ++++ b/ath/if_ath.c
14306 +@@ -397,6 +397,7 @@
14307 + static int maxvaps = -1;
14308 + static int outdoor = -1;
14309 + static int xchanmode = -1;
14310 ++static int beacon_cal = 1;
14311 + 
14312 + static const char *hal_status_desc[] = {
14313 + 	"No error",
14314 +@@ -422,6 +423,7 @@
14315 + };
14316 + 
14317 + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,52))
14318 ++MODULE_PARM(beacon_cal, "i");
14319 + MODULE_PARM(countrycode, "i");
14320 + MODULE_PARM(maxvaps, "i");
14321 + MODULE_PARM(outdoor, "i");
14322 +@@ -434,6 +436,7 @@
14323 + MODULE_PARM(ratectl, "s");
14324 + #else
14325 + #include <linux/moduleparam.h>
14326 ++module_param(beacon_cal, int, 0600);
14327 + module_param(countrycode, int, 0600);
14328 + module_param(maxvaps, int, 0600);
14329 + module_param(outdoor, int, 0600);
14330 +@@ -2598,7 +2601,8 @@
14331 + 		}
14332 + 		if (!sc->sc_invalid) {
14333 + 			del_timer_sync(&sc->sc_dfs_cac_timer);
14334 +-			del_timer_sync(&sc->sc_cal_ch);
14335 ++			if (!sc->sc_beacon_cal)
14336 ++				del_timer_sync(&sc->sc_cal_ch);
14337 + 		}
14338 + 		ath_draintxq(sc);
14339 + 		if (!sc->sc_invalid) {
14340 +@@ -2615,6 +2619,20 @@
14341 + 	return 0;
14342 + }
14343 + 
14344 ++static void ath_set_beacon_cal(struct ath_softc *sc, int val)
14345 ++{
14346 ++	if (sc->sc_beacon_cal == !!val)
14347 ++		return;
14348 ++
14349 ++	if (val) {
14350 ++		del_timer_sync(&sc->sc_cal_ch);
14351 ++	} else {
14352 ++		sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
14353 ++		add_timer(&sc->sc_cal_ch);
14354 ++	}
14355 ++	sc->sc_beacon_cal = !!val && beacon_cal;
14356 ++}
14357 ++
14358 + /*
14359 +  * Stop the device, grabbing the top-level lock to protect
14360 +  * against concurrent entry through ath_init (which can happen
14361 +@@ -2740,6 +2758,12 @@
14362 + 	HAL_STATUS status;
14363 + 
14364 + 	/*
14365 ++	 * XXX: starting the calibration too early seems to lead to
14366 ++	 * problems with the beacons.
14367 ++	 */
14368 ++	sc->sc_lastcal = jiffies;
14369 ++
14370 ++	/*
14371 + 	 * Convert to a HAL channel description with the flags
14372 + 	 * constrained to reflect the current operating mode.
14373 + 	 */
14374 +@@ -5145,6 +5169,8 @@
14375 + 			"Invoking ath_hal_txstart with sc_bhalq: %d\n",
14376 + 			sc->sc_bhalq);
14377 + 		ath_hal_txstart(ah, sc->sc_bhalq);
14378 ++		if (sc->sc_beacon_cal && (jiffies > sc->sc_lastcal + (ath_calinterval * HZ)))
14379 ++			ath_calibrate((unsigned long) sc->sc_dev);
14380 + 
14381 + 		sc->sc_stats.ast_be_xmit++;		/* XXX per-VAP? */
14382 + 	}
14383 +@@ -5394,6 +5420,7 @@
14384 + 		ath_hal_beacontimers(ah, &bs);
14385 + 		sc->sc_imask |= HAL_INT_BMISS;
14386 + 		ath_hal_intrset(ah, sc->sc_imask);
14387 ++		ath_set_beacon_cal(sc, 0);
14388 + 	} else {
14389 + 		ath_hal_intrset(ah, 0);
14390 + 		if (reset_tsf)
14391 +@@ -5405,8 +5432,11 @@
14392 + 			 */
14393 + 			intval |= HAL_BEACON_ENA;
14394 + 			sc->sc_imask |= HAL_INT_SWBA;
14395 ++			ath_set_beacon_cal(sc, 1);
14396 + 			ath_beaconq_config(sc);
14397 +-		}
14398 ++		} else
14399 ++			ath_set_beacon_cal(sc, 0);
14400 ++
14401 + #ifdef ATH_SUPERG_DYNTURBO
14402 + 		ath_beacon_dturbo_config(vap, intval &
14403 + 				~(HAL_BEACON_RESET_TSF | HAL_BEACON_ENA));
14404 +@@ -8870,6 +8900,9 @@
14405 + 			/* Enter DFS wait period */
14406 + 			mod_timer(&sc->sc_dfs_cac_timer,
14407 + 				jiffies + (sc->sc_dfs_cac_period * HZ));
14408 ++
14409 ++			/* This is a good time to start a calibration */
14410 ++			ath_set_beacon_cal(sc, 1);
14411 + 		}
14412 + 		/*
14413 + 		 * re configure beacons when it is a turbo mode switch.
14414 +@@ -8979,8 +9012,11 @@
14415 + 		sc->sc_curchan.channel, sc->sc_curchan.channelFlags,
14416 + 		isIQdone ? "done" : "not done");
14417 + 
14418 +-	sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
14419 +-	add_timer(&sc->sc_cal_ch);
14420 ++	sc->sc_lastcal = jiffies;
14421 ++	if (!sc->sc_beacon_cal) {
14422 ++		sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
14423 ++		add_timer(&sc->sc_cal_ch);
14424 ++	}
14425 + }
14426 + 
14427 + static void
14428 +@@ -9087,7 +9123,8 @@
14429 + 		ieee80211_state_name[vap->iv_state],
14430 + 		ieee80211_state_name[nstate]);
14431 + 
14432 +-	del_timer(&sc->sc_cal_ch);		/* periodic calibration timer */
14433 ++	if (!sc->sc_beacon_cal)
14434 ++		del_timer(&sc->sc_cal_ch);		/* periodic calibration timer */
14435 + 
14436 + 	ath_hal_setledstate(ah, leds[nstate]);	/* set LED */
14437 + 	netif_stop_queue(dev);			/* before we do anything else */
14438 +@@ -9312,7 +9349,8 @@
14439 + 				"VAP -> DFSWAIT_PENDING \n");
14440 + 			/* start calibration timer with a really small value 
14441 + 			 * 1/10 sec */
14442 +-			mod_timer(&sc->sc_cal_ch, jiffies + (HZ/10));
14443 ++			if (!sc->sc_beacon_cal)
14444 ++				mod_timer(&sc->sc_cal_ch, jiffies + (HZ/10));
14445 + 			/* wake the receiver */
14446 + 			netif_wake_queue(dev);
14447 + 			/* don't do the other usual stuff... */
14448 +@@ -9355,7 +9393,7 @@
14449 + 	error = avp->av_newstate(vap, nstate, arg);
14450 + 
14451 + 	/* Finally, start any timers. */
14452 +-	if (nstate == IEEE80211_S_RUN) {
14453 ++	if (nstate == IEEE80211_S_RUN && !sc->sc_beacon_cal) {
14454 + 		/* start periodic recalibration timer */
14455 + 		mod_timer(&sc->sc_cal_ch, jiffies + (ath_calinterval * HZ));
14456 + 	}
14457 +--- a/ath/if_athvar.h
14458 ++++ b/ath/if_athvar.h
14459 +@@ -778,6 +778,8 @@
14460 + 	struct ieee80211vap **sc_bslot;		/* beacon xmit slots */
14461 + 	int sc_bnext;				/* next slot for beacon xmit */
14462 + 
14463 ++	int sc_beacon_cal;			/* use beacon timer for calibration */
14464 ++	u_int64_t sc_lastcal;			/* last time the calibration was performed */
14465 + 	struct timer_list sc_cal_ch;		/* calibration timer */
14466 + 	HAL_NODE_STATS sc_halstats;		/* station-mode rssi stats */
14467 + 
14468 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/331-memory_alloc.patch kamikaze_7.09/package/madwifi/patches/331-memory_alloc.patch
14469 --- kamikaze_7.09.orig/package/madwifi/patches/331-memory_alloc.patch	1970-01-01 01:00:00.000000000 +0100
14470 +++ kamikaze_7.09/package/madwifi/patches/331-memory_alloc.patch	2008-06-19 17:34:17.000000000 +0200
14471 @@ -0,0 +1,36 @@
14472 +--- a/ath/if_ath.c
14473 ++++ b/ath/if_ath.c
14474 +@@ -3318,17 +3318,18 @@
14475 + 	 * without affecting any other bridge ports. */
14476 + 	if (skb_cloned(skb)) {
14477 + 		/* Remember the original SKB so we can free up our references */
14478 +-		struct sk_buff *skb_orig = skb;
14479 +-		skb = skb_copy(skb, GFP_ATOMIC);
14480 +-		if (skb == NULL) {
14481 ++		struct sk_buff *skb_new;
14482 ++		skb_new = skb_copy(skb, GFP_ATOMIC);
14483 ++		if (skb_new == NULL) {
14484 + 			DPRINTF(sc, ATH_DEBUG_XMIT,
14485 + 				"Dropping; skb_copy failure.\n");
14486 + 			/* No free RAM, do not requeue! */
14487 + 			goto hardstart_fail;
14488 + 		}
14489 +-		ieee80211_skb_copy_noderef(skb_orig, skb);
14490 +-		ieee80211_dev_kfree_skb(&skb_orig);
14491 +-	} 
14492 ++		ieee80211_skb_copy_noderef(skb, skb_new);
14493 ++		ieee80211_dev_kfree_skb(&skb);
14494 ++		skb = skb_new;
14495 ++	}
14496 + 	eh = (struct ether_header *)skb->data;
14497 + 
14498 + #ifdef ATH_SUPERG_FF
14499 +@@ -3599,6 +3600,8 @@
14500 + 	sc->sc_stats.ast_tx_mgmt++;
14501 + 	return 0;
14502 + bad:
14503 ++	if (skb)
14504 ++		ieee80211_dev_kfree_skb(&skb);
14505 + 	ath_return_txbuf(sc, &bf);
14506 + 	return error;
14507 + }
14508 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/332-reset_beacons.patch kamikaze_7.09/package/madwifi/patches/332-reset_beacons.patch
14509 --- kamikaze_7.09.orig/package/madwifi/patches/332-reset_beacons.patch	1970-01-01 01:00:00.000000000 +0100
14510 +++ kamikaze_7.09/package/madwifi/patches/332-reset_beacons.patch	2008-06-19 17:34:17.000000000 +0200
14511 @@ -0,0 +1,11 @@
14512 +--- a/ath/if_ath.c
14513 ++++ b/ath/if_ath.c
14514 +@@ -8911,7 +8911,7 @@
14515 + 		 * re configure beacons when it is a turbo mode switch.
14516 + 		 * HW seems to turn off beacons during turbo mode switch.
14517 + 		 */
14518 +-		if (sc->sc_beacons && tswitch && !sc->sc_dfs_cac)
14519 ++		if (sc->sc_beacons && !sc->sc_dfs_cac)
14520 + 			ath_beacon_config(sc, NULL);
14521 + 		/*
14522 + 		 * Re-enable interrupts.
14523 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/333-apscan_mode.patch kamikaze_7.09/package/madwifi/patches/333-apscan_mode.patch
14524 --- kamikaze_7.09.orig/package/madwifi/patches/333-apscan_mode.patch	1970-01-01 01:00:00.000000000 +0100
14525 +++ kamikaze_7.09/package/madwifi/patches/333-apscan_mode.patch	2008-06-19 17:34:17.000000000 +0200
14526 @@ -0,0 +1,15 @@
14527 +--- a/net80211/ieee80211_scan_ap.c
14528 ++++ b/net80211/ieee80211_scan_ap.c
14529 +@@ -781,12 +781,6 @@
14530 + 				/* break the loop as the subsequent chans won't be 
14531 + 				 * better */
14532 + 				break;
14533 +-
14534 +-			if (!IEEE80211_ARE_CHANS_SAME_MODE(c->chan,
14535 +-				ic->ic_bsschan))
14536 +-				/* break the loop as the subsequent chans won't be 
14537 +-				 * better */
14538 +-				break;
14539 + 		}
14540 + 
14541 + 		if (sta_assoc != 0) {
14542 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/334-input.patch kamikaze_7.09/package/madwifi/patches/334-input.patch
14543 --- kamikaze_7.09.orig/package/madwifi/patches/334-input.patch	1970-01-01 01:00:00.000000000 +0100
14544 +++ kamikaze_7.09/package/madwifi/patches/334-input.patch	2008-06-19 17:34:17.000000000 +0200
14545 @@ -0,0 +1,12 @@
14546 +--- a/net80211/ieee80211_input.c
14547 ++++ b/net80211/ieee80211_input.c
14548 +@@ -950,6 +950,9 @@
14549 + 	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
14550 + 		struct sk_buff *skb1;
14551 + 
14552 ++		if ((vap->iv_dev->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
14553 ++			continue;
14554 ++
14555 + 		if (TAILQ_NEXT(vap, iv_next) != NULL) {
14556 + 			skb1 = skb_copy(skb, GFP_ATOMIC);
14557 + 			if (skb1 == NULL) {
14558 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/340-maxrate.patch kamikaze_7.09/package/madwifi/patches/340-maxrate.patch
14559 --- kamikaze_7.09.orig/package/madwifi/patches/340-maxrate.patch	1970-01-01 01:00:00.000000000 +0100
14560 +++ kamikaze_7.09/package/madwifi/patches/340-maxrate.patch	2008-06-19 17:34:17.000000000 +0200
14561 @@ -0,0 +1,98 @@
14562 +--- a/ath/if_ath.c
14563 ++++ b/ath/if_ath.c
14564 +@@ -1307,6 +1307,7 @@
14565 + 	vap->iv_key_set = ath_key_set;
14566 + 	vap->iv_key_update_begin = ath_key_update_begin;
14567 + 	vap->iv_key_update_end = ath_key_update_end;
14568 ++	vap->iv_maxrateindex = 0;
14569 + 	if (sc->sc_default_ieee80211_debug) {
14570 + 		/* User specified defaults for new VAPs were provided, so
14571 + 		 * use those (only). */
14572 +--- a/ath_rate/minstrel/minstrel.c
14573 ++++ b/ath_rate/minstrel/minstrel.c
14574 +@@ -622,8 +622,12 @@
14575 + 			return;
14576 + 		}
14577 + 		sn->static_rate_ndx = -1;
14578 ++		if (vap->iv_maxrateindex == 0 || ni->ni_rates.rs_nrates <= 0
14579 ++		    || vap->iv_maxrateindex > ni->ni_rates.rs_nrates)
14580 ++			sn->num_rates = ni->ni_rates.rs_nrates;
14581 ++		else
14582 ++			sn->num_rates = vap->iv_maxrateindex;
14583 + 
14584 +-		sn->num_rates = ni->ni_rates.rs_nrates;
14585 + 		for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
14586 + 			sn->rs_rateattempts 	[x] = 0;
14587 + 			sn->rs_thisprob 	[x] = 0;
14588 +--- a/ath_rate/sample/sample.c
14589 ++++ b/ath_rate/sample/sample.c
14590 +@@ -835,7 +835,12 @@
14591 + 	}
14592 + 	sn->static_rate_ndx = -1;
14593 + 
14594 +-	sn->num_rates = ni->ni_rates.rs_nrates;
14595 ++	if (vap->iv_maxrateindex == 0 || ni->ni_rates.rs_nrates <= 0
14596 ++	    || vap->iv_maxrateindex > ni->ni_rates.rs_nrates)
14597 ++		sn->num_rates = ni->ni_rates.rs_nrates;
14598 ++	else
14599 ++		sn->num_rates = vap->iv_maxrateindex;
14600 ++
14601 + 	for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
14602 + 		sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;
14603 + 		sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];
14604 +--- a/net80211/ieee80211_ioctl.h
14605 ++++ b/net80211/ieee80211_ioctl.h
14606 +@@ -641,6 +641,7 @@
14607 + 							   FCC requires 30m, so that is the default. */
14608 + 	IEEE80211_PARAM_BEACON_MISS_THRESH	= 73,	/* Beacon miss threshold (in beacons) */
14609 + 	IEEE80211_PARAM_BEACON_MISS_THRESH_MS	= 74,	/* Beacon miss threshold (in ms) */
14610 ++	IEEE80211_PARAM_MAXRATE			= 75,	/* Maximum rate (by table index) */
14611 + };
14612 + 
14613 + #define	SIOCG80211STATS			(SIOCDEVPRIVATE+2)
14614 +--- a/net80211/ieee80211_var.h
14615 ++++ b/net80211/ieee80211_var.h
14616 +@@ -281,6 +281,7 @@
14617 + 	struct ieee80211_spy iv_spy;         		/* IWSPY support */
14618 + 	struct ieee80211_app_ie app_ie[IEEE80211_APPIE_NUM_OF_FRAME]; /* app-specified IEs by frame type */
14619 + 	u_int32_t app_filter;				/* filters which management frames are forwarded to app */
14620 ++	int iv_maxrateindex;
14621 + };
14622 + 
14623 + /* Debug functions need the defintion of struct ieee80211vap because iv_debug 
14624 +--- a/net80211/ieee80211_wireless.c
14625 ++++ b/net80211/ieee80211_wireless.c
14626 +@@ -2839,6 +2839,12 @@
14627 + 		else
14628 + 			ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
14629 + 		break;
14630 ++	case IEEE80211_PARAM_MAXRATE:
14631 ++		if (value > 0)
14632 ++			vap->iv_maxrateindex = value;
14633 ++		else
14634 ++			vap->iv_maxrateindex = 0;
14635 ++		break;
14636 + #ifdef ATH_REVERSE_ENGINEERING
14637 + 	case IEEE80211_PARAM_DUMPREGS:
14638 + 		ieee80211_dump_registers(dev, info, w, extra);
14639 +@@ -3174,6 +3180,9 @@
14640 + 		else
14641 + 			param[0] = 0;
14642 + 		break;
14643 ++	case IEEE80211_PARAM_MAXRATE:
14644 ++		param[0] = vap->iv_maxrateindex;
14645 ++		break;
14646 + 	default:
14647 + 		return -EOPNOTSUPP;
14648 + 	}
14649 +@@ -5610,6 +5619,10 @@
14650 + 	  0, IW_PRIV_TYPE_APPIEBUF, "getiebuf" },
14651 + 	{ IEEE80211_IOCTL_FILTERFRAME,
14652 + 	  IW_PRIV_TYPE_FILTER , 0, "setfilter" },
14653 ++	{IEEE80211_PARAM_MAXRATE,
14654 ++	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maxrate"},
14655 ++	{IEEE80211_PARAM_MAXRATE,
14656 ++	 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_maxrate"},
14657 + 
14658 + #ifdef ATH_REVERSE_ENGINEERING
14659 + 	/*
14660 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/341-minrate.patch kamikaze_7.09/package/madwifi/patches/341-minrate.patch
14661 --- kamikaze_7.09.orig/package/madwifi/patches/341-minrate.patch	1970-01-01 01:00:00.000000000 +0100
14662 +++ kamikaze_7.09/package/madwifi/patches/341-minrate.patch	2008-06-19 17:34:17.000000000 +0200
14663 @@ -0,0 +1,114 @@
14664 +--- a/ath/if_ath.c
14665 ++++ b/ath/if_ath.c
14666 +@@ -1308,6 +1308,7 @@
14667 + 	vap->iv_key_update_begin = ath_key_update_begin;
14668 + 	vap->iv_key_update_end = ath_key_update_end;
14669 + 	vap->iv_maxrateindex = 0;
14670 ++	vap->iv_minrateindex = 0;
14671 + 	if (sc->sc_default_ieee80211_debug) {
14672 + 		/* User specified defaults for new VAPs were provided, so
14673 + 		 * use those (only). */
14674 +--- a/ath_rate/minstrel/minstrel.c
14675 ++++ b/ath_rate/minstrel/minstrel.c
14676 +@@ -638,9 +638,15 @@
14677 + 			sn->rs_succ_hist	[x] = 0;
14678 + 			sn->rs_att_hist 	[x] = 0;
14679 + 			sn->rs_this_tp 		[x] = 0;
14680 +-
14681 ++			if (vap->iv_minrateindex && vap->iv_minrateindex<ni->ni_rates.rs_nrates)
14682 ++			{
14683 ++			int idx = vap->iv_minrateindex; 
14684 ++			sn->rates[x].rate = ni->ni_rates.rs_rates[idx] & IEEE80211_RATE_VAL;
14685 ++			sn->rates[x].rix = sc->sc_rixmap[sn->rates[idx].rate];
14686 ++			}else{
14687 + 			sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;
14688 + 			sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];
14689 ++			}
14690 + 			if (sn->rates[x].rix == 0xff) {
14691 + 				DPRINTF(sc, "%s: %s ignore bogus rix at %d\n",
14692 + 					dev_info, __func__, x);
14693 +@@ -649,7 +655,7 @@
14694 + 			sn->rates[x].rateCode = rt->info[sn->rates[x].rix].rateCode;
14695 + 			sn->rates[x].shortPreambleRateCode =
14696 + 				rt->info[sn->rates[x].rix].rateCode |
14697 +-				rt->info[sn->rates[x].rix].shortPreamble;
14698 ++				rt->info[sn->rates[x].rix].shortPreamble;			
14699 + 		}
14700 + 
14701 + 		ath_fill_sample_table(sn);
14702 +--- a/ath_rate/sample/sample.c
14703 ++++ b/ath_rate/sample/sample.c
14704 +@@ -842,8 +842,15 @@
14705 + 		sn->num_rates = vap->iv_maxrateindex;
14706 + 
14707 + 	for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
14708 +-		sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;
14709 +-		sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];
14710 ++		if (vap->iv_minrateindex && vap->iv_minrateindex<ni->ni_rates.rs_nrates)
14711 ++			{
14712 ++			int idx = vap->iv_minrateindex; 
14713 ++			sn->rates[x].rate = ni->ni_rates.rs_rates[idx] & IEEE80211_RATE_VAL;
14714 ++			sn->rates[x].rix = sc->sc_rixmap[sn->rates[idx].rate];
14715 ++			}else{
14716 ++			sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;
14717 ++			sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];
14718 ++			}
14719 + 		if (sn->rates[x].rix == 0xff) {
14720 + 			DPRINTF(sc, ATH_DEBUG_RATE, "%s: %s ignore bogus rix at %u\n",
14721 + 				dev_info, __func__, x);
14722 +--- a/net80211/ieee80211_ioctl.h
14723 ++++ b/net80211/ieee80211_ioctl.h
14724 +@@ -642,6 +642,7 @@
14725 + 	IEEE80211_PARAM_BEACON_MISS_THRESH	= 73,	/* Beacon miss threshold (in beacons) */
14726 + 	IEEE80211_PARAM_BEACON_MISS_THRESH_MS	= 74,	/* Beacon miss threshold (in ms) */
14727 + 	IEEE80211_PARAM_MAXRATE			= 75,	/* Maximum rate (by table index) */
14728 ++	IEEE80211_PARAM_MINRATE			= 76,	/* Maximum rate (by table index) */
14729 + };
14730 + 
14731 + #define	SIOCG80211STATS			(SIOCDEVPRIVATE+2)
14732 +--- a/net80211/ieee80211_var.h
14733 ++++ b/net80211/ieee80211_var.h
14734 +@@ -282,6 +282,7 @@
14735 + 	struct ieee80211_app_ie app_ie[IEEE80211_APPIE_NUM_OF_FRAME]; /* app-specified IEs by frame type */
14736 + 	u_int32_t app_filter;				/* filters which management frames are forwarded to app */
14737 + 	int iv_maxrateindex;
14738 ++	int iv_minrateindex;
14739 + };
14740 + 
14741 + /* Debug functions need the defintion of struct ieee80211vap because iv_debug 
14742 +--- a/net80211/ieee80211_wireless.c
14743 ++++ b/net80211/ieee80211_wireless.c
14744 +@@ -2845,6 +2845,12 @@
14745 + 		else
14746 + 			vap->iv_maxrateindex = 0;
14747 + 		break;
14748 ++	case IEEE80211_PARAM_MINRATE:
14749 ++		if (value > 0)
14750 ++			vap->iv_minrateindex = value;
14751 ++		else
14752 ++			vap->iv_minrateindex = 0;
14753 ++		break;
14754 + #ifdef ATH_REVERSE_ENGINEERING
14755 + 	case IEEE80211_PARAM_DUMPREGS:
14756 + 		ieee80211_dump_registers(dev, info, w, extra);
14757 +@@ -3183,6 +3189,9 @@
14758 + 	case IEEE80211_PARAM_MAXRATE:
14759 + 		param[0] = vap->iv_maxrateindex;
14760 + 		break;
14761 ++	case IEEE80211_PARAM_MINRATE:
14762 ++		param[0] = vap->iv_minrateindex;
14763 ++		break;
14764 + 	default:
14765 + 		return -EOPNOTSUPP;
14766 + 	}
14767 +@@ -5623,6 +5632,10 @@
14768 + 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maxrate"},
14769 + 	{IEEE80211_PARAM_MAXRATE,
14770 + 	 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_maxrate"},
14771 ++	{IEEE80211_PARAM_MINRATE,
14772 ++	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "minrate"},
14773 ++	{IEEE80211_PARAM_MINRATE,
14774 ++	 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_minrate"},
14775 + 
14776 + #ifdef ATH_REVERSE_ENGINEERING
14777 + 	/*
14778 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/342-performance.patch kamikaze_7.09/package/madwifi/patches/342-performance.patch
14779 --- kamikaze_7.09.orig/package/madwifi/patches/342-performance.patch	1970-01-01 01:00:00.000000000 +0100
14780 +++ kamikaze_7.09/package/madwifi/patches/342-performance.patch	2008-06-19 17:34:17.000000000 +0200
14781 @@ -0,0 +1,263 @@
14782 +--- a/ath/if_ath.c
14783 ++++ b/ath/if_ath.c
14784 +@@ -3237,7 +3237,6 @@
14785 + 	struct ath_softc *sc = dev->priv;
14786 + 	struct ieee80211_node *ni = NULL;
14787 + 	struct ath_buf *bf = NULL;
14788 +-	struct ether_header *eh;
14789 + 	ath_bufhead bf_head;
14790 + 	struct ath_buf *tbf, *tempbf;
14791 + 	struct sk_buff *tskb;
14792 +@@ -3249,6 +3248,7 @@
14793 + 	*/
14794 + 	int requeue = 0;
14795 + #ifdef ATH_SUPERG_FF
14796 ++	struct ether_header *eh;
14797 + 	unsigned int pktlen;
14798 + 	struct ieee80211com *ic = &sc->sc_ic;
14799 + 	struct ath_node *an;
14800 +@@ -3314,27 +3314,9 @@
14801 + 		requeue = 1;
14802 + 		goto hardstart_fail;
14803 + 	}
14804 +-#endif
14805 + 
14806 +-	/* If the skb data is shared, we will copy it so we can strip padding
14807 +-	 * without affecting any other bridge ports. */
14808 +-	if (skb_cloned(skb)) {
14809 +-		/* Remember the original SKB so we can free up our references */
14810 +-		struct sk_buff *skb_new;
14811 +-		skb_new = skb_copy(skb, GFP_ATOMIC);
14812 +-		if (skb_new == NULL) {
14813 +-			DPRINTF(sc, ATH_DEBUG_XMIT,
14814 +-				"Dropping; skb_copy failure.\n");
14815 +-			/* No free RAM, do not requeue! */
14816 +-			goto hardstart_fail;
14817 +-		}
14818 +-		ieee80211_skb_copy_noderef(skb, skb_new);
14819 +-		ieee80211_dev_kfree_skb(&skb);
14820 +-		skb = skb_new;
14821 +-	}
14822 + 	eh = (struct ether_header *)skb->data;
14823 + 
14824 +-#ifdef ATH_SUPERG_FF
14825 + 	/* NB: use this lock to protect an->an_tx_ffbuf (and txq->axq_stageq)
14826 + 	 *     in athff_can_aggregate() call too. */
14827 + 	ATH_TXQ_LOCK_IRQ(txq);
14828 +--- a/net80211/ieee80211_output.c
14829 ++++ b/net80211/ieee80211_output.c
14830 +@@ -283,7 +283,7 @@
14831 + 	 * normal vap. */
14832 + 	if (vap->iv_xrvap && (ni == vap->iv_bss) &&
14833 + 	    vap->iv_xrvap->iv_sta_assoc) {
14834 +-		struct sk_buff *skb1 = skb_copy(skb, GFP_ATOMIC);
14835 ++		struct sk_buff *skb1 = skb_clone(skb, GFP_ATOMIC);
14836 + 		if (skb1) {
14837 + 			memset(SKB_CB(skb1), 0, sizeof(struct ieee80211_cb));
14838 + #ifdef IEEE80211_DEBUG_REFCNT
14839 +@@ -566,7 +566,7 @@
14840 + 	struct ieee80211_key *key, struct sk_buff *skb, int ismulticast)
14841 + {
14842 + 	/* XXX pre-calculate per node? */
14843 +-	int need_headroom = LLC_SNAPFRAMELEN + hdrsize + IEEE80211_ADDR_LEN;
14844 ++	int need_headroom = LLC_SNAPFRAMELEN + hdrsize;
14845 + 	int need_tailroom = 0;
14846 + #ifdef ATH_SUPERG_FF
14847 + 	int isff = ATH_FF_MAGIC_PRESENT(skb);
14848 +@@ -608,109 +608,56 @@
14849 + 				need_tailroom += cip->ic_miclen;
14850 + 	}
14851 + 
14852 +-	if (skb_shared(skb)) {
14853 +-		/* Take our own reference to the node in the clone */
14854 +-		ieee80211_ref_node(SKB_CB(skb)->ni);
14855 +-		/* Unshare the node, decrementing users in the old skb */
14856 +-		skb = skb_unshare(skb, GFP_ATOMIC);
14857 ++	need_headroom -= skb_headroom(skb);
14858 ++	if (isff)
14859 ++		need_tailroom -= skb_tailroom(skb2);
14860 ++	else
14861 ++		need_tailroom -= skb_tailroom(skb);
14862 ++
14863 ++	if (need_headroom < 0)
14864 ++		need_headroom = 0;
14865 ++	if (need_tailroom < 0)
14866 ++		need_tailroom = 0;
14867 ++
14868 ++	if (skb_cloned(skb) || (need_headroom > 0) ||
14869 ++		(!isff && (need_tailroom > 0))) {
14870 ++
14871 ++		if (pskb_expand_head(skb, need_headroom, need_tailroom, GFP_ATOMIC)) {
14872 ++			IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14873 ++				"%s: cannot expand storage (tail)\n", __func__);
14874 ++			goto error;
14875 ++		}
14876 + 	}
14877 + 
14878 + #ifdef ATH_SUPERG_FF
14879 + 	if (isff) {
14880 +-		if (skb == NULL) {
14881 +-			IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14882 +-				"%s: cannot unshare for encapsulation\n",
14883 +-				__func__);
14884 +-			vap->iv_stats.is_tx_nobuf++;
14885 +-			ieee80211_dev_kfree_skb(&skb2);
14886 +-
14887 +-			return NULL;
14888 +-		}
14889 ++		inter_headroom -= skb_headroom(skb2);
14890 ++		if (inter_headroom < 0)
14891 ++			inter_headroom = 0;
14892 ++		if ((skb_cloned(skb2) ||
14893 ++			(inter_headroom > 0) || (need_tailroom > 0))) {
14894 + 
14895 +-		/* first skb header */
14896 +-		if (skb_headroom(skb) < need_headroom) {
14897 +-			struct sk_buff *tmp = skb;
14898 +-			skb = skb_realloc_headroom(skb, need_headroom);
14899 +-			if (skb == NULL) {
14900 ++			if (pskb_expand_head(skb2, inter_headroom,
14901 ++				need_tailroom, GFP_ATOMIC)) {
14902 + 				IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14903 +-					"%s: cannot expand storage (head1)\n",
14904 +-					__func__);
14905 +-				vap->iv_stats.is_tx_nobuf++;
14906 +-				ieee80211_dev_kfree_skb(&skb2);
14907 +-				return NULL;
14908 +-			} else
14909 +-				ieee80211_skb_copy_noderef(tmp, skb);
14910 +-			ieee80211_dev_kfree_skb(&tmp);
14911 +-			/* NB: cb[] area was copied, but not next ptr. must do that
14912 +-			 *     prior to return on success. */
14913 +-		}
14914 +-
14915 +-		/* second skb with header and tail adjustments possible */
14916 +-		if (skb_tailroom(skb2) < need_tailroom) {
14917 +-			int n = 0;
14918 +-			if (inter_headroom > skb_headroom(skb2))
14919 +-				n = inter_headroom - skb_headroom(skb2);
14920 +-			if (pskb_expand_head(skb2, n,
14921 +-			    need_tailroom - skb_tailroom(skb2), GFP_ATOMIC)) {
14922 +-				ieee80211_dev_kfree_skb(&skb2);
14923 +-				IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14924 +-					"%s: cannot expand storage (tail2)\n",
14925 +-					__func__);
14926 +-				vap->iv_stats.is_tx_nobuf++;
14927 +-				/* this shouldn't happen, but don't send first ff either */
14928 +-				ieee80211_dev_kfree_skb(&skb);
14929 ++					"%s: cannot expand storage (tail)\n", __func__);
14930 ++				goto error;
14931 + 			}
14932 +-		} else if (skb_headroom(skb2) < inter_headroom) {
14933 +-			struct sk_buff *tmp = skb2;
14934 +-
14935 +-			skb2 = skb_realloc_headroom(skb2, inter_headroom);
14936 +-			if (skb2 == NULL) {
14937 +-				IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14938 +-					"%s: cannot expand storage (head2)\n",
14939 +-					__func__);
14940 +-				vap->iv_stats.is_tx_nobuf++;
14941 +-				/* this shouldn't happen, but don't send first ff either */
14942 +-				ieee80211_dev_kfree_skb(&skb);
14943 +-				skb = NULL;
14944 +-			} else
14945 +-				ieee80211_skb_copy_noderef(tmp, skb);
14946 +-			ieee80211_dev_kfree_skb(&tmp);
14947 + 		}
14948 +-		if (skb) {
14949 +-			skb->next = skb2;
14950 +-		}
14951 +-		return skb;
14952 ++		skb->next = skb2;
14953 + 	}
14954 + #endif /* ATH_SUPERG_FF */
14955 +-	if (skb == NULL) {
14956 +-		IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14957 +-			"%s: cannot unshare for encapsulation\n", __func__);
14958 +-		vap->iv_stats.is_tx_nobuf++;
14959 +-	} else if (skb_tailroom(skb) < need_tailroom) {
14960 +-		int n = 0;
14961 +-		if (need_headroom > skb_headroom(skb))
14962 +-			n = need_headroom - skb_headroom(skb);
14963 +-		if (pskb_expand_head(skb, n, need_tailroom - 
14964 +-					skb_tailroom(skb), GFP_ATOMIC)) {
14965 +-			IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14966 +-				"%s: cannot expand storage (tail)\n", __func__);
14967 +-			vap->iv_stats.is_tx_nobuf++;
14968 +-			ieee80211_dev_kfree_skb(&skb);
14969 +-		}
14970 +-	} else if (skb_headroom(skb) < need_headroom) {
14971 +-		struct sk_buff *tmp = skb;
14972 +-		skb = skb_realloc_headroom(skb, need_headroom);
14973 +-		/* Increment reference count after copy */
14974 +-		if (skb == NULL) {
14975 +-			IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
14976 +-				"%s: cannot expand storage (head)\n", __func__);
14977 +-			vap->iv_stats.is_tx_nobuf++;
14978 +-		} else
14979 +-			ieee80211_skb_copy_noderef(tmp, skb);
14980 +-		ieee80211_dev_kfree_skb(&tmp);
14981 +-	}
14982 + 
14983 + 	return skb;
14984 ++
14985 ++error:
14986 ++	vap->iv_stats.is_tx_nobuf++;
14987 ++	ieee80211_dev_kfree_skb(&skb);
14988 ++#ifdef ATH_SUPERG_FF
14989 ++	if (skb2)
14990 ++		ieee80211_dev_kfree_skb(&skb2);
14991 ++#endif
14992 ++	return NULL;
14993 + }
14994 + 
14995 + #define	KEY_UNDEFINED(k)	((k).wk_cipher == &ieee80211_cipher_none)
14996 +--- a/net80211/ieee80211_input.c
14997 ++++ b/net80211/ieee80211_input.c
14998 +@@ -204,7 +204,6 @@
14999 + 	struct ieee80211_frame *wh;
15000 + 	struct ieee80211_key *key;
15001 + 	struct ether_header *eh;
15002 +-	struct sk_buff *skb2;
15003 + #ifdef ATH_SUPERG_FF
15004 + 	struct llc *llc;
15005 + #endif
15006 +@@ -244,20 +243,6 @@
15007 + 		vap->iv_stats.is_rx_tooshort++;
15008 + 		goto out;
15009 + 	}
15010 +-	/* Clone the SKB... we assume somewhere in this driver that we 'own'
15011 +-	 * the skbuff passed into hard start and we do a lot of messing with it
15012 +-	 * but bridges under some cases will not clone for the first pass of skb
15013 +-	 * to a bridge port, but will then clone for subsequent ones.  This is 
15014 +-	 * odd behavior but it means that if we have trashed the skb we are given
15015 +-	 * then other ports get clones of the residual garbage.
15016 +-	 */
15017 +-	if ((skb2 = skb_copy(skb, GFP_ATOMIC)) == NULL) {
15018 +-		vap->iv_devstats.tx_dropped++;
15019 +-		goto out;
15020 +-	}
15021 +-	ieee80211_skb_copy_noderef(skb, skb2);
15022 +-	ieee80211_dev_kfree_skb(&skb);
15023 +-	skb = skb2;
15024 + 
15025 + 	/*
15026 + 	 * Bit of a cheat here, we use a pointer for a 3-address
15027 +@@ -738,7 +723,7 @@
15028 + 			/* ether_type must be length as FF frames are always LLC/SNAP encap'd */ 
15029 + 			frame_len = ntohs(eh_tmp->ether_type); 
15030 + 
15031 +-			skb1 = skb_copy(skb, GFP_ATOMIC);
15032 ++			skb1 = skb_clone(skb, GFP_ATOMIC);
15033 + 			if (skb1 == NULL)
15034 + 				goto err;
15035 + 			ieee80211_skb_copy_noderef(skb, skb1);
15036 +@@ -1137,7 +1122,7 @@
15037 + 
15038 + 		if (ETHER_IS_MULTICAST(eh->ether_dhost) && !netif_queue_stopped(dev)) {
15039 + 			/* Create a SKB for the BSS to send out. */
15040 +-			skb1 = skb_copy(skb, GFP_ATOMIC);
15041 ++			skb1 = skb_clone(skb, GFP_ATOMIC);
15042 + 			if (skb1)
15043 + 				SKB_CB(skb1)->ni = ieee80211_ref_node(vap->iv_bss); 
15044 + 		}
15045 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/343-txqueue_races.patch kamikaze_7.09/package/madwifi/patches/343-txqueue_races.patch
15046 --- kamikaze_7.09.orig/package/madwifi/patches/343-txqueue_races.patch	1970-01-01 01:00:00.000000000 +0100
15047 +++ kamikaze_7.09/package/madwifi/patches/343-txqueue_races.patch	2008-06-19 17:34:17.000000000 +0200
15048 @@ -0,0 +1,34 @@
15049 +Merged from madwifi trunk r3551, r3552
15050 +
15051 +--- a/ath/if_ath.c
15052 ++++ b/ath/if_ath.c
15053 +@@ -8244,6 +8244,17 @@
15054 + 			goto bf_fail;
15055 + 		}
15056 + 
15057 ++		/* We make sure we don't remove the TX descriptor on
15058 ++		 * which the HW is pointing since it contains the
15059 ++		 * ds_link field, except if this is the last TX
15060 ++		 * descriptor in the queue */
15061 ++
15062 ++		if ((txq->axq_depth > 1) &&
15063 ++		    (bf->bf_daddr == ath_hal_gettxbuf(ah, txq->axq_qnum))) {
15064 ++			ATH_TXQ_UNLOCK_IRQ_EARLY(txq);
15065 ++			goto bf_fail;
15066 ++		}
15067 ++
15068 + 		ATH_TXQ_REMOVE_HEAD(txq, bf_list);
15069 + 		ATH_TXQ_UNLOCK_IRQ(txq);
15070 + 
15071 +--- a/ath/if_athvar.h
15072 ++++ b/ath/if_athvar.h
15073 +@@ -586,7 +586,8 @@
15074 + } while (0)
15075 + #define ATH_TXQ_REMOVE_HEAD(_tq, _field) do { \
15076 + 	STAILQ_REMOVE_HEAD(&(_tq)->axq_q, _field); \
15077 +-	(_tq)->axq_depth--; \
15078 ++	if (--(_tq)->axq_depth <= 0) \
15079 ++		(_tq)->axq_link = NULL; \
15080 + } while (0)
15081 + /* move buffers from MCASTQ to CABQ */
15082 + #define ATH_TXQ_MOVE_MCASTQ(_tqs,_tqd) do { \
15083 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/344-minstrel_failcnt.patch kamikaze_7.09/package/madwifi/patches/344-minstrel_failcnt.patch
15084 --- kamikaze_7.09.orig/package/madwifi/patches/344-minstrel_failcnt.patch	1970-01-01 01:00:00.000000000 +0100
15085 +++ kamikaze_7.09/package/madwifi/patches/344-minstrel_failcnt.patch	2008-06-19 17:34:17.000000000 +0200
15086 @@ -0,0 +1,11 @@
15087 +--- a/ath_rate/minstrel/minstrel.c
15088 ++++ b/ath_rate/minstrel/minstrel.c
15089 +@@ -475,7 +475,7 @@
15090 + 		/* 'tries' is the total number of times we have endeavoured to
15091 + 		 * send this packet, and is a sum of the #attempts at each
15092 + 		 * level in the multi-rate retry chain */
15093 +-		tries = ts->ts_shortretry + ts->ts_longretry + 1;
15094 ++		tries = ts->ts_longretry + 1;
15095 + 
15096 + 		if (sn->num_rates <= 0) {
15097 + 			DPRINTF(sc, "%s: " MAC_FMT " %s no rates yet\n", dev_info,
15098 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/345-minstrel_sampling.patch kamikaze_7.09/package/madwifi/patches/345-minstrel_sampling.patch
15099 --- kamikaze_7.09.orig/package/madwifi/patches/345-minstrel_sampling.patch	1970-01-01 01:00:00.000000000 +0100
15100 +++ kamikaze_7.09/package/madwifi/patches/345-minstrel_sampling.patch	2008-06-19 17:34:17.000000000 +0200
15101 @@ -0,0 +1,80 @@
15102 +--- a/ath/if_ath.c
15103 ++++ b/ath/if_ath.c
15104 +@@ -8094,6 +8094,7 @@
15105 + 		ath_hal_setupxtxdesc(sc->sc_ah, ds, mrr.rate1, mrr.retries1,
15106 + 				     mrr.rate2, mrr.retries2,
15107 + 				     mrr.rate3, mrr.retries3);
15108 ++		bf->rcflags = mrr.privflags;
15109 + 	}
15110 + 
15111 + #ifndef ATH_SUPERG_FF
15112 +--- a/ath/if_athvar.h
15113 ++++ b/ath/if_athvar.h
15114 +@@ -446,6 +446,7 @@
15115 + 	u_int16_t bf_flags;				/* tx descriptor flags */
15116 + 	u_int64_t bf_tsf;
15117 + 	int16_t bf_channoise;
15118 ++	unsigned int rcflags;
15119 + #ifdef ATH_SUPERG_FF
15120 + 	/* XXX: combine this with bf_skbaddr if it ever changes to accommodate
15121 + 	 *      multiple segments.
15122 +--- a/ath_rate/minstrel/minstrel.c
15123 ++++ b/ath_rate/minstrel/minstrel.c
15124 +@@ -333,15 +333,19 @@
15125 + 		if (sn->static_rate_ndx >= 0) {
15126 + 			    ndx = sn->static_rate_ndx;
15127 + 		} else {
15128 ++			int delta;
15129 + 			sn->packet_count++;
15130 + 			sn->random_n = (sn->a * sn->random_n) + sn->b;
15131 + 			offset = sn->random_n & 0xf;
15132 +-			if ((((100 * sn->sample_count) / (sn->sample_count + sn->packet_count)) < ath_lookaround_rate) && (offset < 2)) {
15133 ++			delta = (sn->packet_count * ath_lookaround_rate / 100) - sn->sample_count;
15134 ++			if ((delta > 0) && (offset < 2)) {
15135 + 				sn->sample_count++;
15136 + 				sn->is_sampling = 1;
15137 + 				if (sn->packet_count >= 10000) {
15138 + 					sn->sample_count = 0;
15139 + 					sn->packet_count = 0;
15140 ++				} else if (delta > sn->num_rates * 2) {
15141 ++					sn->sample_count += ((delta - sn->num_rates * 2) * ath_lookaround_rate) / 100;
15142 + 				}
15143 + 
15144 + 				/* Don't look for slowest rate (i.e. slowest
15145 +@@ -398,11 +402,14 @@
15146 + 		if (sn->num_rates <= 0)
15147 + 			return;
15148 + 
15149 ++		mrr->privflags = sn->is_sampling;
15150 + 		if (sn->is_sampling) {
15151 + 			sn->is_sampling = 0;
15152 +-			if (sn->rs_sample_rate_slower)
15153 ++			if (sn->rs_sample_rate_slower) {
15154 + 				rc1 = sn->rs_sample_rate;
15155 +-			else
15156 ++				if (sn->sample_count > 0)
15157 ++					sn->sample_count--;
15158 ++			} else
15159 + 				rc1 = sn->max_tp_rate;
15160 + 		} else {
15161 + 			rc1 = sn->max_tp_rate2;
15162 +@@ -525,6 +532,9 @@
15163 + 		if (tries <= tries1)
15164 + 			return;
15165 + 
15166 ++		if (bf->rcflags)
15167 ++			sn->sample_count++;
15168 ++
15169 + 		if  (tries2 < 0)
15170 + 			return;
15171 + 		tries = tries - tries1;
15172 +--- a/net80211/ieee80211_rate.h
15173 ++++ b/net80211/ieee80211_rate.h
15174 +@@ -87,6 +87,7 @@
15175 + 	int retries2;
15176 + 	int rate3;
15177 + 	int retries3;
15178 ++	int privflags;
15179 + };
15180 + 
15181 + struct ieee80211_rate_ops {
15182 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/346-protmode_trig.patch kamikaze_7.09/package/madwifi/patches/346-protmode_trig.patch
15183 --- kamikaze_7.09.orig/package/madwifi/patches/346-protmode_trig.patch	1970-01-01 01:00:00.000000000 +0100
15184 +++ kamikaze_7.09/package/madwifi/patches/346-protmode_trig.patch	2008-06-19 17:34:17.000000000 +0200
15185 @@ -0,0 +1,135 @@
15186 +--- a/net80211/ieee80211.c
15187 ++++ b/net80211/ieee80211.c
15188 +@@ -333,7 +333,9 @@
15189 + 			IEEE80211_MS_TO_TU(IEEE80211_BMISSTHRESH_DEFAULT_MS), 
15190 + 			ic->ic_lintval), ic->ic_lintval);
15191 + 	}
15192 +-		
15193 ++	ic->ic_protmode_timeout = IEEE80211_PROTMODE_TIMEOUT;
15194 ++	ic->ic_protmode_rssi = IEEE80211_PROTMODE_RSSITHR;
15195 ++
15196 + 	IEEE80211_LOCK_INIT(ic, "ieee80211com");
15197 + 	IEEE80211_VAPS_LOCK_INIT(ic, "ieee80211com_vaps");
15198 + 	TAILQ_INIT(&ic->ic_vaps);
15199 +--- a/net80211/ieee80211_input.c
15200 ++++ b/net80211/ieee80211_input.c
15201 +@@ -3411,14 +3411,18 @@
15202 + 			IEEE80211_IS_CHAN_ANYG(ic->ic_curchan)) {
15203 + 
15204 + 			/* Assume no ERP IE == 11b AP */
15205 +-			if ((!has_erp || (has_erp && (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) &&
15206 +-				!(ic->ic_flags & IEEE80211_F_USEPROT)) {
15207 ++			if ((!has_erp || (has_erp &&
15208 ++				(scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) &&
15209 ++				(rssi > ic->ic_protmode_rssi)) {
15210 + 				struct ieee80211vap *tmpvap;
15211 + 
15212 +-				ic->ic_flags |= IEEE80211_F_USEPROT;
15213 +-				TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
15214 +-					tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
15215 ++				if (!(ic->ic_flags & IEEE80211_F_USEPROT)) {
15216 ++					ic->ic_flags |= IEEE80211_F_USEPROT;
15217 ++					TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
15218 ++						tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
15219 ++					}
15220 + 				}
15221 ++				ic->ic_protmode_lasttrig = jiffies;
15222 + 			}
15223 + 		}
15224 + 
15225 +--- a/net80211/ieee80211_ioctl.h
15226 ++++ b/net80211/ieee80211_ioctl.h
15227 +@@ -643,6 +643,8 @@
15228 + 	IEEE80211_PARAM_BEACON_MISS_THRESH_MS	= 74,	/* Beacon miss threshold (in ms) */
15229 + 	IEEE80211_PARAM_MAXRATE			= 75,	/* Maximum rate (by table index) */
15230 + 	IEEE80211_PARAM_MINRATE			= 76,	/* Maximum rate (by table index) */
15231 ++	IEEE80211_PARAM_PROTMODE_RSSI		= 77,	/* RSSI Threshold for enabling protection mode */
15232 ++	IEEE80211_PARAM_PROTMODE_TIMEOUT	= 78,	/* Timeout for expiring protection mode */
15233 + };
15234 + 
15235 + #define	SIOCG80211STATS			(SIOCDEVPRIVATE+2)
15236 +--- a/net80211/ieee80211_var.h
15237 ++++ b/net80211/ieee80211_var.h
15238 +@@ -128,6 +128,9 @@
15239 + 
15240 + #define	IEEE80211_APPIE_MAX	1024
15241 + 
15242 ++#define IEEE80211_PROTMODE_RSSITHR	15	/* default rssi threshold for protection mode trigger */
15243 ++#define IEEE80211_PROTMODE_TIMEOUT	30	/* timeout for keeping protection mode alive */
15244 ++
15245 + #define IEEE80211_PWRCONSTRAINT_VAL(ic) \
15246 + 	(((ic)->ic_bsschan->ic_maxregpower > (ic)->ic_curchanmaxpwr) ? \
15247 + 	    (ic)->ic_bsschan->ic_maxregpower - (ic)->ic_curchanmaxpwr : 0)
15248 +@@ -324,6 +327,9 @@
15249 + 	u_int16_t ic_newtxpowlimit; 		/* tx power limit to change to (in 0.5 dBm) */
15250 + 	u_int16_t ic_uapsdmaxtriggers; 		/* max triggers that could arrive */
15251 + 	u_int8_t ic_coverageclass; 		/* coverage class */
15252 ++	u_int8_t ic_protmode_rssi;			/* rssi threshold for protection mode */
15253 ++	u_int64_t ic_protmode_lasttrig;		/* last trigger for protection mode */
15254 ++	u_int16_t ic_protmode_timeout;		/* protection mode timeout */
15255 + 
15256 + 	/* Channel state:
15257 + 	 *
15258 +--- a/net80211/ieee80211_wireless.c
15259 ++++ b/net80211/ieee80211_wireless.c
15260 +@@ -2312,6 +2312,12 @@
15261 + 		    IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
15262 + 			retv = ENETRESET;
15263 + 		break;
15264 ++	case IEEE80211_PARAM_PROTMODE_TIMEOUT:
15265 ++		ic->ic_protmode_timeout = value;
15266 ++		break;
15267 ++	case IEEE80211_PARAM_PROTMODE_RSSI:
15268 ++		ic->ic_protmode_rssi = value;
15269 ++		break;
15270 + 	case IEEE80211_PARAM_MCASTCIPHER:
15271 + 		if ((vap->iv_caps & cipher2cap(value)) == 0 &&
15272 + 		    !ieee80211_crypto_available(vap, value))
15273 +@@ -2955,6 +2961,12 @@
15274 + 	case IEEE80211_PARAM_PROTMODE:
15275 + 		param[0] = ic->ic_protmode;
15276 + 		break;
15277 ++	case IEEE80211_PARAM_PROTMODE_TIMEOUT:
15278 ++		param[0] = ic->ic_protmode_timeout;
15279 ++		break;
15280 ++	case IEEE80211_PARAM_PROTMODE_RSSI:
15281 ++		param[0] = ic->ic_protmode_rssi;
15282 ++		break;
15283 + 	case IEEE80211_PARAM_MCASTCIPHER:
15284 + 		param[0] = rsn->rsn_mcastcipher;
15285 + 		break;
15286 +@@ -5346,6 +5358,14 @@
15287 + 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "protmode" },
15288 + 	{ IEEE80211_PARAM_PROTMODE,
15289 + 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_protmode" },
15290 ++	{ IEEE80211_PARAM_PROTMODE_RSSI,
15291 ++	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "protrssi" },
15292 ++	{ IEEE80211_PARAM_PROTMODE_RSSI,
15293 ++	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_protrssi" },
15294 ++	{ IEEE80211_PARAM_PROTMODE_TIMEOUT,
15295 ++	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "prottime" },
15296 ++	{ IEEE80211_PARAM_PROTMODE_TIMEOUT,
15297 ++	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_prottime" },
15298 + 	{ IEEE80211_PARAM_MCASTCIPHER,
15299 + 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "mcastcipher" },
15300 + 	{ IEEE80211_PARAM_MCASTCIPHER,
15301 +--- a/net80211/ieee80211_node.c
15302 ++++ b/net80211/ieee80211_node.c
15303 +@@ -1877,6 +1877,17 @@
15304 + 
15305 + 	ieee80211_scan_timeout(ic);
15306 + 	ieee80211_timeout_stations(&ic->ic_sta);
15307 ++	if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
15308 ++		(ic->ic_protmode_lasttrig + ic->ic_protmode_timeout * HZ <
15309 ++			jiffies)) {
15310 ++		struct ieee80211vap *tmpvap;
15311 ++
15312 ++		/* expire protection mode */
15313 ++		ic->ic_flags &= ~IEEE80211_F_USEPROT;
15314 ++		TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
15315 ++			tmpvap->iv_flags_ext |= IEEE80211_FEXT_ERPUPDATE;
15316 ++		}
15317 ++	}
15318 + 
15319 + 	ic->ic_inact.expires = jiffies + IEEE80211_INACT_WAIT * HZ;
15320 + 	add_timer(&ic->ic_inact);
15321 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/347-tuning.patch kamikaze_7.09/package/madwifi/patches/347-tuning.patch
15322 --- kamikaze_7.09.orig/package/madwifi/patches/347-tuning.patch	1970-01-01 01:00:00.000000000 +0100
15323 +++ kamikaze_7.09/package/madwifi/patches/347-tuning.patch	2008-06-19 17:34:17.000000000 +0200
15324 @@ -0,0 +1,99 @@
15325 +--- a/ath/if_ath.c
15326 ++++ b/ath/if_ath.c
15327 +@@ -10265,11 +10265,11 @@
15328 + 	sc->sc_currates = rt;
15329 + 	sc->sc_curmode = mode;
15330 + 	/*
15331 +-	 * All protection frames are transmitted at 2Mb/s for
15332 +-	 * 11g, otherwise at 1Mb/s.
15333 ++	 * All protection frames are transmitted at 11Mb/s for
15334 ++	 * 11g, otherwise at 2Mb/s.
15335 + 	 * XXX select protection rate index from rate table.
15336 + 	 */
15337 +-	sc->sc_protrix = (mode == IEEE80211_MODE_11G ? 1 : 0);
15338 ++	sc->sc_protrix = (mode == IEEE80211_MODE_11G ? 3 : 1);
15339 + 	/* rate index used to send mgt frames */
15340 + 	sc->sc_minrateix = 0;
15341 + }
15342 +--- a/ath/if_athvar.h
15343 ++++ b/ath/if_athvar.h
15344 +@@ -272,6 +272,10 @@
15345 + #define AES_ICV_FIELD_SIZE      8       /* AES ICV field size */
15346 + #define EXT_IV_FIELD_SIZE       4       /* ext IV field size */
15347 + 
15348 ++/* This is what the HAL uses by default for 11a+g */
15349 ++#define ATH_DEFAULT_CWMIN	15
15350 ++#define ATH_DEFAULT_CWMAX	1023
15351 ++
15352 + /* XR specific macros */
15353 + 
15354 + #define XR_DEFAULT_GRPPOLL_RATE_STR 	"0.25 1 1 3 3 6 6 20"
15355 +--- a/ath_rate/minstrel/minstrel.c
15356 ++++ b/ath_rate/minstrel/minstrel.c
15357 +@@ -197,7 +197,7 @@
15358 + 		unsigned int x = 0, tt = 0;
15359 + 		unsigned int cix = rt->info[rix].controlRate;
15360 + 		int rts = 0, cts = 0;
15361 +-		int cw = WIFI_CW_MIN;
15362 ++		int cw = ATH_DEFAULT_CWMIN;
15363 + 
15364 + 		KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
15365 + 
15366 +@@ -281,7 +281,7 @@
15367 + 		tt += (long_retries + 1) * ath_hal_computetxtime(sc->sc_ah, rt, length,
15368 + 							rix, AH_TRUE);
15369 + 		for (x = 0; x <= short_retries + long_retries; x++) {
15370 +-			cw = MIN(WIFI_CW_MAX, (cw + 1) * 2);
15371 ++			cw = MIN(ATH_DEFAULT_CWMAX, (cw + 1) * 2);
15372 + 			tt += (t_slot * cw / 2);
15373 + 		}
15374 + 		return tt;
15375 +--- a/ath_rate/minstrel/minstrel.h
15376 ++++ b/ath_rate/minstrel/minstrel.h
15377 +@@ -180,14 +180,6 @@
15378 + #define MAX(a,b)        ((a) > (b) ? (a) : (b))
15379 + #endif
15380 + 
15381 +-#if 0
15382 +-#define WIFI_CW_MIN 31
15383 +-#define WIFI_CW_MAX 1023
15384 +-#else
15385 +-#define WIFI_CW_MIN 3
15386 +-#define WIFI_CW_MAX 10
15387 +-#endif
15388 +-
15389 + /*
15390 +  * Definitions for pulling the rate and trie counts from
15391 +  * a 5212 h/w descriptor. These Don't belong here; the
15392 +--- a/ath_rate/sample/sample.c
15393 ++++ b/ath_rate/sample/sample.c
15394 +@@ -170,7 +170,7 @@
15395 + 	struct ieee80211com *ic = &sc->sc_ic;
15396 + 	unsigned int tt = 0;
15397 + 	unsigned int x;
15398 +-	unsigned int cw = WIFI_CW_MIN;
15399 ++	unsigned int cw = ATH_DEFAULT_CWMIN;
15400 + 	unsigned int cix = rt->info[rix].controlRate;
15401 + 	KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
15402 + 
15403 +@@ -254,7 +254,7 @@
15404 + 	tt += (long_retries+1)*ath_hal_computetxtime(sc->sc_ah, rt, length,
15405 + 						rix, AH_TRUE);
15406 + 	for (x = 0; x <= short_retries + long_retries; x++) {
15407 +-		cw = MIN(WIFI_CW_MAX, (cw + 1) * 2);
15408 ++		cw = MIN(ATH_DEFAULT_CWMAX, (cw + 1) * 2);
15409 + 		tt += (t_slot * cw / 2);
15410 + 	}
15411 + 	return tt;
15412 +--- a/ath_rate/sample/sample.h
15413 ++++ b/ath_rate/sample/sample.h
15414 +@@ -106,9 +106,6 @@
15415 + #define MAX(a,b)        ((a) > (b) ? (a) : (b))
15416 + #endif
15417 + 
15418 +-#define WIFI_CW_MIN 31
15419 +-#define WIFI_CW_MAX 1023
15420 +-
15421 + /*
15422 +  * Definitions for pulling the rate and trie counts from
15423 +  * a 5212 h/w descriptor. These Don't belong here; the
15424 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/348-ackcts.patch kamikaze_7.09/package/madwifi/patches/348-ackcts.patch
15425 --- kamikaze_7.09.orig/package/madwifi/patches/348-ackcts.patch	1970-01-01 01:00:00.000000000 +0100
15426 +++ kamikaze_7.09/package/madwifi/patches/348-ackcts.patch	2008-06-19 17:34:17.000000000 +0200
15427 @@ -0,0 +1,38 @@
15428 +--- a/ath/if_ath.c
15429 ++++ b/ath/if_ath.c
15430 +@@ -2721,6 +2721,9 @@
15431 + static int
15432 + ath_set_ack_bitrate(struct ath_softc *sc, int high)
15433 + {
15434 ++	if (!sc->sc_ackrate_override)
15435 ++		return 0;
15436 ++
15437 + 	if (ar_device(sc->devid) == 5212 || ar_device(sc->devid) == 5213) {
15438 + 		/* set ack to be sent at low bit-rate */
15439 + 		/* registers taken from the OpenBSD 5212 HAL */
15440 +@@ -10780,8 +10783,13 @@
15441 + 				break;
15442 + #endif
15443 + 			case ATH_ACKRATE:
15444 +-				sc->sc_ackrate = val;
15445 +-				ath_set_ack_bitrate(sc, sc->sc_ackrate);
15446 ++				if (val == -1)
15447 ++					sc->sc_ackrate_override = 0;
15448 ++				else {
15449 ++					sc->sc_ackrate_override = 1;
15450 ++					sc->sc_ackrate = val;
15451 ++					ath_set_ack_bitrate(sc, sc->sc_ackrate);
15452 ++				}
15453 + 				break;
15454 + 			case ATH_RP:
15455 + 				ath_rp_record(sc,
15456 +--- a/ath/if_athvar.h
15457 ++++ b/ath/if_athvar.h
15458 +@@ -681,6 +681,7 @@
15459 + 	unsigned int	sc_devstopped:1;	/* stopped due to of no tx bufs */
15460 + 	unsigned int	sc_stagbeacons:1;	/* use staggered beacons */
15461 + 	unsigned int	sc_dfswait:1;		/* waiting on channel for radar detect */
15462 ++	unsigned int	sc_ackrate_override:1;	/* override ack rate */
15463 + 	unsigned int	sc_ackrate:1;		/* send acks at high bitrate */
15464 + 	unsigned int	sc_dfs_cac:1;		/* waiting on channel for radar detect */
15465 + 	unsigned int	sc_hasintmit:1;		/* Interference mitigation */
15466 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/349-reset.patch kamikaze_7.09/package/madwifi/patches/349-reset.patch
15467 --- kamikaze_7.09.orig/package/madwifi/patches/349-reset.patch	1970-01-01 01:00:00.000000000 +0100
15468 +++ kamikaze_7.09/package/madwifi/patches/349-reset.patch	2008-06-19 17:34:17.000000000 +0200
15469 @@ -0,0 +1,12 @@
15470 +--- a/ath/if_ath.c
15471 ++++ b/ath/if_ath.c
15472 +@@ -8853,8 +8853,7 @@
15473 + 		 * needed to do the reset with chanchange = AH_FALSE in order
15474 + 		 * to receive traffic when peforming high velocity channel
15475 + 		 * changes. */
15476 +-		if (!ath_hal_reset(ah, sc->sc_opmode, &hchan, AH_TRUE, &status)   ||
15477 +-		    !ath_hal_reset(ah, sc->sc_opmode, &hchan, AH_FALSE, &status)) {
15478 ++		if (!ath_hal_reset(ah, sc->sc_opmode, &hchan, AH_TRUE, &status)) {
15479 + 			EPRINTF(sc, "Unable to reset channel %u (%u MHz) "
15480 + 				"flags 0x%x '%s' (HAL status %u)\n",
15481 + 				ieee80211_chan2ieee(ic, chan), chan->ic_freq,
15482 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/350-wisoc_softled.patch kamikaze_7.09/package/madwifi/patches/350-wisoc_softled.patch
15483 --- kamikaze_7.09.orig/package/madwifi/patches/350-wisoc_softled.patch	1970-01-01 01:00:00.000000000 +0100
15484 +++ kamikaze_7.09/package/madwifi/patches/350-wisoc_softled.patch	2008-06-19 17:34:17.000000000 +0200
15485 @@ -0,0 +1,11 @@
15486 +--- a/ath/if_ath_ahb.c
15487 ++++ b/ath/if_ath_ahb.c
15488 +@@ -245,6 +245,8 @@
15489 + 	num_activesc++;
15490 + 	/* Ready to process interrupts */
15491 + 
15492 ++	sc->aps_sc.sc_softled = 1; /* SoftLED over GPIO */
15493 ++	sc->aps_sc.sc_ledpin = config->board->sysLedGpio;
15494 + 	sc->aps_sc.sc_invalid = 0;
15495 + 	return 0;
15496 + 
15497 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/351-scanlist.patch kamikaze_7.09/package/madwifi/patches/351-scanlist.patch
15498 --- kamikaze_7.09.orig/package/madwifi/patches/351-scanlist.patch	1970-01-01 01:00:00.000000000 +0100
15499 +++ kamikaze_7.09/package/madwifi/patches/351-scanlist.patch	2008-06-19 17:34:17.000000000 +0200
15500 @@ -0,0 +1,875 @@
15501 +--- a/net80211/ieee80211_scan_sta.c
15502 ++++ b/net80211/ieee80211_scan_sta.c
15503 +@@ -317,147 +317,6 @@
15504 + #undef ISPROBE
15505 + }
15506 + 
15507 +-static struct ieee80211_channel *
15508 +-find11gchannel(struct ieee80211com *ic, int i, int freq)
15509 +-{
15510 +-	struct ieee80211_channel *c;
15511 +-	int j;
15512 +-
15513 +-	/*
15514 +-	 * The normal ordering in the channel list is b channel
15515 +-	 * immediately followed by g so optimize the search for
15516 +-	 * this.  We'll still do a full search just in case.
15517 +-	 */
15518 +-	for (j = i+1; j < ic->ic_nchans; j++) {
15519 +-		c = &ic->ic_channels[j];
15520 +-		if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
15521 +-			return c;
15522 +-	}
15523 +-	for (j = 0; j < i; j++) {
15524 +-		c = &ic->ic_channels[j];
15525 +-		if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
15526 +-			return c;
15527 +-	}
15528 +-	return NULL;
15529 +-}
15530 +-static const u_int chanflags[] = {
15531 +-	IEEE80211_CHAN_B,	/* IEEE80211_MODE_AUTO */
15532 +-	IEEE80211_CHAN_A,	/* IEEE80211_MODE_11A */
15533 +-	IEEE80211_CHAN_B,	/* IEEE80211_MODE_11B */
15534 +-	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_11G */
15535 +-	IEEE80211_CHAN_FHSS,	/* IEEE80211_MODE_FH */
15536 +-	IEEE80211_CHAN_A,	/* IEEE80211_MODE_TURBO_A */ /* for turbo mode look for AP in normal channel */
15537 +-	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_TURBO_G */
15538 +-	IEEE80211_CHAN_ST,	/* IEEE80211_MODE_TURBO_STATIC_A */
15539 +-};
15540 +-
15541 +-static void
15542 +-add_channels(struct ieee80211com *ic,
15543 +-	struct ieee80211_scan_state *ss,
15544 +-	enum ieee80211_phymode mode, const u_int16_t freq[], int nfreq)
15545 +-{
15546 +-	struct ieee80211_channel *c, *cg;
15547 +-	u_int modeflags;
15548 +-	int i;
15549 +-
15550 +-	KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode));
15551 +-	modeflags = chanflags[mode];
15552 +-	for (i = 0; i < nfreq; i++) {
15553 +-		c = ieee80211_find_channel(ic, freq[i], modeflags);
15554 +-		if (c == NULL || isclr(ic->ic_chan_active, c->ic_ieee))
15555 +-			continue;
15556 +-		if (mode == IEEE80211_MODE_AUTO) {
15557 +-			/*
15558 +-			 * XXX special-case 11b/g channels so we select
15559 +-			 *     the g channel if both are present.
15560 +-			 */
15561 +-			if (IEEE80211_IS_CHAN_B(c) &&
15562 +-			    (cg = find11gchannel(ic, i, c->ic_freq)) != NULL)
15563 +-				c = cg;
15564 +-		}
15565 +-		if (ss->ss_last >= IEEE80211_SCAN_MAX)
15566 +-			break;
15567 +-		ss->ss_chans[ss->ss_last++] = c;
15568 +-	}
15569 +-}
15570 +-
15571 +-static const u_int16_t rcl1[] =		/* 8 FCC channel: 52, 56, 60, 64, 36, 40, 44, 48 */
15572 +-{ 5260, 5280, 5300, 5320, 5180, 5200, 5220, 5240 };
15573 +-static const u_int16_t rcl2[] =		/* 4 MKK channels: 34, 38, 42, 46 */
15574 +-{ 5170, 5190, 5210, 5230 };
15575 +-static const u_int16_t rcl3[] =		/* 2.4Ghz ch: 1,6,11,7,13 */
15576 +-{ 2412, 2437, 2462, 2442, 2472 };
15577 +-static const u_int16_t rcl4[] =		/* 5 FCC channel: 149, 153, 161, 165 */
15578 +-{ 5745, 5765, 5785, 5805, 5825 };
15579 +-static const u_int16_t rcl7[] =		/* 11 ETSI channel: 100,104,108,112,116,120,124,128,132,136,140 */
15580 +-{ 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, 5700 };
15581 +-static const u_int16_t rcl8[] =		/* 2.4Ghz ch: 2,3,4,5,8,9,10,12 */
15582 +-{ 2417, 2422, 2427, 2432, 2447, 2452, 2457, 2467 };
15583 +-static const u_int16_t rcl9[] =		/* 2.4Ghz ch: 14 */
15584 +-{ 2484 };
15585 +-static const u_int16_t rcl10[] =	/* Added Korean channels 2312-2372 */
15586 +-{ 2312, 2317, 2322, 2327, 2332, 2337, 2342, 2347, 2352, 2357, 2362, 2367, 2372 };
15587 +-static const u_int16_t rcl11[] =	/* Added Japan channels in 4.9/5.0 spectrum */
15588 +-{ 5040, 5060, 5080, 4920, 4940, 4960, 4980 };
15589 +-#ifdef ATH_TURBO_SCAN
15590 +-static const u_int16_t rcl5[] =		/* 3 static turbo channels */
15591 +-{ 5210, 5250, 5290 };
15592 +-static const u_int16_t rcl6[] =		/* 2 static turbo channels */
15593 +-{ 5760, 5800 };
15594 +-static const u_int16_t rcl6x[] =		/* 4 FCC3 turbo channels */
15595 +-{ 5540, 5580, 5620, 5660 };
15596 +-static const u_int16_t rcl12[] =		/* 2.4Ghz Turbo channel 6 */
15597 +-{ 2437 };
15598 +-static const u_int16_t rcl13[] =		/* dynamic Turbo channels */
15599 +-{ 5200, 5240, 5280, 5765, 5805 };
15600 +-#endif /* ATH_TURBO_SCAN */
15601 +-
15602 +-struct scanlist {
15603 +-	u_int16_t	mode;
15604 +-	u_int16_t	count;
15605 +-	const u_int16_t	*list;
15606 +-};
15607 +-
15608 +-#define	IEEE80211_MODE_TURBO_STATIC_A	IEEE80211_MODE_MAX
15609 +-#define	X(a)	.count = sizeof(a)/sizeof(a[0]), .list = a
15610 +-
15611 +-static const struct scanlist staScanTable[] = {
15612 +-	{ IEEE80211_MODE_11B,   		X(rcl3) },
15613 +-	{ IEEE80211_MODE_11A,   		X(rcl1) },
15614 +-	{ IEEE80211_MODE_11A,   		X(rcl2) },
15615 +-	{ IEEE80211_MODE_11B,   		X(rcl8) },
15616 +-	{ IEEE80211_MODE_11B,   		X(rcl9) },
15617 +-	{ IEEE80211_MODE_11A,   		X(rcl4) },
15618 +-#ifdef ATH_TURBO_SCAN
15619 +-	{ IEEE80211_MODE_TURBO_STATIC_A,	X(rcl5) },
15620 +-	{ IEEE80211_MODE_TURBO_STATIC_A,	X(rcl6) },
15621 +-	{ IEEE80211_MODE_TURBO_A,		X(rcl6x) },
15622 +-	{ IEEE80211_MODE_TURBO_A,		X(rcl13) },
15623 +-#endif /* ATH_TURBO_SCAN */
15624 +-	{ IEEE80211_MODE_11A,			X(rcl7) },
15625 +-	{ IEEE80211_MODE_11B,			X(rcl10) },
15626 +-	{ IEEE80211_MODE_11A,			X(rcl11) },
15627 +-#ifdef ATH_TURBO_SCAN
15628 +-	{ IEEE80211_MODE_TURBO_G,		X(rcl12) },
15629 +-#endif /* ATH_TURBO_SCAN */
15630 +-	{ .list = NULL }
15631 +-};
15632 +-
15633 +-#undef X
15634 +-
15635 +-static int
15636 +-checktable(const struct scanlist *scan, const struct ieee80211_channel *c)
15637 +-{
15638 +-	int i;
15639 +-
15640 +-	for (; scan->list != NULL; scan++) {
15641 +-		for (i = 0; i < scan->count; i++)
15642 +-			if (scan->list[i] == c->ic_freq)
15643 +-				return 1;
15644 +-	}
15645 +-	return 0;
15646 +-}
15647 +-
15648 + /*
15649 +  * Start a station-mode scan by populating the channel list.
15650 +  */
15651 +@@ -466,81 +325,14 @@
15652 + {
15653 + 	struct ieee80211com *ic = vap->iv_ic;
15654 + 	struct sta_table *st = ss->ss_priv;
15655 +-	const struct scanlist *scan;
15656 + 	enum ieee80211_phymode mode;
15657 + 	struct ieee80211_channel *c;
15658 + 	int i;
15659 + 
15660 + 	ss->ss_last = 0;
15661 +-	/*
15662 +-	 * Use the table of ordered channels to construct the list
15663 +-	 * of channels for scanning.  Any channels in the ordered
15664 +-	 * list not in the master list will be discarded.
15665 +-	 */
15666 +-	for (scan = staScanTable; scan->list != NULL; scan++) {
15667 +-		mode = scan->mode;
15668 +-		if (vap->iv_des_mode != IEEE80211_MODE_AUTO) {
15669 +-			/*
15670 +-			 * If a desired mode was specified, scan only 
15671 +-			 * channels that satisfy that constraint.
15672 +-			 */
15673 +-			if (vap->iv_des_mode != mode) {
15674 +-				/*
15675 +-				 * The scan table marks 2.4Ghz channels as b
15676 +-				 * so if the desired mode is 11g, then use
15677 +-				 * the 11b channel list but upgrade the mode.
15678 +-				 */
15679 +-				if (vap->iv_des_mode != IEEE80211_MODE_11G ||
15680 +-				    mode != IEEE80211_MODE_11B)
15681 +-					continue;
15682 +-				mode = IEEE80211_MODE_11G;	/* upgrade */
15683 +-			}
15684 +-		} else {
15685 +-			/*
15686 +-			 * This lets ieee80211_scan_add_channels
15687 +-			 * upgrade an 11b channel to 11g if available.
15688 +-			 */
15689 +-			if (mode == IEEE80211_MODE_11B)
15690 +-				mode = IEEE80211_MODE_AUTO;
15691 +-		}
15692 +-		/* XR does not operate on turbo channels */
15693 +-		if ((vap->iv_flags & IEEE80211_F_XR) &&
15694 +-		    (mode == IEEE80211_MODE_TURBO_A ||
15695 +-		     mode == IEEE80211_MODE_TURBO_G))
15696 +-			continue;
15697 +-		/*
15698 +-		 * Add the list of the channels; any that are not
15699 +-		 * in the master channel list will be discarded.
15700 +-		 */
15701 +-		add_channels(ic, ss, mode, scan->list, scan->count);
15702 +-	}
15703 +-
15704 +-	/*
15705 +-	 * Add the channels from the ic (from HAL) that are not present
15706 +-	 * in the staScanTable.
15707 +-	 */
15708 +-	for (i = 0; i < ic->ic_nchans; i++) {
15709 +-		c = &ic->ic_channels[i];
15710 +-		/*
15711 +-		 * scan dynamic turbo channels in normal mode.
15712 +-		 */
15713 +-		if (IEEE80211_IS_CHAN_DTURBO(c))
15714 +-			continue;
15715 +-		mode = ieee80211_chan2mode(c);
15716 +-		if (vap->iv_des_mode != IEEE80211_MODE_AUTO) {
15717 +-			/*
15718 +-			 * If a desired mode was specified, scan only 
15719 +-			 * channels that satisfy that constraint.
15720 +-			 */
15721 +-			if (vap->iv_des_mode != mode)
15722 +-				continue;
15723 +-
15724 +-		}
15725 +-		if (!checktable(staScanTable, c))
15726 +-			ss->ss_chans[ss->ss_last++] = c;
15727 +-	}
15728 +-
15729 ++	ieee80211_scan_add_channels(ic, ss, vap->iv_des_mode);
15730 + 	ss->ss_next = 0;
15731 ++
15732 + 	/* XXX tunables */
15733 + 	/* 
15734 + 	 * The scanner will stay on station for ss_maxdwell ms (using a 
15735 +@@ -749,17 +541,7 @@
15736 + 	fail = 0;
15737 + 	if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, se->se_chan)))
15738 + 		fail |= 0x01;
15739 +-	/*
15740 +-	 * NB: normally the desired mode is used to construct
15741 +-	 * the channel list, but it's possible for the scan
15742 +-	 * cache to include entries for stations outside this
15743 +-	 * list so we check the desired mode here to weed them
15744 +-	 * out.
15745 +-	 */
15746 +-	if (vap->iv_des_mode != IEEE80211_MODE_AUTO &&
15747 +-	    (se->se_chan->ic_flags & IEEE80211_CHAN_ALLTURBO) !=
15748 +-	    chanflags[vap->iv_des_mode])
15749 +-		fail |= 0x01;
15750 ++
15751 + 	if (vap->iv_opmode == IEEE80211_M_IBSS) {
15752 + 		if ((se->se_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
15753 + 			fail |= 0x02;
15754 +@@ -1168,78 +950,6 @@
15755 + 	.scan_default		= ieee80211_sta_join,
15756 + };
15757 + 
15758 +-/*
15759 +- * Start an adhoc-mode scan by populating the channel list.
15760 +- */
15761 +-static int
15762 +-adhoc_start(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
15763 +-{
15764 +-	struct ieee80211com *ic = vap->iv_ic;
15765 +-	struct sta_table *st = ss->ss_priv;
15766 +-	const struct scanlist *scan;
15767 +-	enum ieee80211_phymode mode;
15768 +-
15769 +-	ss->ss_last = 0;
15770 +-	/*
15771 +-	 * Use the table of ordered channels to construct the list
15772 +-	 * of channels for scanning.  Any channels in the ordered
15773 +-	 * list not in the master list will be discarded.
15774 +-	 */
15775 +-	for (scan = staScanTable; scan->list != NULL; scan++) {
15776 +-		mode = scan->mode;
15777 +-		if (vap->iv_des_mode != IEEE80211_MODE_AUTO) {
15778 +-			/*
15779 +-			 * If a desired mode was specified, scan only 
15780 +-			 * channels that satisfy that constraint.
15781 +-			 */
15782 +-			if (vap->iv_des_mode != mode) {
15783 +-				/*
15784 +-				 * The scan table marks 2.4Ghz channels as b
15785 +-				 * so if the desired mode is 11g, then use
15786 +-				 * the 11b channel list but upgrade the mode.
15787 +-				 */
15788 +-				if (vap->iv_des_mode != IEEE80211_MODE_11G ||
15789 +-				    mode != IEEE80211_MODE_11B)
15790 +-					continue;
15791 +-				mode = IEEE80211_MODE_11G;	/* upgrade */
15792 +-			}
15793 +-		} else {
15794 +-			/*
15795 +-			 * This lets ieee80211_scan_add_channels
15796 +-			 * upgrade an 11b channel to 11g if available.
15797 +-			 */
15798 +-			if (mode == IEEE80211_MODE_11B)
15799 +-				mode = IEEE80211_MODE_AUTO;
15800 +-		}
15801 +-		/* XR does not operate on turbo channels */
15802 +-		if ((vap->iv_flags & IEEE80211_F_XR) &&
15803 +-		    (mode == IEEE80211_MODE_TURBO_A ||
15804 +-		     mode == IEEE80211_MODE_TURBO_G))
15805 +-			continue;
15806 +-		/*
15807 +-		 * Add the list of the channels; any that are not
15808 +-		 * in the master channel list will be discarded.
15809 +-		 */
15810 +-		add_channels(ic, ss, mode, scan->list, scan->count);
15811 +-	}
15812 +-	ss->ss_next = 0;
15813 +-	/* XXX tunables */
15814 +-	ss->ss_mindwell = msecs_to_jiffies(200);	/* 200ms */
15815 +-	ss->ss_maxdwell = msecs_to_jiffies(200);	/* 200ms */
15816 +-
15817 +-#ifdef IEEE80211_DEBUG
15818 +-	if (ieee80211_msg_scan(vap)) {
15819 +-		printk("%s: scan set ", vap->iv_dev->name);
15820 +-		ieee80211_scan_dump_channels(ss);
15821 +-		printk(" dwell min %ld max %ld\n",
15822 +-			ss->ss_mindwell, ss->ss_maxdwell);
15823 +-	}
15824 +-#endif /* IEEE80211_DEBUG */
15825 +-
15826 +-	st->st_newscan = 1;
15827 +-
15828 +-	return 0;
15829 +-}
15830 + 
15831 + /*
15832 +  * Select a channel to start an adhoc network on.
15833 +@@ -1405,7 +1115,7 @@
15834 + 	.scan_name		= "default",
15835 + 	.scan_attach		= sta_attach,
15836 + 	.scan_detach		= sta_detach,
15837 +-	.scan_start		= adhoc_start,
15838 ++	.scan_start		= sta_start,
15839 + 	.scan_restart		= sta_restart,
15840 + 	.scan_cancel		= sta_cancel,
15841 + 	.scan_end		= adhoc_pick_bss,
15842 +--- a/net80211/ieee80211.c
15843 ++++ b/net80211/ieee80211.c
15844 +@@ -278,6 +278,11 @@
15845 + 			("channel with bogus ieee number %u", c->ic_ieee));
15846 + 		setbit(ic->ic_chan_avail, c->ic_ieee);
15847 + 
15848 ++		if (c->ic_scanflags & IEEE80211_NOSCAN_DEFAULT)
15849 ++			c->ic_scanflags |= IEEE80211_NOSCAN_SET;
15850 ++		else
15851 ++			c->ic_scanflags &= ~IEEE80211_NOSCAN_SET;
15852 ++
15853 + 		/* Identify mode capabilities. */
15854 + 		if (IEEE80211_IS_CHAN_A(c))
15855 + 			ic->ic_modecaps |= 1 << IEEE80211_MODE_11A;
15856 +--- a/net80211/_ieee80211.h
15857 ++++ b/net80211/_ieee80211.h
15858 +@@ -132,6 +132,11 @@
15859 + 	IEEE80211_SCAN_FIRST	= 2,	/* take first suitable candidate */
15860 + };
15861 + 
15862 ++enum ieee80211_scanflags {
15863 ++	IEEE80211_NOSCAN_DEFAULT = (1 << 0),
15864 ++	IEEE80211_NOSCAN_SET     = (1 << 1),
15865 ++};
15866 ++
15867 + /*
15868 +  * Channels are specified by frequency and attributes.
15869 +  */
15870 +@@ -142,6 +147,7 @@
15871 + 	int8_t ic_maxregpower;	/* maximum regulatory tx power in dBm */
15872 + 	int8_t ic_maxpower;	/* maximum tx power in dBm */
15873 + 	int8_t ic_minpower;	/* minimum tx power in dBm */
15874 ++	u_int8_t ic_scanflags;
15875 + };
15876 + 
15877 + #define	IEEE80211_CHAN_MAX	255
15878 +--- a/net80211/ieee80211_ioctl.h
15879 ++++ b/net80211/ieee80211_ioctl.h
15880 +@@ -555,6 +555,7 @@
15881 + #define	IEEE80211_IOCTL_WDSADDMAC	(SIOCIWFIRSTPRIV+26)
15882 + #define	IEEE80211_IOCTL_WDSDELMAC	(SIOCIWFIRSTPRIV+28)
15883 + #define	IEEE80211_IOCTL_KICKMAC		(SIOCIWFIRSTPRIV+30)
15884 ++#define	IEEE80211_IOCTL_SETSCANLIST	(SIOCIWFIRSTPRIV+31)
15885 + 
15886 + enum {
15887 + 	IEEE80211_WMMPARAMS_CWMIN       = 1,
15888 +--- a/net80211/ieee80211_scan_ap.c
15889 ++++ b/net80211/ieee80211_scan_ap.c
15890 +@@ -129,131 +129,7 @@
15891 + 
15892 + static int ap_flush(struct ieee80211_scan_state *);
15893 + static void action_tasklet(IEEE80211_TQUEUE_ARG);
15894 +-static struct ieee80211_channel *find11gchannel(struct ieee80211com *ic, 
15895 +-		int i, int freq);
15896 + 
15897 +-static const u_int chanflags[] = {
15898 +-	IEEE80211_CHAN_B,	/* IEEE80211_MODE_AUTO */
15899 +-	IEEE80211_CHAN_A,	/* IEEE80211_MODE_11A */
15900 +-	IEEE80211_CHAN_B,	/* IEEE80211_MODE_11B */
15901 +-	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_11G */
15902 +-	IEEE80211_CHAN_FHSS,	/* IEEE80211_MODE_FH */
15903 +-	IEEE80211_CHAN_A,	/* IEEE80211_MODE_TURBO_A */ /* for turbo mode 
15904 +-							      * look for AP in 
15905 +-							      * normal channel 
15906 +-							      */
15907 +-	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_TURBO_G */
15908 +-	IEEE80211_CHAN_ST,	/* IEEE80211_MODE_TURBO_STATIC_A */
15909 +-};
15910 +-
15911 +-static const u_int16_t rcl1[] =		/* 8 FCC channel: 52, 56, 60, 64, 
15912 +-					 *                36, 40, 44, 48 */
15913 +-{ 5260, 5280, 5300, 5320, 5180, 5200, 5220, 5240 };
15914 +-static const u_int16_t rcl2[] =		/* 4 MKK channels: 34, 38, 42, 46 */
15915 +-{ 5170, 5190, 5210, 5230 };
15916 +-static const u_int16_t rcl3[] =		/* 2.4Ghz ch: 1,6,11,7,13 */
15917 +-{ 2412, 2437, 2462, 2442, 2472 };
15918 +-static const u_int16_t rcl4[] =		/* 5 FCC channel: 149, 153, 161, 165 */
15919 +-{ 5745, 5765, 5785, 5805, 5825 };
15920 +-static const u_int16_t rcl7[] =		/* 11 ETSI channel: 100, 104, 108, 112,
15921 +-					 *                  116, 120, 124, 128, 
15922 +-					 *                  132, 136, 140 */
15923 +-{ 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, 5700 };
15924 +-static const u_int16_t rcl8[] =		/* 2.4Ghz ch: 2,3,4,5,8,9,10,12 */
15925 +-{ 2417, 2422, 2427, 2432, 2447, 2452, 2457, 2467 };
15926 +-static const u_int16_t rcl9[] =		/* 2.4Ghz ch: 14 */
15927 +-{ 2484 };
15928 +-static const u_int16_t rcl10[] =	/* Added Korean channels 2312-2372 */
15929 +-{ 2312, 2317, 2322, 2327, 2332, 2337, 2342, 2347, 2352, 2357, 2362, 2367, 2372 };
15930 +-static const u_int16_t rcl11[] =	/* Added Japan channels in 4.9/5.0 spectrum */
15931 +-{ 5040, 5060, 5080, 4920, 4940, 4960, 4980 };
15932 +-#ifdef ATH_TURBO_SCAN
15933 +-static const u_int16_t rcl5[] =		/* 3 static turbo channels */
15934 +-{ 5210, 5250, 5290 };
15935 +-static const u_int16_t rcl6[] =		/* 2 static turbo channels */
15936 +-{ 5760, 5800 };
15937 +-static const u_int16_t rcl6x[] =		/* 4 FCC3 turbo channels */
15938 +-{ 5540, 5580, 5620, 5660 };
15939 +-static const u_int16_t rcl12[] =		/* 2.4Ghz Turbo channel 6 */
15940 +-{ 2437 };
15941 +-static const u_int16_t rcl13[] =		/* dynamic Turbo channels */
15942 +-{ 5200, 5240, 5280, 5765, 5805 };
15943 +-#endif /* ATH_TURBO_SCAN */
15944 +-
15945 +-struct scanlist {
15946 +-	u_int16_t	mode;
15947 +-	u_int16_t	count;
15948 +-	const u_int16_t	*list;
15949 +-};
15950 +-
15951 +-#define	IEEE80211_MODE_TURBO_STATIC_A	IEEE80211_MODE_MAX
15952 +-#define	X(a)	.count = ARRAY_SIZE(a), .list = a
15953 +-
15954 +-static const struct scanlist staScanTable[] = {
15955 +-	{ IEEE80211_MODE_11B,   		X(rcl3)  },
15956 +-	{ IEEE80211_MODE_11A,   		X(rcl1)  },
15957 +-	{ IEEE80211_MODE_11A,   		X(rcl2)  },
15958 +-	{ IEEE80211_MODE_11B,   		X(rcl8)  },
15959 +-	{ IEEE80211_MODE_11B,   		X(rcl9)  },
15960 +-	{ IEEE80211_MODE_11A,   		X(rcl4)  },
15961 +-#ifdef ATH_TURBO_SCAN
15962 +-	{ IEEE80211_MODE_TURBO_STATIC_A,	X(rcl5)  },
15963 +-	{ IEEE80211_MODE_TURBO_STATIC_A,	X(rcl6)  },
15964 +-	{ IEEE80211_MODE_TURBO_A,		X(rcl6x) },
15965 +-	{ IEEE80211_MODE_TURBO_A,		X(rcl13) },
15966 +-#endif /* ATH_TURBO_SCAN */
15967 +-	{ IEEE80211_MODE_11A,			X(rcl7)  },
15968 +-	{ IEEE80211_MODE_11B,			X(rcl10) },
15969 +-	{ IEEE80211_MODE_11A,			X(rcl11) },
15970 +-#ifdef ATH_TURBO_SCAN
15971 +-	{ IEEE80211_MODE_TURBO_G,		X(rcl12) },
15972 +-#endif /* ATH_TURBO_SCAN */
15973 +-	{ .list = NULL }
15974 +-};
15975 +-
15976 +-#undef X
15977 +-/* This function must be invoked with locks acquired */
15978 +-static void
15979 +-add_channels(struct ieee80211com *ic,
15980 +-	struct ieee80211_scan_state *ss,
15981 +-	enum ieee80211_phymode mode, const u_int16_t freq[], int nfreq)
15982 +-{
15983 +-	struct ieee80211_channel *c, *cg;
15984 +-	u_int modeflags;
15985 +-	int i;
15986 +-
15987 +-	KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode));
15988 +-	modeflags = chanflags[mode];
15989 +-	for (i = 0; i < nfreq; i++) {
15990 +-		c = ieee80211_find_channel(ic, freq[i], modeflags);
15991 +-		if ((c == NULL) || isclr(ic->ic_chan_active, c->ic_ieee))
15992 +-			continue;
15993 +-		if (mode == IEEE80211_MODE_AUTO) {
15994 +-			/* XXX special-case 11b/g channels so we select
15995 +-			 *     the g channel if both are present. */
15996 +-			if (IEEE80211_IS_CHAN_B(c) &&
15997 +-			    (cg = find11gchannel(ic, i, c->ic_freq)) != NULL)
15998 +-				c = cg;
15999 +-		}
16000 +-		if (ss->ss_last >= IEEE80211_SCAN_MAX)
16001 +-			break;
16002 +-		ss->ss_chans[ss->ss_last++] = c;
16003 +-	}
16004 +-}
16005 +-
16006 +-/* This function must be invoked with locks acquired */
16007 +-static int
16008 +-checktable(const struct scanlist *scan, const struct ieee80211_channel *c)
16009 +-{
16010 +-	int i;
16011 +-
16012 +-	for (; scan->list != NULL; scan++) {
16013 +-		for (i = 0; i < scan->count; i++)
16014 +-			if (scan->list[i] == c->ic_freq)
16015 +-				return 1;
16016 +-	}
16017 +-	return 0;
16018 +-}
16019 + 
16020 + /*
16021 +  * Attach prior to any scanning work.
16022 +@@ -327,29 +203,6 @@
16023 + 		ieee80211_saveie(iep, ie);
16024 + }
16025 + 
16026 +-/* This function must be invoked with locks acquired */
16027 +-static struct ieee80211_channel *
16028 +-find11gchannel(struct ieee80211com *ic, int i, int freq)
16029 +-{
16030 +-	struct ieee80211_channel *c;
16031 +-	int j;
16032 +-
16033 +-	/* The normal ordering in the channel list is b channel
16034 +-	 * immediately followed by g so optimize the search for
16035 +-	 * this.  We'll still do a full search just in case. */
16036 +-	for (j = i + 1; j < ic->ic_nchans; j++) {
16037 +-		c = &ic->ic_channels[j];
16038 +-		if ((c->ic_freq == freq) && IEEE80211_IS_CHAN_ANYG(c))
16039 +-			return c;
16040 +-	}
16041 +-	for (j = 0; j < i; j++) {
16042 +-		c = &ic->ic_channels[j];
16043 +-		if ((c->ic_freq == freq) && IEEE80211_IS_CHAN_ANYG(c))
16044 +-			return c;
16045 +-	}
16046 +-	return NULL;
16047 +-}
16048 +-
16049 + /*
16050 +  * Start an ap scan by populating the channel list.
16051 +  */
16052 +@@ -358,8 +211,6 @@
16053 + {
16054 + 	struct ap_state *as 	    = ss->ss_priv;
16055 + 	struct ieee80211com *ic     = NULL;
16056 +-	const struct scanlist *sl   = NULL;
16057 +-	struct ieee80211_channel *c = NULL;
16058 + 	int i;
16059 + 	unsigned int mode = 0;
16060 + 
16061 +@@ -368,80 +219,8 @@
16062 + 	/* Determine mode flags to match, or leave zero for auto mode */
16063 + 	as->as_vap_desired_mode = vap->iv_des_mode;
16064 + 	as->as_required_mode    = 0;
16065 +-	if (as->as_vap_desired_mode != IEEE80211_MODE_AUTO) {
16066 +-		as->as_required_mode = chanflags[as->as_vap_desired_mode];
16067 +-		if ((vap->iv_ath_cap & IEEE80211_ATHC_TURBOP) && 
16068 +-		    (as->as_required_mode != IEEE80211_CHAN_ST)) {
16069 +-			/* Fixup for dynamic turbo flags */
16070 +-			if (as->as_vap_desired_mode == IEEE80211_MODE_11G)
16071 +-				as->as_required_mode = IEEE80211_CHAN_108G;
16072 +-			else
16073 +-				as->as_required_mode = IEEE80211_CHAN_108A;
16074 +-		}
16075 +-	}
16076 +-
16077 +-	ss->ss_last = 0;
16078 +-	/* Use the table of ordered channels to construct the list
16079 +-	 * of channels for scanning.  Any channels in the ordered
16080 +-	 * list not in the master list will be discarded. */
16081 +-	for (sl = staScanTable; sl->list != NULL; sl++) {
16082 +-		mode = sl->mode;
16083 +-
16084 +-		/* The scan table marks 2.4Ghz channels as b
16085 +-		 * so if the desired mode is 11g, then use
16086 +-		 * the 11b channel list but upgrade the mode. */
16087 +-		if (as->as_vap_desired_mode &&
16088 +-		    (as->as_vap_desired_mode != mode) && 
16089 +-		    (as->as_vap_desired_mode == IEEE80211_MODE_11G) && 
16090 +-		    (mode == IEEE80211_MODE_11B))
16091 +-			mode = IEEE80211_MODE_11G;
16092 +-
16093 +-		/* If we are in "AUTO" mode, upgrade the mode to auto. 
16094 +-		 * This lets add_channels upgrade an 11b channel to 
16095 +-		 * 11g if available. */
16096 +-		if (!as->as_vap_desired_mode && (mode == IEEE80211_MODE_11B))
16097 +-			mode = IEEE80211_MODE_AUTO;
16098 +-
16099 +-		/* Add the list of the channels; any that are not
16100 +-		 * in the master channel list will be discarded. */
16101 +-		add_channels(ic, ss, mode, sl->list, sl->count);
16102 +-	}
16103 +-
16104 +-	/* Add the channels from the ic (from HAL) that are not present
16105 +-	 * in the staScanTable, assuming they pass the sanity checks... */
16106 +-	for (i = 0; i < ic->ic_nchans; i++) {
16107 +-		c = &ic->ic_channels[i];
16108 +-
16109 +-		/* XR is not supported on turbo channels */
16110 +-		if (IEEE80211_IS_CHAN_TURBO(c) && vap->iv_flags & IEEE80211_F_XR)
16111 +-			continue;
16112 ++	ieee80211_scan_add_channels(ic, ss, vap->iv_des_mode);
16113 + 
16114 +-		/* Dynamic channels are scanned in base mode */
16115 +-		if (!as->as_required_mode && !IEEE80211_IS_CHAN_ST(c))
16116 +-			continue;
16117 +-
16118 +-		/* Use any 11g channel instead of 11b one. */
16119 +-		if (vap->iv_des_mode == IEEE80211_MODE_AUTO && 
16120 +-		    IEEE80211_IS_CHAN_B(c) &&
16121 +-		    find11gchannel(ic, i, c->ic_freq))
16122 +-			continue;
16123 +-
16124 +-		/* Do not add channels already put into the scan list by the
16125 +-		 * scan table - these have already been filtered by mode
16126 +-		 * and for whether they are in the active channel list. */
16127 +-		if (checktable(staScanTable, c))
16128 +-			continue;
16129 +-
16130 +-		/* Make sure the channel is active */
16131 +-		if ((c == NULL) || isclr(ic->ic_chan_active, c->ic_ieee))
16132 +-			continue;
16133 +-
16134 +-		/* Don't overrun */
16135 +-		if (ss->ss_last >= IEEE80211_SCAN_MAX)
16136 +-			break;
16137 +-
16138 +-		ss->ss_chans[ss->ss_last++] = c;
16139 +-	}
16140 + 	ss->ss_next = 0;
16141 + 	/* XXX tunables */
16142 + 	ss->ss_mindwell = msecs_to_jiffies(200);	/* 200ms */
16143 +@@ -759,13 +538,6 @@
16144 + 		if (IEEE80211_IS_CHAN_RADAR(c->chan))
16145 + 			continue;
16146 + 
16147 +-		/* Do not select 802.11a ST if mode is specified and is not 
16148 +-		 * 802.11a ST */
16149 +-		if (as->as_required_mode &&
16150 +-		    IEEE80211_IS_CHAN_STURBO(c->chan) &&
16151 +-		    (as->as_vap_desired_mode != IEEE80211_MODE_TURBO_STATIC_A))
16152 +-			continue;
16153 +-
16154 + 		/* Verify mode matches any fixed mode specified */
16155 + 		if((c->chan->ic_flags & as->as_required_mode) != 
16156 + 				as->as_required_mode)
16157 +--- a/net80211/ieee80211_scan.c
16158 ++++ b/net80211/ieee80211_scan.c
16159 +@@ -958,6 +958,80 @@
16160 + 	}
16161 + }
16162 + 
16163 ++static const u_int chanflags[] = {
16164 ++	0,	/* IEEE80211_MODE_AUTO */
16165 ++	IEEE80211_CHAN_A,	/* IEEE80211_MODE_11A */
16166 ++	IEEE80211_CHAN_B,	/* IEEE80211_MODE_11B */
16167 ++	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_11G */
16168 ++	IEEE80211_CHAN_FHSS,	/* IEEE80211_MODE_FH */
16169 ++	IEEE80211_CHAN_A,	/* IEEE80211_MODE_TURBO_A */ /* for turbo mode look for AP in normal channel */
16170 ++	IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_TURBO_G */
16171 ++	IEEE80211_CHAN_ST,	/* IEEE80211_MODE_TURBO_STATIC_A */
16172 ++};
16173 ++
16174 ++static struct ieee80211_channel *
16175 ++find11gchannel(struct ieee80211com *ic, int i, int freq)
16176 ++{
16177 ++	struct ieee80211_channel *c;
16178 ++	int j;
16179 ++
16180 ++	/*
16181 ++	 * The normal ordering in the channel list is b channel
16182 ++	 * immediately followed by g so optimize the search for
16183 ++	 * this.  We'll still do a full search just in case.
16184 ++	 */
16185 ++	for (j = i+1; j < ic->ic_nchans; j++) {
16186 ++		c = &ic->ic_channels[j];
16187 ++		if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
16188 ++			return c;
16189 ++	}
16190 ++	for (j = 0; j < i; j++) {
16191 ++		c = &ic->ic_channels[j];
16192 ++		if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
16193 ++			return c;
16194 ++	}
16195 ++	return NULL;
16196 ++}
16197 ++
16198 ++
16199 ++void
16200 ++ieee80211_scan_add_channels(struct ieee80211com *ic,
16201 ++	struct ieee80211_scan_state *ss,
16202 ++	enum ieee80211_phymode mode)
16203 ++{
16204 ++	struct ieee80211_channel *c, *cg;
16205 ++	u_int modeflags;
16206 ++	int i;
16207 ++
16208 ++	KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode));
16209 ++	modeflags = chanflags[mode];
16210 ++	for (i = 0; i < ic->ic_nchans; i++) {
16211 ++		c = &ic->ic_channels[i];
16212 ++		if (c == NULL || isclr(ic->ic_chan_active, c->ic_ieee))
16213 ++			continue;
16214 ++		if (c->ic_scanflags & IEEE80211_NOSCAN_SET)
16215 ++			continue;
16216 ++		if (modeflags &&
16217 ++			((c->ic_flags & IEEE80211_CHAN_ALLTURBO) !=
16218 ++			 (modeflags & IEEE80211_CHAN_ALLTURBO)))
16219 ++			continue;
16220 ++		if (mode == IEEE80211_MODE_AUTO) {
16221 ++			/*
16222 ++			 * XXX special-case 11b/g channels so we select
16223 ++			 *     the g channel if both are present.
16224 ++			 */
16225 ++			if (IEEE80211_IS_CHAN_B(c) &&
16226 ++			    (cg = find11gchannel(ic, i, c->ic_freq)) != NULL)
16227 ++				continue;
16228 ++		}
16229 ++		if (ss->ss_last >= IEEE80211_SCAN_MAX)
16230 ++			break;
16231 ++		ss->ss_chans[ss->ss_last++] = c;
16232 ++	}
16233 ++}
16234 ++EXPORT_SYMBOL(ieee80211_scan_add_channels);
16235 ++
16236 ++
16237 + /*
16238 +  * Execute radar channel change. This is called when a radar/dfs
16239 +  * signal is detected.  AP mode only.  Return 1 on success, 0 on
16240 +--- a/net80211/ieee80211_scan.h
16241 ++++ b/net80211/ieee80211_scan.h
16242 +@@ -219,4 +219,7 @@
16243 + void ieee80211_scanner_unregister(enum ieee80211_opmode,
16244 + 	const struct ieee80211_scanner *);
16245 + void ieee80211_scanner_unregister_all(const struct ieee80211_scanner *);
16246 ++void ieee80211_scan_add_channels(struct ieee80211com *ic,
16247 ++	struct ieee80211_scan_state *ss,
16248 ++	enum ieee80211_phymode mode);
16249 + #endif /* _NET80211_IEEE80211_SCAN_H_ */
16250 +--- a/net80211/ieee80211_wireless.c
16251 ++++ b/net80211/ieee80211_wireless.c
16252 +@@ -3873,6 +3873,106 @@
16253 + 	return ieee80211_ioctl_setmlme(dev, info, w, (char *)&mlme);
16254 + }
16255 + 
16256 ++static inline void setflag(struct ieee80211_channel *c, int flag)
16257 ++{
16258 ++	if (flag)
16259 ++		c->ic_scanflags |= IEEE80211_NOSCAN_SET;
16260 ++	else
16261 ++		c->ic_scanflags &= ~IEEE80211_NOSCAN_SET;
16262 ++}
16263 ++
16264 ++static void setscanflag(struct ieee80211com *ic, int min, int max, int set)
16265 ++{
16266 ++	int i;
16267 ++
16268 ++	for (i = 0; i < ic->ic_nchans; i++) {
16269 ++		struct ieee80211_channel *c = &ic->ic_channels[i];
16270 ++
16271 ++		if (min == -1) {
16272 ++			if (!(c->ic_scanflags & IEEE80211_NOSCAN_DEFAULT))
16273 ++				setflag(c, set);
16274 ++		} else if ((c->ic_freq >= min) && (c->ic_freq <= max)) {
16275 ++			setflag(c, set);
16276 ++		}
16277 ++	}
16278 ++}
16279 ++
16280 ++static int
16281 ++ieee80211_ioctl_setscanlist(struct net_device *dev,
16282 ++	struct iw_request_info *info,
16283 ++	struct iw_point *data, char *extra)
16284 ++{
16285 ++	struct ieee80211vap *vap = dev->priv;
16286 ++	struct ieee80211com *ic = vap->iv_ic;
16287 ++	char *s, *next;
16288 ++	int val = 1;
16289 ++
16290 ++	if (data->length <= 0)
16291 ++		return -EINVAL;
16292 ++
16293 ++	s = kmalloc(data->length + 1, GFP_KERNEL);
16294 ++	if (!s)
16295 ++		return -ENOMEM;
16296 ++
16297 ++	memset(s, 0, data->length + 1);
16298 ++	if (copy_from_user(s, data->pointer, data->length))
16299 ++		return -EFAULT;
16300 ++
16301 ++	s[data->length - 1] = '\0';		/* ensure null termination */
16302 ++
16303 ++	switch(*s) {
16304 ++		case '-':
16305 ++			val = 1;
16306 ++			break;
16307 ++		case '+':
16308 ++			val = 0;
16309 ++			break;
16310 ++		default:
16311 ++			goto error;
16312 ++	}
16313 ++	s++;
16314 ++	next = s;
16315 ++	do {
16316 ++		next = strchr(s, ',');
16317 ++		if (next) {
16318 ++			*next = 0;
16319 ++			next++;
16320 ++		}
16321 ++		if (!strcmp(s, "ALL")) {
16322 ++			setscanflag(ic, 0, 10000, val);
16323 ++		} else if (!strcmp(s, "REG")) {
16324 ++			setscanflag(ic, -1, -1, val);
16325 ++		} else {
16326 ++			int min, max;
16327 ++			char *n, *end = NULL;
16328 ++
16329 ++			n = strchr(s, '-');
16330 ++			if (n) {
16331 ++				*n = 0;
16332 ++				n++;
16333 ++			}
16334 ++			min = simple_strtoul(s, &end, 10);
16335 ++			if (end && *end)
16336 ++				goto error;
16337 ++			if (n) {
16338 ++				max = simple_strtoul(n, &end, 10);
16339 ++				if (end && *end)
16340 ++					goto error;
16341 ++			} else {
16342 ++				max = min;
16343 ++			}
16344 ++			setscanflag(ic, min, max, val);
16345 ++		}
16346 ++		s = next;
16347 ++	} while (next);
16348 ++	return 0;
16349 ++
16350 ++error:
16351 ++	if (s)
16352 ++		kfree(s);
16353 ++	return -EINVAL;
16354 ++}
16355 ++
16356 + static int
16357 + ieee80211_ioctl_addmac(struct net_device *dev, struct iw_request_info *info,
16358 + 	void *w, char *extra)
16359 +@@ -5656,6 +5756,8 @@
16360 + 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "minrate"},
16361 + 	{IEEE80211_PARAM_MINRATE,
16362 + 	 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_minrate"},
16363 ++	{ IEEE80211_IOCTL_SETSCANLIST,
16364 ++	 IW_PRIV_TYPE_CHAR | 255, 0, "setscanlist"},
16365 + 
16366 + #ifdef ATH_REVERSE_ENGINEERING
16367 + 	/*
16368 +@@ -5753,6 +5855,7 @@
16369 + 	set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsmac),
16370 + 	set_priv(IEEE80211_IOCTL_WDSDELMAC, ieee80211_ioctl_wdsdelmac),
16371 + 	set_priv(IEEE80211_IOCTL_KICKMAC, ieee80211_ioctl_kickmac),
16372 ++	set_priv(IEEE80211_IOCTL_SETSCANLIST, ieee80211_ioctl_setscanlist),
16373 + #ifdef ATH_REVERSE_ENGINEERING
16374 + 	set_priv(IEEE80211_IOCTL_READREG, ieee80211_ioctl_readreg),
16375 + 	set_priv(IEEE80211_IOCTL_WRITEREG, ieee80211_ioctl_writereg),
16376 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/352-ani_fix.patch kamikaze_7.09/package/madwifi/patches/352-ani_fix.patch
16377 --- kamikaze_7.09.orig/package/madwifi/patches/352-ani_fix.patch	1970-01-01 01:00:00.000000000 +0100
16378 +++ kamikaze_7.09/package/madwifi/patches/352-ani_fix.patch	2008-06-19 17:34:17.000000000 +0200
16379 @@ -0,0 +1,288 @@
16380 +Index: madwifi-trunk-r3314/ath/if_ath.c
16381 +===================================================================
16382 +--- madwifi-trunk-r3314.orig/ath/if_ath.c	2008-06-13 10:39:28.000000000 +0200
16383 ++++ madwifi-trunk-r3314/ath/if_ath.c	2008-06-13 10:39:54.000000000 +0200
16384 +@@ -1014,9 +1014,7 @@
16385 + 	 */
16386 + 	sc->sc_hasveol = ath_hal_hasveol(ah);
16387 + 
16388 +-	/* Interference mitigation/ambient noise immunity (ANI).
16389 +-	 * In modes other than HAL_M_STA, it causes receive sensitivity
16390 +-	 * problems for OFDM. */
16391 ++	/* Interference mitigation/ambient noise immunity (ANI). */
16392 + 	sc->sc_hasintmit = ath_hal_hasintmit(ah);
16393 + 
16394 + 	/* get mac address from hardware */
16395 +@@ -1144,6 +1142,11 @@
16396 + 	sc->sc_rp_lasttsf	= 0;
16397 + 	sc->sc_last_tsf		= 0;
16398 + 
16399 ++	/* set all 3 to auto */
16400 ++	sc->sc_intmit = -1;
16401 ++	sc->sc_noise_immunity = -1;
16402 ++	sc->sc_ofdm_weak_det = -1;
16403 ++
16404 + 	return 0;
16405 + bad3:
16406 + 	ieee80211_ifdetach(ic);
16407 +@@ -2347,16 +2350,6 @@
16408 + 		}
16409 + 		if (status & HAL_INT_MIB) {
16410 + 			sc->sc_stats.ast_mib++;
16411 +-			/* When the card receives lots of PHY errors, the MIB
16412 +-			 * interrupt will fire at a very rapid rate. We will use
16413 +-			 * a timer to enforce at least 1 jiffy delay between
16414 +-			 * MIB interrupts. This should be unproblematic, since
16415 +-			 * the hardware will continue to update the counters in 
16416 +-			 * the mean time. */
16417 +-			sc->sc_imask &= ~HAL_INT_MIB;
16418 +-			ath_hal_intrset(ah, sc->sc_imask);
16419 +-			mod_timer(&sc->sc_mib_enable, jiffies + 1);
16420 +-
16421 + 			/* Let the HAL handle the event. */
16422 + 			ath_hal_mibevent(ah, &sc->sc_halstats);
16423 + 		}
16424 +@@ -2426,6 +2419,43 @@
16425 + 	return flags;
16426 + }
16427 + 
16428 ++static int ath_setintmit(struct ath_softc *sc)
16429 ++{
16430 ++	struct ath_hal *ah = sc->sc_ah;
16431 ++	int ret;
16432 ++	int val;
16433 ++
16434 ++	if (!sc->sc_hasintmit)
16435 ++		return 0;
16436 ++
16437 ++	switch(sc->sc_intmit) {
16438 ++		case -1:
16439 ++			if (sc->sc_opmode != IEEE80211_M_MONITOR)
16440 ++				val = 1;
16441 ++			else
16442 ++				val = 0;
16443 ++			break;
16444 ++		case 0: /* disabled */
16445 ++		case 1: /* enabled */
16446 ++			val = sc->sc_intmit;
16447 ++			break;
16448 ++		default:
16449 ++			return 0;
16450 ++	}
16451 ++	ret = ath_hal_setintmit(ah, val);
16452 ++	if (val)
16453 ++		goto done;
16454 ++
16455 ++	/* manual settings */
16456 ++	if ((sc->sc_noise_immunity >= 0) && (sc->sc_noise_immunity <= 5))
16457 ++		ath_hal_setcapability(ah, HAL_CAP_INTMIT, 2, sc->sc_noise_immunity, NULL);
16458 ++	if ((sc->sc_ofdm_weak_det == 0) || (sc->sc_ofdm_weak_det == 1))
16459 ++		ath_hal_setcapability(ah, HAL_CAP_INTMIT, 3, sc->sc_ofdm_weak_det, NULL);
16460 ++
16461 ++done:
16462 ++	return ret;
16463 ++}
16464 ++
16465 + /*
16466 +  * Context: process context
16467 +  */
16468 +@@ -2491,8 +2521,7 @@
16469 + 	if (sc->sc_softled)
16470 + 		ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);
16471 + 
16472 +-	if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
16473 +-		ath_hal_setintmit(ah, 0);
16474 ++	ath_setintmit(sc);
16475 + 
16476 + 	/*
16477 + 	 * This is needed only to setup initial state
16478 +@@ -2528,7 +2557,7 @@
16479 + 	 * Enable MIB interrupts when there are hardware phy counters.
16480 + 	 * Note we only do this (at the moment) for station mode.
16481 + 	 */
16482 +-	if (sc->sc_needmib && ic->ic_opmode == IEEE80211_M_STA)
16483 ++	if (sc->sc_needmib && ath_hal_getintmit(ah, NULL))
16484 + 		sc->sc_imask |= HAL_INT_MIB;
16485 + 	ath_hal_intrset(ah, sc->sc_imask);
16486 + 
16487 +@@ -2785,9 +2814,7 @@
16488 + 		EPRINTF(sc, "Unable to reset hardware: '%s' (HAL status %u)\n",
16489 + 			ath_get_hal_status_desc(status), status);
16490 + 
16491 +-	if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
16492 +-		ath_hal_setintmit(ah, 0);
16493 +-
16494 ++	ath_setintmit(sc);
16495 + 	ath_update_txpow(sc);		/* update tx power state */
16496 + 	ath_radar_update(sc);
16497 + 	ath_setdefantenna(sc, sc->sc_defant);
16498 +@@ -4165,6 +4192,8 @@
16499 + 	if (sc->sc_nmonvaps > 0)
16500 + 		rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
16501 + 			  HAL_RX_FILTER_PROBEREQ | HAL_RX_FILTER_PROM);
16502 ++	if (sc->sc_hasintmit && !sc->sc_needmib && ath_hal_getintmit(ah, NULL))
16503 ++		rfilt |= HAL_RX_FILTER_PHYERR;
16504 + 	if (sc->sc_curchan.privFlags & CHANNEL_DFS)
16505 + 		rfilt |= (HAL_RX_FILTER_PHYERR | HAL_RX_FILTER_PHYRADAR);
16506 + 	return rfilt;
16507 +@@ -6513,9 +6542,6 @@
16508 + 			rs->rs_rssi = 0;
16509 + 
16510 + 		len = rs->rs_datalen;
16511 +-		/* DMA sync. dies spectacularly if len == 0 */
16512 +-		if (len == 0)
16513 +-			goto rx_next;
16514 + 
16515 + 		if (rs->rs_more) {
16516 + 			/*
16517 +@@ -8865,9 +8891,7 @@
16518 + 		if (sc->sc_softled)
16519 + 			ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);
16520 + 
16521 +-		if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
16522 +-			ath_hal_setintmit(ah, 0);
16523 +-
16524 ++		ath_setintmit(sc);
16525 + 		sc->sc_curchan = hchan;
16526 + 		ath_update_txpow(sc);		/* update tx power state */
16527 + 		ath_radar_update(sc);
16528 +@@ -10644,9 +10668,54 @@
16529 + 	ATH_RP_IGNORED 		= 24,
16530 + 	ATH_RADAR_IGNORED       = 25,
16531 + 	ATH_MAXVAPS  		= 26,
16532 ++	ATH_INTMIT			= 27,
16533 ++	ATH_NOISE_IMMUNITY	= 28,
16534 ++	ATH_OFDM_WEAK_DET	= 29
16535 + };
16536 + 
16537 + static int
16538 ++ath_sysctl_set_intmit(struct ath_softc *sc, long ctl, u_int val)
16539 ++{
16540 ++	int ret;
16541 ++
16542 ++	switch(ctl) {
16543 ++	case ATH_INTMIT:
16544 ++		sc->sc_intmit = val;
16545 ++		break;
16546 ++	case ATH_NOISE_IMMUNITY:
16547 ++		sc->sc_noise_immunity = val;
16548 ++		break;
16549 ++	case ATH_OFDM_WEAK_DET:
16550 ++		sc->sc_ofdm_weak_det = val;
16551 ++		break;
16552 ++	default:
16553 ++		return -EINVAL;
16554 ++	}
16555 ++	ret = ath_setintmit(sc);
16556 ++	ath_calcrxfilter(sc);
16557 ++	return ret;
16558 ++}
16559 ++
16560 ++static int
16561 ++ath_sysctl_get_intmit(struct ath_softc *sc, long ctl, u_int *val)
16562 ++{
16563 ++	struct ath_hal *ah = sc->sc_ah;
16564 ++
16565 ++	switch(ctl) {
16566 ++	case ATH_INTMIT:
16567 ++		*val = (ath_hal_getcapability(ah, HAL_CAP_INTMIT, 1, NULL) == HAL_OK);
16568 ++		break;
16569 ++	case ATH_NOISE_IMMUNITY:
16570 ++		return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 2, val);
16571 ++	case ATH_OFDM_WEAK_DET:
16572 ++		return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 3, val);
16573 ++	default:
16574 ++		return -EINVAL;
16575 ++	}
16576 ++	return 0;
16577 ++}
16578 ++
16579 ++static int
16580 + ATH_SYSCTL_DECL(ath_sysctl_halparam, ctl, write, filp, buffer, lenp, ppos)
16581 + {
16582 + 	struct ath_softc *sc = ctl->extra1;
16583 +@@ -10832,6 +10901,11 @@
16584 + 			case ATH_RADAR_IGNORED:
16585 + 				sc->sc_radar_ignored = val;
16586 + 				break;
16587 ++			case ATH_INTMIT:
16588 ++			case ATH_NOISE_IMMUNITY:
16589 ++			case ATH_OFDM_WEAK_DET:
16590 ++				ret = ath_sysctl_set_intmit(sc, (long)ctl->extra2, val);
16591 ++				break;
16592 + 			default:
16593 + 				ret = -EINVAL;
16594 + 				break;
16595 +@@ -10898,6 +10972,11 @@
16596 + 		case ATH_RADAR_IGNORED:
16597 + 			val = sc->sc_radar_ignored;
16598 + 			break;
16599 ++		case ATH_INTMIT:
16600 ++		case ATH_NOISE_IMMUNITY:
16601 ++		case ATH_OFDM_WEAK_DET:
16602 ++			ret = ath_sysctl_get_intmit(sc, (long)ctl->extra2, &val);
16603 ++			break;
16604 + 		default:
16605 + 			ret = -EINVAL;
16606 + 			break;
16607 +@@ -11075,6 +11154,24 @@
16608 + 	  .proc_handler = ath_sysctl_halparam,
16609 + 	  .extra2	= (void *)ATH_RADAR_IGNORED,
16610 + 	},
16611 ++	{ .ctl_name	= CTL_AUTO,
16612 ++	  .procname     = "intmit",
16613 ++	  .mode         = 0644,
16614 ++	  .proc_handler = ath_sysctl_halparam,
16615 ++	  .extra2	= (void *)ATH_INTMIT,
16616 ++	},
16617 ++	{ .ctl_name	= CTL_AUTO,
16618 ++	  .procname     = "noise_immunity",
16619 ++	  .mode         = 0644,
16620 ++	  .proc_handler = ath_sysctl_halparam,
16621 ++	  .extra2	= (void *)ATH_NOISE_IMMUNITY,
16622 ++	},
16623 ++	{ .ctl_name	= CTL_AUTO,
16624 ++	  .procname     = "ofdm_weak_det",
16625 ++	  .mode         = 0644,
16626 ++	  .proc_handler = ath_sysctl_halparam,
16627 ++	  .extra2	= (void *)ATH_OFDM_WEAK_DET,
16628 ++	},
16629 + 	{ 0 }
16630 + };
16631 + 
16632 +Index: madwifi-trunk-r3314/ath/if_athvar.h
16633 +===================================================================
16634 +--- madwifi-trunk-r3314.orig/ath/if_athvar.h	2008-06-13 10:39:28.000000000 +0200
16635 ++++ madwifi-trunk-r3314/ath/if_athvar.h	2008-06-13 10:39:32.000000000 +0200
16636 +@@ -693,6 +693,10 @@
16637 + 	unsigned int sc_txcont_power; /* Continuous transmit power in 0.5dBm units */
16638 + 	unsigned int sc_txcont_rate;  /* Continuous transmit rate in Mbps */
16639 + 
16640 ++	int8_t sc_intmit; /* Interference mitigation enabled, -1 = auto, based on mode, 0/1 = off/on */
16641 ++	int8_t sc_noise_immunity; /* Noise immunity level, 0-4, -1 == auto) */
16642 ++	int8_t sc_ofdm_weak_det; /* OFDM weak frames detection, -1 == auto */
16643 ++
16644 + 	/* rate tables */
16645 + 	const HAL_RATE_TABLE *sc_rates[IEEE80211_MODE_MAX];
16646 + 	const HAL_RATE_TABLE *sc_currates;	/* current rate table */
16647 +Index: madwifi-trunk-r3314/ath/if_ath_hal.h
16648 +===================================================================
16649 +--- madwifi-trunk-r3314.orig/ath/if_ath_hal.h	2008-06-13 10:39:26.000000000 +0200
16650 ++++ madwifi-trunk-r3314/ath/if_ath_hal.h	2008-06-13 10:39:32.000000000 +0200
16651 +@@ -67,14 +67,14 @@
16652 + 
16653 + static inline HAL_BOOL ath_hal_getdiagstate(struct ath_hal *ah, int request,
16654 + 					    const void *args, u_int32_t argsize,
16655 +-					    void **result,
16656 ++					    void *result,
16657 + 					    u_int32_t *resultsize)
16658 + {
16659 + 	HAL_BOOL ret;
16660 + 	ATH_HAL_LOCK_IRQ(ah->ah_sc);
16661 + 	ath_hal_set_function(__func__);
16662 + 	ret =
16663 +-	    ah->ah_getDiagState(ah, request, args, argsize, *result,
16664 ++	    ah->ah_getDiagState(ah, request, args, argsize, result,
16665 + 				resultsize);
16666 + 	ath_hal_set_function(NULL);
16667 + 	ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
16668 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/400-changeset_r3402.patch kamikaze_7.09/package/madwifi/patches/400-changeset_r3402.patch
16669 --- kamikaze_7.09.orig/package/madwifi/patches/400-changeset_r3402.patch	1970-01-01 01:00:00.000000000 +0100
16670 +++ kamikaze_7.09/package/madwifi/patches/400-changeset_r3402.patch	2008-06-19 17:34:17.000000000 +0200
16671 @@ -0,0 +1,35 @@
16672 +--- a/ath_hal/ah_os.h
16673 ++++ b/ath_hal/ah_os.h
16674 +@@ -194,10 +194,6 @@
16675 +  */
16676 + #if (AH_BYTE_ORDER == AH_BIG_ENDIAN)
16677 + #define is_reg_le(__reg) ((0x4000 <= (__reg) && (__reg) < 0x5000))
16678 +-#else
16679 +-#define is_reg_le(__reg) 1
16680 +-#endif
16681 +-
16682 + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
16683 + #define _OS_REG_WRITE(_ah, _reg, _val) do {			\
16684 + 	 is_reg_le(_reg) ?					\
16685 +@@ -219,6 +215,21 @@
16686 + 	 readl((_ah)->ah_sh + (_reg)) :				\
16687 + 	 cpu_to_le32(readl((_ah)->ah_sh + (_reg))))
16688 + #endif				/* KERNEL_VERSION(2,6,12) */
16689 ++#else				/* AH_BYTE_ORDER != AH_BIG_ENDIAN */
16690 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
16691 ++#define _OS_REG_WRITE(_ah, _reg, _val) do {			\
16692 ++	 iowrite32((_val), (_ah)->ah_sh + (_reg));		\
16693 ++	} while (0)
16694 ++#define _OS_REG_READ(_ah, _reg)					\
16695 ++	ioread32((_ah)->ah_sh + (_reg))
16696 ++#else
16697 ++#define _OS_REG_WRITE(_ah, _reg, _val) do {			\
16698 ++	 writel((_val), (_ah)->ah_sh + (_reg));			\
16699 ++	} while (0)
16700 ++#define _OS_REG_READ(_ah, _reg)					\
16701 ++	readl((_ah)->ah_sh + (_reg))
16702 ++#endif				/* KERNEL_VERSION(2,6,12) */
16703 ++#endif				/* AH_BYTE_ORDER != AH_BIG_ENDIAN */
16704 + 
16705 + /*
16706 +  * The functions in this section are not intended to be invoked by MadWifi
16707 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/401-changeset_r3602.patch kamikaze_7.09/package/madwifi/patches/401-changeset_r3602.patch
16708 --- kamikaze_7.09.orig/package/madwifi/patches/401-changeset_r3602.patch	1970-01-01 01:00:00.000000000 +0100
16709 +++ kamikaze_7.09/package/madwifi/patches/401-changeset_r3602.patch	2008-06-19 17:34:17.000000000 +0200
16710 @@ -0,0 +1,11 @@
16711 +--- a/net80211/ieee80211_linux.h
16712 ++++ b/net80211/ieee80211_linux.h
16713 +@@ -312,6 +312,8 @@
16714 + /* __skb_append got a third parameter in 2.6.14 */
16715 + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
16716 + #define __skb_append(a,b,c)	__skb_append(a, b)
16717 ++#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
16718 ++#define __skb_append(a,b,c)	__skb_queue_after(c, a, b)
16719 + #endif
16720 + 
16721 + /*
16722 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/402-changeset_r3603.patch kamikaze_7.09/package/madwifi/patches/402-changeset_r3603.patch
16723 --- kamikaze_7.09.orig/package/madwifi/patches/402-changeset_r3603.patch	1970-01-01 01:00:00.000000000 +0100
16724 +++ kamikaze_7.09/package/madwifi/patches/402-changeset_r3603.patch	2008-06-19 17:34:17.000000000 +0200
16725 @@ -0,0 +1,176 @@
16726 +--- a/Makefile
16727 ++++ b/Makefile
16728 +@@ -40,10 +40,7 @@
16729 + # Makefile for the HAL-based Atheros driver.
16730 + #
16731 + 
16732 +-ifeq ($(obj),)
16733 +-obj=	.
16734 +-endif
16735 +-
16736 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16737 + TOP = $(obj)
16738 + 
16739 + ifneq (svnversion.h,$(MAKECMDGOALS))
16740 +--- a/ath/Makefile
16741 ++++ b/ath/Makefile
16742 +@@ -40,10 +40,7 @@
16743 + # Makefile for the Atheros WLAN driver.
16744 + #
16745 + 
16746 +-ifeq ($(obj),)
16747 +-obj=	.
16748 +-endif
16749 +-
16750 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16751 + TOP = $(obj)/..
16752 + 
16753 + ifeq ($(strip $(BUS)),AHB)
16754 +--- a/ath_hal/Makefile
16755 ++++ b/ath_hal/Makefile
16756 +@@ -40,10 +40,7 @@
16757 + # Makefile for the Atheros WLAN driver.
16758 + #
16759 + 
16760 +-ifeq ($(obj),)
16761 +-obj=	.
16762 +-endif
16763 +-
16764 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16765 + TOP = $(obj)/..
16766 + 
16767 + include $(TOP)/Makefile.inc
16768 +--- a/ath_rate/Makefile
16769 ++++ b/ath_rate/Makefile
16770 +@@ -1,7 +1,4 @@
16771 +-ifeq ($(obj),)
16772 +-obj=	.
16773 +-endif
16774 +-
16775 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16776 + TOP = $(obj)/..
16777 + 
16778 + obj-y := amrr/ onoe/ sample/ minstrel/
16779 +--- a/ath_rate/amrr/Makefile
16780 ++++ b/ath_rate/amrr/Makefile
16781 +@@ -40,10 +40,7 @@
16782 + #
16783 + # Makefile for the Atheros Rate Control Support.
16784 + #
16785 +-ifeq ($(obj),)
16786 +-obj=	.
16787 +-endif
16788 +-
16789 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16790 + TOP = $(obj)/../..
16791 + 
16792 + obj-m		+= ath_rate_amrr.o
16793 +--- a/ath_rate/minstrel/Makefile
16794 ++++ b/ath_rate/minstrel/Makefile
16795 +@@ -38,10 +38,7 @@
16796 + #
16797 + # Makefile for the Atheros Rate Control Support.
16798 + #
16799 +-ifeq ($(obj),)
16800 +-obj=	.
16801 +-endif
16802 +-
16803 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16804 + TOP = $(obj)/../..
16805 + 
16806 + obj-m		+= ath_rate_minstrel.o
16807 +--- a/ath_rate/onoe/Makefile
16808 ++++ b/ath_rate/onoe/Makefile
16809 +@@ -40,10 +40,7 @@
16810 + #
16811 + # Makefile for the Atheros Rate Control Support.
16812 + #
16813 +-ifeq ($(obj),)
16814 +-obj=	.
16815 +-endif
16816 +-
16817 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16818 + TOP = $(obj)/../..
16819 + 
16820 + obj-m		+= ath_rate_onoe.o
16821 +--- a/ath_rate/sample/Makefile
16822 ++++ b/ath_rate/sample/Makefile
16823 +@@ -38,10 +38,7 @@
16824 + #
16825 + # Makefile for the Atheros Rate Control Support.
16826 + #
16827 +-ifeq ($(obj),)
16828 +-obj=	.
16829 +-endif
16830 +-
16831 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16832 + TOP = $(obj)/../..
16833 + 
16834 + obj-m		+= ath_rate_sample.o
16835 +--- a/net80211/Makefile
16836 ++++ b/net80211/Makefile
16837 +@@ -39,10 +39,7 @@
16838 + #
16839 + # Makefile for the 802.11 WLAN modules.
16840 + #
16841 +-ifeq ($(obj),)
16842 +-obj=	.
16843 +-endif
16844 +-
16845 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16846 + TOP = $(obj)/..
16847 + #
16848 + # There is one authenticator mechanism: an in-kernel implementation
16849 +--- a/regression/Makefile
16850 ++++ b/regression/Makefile
16851 +@@ -1,7 +1,4 @@
16852 +-ifeq ($(obj),)
16853 +-obj=	.
16854 +-endif
16855 +-
16856 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16857 + TOP = $(obj)/..
16858 + 
16859 + obj-y := ccmp/ tkip/ wep/
16860 +--- a/regression/ccmp/Makefile
16861 ++++ b/regression/ccmp/Makefile
16862 +@@ -1,10 +1,7 @@
16863 + #
16864 + # Makefile for the CCMP regression test.
16865 + #
16866 +-ifeq ($(obj),)
16867 +-obj=	.
16868 +-endif
16869 +-
16870 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16871 + TOP = $(obj)/../..
16872 + 
16873 + obj-m			+= ath_test_ccmp.o
16874 +--- a/regression/tkip/Makefile
16875 ++++ b/regression/tkip/Makefile
16876 +@@ -1,10 +1,7 @@
16877 + #
16878 + # Makefile for the TKIP regression test.
16879 + #
16880 +-ifeq ($(obj),)
16881 +-obj=	.
16882 +-endif
16883 +-
16884 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16885 + TOP = $(obj)/../..
16886 + 
16887 + obj-m			+= ath_test_tkip.o
16888 +--- a/regression/wep/Makefile
16889 ++++ b/regression/wep/Makefile
16890 +@@ -1,10 +1,7 @@
16891 + #
16892 + # Makefile for the WEP regression test.
16893 + #
16894 +-ifeq ($(obj),)
16895 +-obj=	.
16896 +-endif
16897 +-
16898 ++obj := $(firstword $(obj) $(SUBDIRS) .)
16899 + TOP = $(obj)/../..
16900 + 
16901 + obj-m			+= ath_test_wep.o
16902 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/403-changeset_r3605.patch kamikaze_7.09/package/madwifi/patches/403-changeset_r3605.patch
16903 --- kamikaze_7.09.orig/package/madwifi/patches/403-changeset_r3605.patch	1970-01-01 01:00:00.000000000 +0100
16904 +++ kamikaze_7.09/package/madwifi/patches/403-changeset_r3605.patch	2008-06-19 17:34:17.000000000 +0200
16905 @@ -0,0 +1,70 @@
16906 +--- a/include/compat.h
16907 ++++ b/include/compat.h
16908 +@@ -182,6 +182,13 @@
16909 + #define DEV_ATH CTL_UNNUMBERED
16910 + #endif
16911 + 
16912 ++/* __skb_append got a third parameter in 2.6.14 */
16913 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
16914 ++#define __skb_queue_after(_list, _old, _new)	__skb_append(_old, _new)
16915 ++#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
16916 ++#define __skb_queue_after(_list, _old, _new)	__skb_append(_old, _new, _list)
16917 ++#endif
16918 ++
16919 + #endif /* __KERNEL__ */
16920 + 
16921 + #endif /* _ATH_COMPAT_H_ */
16922 +--- a/net80211/ieee80211_linux.h
16923 ++++ b/net80211/ieee80211_linux.h
16924 +@@ -309,13 +309,6 @@
16925 + #define	ACL_LOCK_CHECK(_as)
16926 + #endif
16927 + 
16928 +-/* __skb_append got a third parameter in 2.6.14 */
16929 +-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
16930 +-#define __skb_append(a,b,c)	__skb_append(a, b)
16931 +-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
16932 +-#define __skb_append(a,b,c)	__skb_queue_after(c, a, b)
16933 +-#endif
16934 +-
16935 + /*
16936 +  * Per-node power-save queue definitions.  Beware of control
16937 +  * flow with IEEE80211_NODE_SAVEQ_LOCK/IEEE80211_NODE_SAVEQ_UNLOCK.
16938 +@@ -359,16 +352,16 @@
16939 + 	_skb = __skb_dequeue(&(_ni)->ni_savedq);		\
16940 + 	(_qlen) = skb_queue_len(&(_ni)->ni_savedq);		\
16941 + } while (0)
16942 +-#define	_IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _skb, _qlen, _age) do {\
16943 +-	struct sk_buff *tail = skb_peek_tail(&(_ni)->ni_savedq);\
16944 +-	if (tail != NULL) {					\
16945 +-		_age -= M_AGE_GET(tail);			\
16946 +-		__skb_append(tail, _skb, &(_ni)->ni_savedq);	\
16947 +-	} else { 						\
16948 +-		__skb_queue_head(&(_ni)->ni_savedq, _skb);	\
16949 +-	}							\
16950 +-	M_AGE_SET(_skb, _age);					\
16951 +-	(_qlen) = skb_queue_len(&(_ni)->ni_savedq); 		\
16952 ++#define	_IEEE80211_NODE_SAVEQ_ENQUEUE(_ni, _skb, _qlen, _age) do {	\
16953 ++	struct sk_buff *tail = skb_peek_tail(&(_ni)->ni_savedq);	\
16954 ++	if (tail != NULL) {						\
16955 ++		_age -= M_AGE_GET(tail);				\
16956 ++		__skb_queue_after(&(_ni)->ni_savedq, tail, _skb);	\
16957 ++	} else { 							\
16958 ++		__skb_queue_head(&(_ni)->ni_savedq, _skb);		\
16959 ++	}								\
16960 ++	M_AGE_SET(_skb, _age);						\
16961 ++	(_qlen) = skb_queue_len(&(_ni)->ni_savedq); 			\
16962 + } while (0)
16963 + 
16964 + /*
16965 +--- a/net80211/ieee80211_power.c
16966 ++++ b/net80211/ieee80211_power.c
16967 +@@ -243,7 +243,7 @@
16968 + 	tail = skb_peek_tail(&ni->ni_savedq);
16969 + 	if (tail != NULL) {
16970 + 		age -= M_AGE_GET(tail);
16971 +-		__skb_append(tail, skb, &ni->ni_savedq);
16972 ++		__skb_queue_after(&ni->ni_savedq, tail, skb);
16973 + 	} else
16974 + 		__skb_queue_head(&ni->ni_savedq, skb);
16975 + 	M_AGE_SET(skb, age);
16976 diff -Nur kamikaze_7.09.orig/package/madwifi/patches/404-linux24_fix.patch kamikaze_7.09/package/madwifi/patches/404-linux24_fix.patch
16977 --- kamikaze_7.09.orig/package/madwifi/patches/404-linux24_fix.patch	1970-01-01 01:00:00.000000000 +0100
16978 +++ kamikaze_7.09/package/madwifi/patches/404-linux24_fix.patch	2008-06-19 17:34:17.000000000 +0200
16979 @@ -0,0 +1,17 @@
16980 +Index: madwifi-trunk-r3314/ath_hal/Makefile
16981 +===================================================================
16982 +--- madwifi-trunk-r3314.orig/ath_hal/Makefile	2008-06-07 17:08:42.354855646 +0200
16983 ++++ madwifi-trunk-r3314/ath_hal/Makefile	2008-06-07 17:09:03.260046968 +0200
16984 +@@ -78,10 +78,11 @@
16985 + quiet_cmd_uudecode = UUDECODE $@
16986 +       cmd_uudecode = $(obj)/uudecode -o $@ $<
16987 + 
16988 +-$(obj)/$(TARGET).hal.o: $(HAL)/public/$(TARGET).hal.o.uu $(obj)/uudecode
16989 + ifdef LINUX24
16990 ++$(TARGET).hal.o: $(HAL)/public/$(TARGET).hal.o.uu $(obj)/uudecode
16991 + 	$(Q)$(obj)/uudecode -o $@ $<
16992 + else
16993 ++$(obj)/$(TARGET).hal.o: $(HAL)/public/$(TARGET).hal.o.uu $(obj)/uudecode
16994 + 	$(call if_changed,uudecode)
16995 + endif
16996 + 
16997 diff -Nur kamikaze_7.09.orig/package/netperf/files/netserver.init kamikaze_7.09/package/netperf/files/netserver.init
16998 --- kamikaze_7.09.orig/package/netperf/files/netserver.init	1970-01-01 01:00:00.000000000 +0100
16999 +++ kamikaze_7.09/package/netperf/files/netserver.init	2008-06-19 17:34:17.000000000 +0200
17000 @@ -0,0 +1,11 @@
17001 +#!/bin/sh /etc/rc.common
17002 +# Copyright (C) 2006 OpenWrt.org
17003 +START=50
17004 +
17005 +start() {
17006 +	/usr/bin/netserver
17007 +}
17008 +
17009 +stop() {
17010 +	killall netserver
17011 +}
17012 diff -Nur kamikaze_7.09.orig/package/netperf/Makefile kamikaze_7.09/package/netperf/Makefile
17013 --- kamikaze_7.09.orig/package/netperf/Makefile	1970-01-01 01:00:00.000000000 +0100
17014 +++ kamikaze_7.09/package/netperf/Makefile	2008-06-19 17:34:17.000000000 +0200
17015 @@ -0,0 +1,46 @@
17016 +#
17017 +# Copyright (C) 2006 OpenWrt.org
17018 +#
17019 +# This is free software, licensed under the GNU General Public License v2.
17020 +# See /LICENSE for more information.
17021 +#
17022 +# $Id: Makefile 8398 2007-08-11 16:06:22Z olli $
17023 +
17024 +include $(TOPDIR)/rules.mk
17025 +
17026 +PKG_NAME:=netperf
17027 +PKG_VERSION:=2.4.3
17028 +PKG_RELEASE:=2
17029 +
17030 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
17031 +PKG_SOURCE_URL:=ftp://ftp.netperf.org/netperf/
17032 +PKG_MD5SUM:=8b1f48500443b18b825ae2763a51eced
17033 +
17034 +include $(INCLUDE_DIR)/package.mk
17035 +
17036 +define Package/netperf
17037 +  SECTION:=net
17038 +  CATEGORY:=Network
17039 +  TITLE:=Network performance measurement tool
17040 +  URL:=http://www.netperf.org/
17041 +endef
17042 +
17043 +define Package/netperf/install
17044 +	$(INSTALL_DIR) $(1)/etc/init.d
17045 +	$(INSTALL_BIN) ./files/netserver.init $(1)/etc/init.d/netserver
17046 +	$(INSTALL_DIR) $(1)/usr/bin
17047 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/netperf $(1)/usr/bin/
17048 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/netserver $(1)/usr/bin/
17049 +	$(INSTALL_DIR) $(1)/lib/netperf
17050 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/arr_script $(1)/lib/netperf
17051 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/packet_byte_script $(1)/lib/netperf
17052 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/sctp_stream_script $(1)/lib/netperf
17053 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/snapshot_script $(1)/lib/netperf
17054 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/tcp_range_script $(1)/lib/netperf
17055 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/tcp_rr_script $(1)/lib/netperf
17056 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/tcp_stream_script $(1)/lib/netperf
17057 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/udp_rr_script $(1)/lib/netperf
17058 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/doc/examples/udp_stream_script $(1)/lib/netperf
17059 +endef
17060 +
17061 +$(eval $(call BuildPackage,netperf))
17062 diff -Nur kamikaze_7.09.orig/package/olsrd/files/olsr.config kamikaze_7.09/package/olsrd/files/olsr.config
17063 --- kamikaze_7.09.orig/package/olsrd/files/olsr.config	1970-01-01 01:00:00.000000000 +0100
17064 +++ kamikaze_7.09/package/olsrd/files/olsr.config	2008-06-19 17:34:17.000000000 +0200
17065 @@ -0,0 +1,40 @@
17066 +config "olsr" "general"
17067 +	option DebugLevel	'0'
17068 +	option IpVersion	'4'
17069 +	option AllowNoInt	'yes'
17070 +	option Pollrate	'0.025'
17071 +	option TcRedundancy	'2'
17072 +	option MprCoverage	'7'
17073 +	option LinkQualityFishEye	'1'
17074 +	option LinkQualityWinSize	'100'
17075 +	option LinkQualityDijkstraLimit	'0 9.0'
17076 +	option LinkQualityLevel	'2'
17077 +	option UseHysteresis	'no'
17078 +
17079 +config "LoadPlugin" "arprefresh"
17080 +	option Library	'olsrd_arprefresh.so.0.1'
17081 +
17082 +config "LoadPlugin" "dyn_gw_plain"
17083 +	option Library	'olsrd_dyn_gw_plain.so.0.4'
17084 +
17085 +config "LoadPlugin" "nameservice"
17086 +	option Library	'olsrd_nameservice.so.0.3'
17087 +	option name	'sven-ola-gs'
17088 +	option hosts_file	'/var/etc/hosts'
17089 +	option suffix	'.olsr'
17090 +	option latlon_infile	'/var/run/latlon.txt'
17091 +
17092 +config "LoadPlugin" "txtinfo"
17093 +	option Library	'olsrd_txtinfo.so.0.1'
17094 +	option Accept	'127.0.0.1'
17095 +
17096 +config "Interface"
17097 +	option Interface	"wlan"
17098 +	option HelloInterval	'6.0'
17099 +	option HelloValidityTime	'108.0'
17100 +	option TcInterval	'4.0'
17101 +	option TcValidityTime	'324.0'
17102 +	option MidInterval	'18.0'
17103 +	option MidValidityTime	'324.0'
17104 +	option HnaInterval	'18.0'
17105 +	option HnaValidityTime	'108.0'
17106 diff -Nur kamikaze_7.09.orig/package/olsrd/files/olsrd.init kamikaze_7.09/package/olsrd/files/olsrd.init
17107 --- kamikaze_7.09.orig/package/olsrd/files/olsrd.init	1970-01-01 01:00:00.000000000 +0100
17108 +++ kamikaze_7.09/package/olsrd/files/olsrd.init	2008-06-19 17:34:17.000000000 +0200
17109 @@ -0,0 +1,333 @@
17110 +#!/bin/sh /etc/rc.common
17111 +START=50
17112 +
17113 +BIN=olsrd
17114 +CONF_F=/var/etc/olsrd.conf
17115 +USE_CONF_F=
17116 +DEFAULT=/etc/default/olsrd
17117 +RUN_D=/var/run
17118 +PID_F=$RUN_D/$BIN.pid
17119 +
17120 +format_olsr_option() {
17121 +	local str="$*"
17122 +	echo -n "$str" | tr -d '\n\r\t\v '
17123 +}
17124 +
17125 +format_olsr_value() {
17126 +	local str="$*"
17127 +	echo -n "$str" | tr -d '\n\r\v'
17128 +}
17129 +
17130 +format_olsr_param() {
17131 +	local str="$*"
17132 +	echo -n "$str" | tr -d '\n\r\v"'
17133 +}
17134 +
17135 +format_uci_varname() {
17136 +	local str="$*"
17137 +	echo -n "$str" | sed -e 's/[^a-zA-Z0-9_]//g'
17138 +}
17139 +
17140 +foreach_olsr() {
17141 +	local cfg="$1"
17142 +	local option
17143 +	local value
17144 +
17145 +	for option in $CONFIG_OPTIONS
17146 +	do
17147 +		config_get value "$cfg" "$option"
17148 +		option=$(format_olsr_option "$option")
17149 +		value=$(format_olsr_value "$value")
17150 +
17151 +		if [ -n "$value" -a "$option" != "ConfigFile" ]; then
17152 +			echo "$option $value" >> "$CONF_F"
17153 +		fi
17154 +	done
17155 +	echo >> "$CONF_F"
17156 +}
17157 +
17158 +foreach_Hna4() {
17159 +	local cfg="$1"
17160 +	local netaddr
17161 +	local netmask
17162 +
17163 +	config_get netaddr "$cfg" NetAddr
17164 +	config_get netmask "$cfg" NetMask
17165 +	netaddr=$(format_olsr_option "$netaddr")
17166 +	netmask=$(format_olsr_option "$netmask")
17167 +
17168 +	if [ -n "$netaddr" -a -n "$netmask" ]; then
17169 +		if [ "$HNA4_COUNT" -le 0 ]; then
17170 +			echo "Hna4" >> "$CONF_F"
17171 +			echo "{" >> "$CONF_F"
17172 +		fi
17173 +
17174 +		echo "	$netaddr $netmask" >> "$CONF_F"
17175 +		HNA4_COUNT=$((HNA4_COUNT + 1))
17176 +	fi
17177 +}
17178 +
17179 +write_Hna4() {
17180 +	if [ "$HNA4_COUNT" -gt 0 ]; then
17181 +		echo "}" >> "$CONF_F"
17182 +		echo >> "$CONF_F"
17183 +	fi
17184 +}
17185 +
17186 +foreach_Hna6() {
17187 +	local cfg="$1"
17188 +	local netaddr
17189 +	local netmask
17190 +
17191 +	config_get netaddr "$cfg" NetAddr
17192 +	config_get prefix "$cfg" Prefix
17193 +	netaddr=$(format_olsr_option "$netaddr")
17194 +	prefix=$(format_olsr_option "$prefix")
17195 +
17196 +	if [ -n "$netaddr" -a -n "$prefix" ]; then
17197 +		if [ "$HNA6_COUNT" -le 0 ]; then
17198 +			echo "Hna6" >> "$CONF_F"
17199 +			echo "{" >> "$CONF_F"
17200 +		fi
17201 +
17202 +		echo "	$netaddr $prefix" >> "$CONF_F"
17203 +		HNA6_COUNT=$((HNA6_COUNT + 1))
17204 +	fi
17205 +}
17206 +
17207 +write_Hna6() {
17208 +	if [ "$HNA6_COUNT" -gt 0 ]; then
17209 +		echo "}" >> "$CONF_F"
17210 +		echo >> "$CONF_F"
17211 +	fi
17212 +}
17213 +
17214 +foreach_IpcConnect() {
17215 +	local cfg="$1"
17216 +	local option
17217 +	local value
17218 +	local c
17219 +
17220 +	echo "IpcConnect" >> "$CONF_F"
17221 +	echo -n "{" >> "$CONF_F"
17222 +
17223 +	for option in $CONFIG_OPTIONS
17224 +	do
17225 +		config_get value "$cfg" "$option"
17226 +		option=$(format_olsr_option "$option")
17227 +		value=$(format_olsr_value "$value")
17228 +
17229 +		if [ -n "$value" ]; then
17230 +			if [ "$option" = "Host" ]; then
17231 +				for item in $value
17232 +				do
17233 +					echo >> "$CONF_F"
17234 +					echo -n "	$option $item" >> "$CONF_F"
17235 +				done
17236 +			elif [ "$option" = "Net" ]; then
17237 +				c=0
17238 +				for item in $value
17239 +				do
17240 +					if [ $((c % 2)) -eq 0 ]; then
17241 +						echo >> "$CONF_F"
17242 +						echo -n "	$option $item" >> "$CONF_F"
17243 +					else
17244 +						echo -n " $item" >> "$CONF_F"
17245 +					fi
17246 +					c=$((c + 1))
17247 +				done
17248 +			else
17249 +				echo >> "$CONF_F"
17250 +				echo -n "	$option $value" >> "$CONF_F"
17251 +			fi
17252 +		fi
17253 +	done
17254 +
17255 +	echo >> "$CONF_F"
17256 +	echo "}" >> "$CONF_F"
17257 +	echo >> "$CONF_F"
17258 +}
17259 +
17260 +foreach_LoadPlugin() {
17261 +	local cfg="$1"
17262 +	local library
17263 +	local option
17264 +	local value
17265 +	local is_ip_addr
17266 +	local item
17267 +	local c
17268 +
17269 +	config_get library "$cfg" Library
17270 +	library=$(format_olsr_param "$library")
17271 +
17272 +	if [ -n "$library" ]; then
17273 +		echo "LoadPlugin \"$library\"" >> "$CONF_F"
17274 +		echo -n "{" >> "$CONF_F"
17275 +
17276 +		for option in $CONFIG_OPTIONS
17277 +		do
17278 +			config_get value "$cfg" "$option"
17279 +			option=$(format_olsr_param "$option")
17280 +			value=$(format_olsr_param "$value")
17281 +
17282 +			if [ -n "$value" ]; then
17283 +				option=$(echo "$option" | sed -e y/[_]/[-]/)
17284 +
17285 +				is_ip_addr=$(echo "$option" | sed -e 's/[^-]//g')
17286 +				if [ "$is_ip_addr" = "---" ]; then
17287 +					option=$(echo "$option" | sed -e y/[-]/[.]/)
17288 +				fi
17289 +
17290 +				if [ "$option" = "Ping" -o "$option" = "redistribute" -o "$option" = "Host" -o "$option" = "NonOlsrIf" -o "$option" = "name" -o "$is_ip_addr" = "---" ]; then
17291 +					for item in $value
17292 +					do
17293 +						echo >> "$CONF_F"
17294 +						echo -n "	PlParam \"$option\" \"$item\"" >> "$CONF_F"
17295 +					done
17296 +				elif [ "$option" = "Net" -o "$option" = "HNA" ]; then
17297 +					c=0
17298 +					for item in $value
17299 +					do
17300 +						if [ $((c % 2)) -eq 0 ]; then
17301 +							echo >> "$CONF_F"
17302 +							echo -n "	PlParam \"$option\" \"$item" >> "$CONF_F"
17303 +						else
17304 +							echo -n " $item\"" >> "$CONF_F"
17305 +						fi
17306 +						c=$((c + 1))
17307 +					done
17308 +				elif [ "$option" != "Library" ]; then
17309 +					echo >> "$CONF_F"
17310 +					echo -n "	PlParam \"$option\" \"$value\"" >> "$CONF_F"
17311 +				fi
17312 +			fi
17313 +		done
17314 +
17315 +		echo >> "$CONF_F"
17316 +		echo "}" >> "$CONF_F"
17317 +		echo >> "$CONF_F"
17318 +	fi
17319 +}
17320 +
17321 +foreach_Interface() {
17322 +	local cfg="$1"
17323 +	local interfaces
17324 +	local interface
17325 +	local ifname
17326 +	local option
17327 +	local value
17328 +	local item
17329 +	local c
17330 +
17331 +	config_get interfaces "$cfg" Interface
17332 +
17333 +	if [ -n "$interfaces" ]; then
17334 +		echo -n "Interface" >> "$CONF_F"
17335 +
17336 +		for interface in $interfaces
17337 +		do
17338 +			interface=$(format_uci_varname "$interface")
17339 +			config_get ifnames "$interface" ifname
17340 +			for ifname in $ifnames
17341 +			do
17342 +				ifname=$(format_olsr_param "$ifname")
17343 +				echo -n " \"$ifname\"" >> "$CONF_F"
17344 +			done
17345 +		done
17346 +
17347 +		echo >> "$CONF_F"
17348 +		echo -n "{" >> "$CONF_F"
17349 +
17350 +		for option in $CONFIG_OPTIONS
17351 +		do
17352 +			config_get value "$cfg" "$option"
17353 +			option=$(format_olsr_option "$option")
17354 +			value=$(format_olsr_value "$value")
17355 +
17356 +			if [ -n "$value" ]; then
17357 +				if [ "$option" = "LinkQualityMult" ]; then
17358 +					c=0
17359 +					for item in $value
17360 +					do
17361 +						if [ $((c % 2)) -eq 0 ]; then
17362 +							echo >> "$CONF_F"
17363 +							echo -n "	$option $item" >> "$CONF_F"
17364 +						else
17365 +							echo -n " $item" >> "$CONF_F"
17366 +						fi
17367 +						c=$((c + 1))
17368 +					done
17369 +				elif [ "$option" != "Interface" ]; then
17370 +					echo >> "$CONF_F"
17371 +					echo -n "	$option $value" >> "$CONF_F"
17372 +				fi
17373 +			fi
17374 +		done
17375 +
17376 +		echo >> "$CONF_F"
17377 +		echo "}" >> "$CONF_F"
17378 +	fi
17379 +}
17380 +
17381 +write_config() {
17382 +	include /lib/network
17383 +	scan_interfaces
17384 +	config_load /var/state/network
17385 +
17386 +	config_cb() {
17387 +		local cfgtype="$1"
17388 +		local name="$2"
17389 +		CONFIG_TYPE="$cfgtype"
17390 +	}
17391 +
17392 +	option_cb() {
17393 +		local varname="$1"
17394 +		local value="$2"
17395 +
17396 +		if [ "$CONFIG_TYPE" = "OLSR" -a "$varname" = "ConfigFile" ]; then
17397 +			USE_CONF_F="$value"
17398 +		fi
17399 +
17400 +		if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then
17401 +			CONFIG_OPTIONS="$CONFIG_OPTIONS $varname "
17402 +		fi
17403 +	}
17404 +
17405 +	CONFIG_OPTIONS=""
17406 +	config_load olsr
17407 +
17408 +	if [ -n "$USE_CONF_F" ]; then
17409 +		return 0
17410 +	else
17411 +		USE_CONF_F="$CONF_F"
17412 +	fi
17413 +
17414 +	mkdir -p $(dirname "$CONF_F")
17415 +	> "$CONF_F"
17416 +	config_foreach foreach_olsr olsr
17417 +	HNA4_COUNT=0
17418 +	config_foreach foreach_Hna4 Hna4
17419 +	write_Hna4
17420 +	HNA6_COUNT=0
17421 +	config_foreach foreach_Hna6 Hna6
17422 +	write_Hna6
17423 +	config_foreach foreach_IpcConnect IpcConnect
17424 +	config_foreach foreach_LoadPlugin LoadPlugin
17425 +	config_foreach foreach_Interface Interface
17426 +}
17427 +
17428 +start() {
17429 +	[ -z "$USE_CONF_F" ] && write_config
17430 +
17431 +	[ -f $DEFAULT ] && . $DEFAULT
17432 +	$BIN -f "$USE_CONF_F" -nofork $OPTIONS &
17433 +
17434 +	# write pid file (but strip out own pid ($$))
17435 +	mkdir -p $RUN_D
17436 +	PID=`pidof $BIN`
17437 +	echo ${PID%$$} > $PID_F
17438 +}
17439 +
17440 +stop() {
17441 +	killall olsrd
17442 +}
17443 diff -Nur kamikaze_7.09.orig/package/olsrd/files/olsrd_secure_key kamikaze_7.09/package/olsrd/files/olsrd_secure_key
17444 --- kamikaze_7.09.orig/package/olsrd/files/olsrd_secure_key	1970-01-01 01:00:00.000000000 +0100
17445 +++ kamikaze_7.09/package/olsrd/files/olsrd_secure_key	2008-06-19 17:34:17.000000000 +0200
17446 @@ -0,0 +1 @@
17447 +1234567890123456
17448 \ Kein Zeilenumbruch am Dateiende.
17449 diff -Nur kamikaze_7.09.orig/package/olsrd/Makefile kamikaze_7.09/package/olsrd/Makefile
17450 --- kamikaze_7.09.orig/package/olsrd/Makefile	1970-01-01 01:00:00.000000000 +0100
17451 +++ kamikaze_7.09/package/olsrd/Makefile	2008-06-19 17:34:17.000000000 +0200
17452 @@ -0,0 +1,163 @@
17453 +# 
17454 +# Copyright (C) 2007 OpenWrt.org
17455 +#
17456 +# This is free software, licensed under the GNU General Public License v2.
17457 +# See /LICENSE for more information.
17458 +#
17459 +# $Id: Makefile 11266 2008-05-25 16:30:46Z blogic $
17460 +
17461 +include $(TOPDIR)/rules.mk
17462 +
17463 +PKG_NAME:=olsrd
17464 +PKG_VERSION:=0.5.6-rc5
17465 +PKG_RELEASE:=1
17466 +
17467 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)/
17468 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
17469 +PKG_SOURCE_URL:=http://www.olsr.org/releases/0.5
17470 +PKG_MD5SUM:=139f71b37bd9a19804d0accf3a07b457
17471 +
17472 +PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
17473 +
17474 +include $(INCLUDE_DIR)/package.mk
17475 +
17476 +define Package/olsrd/template
17477 +  SECTION:=net
17478 +  CATEGORY:=Network
17479 +  TITLE:=OLSR (Optimized Link State Routing) daemon
17480 +  URL:=http://www.olsr.org/
17481 +  MENU:=1
17482 +endef
17483 +
17484 +define Package/olsrd
17485 +  $(call Package/olsrd/template)
17486 +  MENU:=1
17487 +endef
17488 +
17489 +define Package/olsrd/conffiles
17490 +/etc/olsrd.conf
17491 +endef
17492 +
17493 +define Package/olsrd-mod-dot-draw
17494 +  $(call Package/olsrd/template)
17495 +  DEPENDS:=olsrd
17496 +  TITLE:=Dot topology information plugin
17497 +endef
17498 +
17499 +define Package/olsrd-mod-bmf
17500 +  $(call Package/olsrd/template)
17501 +  DEPENDS:=olsrd +libpthread +kmod-tun
17502 +  TITLE:=Basic multicast forwarding plugin
17503 +endef
17504 +
17505 +define Package/olsrd-mod-dyn-gw
17506 +  $(call Package/olsrd/template)
17507 +  DEPENDS:=olsrd +libpthread
17508 +  TITLE:=Dynamic internet gateway plugin
17509 +endef
17510 +
17511 +define Package/olsrd-mod-httpinfo
17512 +  $(call Package/olsrd/template)
17513 +  DEPENDS:=olsrd
17514 +  TITLE:=Small informative web server plugin
17515 +endef
17516 +
17517 +define Package/olsrd-mod-nameservice
17518 +  $(call Package/olsrd/template)
17519 +  DEPENDS:=olsrd
17520 +  TITLE:=Lightweight hostname resolver plugin
17521 +endef
17522 +
17523 +define Package/olsrd-mod-secure
17524 +  $(call Package/olsrd/template)
17525 +  DEPENDS:=olsrd
17526 +  TITLE:=Message signing plugin to secure routing domain
17527 +endef
17528 +
17529 +define Package/olsrd-mod-txtinfo
17530 +  $(call Package/olsrd/template)
17531 +  DEPENDS:=olsrd
17532 +  TITLE:=Small informative web server plugin
17533 +endef
17534 +
17535 +define Package/olsrd-mod-secure/conffiles
17536 +/etc/olsrd.d/olsrd_secure_key
17537 +endef
17538 +
17539 +define Build/Configure
17540 +endef
17541 +
17542 +define Build/Compile
17543 +	rm -rf $(PKG_INSTALL_DIR)
17544 +	mkdir -p $(PKG_INSTALL_DIR)
17545 +	$(MAKE) -C "$(PKG_BUILD_DIR)" \
17546 +		$(TARGET_CONFIGURE_OPTS) \
17547 +		NODEBUG=1 \
17548 +		CFLAGS="$(TARGET_CFLAGS)" \
17549 +		OS="linux" \
17550 +		INSTALL_PREFIX="$(PKG_INSTALL_DIR)" \
17551 +		LIBDIR="$(PKG_INSTALL_DIR)/usr/lib" \
17552 +		SBINDIR="$(PKG_INSTALL_DIR)/usr/sbin/" \
17553 +		ETCDIR="$(PKG_INSTALL_DIR)/etc" \
17554 +		MANDIR="$(PKG_INSTALL_DIR)/usr/share/man" \
17555 +		STRIP="true" \
17556 +		INSTALL_LIB="true" \
17557 +		SUBDIRS="bmf dot_draw dyn_gw httpinfo nameservice secure txtinfo" \
17558 +		all libs install install_libs
17559 +endef
17560 +
17561 +define Package/olsrd/install
17562 +	$(INSTALL_DIR) $(1)/etc/config
17563 +	$(INSTALL_DATA) ./files/olsr.config $(1)/etc/config/olsr
17564 +	$(INSTALL_DATA) $(PKG_BUILD_DIR)/src/cfgparser/olsrd.conf.example $(1)/etc/olsrd.conf
17565 +	$(INSTALL_DIR) $(1)/usr/sbin
17566 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/olsrd $(1)/usr/sbin/
17567 +	$(INSTALL_DIR) $(1)/etc/init.d
17568 +	$(INSTALL_BIN) ./files/olsrd.init $(1)/etc/init.d/olsrd
17569 +endef
17570 +
17571 +define Package/olsrd-mod-dot-draw/install
17572 +	$(INSTALL_DIR) $(1)/usr/lib
17573 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/dot_draw/olsrd_dot_draw.so.* $(1)/usr/lib/
17574 +endef
17575 +
17576 +define Package/olsrd-mod-bmf/install
17577 +	$(INSTALL_DIR) $(1)/usr/lib
17578 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/bmf/olsrd_bmf.so.* $(1)/usr/lib/
17579 +endef
17580 +
17581 +define Package/olsrd-mod-dyn-gw/install
17582 +	$(INSTALL_DIR) $(1)/usr/lib
17583 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/dyn_gw/olsrd_dyn_gw.so.* $(1)/usr/lib/
17584 +endef
17585 +
17586 +define Package/olsrd-mod-httpinfo/install
17587 +	$(INSTALL_DIR) $(1)/usr/lib
17588 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/httpinfo/olsrd_httpinfo.so.* $(1)/usr/lib/
17589 +endef
17590 +
17591 +define Package/olsrd-mod-nameservice/install
17592 +	$(INSTALL_DIR) $(1)/usr/lib
17593 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/nameservice/olsrd_nameservice.so.* $(1)/usr/lib/
17594 +endef
17595 +
17596 +define Package/olsrd-mod-secure/install
17597 +	$(INSTALL_DIR) $(1)/etc/olsrd.d
17598 +	$(CP) ./files/olsrd_secure_key $(1)/etc/olsrd.d/
17599 +	$(INSTALL_DIR) $(1)/usr/lib
17600 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/secure/olsrd_secure.so.* $(1)/usr/lib/
17601 +endef
17602 +
17603 +define Package/olsrd-mod-txtinfo/install
17604 +	$(INSTALL_DIR) $(1)/usr/lib
17605 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/txtinfo/olsrd_txtinfo.so.* $(1)/usr/lib/
17606 +endef
17607 +
17608 +$(eval $(call BuildPackage,olsrd))
17609 +$(eval $(call BuildPackage,olsrd-mod-dot-draw))
17610 +$(eval $(call BuildPackage,olsrd-mod-bmf))
17611 +$(eval $(call BuildPackage,olsrd-mod-dyn-gw))
17612 +$(eval $(call BuildPackage,olsrd-mod-httpinfo))
17613 +$(eval $(call BuildPackage,olsrd-mod-nameservice))
17614 +$(eval $(call BuildPackage,olsrd-mod-secure))
17615 +$(eval $(call BuildPackage,olsrd-mod-txtinfo))
17616 diff -Nur kamikaze_7.09.orig/package/olsrd/patches/100-debug_level.patch kamikaze_7.09/package/olsrd/patches/100-debug_level.patch
17617 --- kamikaze_7.09.orig/package/olsrd/patches/100-debug_level.patch	1970-01-01 01:00:00.000000000 +0100
17618 +++ kamikaze_7.09/package/olsrd/patches/100-debug_level.patch	2008-06-19 17:34:17.000000000 +0200
17619 @@ -0,0 +1,11 @@
17620 +--- olsrd-0.4.10/files/olsrd.conf.default.rfc	2005-06-04 17:34:05.000000000 +0200
17621 ++++ olsrd-0.4.10.new/files/olsrd.conf.default.rfc	2006-05-21 21:44:55.000000000 +0200
17622 +@@ -9,7 +9,7 @@
17623 + # Debug level(0-9)
17624 + # If set to 0 the daemon runs in the background
17625 + 
17626 +-DebugLevel	1
17627 ++DebugLevel	0
17628 + 
17629 + # IP version to use (4 or 6)
17630 + 
17631 diff -Nur kamikaze_7.09.orig/package/olsrd/patches/110-build_fix.patch kamikaze_7.09/package/olsrd/patches/110-build_fix.patch
17632 --- kamikaze_7.09.orig/package/olsrd/patches/110-build_fix.patch	1970-01-01 01:00:00.000000000 +0100
17633 +++ kamikaze_7.09/package/olsrd/patches/110-build_fix.patch	2008-06-19 17:34:17.000000000 +0200
17634 @@ -0,0 +1,13 @@
17635 +Index: olsrd-0.5.4/Makefile
17636 +===================================================================
17637 +--- olsrd-0.5.4.orig/Makefile	2007-11-03 11:33:37.075400513 +0100
17638 ++++ olsrd-0.5.4/Makefile	2007-11-03 11:33:47.171975883 +0100
17639 +@@ -71,8 +71,6 @@
17640 + $(CFGOBJS):
17641 + 		$(MAKECMD) -C $(CFGDIR)
17642 + 
17643 +-# generate it always
17644 +-.PHONY: src/builddata.c
17645 + src/builddata.c:
17646 + 	@$(RM) "$@"
17647 + 	@echo "#include \"defs.h\"" >> "$@" 
17648 diff -Nur kamikaze_7.09.orig/package/olsrd/patches/120-dyn_gw_interval.patch kamikaze_7.09/package/olsrd/patches/120-dyn_gw_interval.patch
17649 --- kamikaze_7.09.orig/package/olsrd/patches/120-dyn_gw_interval.patch	1970-01-01 01:00:00.000000000 +0100
17650 +++ kamikaze_7.09/package/olsrd/patches/120-dyn_gw_interval.patch	2008-06-19 17:34:17.000000000 +0200
17651 @@ -0,0 +1,20 @@
17652 +--- olsrd-0.5.4/lib/dyn_gw/src/olsrd_dyn_gw-orig.c      2007-10-31 15:14:47.000000000 +0100
17653 ++++ olsrd-0.5.4/lib/dyn_gw/src/olsrd_dyn_gw.c   2007-10-31 15:15:17.000000000 +0100
17654 +@@ -92,7 +92,7 @@
17655 +
17656 +
17657 + /* set default interval, in case none is given in the config file */
17658 +-static int check_interval = 5;
17659 ++static double check_interval = 5;
17660 +
17661 + /* list to store the Ping IP addresses given in the config file */
17662 + struct ping_list {
17663 +@@ -307,7 +307,7 @@
17664 +     struct hna_list *li;
17665 +     struct timespec remainder_spec;
17666 +     /* the time to wait in "Interval" sec (see connfig), default=5sec */
17667 +-    struct timespec sleeptime_spec  = { check_interval, 0L };
17668 ++    struct timespec sleeptime_spec  = { (int) check_interval, 0L };
17669 +
17670 +     for(li = the_hna_list; li; li = li->next){
17671 +       /* check for gw in table entry and if Ping IPs are given also do pings */
17672 diff -Nur kamikaze_7.09.orig/package/openssl/Makefile kamikaze_7.09/package/openssl/Makefile
17673 --- kamikaze_7.09.orig/package/openssl/Makefile	2007-09-20 10:54:43.000000000 +0200
17674 +++ kamikaze_7.09/package/openssl/Makefile	2008-06-19 17:34:17.000000000 +0200
17675 @@ -7,6 +7,7 @@
17676  # $Id: Makefile 6892 2007-04-08 02:13:30Z pavlov $
17677  
17678  include $(TOPDIR)/rules.mk
17679 +include $(INCLUDE_DIR)/kernel.mk
17680  
17681  PKG_NAME:=openssl
17682  PKG_VERSION:=0.9.8e
17683 @@ -33,6 +34,7 @@
17684  
17685  define Package/libopenssl
17686    $(call Package/openssl/Default)
17687 +  SUBMENU:=openssl
17688    SECTION:=libs
17689    CATEGORY:=Libraries
17690    DEPENDS:=+zlib
17691 @@ -58,11 +60,29 @@
17692  /etc/ssl/openssl.cnf
17693  endef
17694  
17695 +define Package/libopenssl-cryptodev
17696 +  SUBMENU:=openssl
17697 +  SECTION:=libs
17698 +  CATEGORY:=Libraries
17699 +  TITLE:=Cryptodev support.
17700 +  DEPENDS:=libopenssl
17701 +endef
17702 +
17703 +define Package/libopenssl-cryptodev/description
17704 +  Adds support for the cryptodev engine to libopenssl.
17705 +endef
17706 +
17707 +
17708  OPENSSL_NO_CIPHERS:= no-idea no-md2 no-mdc2 no-rc2 no-rc5 no-sha0 no-smime \
17709  					no-rmd160 no-aes192 no-ripemd no-camellia no-ans1 no-krb5
17710  OPENSSL_OPTIONS:= shared no-ec no-err no-fips no-hw no-threads zlib-dynamic \
17711  					no-engines no-sse2 no-perlasm
17712  
17713 +ifneq ($(SDK)$(CONFIG_PACKAGE_libopenssl-cryptodev),)
17714 +  OPENSSL_OPTIONS:= shared no-ec no-err no-fips no-krb5 no-threads zlib-dynamic --with-cryptodev --with-cryptodev-digests
17715 +  TARGET_CFLAGS+= -I$(LINUX_DIR)/crypto/ocf
17716 +endif
17717 +
17718  
17719  define Build/Configure
17720  	(cd $(PKG_BUILD_DIR); \
17721 @@ -130,4 +150,5 @@
17722  endef
17723  
17724  $(eval $(call BuildPackage,libopenssl))
17725 +$(eval $(call BuildPackage,libopenssl-cryptodev))
17726  $(eval $(call BuildPackage,openssl-util))
17727 diff -Nur kamikaze_7.09.orig/package/openssl/patches/150-no_engines.patch kamikaze_7.09/package/openssl/patches/150-no_engines.patch
17728 --- kamikaze_7.09.orig/package/openssl/patches/150-no_engines.patch	2007-09-20 10:54:43.000000000 +0200
17729 +++ kamikaze_7.09/package/openssl/patches/150-no_engines.patch	1970-01-01 01:00:00.000000000 +0100
17730 @@ -1,85 +0,0 @@
17731 -Index: openssl-0.9.8e/util/libeay.num
17732 -===================================================================
17733 ---- openssl-0.9.8e.orig/util/libeay.num	2007-06-04 13:23:32.021865832 +0200
17734 -+++ openssl-0.9.8e/util/libeay.num	2007-06-04 13:23:33.045710184 +0200
17735 -@@ -2071,7 +2071,6 @@
17736 - UI_add_error_string                     2633	EXIST::FUNCTION:
17737 - KRB5_CHECKSUM_free                      2634	EXIST::FUNCTION:
17738 - OCSP_REQUEST_get_ext                    2635	EXIST::FUNCTION:
17739 --ENGINE_load_ubsec                       2636	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17740 - ENGINE_register_all_digests             2637	EXIST::FUNCTION:ENGINE
17741 - PKEY_USAGE_PERIOD_it                    2638	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17742 - PKEY_USAGE_PERIOD_it                    2638	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
17743 -@@ -2545,7 +2544,6 @@
17744 - AES_set_encrypt_key                     3024	EXIST::FUNCTION:AES
17745 - OCSP_resp_count                         3025	EXIST::FUNCTION:
17746 - KRB5_CHECKSUM_new                       3026	EXIST::FUNCTION:
17747 --ENGINE_load_cswift                      3027	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17748 - OCSP_onereq_get0_id                     3028	EXIST::FUNCTION:
17749 - ENGINE_set_default_ciphers              3029	EXIST::FUNCTION:ENGINE
17750 - NOTICEREF_it                            3030	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17751 -@@ -2576,7 +2574,6 @@
17752 - i2d_EXTENDED_KEY_USAGE                  3052	EXIST::FUNCTION:
17753 - i2d_OCSP_SIGNATURE                      3053	EXIST::FUNCTION:
17754 - asn1_enc_save                           3054	EXIST::FUNCTION:
17755 --ENGINE_load_nuron                       3055	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17756 - _ossl_old_des_pcbc_encrypt              3056	EXIST::FUNCTION:DES
17757 - PKCS12_MAC_DATA_it                      3057	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17758 - PKCS12_MAC_DATA_it                      3057	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
17759 -@@ -2600,7 +2597,6 @@
17760 - i2d_KRB5_CHECKSUM                       3072	EXIST::FUNCTION:
17761 - ENGINE_set_table_flags                  3073	EXIST::FUNCTION:ENGINE
17762 - AES_options                             3074	EXIST::FUNCTION:AES
17763 --ENGINE_load_chil                        3075	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17764 - OCSP_id_cmp                             3076	EXIST::FUNCTION:
17765 - OCSP_BASICRESP_new                      3077	EXIST::FUNCTION:
17766 - OCSP_REQUEST_get_ext_by_NID             3078	EXIST::FUNCTION:
17767 -@@ -2667,7 +2663,6 @@
17768 - OCSP_CRLID_it                           3127	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
17769 - i2d_KRB5_AUTHENTBODY                    3128	EXIST::FUNCTION:
17770 - OCSP_REQUEST_get_ext_count              3129	EXIST::FUNCTION:
17771 --ENGINE_load_atalla                      3130	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17772 - X509_NAME_it                            3131	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17773 - X509_NAME_it                            3131	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
17774 - USERNOTICE_it                           3132	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17775 -@@ -2762,8 +2757,6 @@
17776 - DES_read_password                       3207	EXIST::FUNCTION:DES
17777 - UI_UTIL_read_pw                         3208	EXIST::FUNCTION:
17778 - UI_UTIL_read_pw_string                  3209	EXIST::FUNCTION:
17779 --ENGINE_load_aep                         3210	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17780 --ENGINE_load_sureware                    3211	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17781 - OPENSSL_add_all_algorithms_noconf       3212	EXIST:!VMS:FUNCTION:
17782 - OPENSSL_add_all_algo_noconf             3212	EXIST:VMS:FUNCTION:
17783 - OPENSSL_add_all_algorithms_conf         3213	EXIST:!VMS:FUNCTION:
17784 -@@ -2772,7 +2765,6 @@
17785 - AES_ofb128_encrypt                      3215	EXIST::FUNCTION:AES
17786 - AES_ctr128_encrypt                      3216	EXIST::FUNCTION:AES
17787 - AES_cfb128_encrypt                      3217	EXIST::FUNCTION:AES
17788 --ENGINE_load_4758cca                     3218	EXIST::FUNCTION:ENGINE,STATIC_ENGINE
17789 - _ossl_096_des_random_seed               3219	EXIST::FUNCTION:DES
17790 - EVP_aes_256_ofb                         3220	EXIST::FUNCTION:AES
17791 - EVP_aes_192_ofb                         3221	EXIST::FUNCTION:AES
17792 -@@ -3107,7 +3099,6 @@
17793 - STORE_method_set_modify_function        3530	EXIST:!VMS:FUNCTION:
17794 - STORE_meth_set_modify_fn                3530	EXIST:VMS:FUNCTION:
17795 - STORE_parse_attrs_next                  3531	EXIST::FUNCTION:
17796 --ENGINE_load_padlock                     3532	EXIST::FUNCTION:ENGINE
17797 - EC_GROUP_set_curve_name                 3533	EXIST::FUNCTION:EC
17798 - X509_CERT_PAIR_it                       3534	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
17799 - X509_CERT_PAIR_it                       3534	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
17800 -Index: openssl-0.9.8e/Configure
17801 -===================================================================
17802 ---- openssl-0.9.8e.orig/Configure	2007-06-04 13:23:32.598778128 +0200
17803 -+++ openssl-0.9.8e/Configure	2007-06-04 13:23:33.046710032 +0200
17804 -@@ -1644,6 +1644,11 @@
17805 - 	close(OUT);
17806 -   }
17807 -   
17808 -+# ugly hack to disable engines
17809 -+if($target eq "mingwx") {
17810 -+	system("sed -e s/^LIB/XLIB/g -i engines/Makefile");
17811 -+}
17812 -+  
17813 - print <<EOF;
17814 - 
17815 - Configured for $target.
17816 diff -Nur kamikaze_7.09.orig/package/openssl/patches/190-linux_ocf.patch kamikaze_7.09/package/openssl/patches/190-linux_ocf.patch
17817 --- kamikaze_7.09.orig/package/openssl/patches/190-linux_ocf.patch	1970-01-01 01:00:00.000000000 +0100
17818 +++ kamikaze_7.09/package/openssl/patches/190-linux_ocf.patch	2008-06-19 17:34:17.000000000 +0200
17819 @@ -0,0 +1,1229 @@
17820 +diff -urN openssl-0.9.8e.old/apps/apps.h openssl-0.9.8e/apps/apps.h
17821 +--- openssl-0.9.8e.old/apps/apps.h	2008-02-26 10:30:37.000000000 -0500
17822 ++++ openssl-0.9.8e/apps/apps.h	2008-02-26 10:31:12.000000000 -0500
17823 +@@ -112,7 +112,7 @@
17824 + #ifndef HEADER_APPS_H
17825 + #define HEADER_APPS_H
17826 + 
17827 +-#include "e_os.h"
17828 ++#include <openssl/e_os.h>
17829 + 
17830 + #include <openssl/bio.h>
17831 + #include <openssl/x509.h>
17832 +diff -urN openssl-0.9.8e.old/apps/progs.h openssl-0.9.8e/apps/progs.h
17833 +--- openssl-0.9.8e.old/apps/progs.h	2008-02-26 10:30:37.000000000 -0500
17834 ++++ openssl-0.9.8e/apps/progs.h	2008-02-26 10:31:12.000000000 -0500
17835 +@@ -125,7 +125,9 @@
17836 + #ifndef OPENSSL_NO_ENGINE
17837 + 	{FUNC_TYPE_GENERAL,"engine",engine_main},
17838 + #endif
17839 ++#ifndef OPENSSL_NO_OCSP
17840 + 	{FUNC_TYPE_GENERAL,"ocsp",ocsp_main},
17841 ++#endif
17842 + 	{FUNC_TYPE_GENERAL,"prime",prime_main},
17843 + #ifndef OPENSSL_NO_MD2
17844 + 	{FUNC_TYPE_MD,"md2",dgst_main},
17845 +diff -urN openssl-0.9.8e.old/apps/speed.c openssl-0.9.8e/apps/speed.c
17846 +--- openssl-0.9.8e.old/apps/speed.c	2008-02-26 10:30:37.000000000 -0500
17847 ++++ openssl-0.9.8e/apps/speed.c	2008-02-26 10:31:12.000000000 -0500
17848 +@@ -288,7 +288,7 @@
17849 +   "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
17850 +   "evp","sha256","sha512"};
17851 + static double results[ALGOR_NUM][SIZE_NUM];
17852 +-static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
17853 ++static int lengths[SIZE_NUM]={16,64,256,1024,2*1024,4*1024};
17854 + static double rsa_results[RSA_NUM][2];
17855 + static double dsa_results[DSA_NUM][2];
17856 + #ifndef OPENSSL_NO_ECDSA
17857 +@@ -324,6 +324,79 @@
17858 + #define START	0
17859 + #define STOP	1
17860 + 
17861 ++#ifdef __linux__
17862 ++/*
17863 ++ * record CPU usage as well
17864 ++ */
17865 ++
17866 ++static int do_cpu = 0;
17867 ++
17868 ++struct cpu_stat {
17869 ++	unsigned int	user;
17870 ++	unsigned int	nice;
17871 ++	unsigned int	system;
17872 ++	unsigned int	idle;
17873 ++	unsigned int	total;
17874 ++};
17875 ++
17876 ++static unsigned int cpu_usage[ALGOR_NUM][SIZE_NUM];
17877 ++static unsigned int rsa_cpu_usage[RSA_NUM][2];
17878 ++static unsigned int dsa_cpu_usage[DSA_NUM][2];
17879 ++static struct cpu_stat cpu_start, cpu_finish;
17880 ++
17881 ++static void
17882 ++get_cpu(int s)
17883 ++{
17884 ++	FILE *fp = NULL;
17885 ++	unsigned char	buf[80];
17886 ++	struct cpu_stat *st = s == START ? &cpu_start : &cpu_finish;
17887 ++
17888 ++	memset(st, 0, sizeof(*st));
17889 ++
17890 ++	if (fp == NULL)
17891 ++		fp = fopen("/proc/stat", "r");
17892 ++	if (!fp)
17893 ++		return;
17894 ++	if (fseek(fp, 0, SEEK_SET) == -1) {
17895 ++		fclose(fp);
17896 ++		return;
17897 ++	}
17898 ++	fscanf(fp, "%s %d %d %d %d", &buf[0], &st->user, &st->nice,
17899 ++		&st->system, &st->idle);
17900 ++	st->total = st->user + st->nice + st->system + st->idle;
17901 ++	fclose(fp);
17902 ++}
17903 ++
17904 ++static unsigned int
17905 ++calc_cpu()
17906 ++{
17907 ++	unsigned int total, res;
17908 ++
17909 ++	total  = cpu_finish.total - cpu_start.total;
17910 ++	if (total <= 0)
17911 ++		return 0;
17912 ++#if 1 // busy
17913 ++	res   = ((cpu_finish.system + cpu_finish.user + cpu_finish.nice) -
17914 ++			 (cpu_start.system + cpu_start.user + cpu_start.nice)) *
17915 ++			 100 / total;
17916 ++#endif
17917 ++#if 0 // system
17918 ++	res   = (cpu_finish.system - cpu_start.system) * 100 / total;
17919 ++#endif
17920 ++#if 0 // user
17921 ++	res   = (cpu_finish.user   - cpu_start.user)   * 100 / total;
17922 ++#endif
17923 ++#if 0 // nice
17924 ++	res   = (cpu_finish.nice   - cpu_start.nice)   * 100 / total;
17925 ++#endif
17926 ++#if 0 // idle
17927 ++	res   = (cpu_finish.idle   - cpu_start.idle)   * 100 / total;
17928 ++#endif
17929 ++	return(res);
17930 ++}
17931 ++
17932 ++#endif
17933 ++
17934 + #if defined(OPENSSL_SYS_NETWARE)
17935 + 
17936 +    /* for NetWare the best we can do is use clock() which returns the
17937 +@@ -354,6 +427,11 @@
17938 + 	{
17939 + 	double ret;
17940 + 
17941 ++#ifdef __linux__
17942 ++	if (do_cpu)
17943 ++		get_cpu(s);
17944 ++#endif
17945 ++
17946 + #ifdef USE_TOD
17947 + 	if(usertime)
17948 + 		{
17949 +@@ -821,6 +899,14 @@
17950 + 			j--;	/* Otherwise, -elapsed gets confused with
17951 + 				   an algorithm. */
17952 + 			}
17953 ++#ifdef __linux__
17954 ++		else if	((argc > 0) && (strcmp(*argv,"-cpu") == 0))
17955 ++			{
17956 ++			do_cpu = 1;
17957 ++			j--;	/* Otherwise, -cpu gets confused with
17958 ++				   an algorithm. */
17959 ++			}
17960 ++#endif
17961 + 		else if	((argc > 0) && (strcmp(*argv,"-evp") == 0))
17962 + 			{
17963 + 			argc--;
17964 +@@ -1234,6 +1320,9 @@
17965 + #ifdef HAVE_FORK
17966 + 			BIO_printf(bio_err,"-multi n        run n benchmarks in parallel.\n");
17967 + #endif
17968 ++#ifdef __linux__
17969 ++			BIO_printf(bio_err,"-cpu            calculate cpu utilisation.\n");
17970 ++#endif
17971 + 			goto end;
17972 + 			}
17973 + 		argc--;
17974 +@@ -1241,11 +1330,6 @@
17975 + 		j++;
17976 + 		}
17977 + 
17978 +-#ifdef HAVE_FORK
17979 +-	if(multi && do_multi(multi))
17980 +-		goto show_res;
17981 +-#endif
17982 +-
17983 + 	if (j == 0)
17984 + 		{
17985 + 		for (i=0; i<ALGOR_NUM; i++)
17986 +@@ -1567,6 +1651,11 @@
17987 + 	signal(SIGALRM,sig_done);
17988 + #endif /* SIGALRM */
17989 + 
17990 ++#ifdef HAVE_FORK /* DM */
17991 ++	if(multi && do_multi(multi))
17992 ++		goto show_res;
17993 ++#endif
17994 ++
17995 + #ifndef OPENSSL_NO_MD2
17996 + 	if (doit[D_MD2])
17997 + 		{
17998 +@@ -1939,8 +2028,6 @@
17999 + 				/* -O3 -fschedule-insns messes up an
18000 + 				 * optimization here!  names[D_EVP]
18001 + 				 * somehow becomes NULL */
18002 +-				print_message(names[D_EVP],save_count,
18003 +-					lengths[j]);
18004 + 
18005 + 				EVP_CIPHER_CTX_init(&ctx);
18006 + 				if(decrypt)
18007 +@@ -1949,6 +2036,9 @@
18008 + 					EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
18009 + 				EVP_CIPHER_CTX_set_padding(&ctx, 0);
18010 + 
18011 ++				print_message(names[D_EVP],save_count,
18012 ++					lengths[j]);
18013 ++
18014 + 				Time_F(START);
18015 + 				if(decrypt)
18016 + 					for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
18017 +@@ -2013,6 +2103,8 @@
18018 + 					}
18019 + 				}
18020 + 			d=Time_F(STOP);
18021 ++			if (do_cpu)
18022 ++				rsa_cpu_usage[j][0] = calc_cpu();
18023 + 			BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
18024 + 				   : "%ld %d bit private RSA's in %.2fs\n",
18025 + 				   count,rsa_bits[j],d);
18026 +@@ -2048,6 +2140,8 @@
18027 + 					}
18028 + 				}
18029 + 			d=Time_F(STOP);
18030 ++			if (do_cpu)
18031 ++				rsa_cpu_usage[j][1] = calc_cpu();
18032 + 			BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
18033 + 				   : "%ld %d bit public RSA's in %.2fs\n",
18034 + 				   count,rsa_bits[j],d);
18035 +@@ -2107,6 +2201,8 @@
18036 + 					}
18037 + 				}
18038 + 			d=Time_F(STOP);
18039 ++			if (do_cpu)
18040 ++				dsa_cpu_usage[j][0] = calc_cpu();
18041 + 			BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
18042 + 				   : "%ld %d bit DSA signs in %.2fs\n",
18043 + 				   count,dsa_bits[j],d);
18044 +@@ -2142,6 +2238,8 @@
18045 + 					}
18046 + 				}
18047 + 			d=Time_F(STOP);
18048 ++			if (do_cpu)
18049 ++				dsa_cpu_usage[j][1] = calc_cpu();
18050 + 			BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
18051 + 				   : "%ld %d bit DSA verify in %.2fs\n",
18052 + 				   count,dsa_bits[j],d);
18053 +@@ -2436,14 +2534,23 @@
18054 + 			fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 
18055 + 			fprintf(stdout,"type        ");
18056 + 			}
18057 +-		for (j=0;  j<SIZE_NUM; j++)
18058 ++		for (j=0;  j<SIZE_NUM; j++) {
18059 + 			fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
18060 ++			if (do_cpu && !mr)
18061 ++				fprintf(stdout, " /cpu");
18062 ++		}
18063 + 		fprintf(stdout,"\n");
18064 + 		}
18065 + 
18066 + 	for (k=0; k<ALGOR_NUM; k++)
18067 + 		{
18068 + 		if (!doit[k]) continue;
18069 ++		if (k == D_EVP) {
18070 ++			if (evp_cipher)
18071 ++				names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
18072 ++			else
18073 ++				names[D_EVP]=OBJ_nid2ln(evp_md->type);
18074 ++		}
18075 + 		if(mr)
18076 + 			fprintf(stdout,"+F:%d:%s",k,names[k]);
18077 + 		else
18078 +@@ -2454,6 +2561,8 @@
18079 + 				fprintf(stdout," %11.2fk",results[k][j]/1e3);
18080 + 			else
18081 + 				fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
18082 ++			if (do_cpu)
18083 ++				fprintf(stdout, mr ? "/%d" : "/%%%-3d", cpu_usage[k][j]);
18084 + 			}
18085 + 		fprintf(stdout,"\n");
18086 + 		}
18087 +@@ -2468,13 +2577,18 @@
18088 + 			j=0;
18089 + 			}
18090 + 		if(mr)
18091 +-			fprintf(stdout,"+F2:%u:%u:%f:%f\n",
18092 +-				k,rsa_bits[k],rsa_results[k][0],
18093 +-				rsa_results[k][1]);
18094 +-		else
18095 +-			fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
18096 +-				rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
18097 +-				1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
18098 ++			fprintf(stdout,"+F2:%u:%u:%f", k,rsa_bits[k],rsa_results[k][0]);
18099 ++		else
18100 ++			fprintf(stdout,"rsa %4u bits %8.6fs",rsa_bits[k],rsa_results[k][0]);
18101 ++		if (do_cpu)
18102 ++			fprintf(stdout, mr ? "/%d": "/%%%-3d", rsa_cpu_usage[k][0]);
18103 ++		fprintf(stdout, mr ? ":%f" : " %8.6fs", rsa_results[k][1]);
18104 ++		if (do_cpu)
18105 ++			fprintf(stdout, mr ? "/%d": "/%%%-3d", rsa_cpu_usage[k][1]);
18106 ++		if(!mr)
18107 ++			fprintf(stdout, " %8.1f %8.1f",
18108 ++					1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
18109 ++		fprintf(stdout, "\n");
18110 + 		}
18111 + #endif
18112 + #ifndef OPENSSL_NO_DSA
18113 +@@ -2488,12 +2602,18 @@
18114 + 			j=0;
18115 + 			}
18116 + 		if(mr)
18117 +-			fprintf(stdout,"+F3:%u:%u:%f:%f\n",
18118 +-				k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
18119 ++			fprintf(stdout,"+F3:%u:%u:%f", k,dsa_bits[k],dsa_results[k][0]);
18120 + 		else
18121 +-			fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
18122 +-				dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
18123 +-				1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
18124 ++			fprintf(stdout,"dsa %4u bits %8.6fs",dsa_bits[k],dsa_results[k][0]);
18125 ++		if (do_cpu)
18126 ++			fprintf(stdout, mr ? "/%d": "/%%%-3d", dsa_cpu_usage[k][0]);
18127 ++		fprintf(stdout, mr ? ":%f" : " %8.6fs", dsa_results[k][1]);
18128 ++		if (do_cpu)
18129 ++			fprintf(stdout, mr ? "/%d": "/%%%-3d", dsa_cpu_usage[k][1]);
18130 ++		if(!mr)
18131 ++			fprintf(stdout, " %8.1f %8.1f",
18132 ++					1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
18133 ++		fprintf(stdout, "\n");
18134 + 		}
18135 + #endif
18136 + #ifndef OPENSSL_NO_ECDSA
18137 +@@ -2618,8 +2738,10 @@
18138 + 
18139 + static void print_result(int alg,int run_no,int count,double time_used)
18140 + 	{
18141 +-	BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
18142 +-		   : "%d %s's in %.2fs\n",count,names[alg],time_used);
18143 ++	if (do_cpu)
18144 ++	    cpu_usage[alg][run_no] = calc_cpu();
18145 ++	BIO_printf(bio_err,mr ? "+R:%ld:%s:%f\n"
18146 ++		   : "%ld %s's in %.2fs\n",count,names[alg],time_used);
18147 + 	results[alg][run_no]=((double)count)/time_used*lengths[run_no];
18148 + 	}
18149 + 
18150 +@@ -2712,29 +2834,11 @@
18151 + 				p=buf+3;
18152 + 				alg=atoi(sstrsep(&p,sep));
18153 + 				sstrsep(&p,sep);
18154 +-				for(j=0 ; j < SIZE_NUM ; ++j)
18155 ++				for(j=0 ; j < SIZE_NUM ; ++j) {
18156 ++					if (do_cpu && strchr(p, '/'))
18157 ++						cpu_usage[alg][j] = atoi(strchr(p, '/') + 1);
18158 + 					results[alg][j]+=atof(sstrsep(&p,sep));
18159 + 				}
18160 +-			else if(!strncmp(buf,"+F2:",4))
18161 +-				{
18162 +-				int k;
18163 +-				double d;
18164 +-				
18165 +-				p=buf+4;
18166 +-				k=atoi(sstrsep(&p,sep));
18167 +-				sstrsep(&p,sep);
18168 +-
18169 +-				d=atof(sstrsep(&p,sep));
18170 +-				if(n)
18171 +-					rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
18172 +-				else
18173 +-					rsa_results[k][0]=d;
18174 +-
18175 +-				d=atof(sstrsep(&p,sep));
18176 +-				if(n)
18177 +-					rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
18178 +-				else
18179 +-					rsa_results[k][1]=d;
18180 + 				}
18181 + 			else if(!strncmp(buf,"+F2:",4))
18182 + 				{
18183 +@@ -2745,12 +2849,18 @@
18184 + 				k=atoi(sstrsep(&p,sep));
18185 + 				sstrsep(&p,sep);
18186 + 
18187 ++				/* before we move the token along */
18188 ++				if (do_cpu && strchr(p, '/'))
18189 ++					rsa_cpu_usage[k][0] = atoi(strchr(p, '/') + 1);
18190 + 				d=atof(sstrsep(&p,sep));
18191 + 				if(n)
18192 + 					rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
18193 + 				else
18194 + 					rsa_results[k][0]=d;
18195 + 
18196 ++				/* before we move the token along */
18197 ++				if (do_cpu && strchr(p, '/'))
18198 ++					rsa_cpu_usage[k][1] = atoi(strchr(p, '/') + 1);
18199 + 				d=atof(sstrsep(&p,sep));
18200 + 				if(n)
18201 + 					rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
18202 +@@ -2766,12 +2876,18 @@
18203 + 				k=atoi(sstrsep(&p,sep));
18204 + 				sstrsep(&p,sep);
18205 + 
18206 ++				/* before we move the token along */
18207 ++				if (do_cpu && strchr(p, '/'))
18208 ++					dsa_cpu_usage[k][0] = atoi(strchr(p, '/') + 1);
18209 + 				d=atof(sstrsep(&p,sep));
18210 + 				if(n)
18211 + 					dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
18212 + 				else
18213 + 					dsa_results[k][0]=d;
18214 + 
18215 ++				/* before we move the token along */
18216 ++				if (do_cpu && strchr(p, '/'))
18217 ++					dsa_cpu_usage[k][1] = atoi(strchr(p, '/') + 1);
18218 + 				d=atof(sstrsep(&p,sep));
18219 + 				if(n)
18220 + 					dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
18221 +diff -urN openssl-0.9.8e.old/config openssl-0.9.8e/config
18222 +--- openssl-0.9.8e.old/config	2008-02-26 10:30:37.000000000 -0500
18223 ++++ openssl-0.9.8e/config	2008-02-26 10:31:12.000000000 -0500
18224 +@@ -48,10 +48,10 @@
18225 + 
18226 + # First get uname entries that we use below
18227 + 
18228 +-MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
18229 +-RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
18230 +-SYSTEM=`(uname -s) 2>/dev/null`  || SYSTEM="unknown"
18231 +-VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
18232 ++[ "$MACHINE" ] || MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
18233 ++[ "$RELEASE" ] || RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
18234 ++[ "$SYSTEM" ]  || SYSTEM=`(uname -s) 2>/dev/null`  || SYSTEM="unknown"
18235 ++[ "$VERSION" ] || VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
18236 + 
18237 + 
18238 + # Now test for ISC and SCO, since it is has a braindamaged uname.
18239 +@@ -270,7 +270,7 @@
18240 + 		echo "ppc-apple-darwin${VERSION}"
18241 + 		;;
18242 + 	    *)
18243 +-		echo "i386-apple-darwin${VERSION}"
18244 ++		echo "${MACHINE}-apple-darwin${VERSION}"
18245 + 		;;
18246 + 	esac
18247 + 	exit 0
18248 +@@ -401,9 +401,9 @@
18249 + 
18250 + # figure out if gcc is available and if so we use it otherwise
18251 + # we fallback to whatever cc does on the system
18252 +-GCCVER=`(gcc -dumpversion) 2>/dev/null`
18253 ++CC="${CC:-gcc}"
18254 ++GCCVER=`(${CC} -dumpversion) 2>/dev/null`
18255 + if [ "$GCCVER" != "" ]; then
18256 +-  CC=gcc
18257 +   # then strip off whatever prefix egcs prepends the number with...
18258 +   # Hopefully, this will work for any future prefixes as well.
18259 +   GCCVER=`echo $GCCVER | LC_ALL=C sed 's/^[a-zA-Z]*\-//'`
18260 +@@ -413,7 +413,7 @@
18261 +   # peak single digit before and after first dot, e.g. 2.95.1 gives 29
18262 +   GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
18263 + else
18264 +-  CC=cc
18265 ++  CC="${CC:-cc}"
18266 + fi
18267 + GCCVER=${GCCVER:-0}
18268 + if [ "$SYSTEM" = "HP-UX" ];then
18269 +@@ -482,6 +482,9 @@
18270 + # script above so we end up with values in vars but that would take
18271 + # more time that I want to waste at the moment
18272 + case "$GUESSOS" in
18273 ++  uClinux*)
18274 ++    OUT=uClinux-dist
18275 ++	;;
18276 +   mips2-sgi-irix)
18277 + 	CPU=`(hinv -t cpu) 2>/dev/null | head -1 | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
18278 + 	CPU=${CPU:-0}
18279 +diff -urN openssl-0.9.8e.old/Configure openssl-0.9.8e/Configure
18280 +--- openssl-0.9.8e.old/Configure	2008-02-26 10:30:37.000000000 -0500
18281 ++++ openssl-0.9.8e/Configure	2008-02-26 10:31:12.000000000 -0500
18282 +@@ -34,6 +34,8 @@
18283 + #		(Default: KRB5_DIR/include)
18284 + # --with-krb5-flavor  Declare what flavor of Kerberos 5 is used.  Currently
18285 + #		supported values are "MIT" and "Heimdal".  A value is required.
18286 ++# --with-cryptodev Force support for cryptodev (ie., ocf-linux)
18287 ++# --with-cryptodev-digests Force support for cryptodev digests (generally slow)
18288 + #
18289 + # --test-sanity Make a number of sanity checks on the data in this file.
18290 + #               This is a debugging tool for OpenSSL developers.
18291 +@@ -528,6 +530,9 @@
18292 + ##### Compaq Non-Stop Kernel (Tandem)
18293 + "tandem-c89","c89:-Ww -D__TANDEM -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -D_TANDEM_SOURCE -DB_ENDIAN::(unknown):::THIRTY_TWO_BIT:::",
18294 + 
18295 ++# uClinux
18296 ++"uClinux-dist","$ENV{'CC'}:\$(CFLAGS)::-D_REENTRANT::\$(LDFLAGS) \$(LDLIBS):BN_LLONG::::::::::::\$(LIBSSL_dlfcn):linux-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):$ENV{'RANLIB'}",
18297 ++
18298 + );
18299 + 
18300 + my @MK1MF_Builds=qw(VC-WIN64I VC-WIN64A
18301 +@@ -574,6 +579,8 @@
18302 + my $no_asm=0;
18303 + my $no_dso=0;
18304 + my $no_gmp=0;
18305 ++my $have_cryptodev=0;
18306 ++my $use_cryptodev_digests=0;
18307 + my @skip=();
18308 + my $Makefile="Makefile";
18309 + my $des_locl="crypto/des/des_locl.h";
18310 +@@ -696,6 +703,14 @@
18311 + 			{
18312 + 			exit(&test_sanity());
18313 + 			}
18314 ++		elsif (/^--with-cryptodev$/)
18315 ++			{
18316 ++				$have_cryptodev = 1;
18317 ++			}
18318 ++		elsif (/^--with-cryptodev-digests$/)
18319 ++			{
18320 ++				$use_cryptodev_digests = 1;
18321 ++			}
18322 + 		elsif (/^reconfigure/ || /^reconf/)
18323 + 			{
18324 + 			if (open(IN,"<$Makefile"))
18325 +@@ -898,6 +913,7 @@
18326 + 			print " OPENSSL_NO_$ALGO";
18327 + 		
18328 + 			if (/^err$/)	{ $flags .= "-DOPENSSL_NO_ERR "; }
18329 ++			elsif (/^hw$/)	{ $flags .= "-DOPENSSL_NO_HW "; }
18330 + 			elsif (/^asm$/)	{ $no_asm = 1; }
18331 + 			}
18332 + 		else
18333 +@@ -1032,6 +1048,16 @@
18334 + 		   $withargs{"krb5-dir"} ne "";
18335 + 	}
18336 + 
18337 ++# enable the linux cryptodev (ocf-linux) support
18338 ++if ($have_cryptodev)
18339 ++	{
18340 ++	if ($use_cryptodev_digests)
18341 ++		{
18342 ++		$cflags = "-DUSE_CRYPTODEV_DIGESTS $cflags";
18343 ++		}
18344 ++	$cflags = "-DHAVE_CRYPTODEV $cflags";
18345 ++	}
18346 ++
18347 + # The DSO code currently always implements all functions so that no
18348 + # applications will have to worry about that from a compilation point
18349 + # of view. However, the "method"s may return zero unless that platform
18350 +diff -urN openssl-0.9.8e.old/crypto/cryptlib.h openssl-0.9.8e/crypto/cryptlib.h
18351 +--- openssl-0.9.8e.old/crypto/cryptlib.h	2008-02-26 10:30:37.000000000 -0500
18352 ++++ openssl-0.9.8e/crypto/cryptlib.h	2008-02-26 10:31:12.000000000 -0500
18353 +@@ -62,7 +62,7 @@
18354 + #include <stdlib.h>
18355 + #include <string.h>
18356 + 
18357 +-#include "e_os.h"
18358 ++#include <openssl/e_os.h>
18359 + 
18360 + #ifdef OPENSSL_USE_APPLINK
18361 + #define BIO_FLAGS_UPLINK 0x8000
18362 +diff -urN openssl-0.9.8e.old/crypto/engine/eng_all.c openssl-0.9.8e/crypto/engine/eng_all.c
18363 +--- openssl-0.9.8e.old/crypto/engine/eng_all.c	2008-02-26 10:30:37.000000000 -0500
18364 ++++ openssl-0.9.8e/crypto/engine/eng_all.c	2008-02-26 10:31:12.000000000 -0500
18365 +@@ -104,13 +104,13 @@
18366 + #endif
18367 + #endif
18368 + #ifndef OPENSSL_NO_HW
18369 +-#if defined(__OpenBSD__) || defined(__FreeBSD__)
18370 ++#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
18371 + 	ENGINE_load_cryptodev();
18372 + #endif
18373 + #endif
18374 + 	}
18375 + 
18376 +-#if defined(__OpenBSD__) || defined(__FreeBSD__)
18377 ++#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
18378 + void ENGINE_setup_bsd_cryptodev(void) {
18379 + 	static int bsd_cryptodev_default_loaded = 0;
18380 + 	if (!bsd_cryptodev_default_loaded) {
18381 +diff -urN openssl-0.9.8e.old/crypto/engine/eng_cryptodev.c openssl-0.9.8e/crypto/engine/eng_cryptodev.c
18382 +--- openssl-0.9.8e.old/crypto/engine/eng_cryptodev.c	2008-02-26 10:30:37.000000000 -0500
18383 ++++ openssl-0.9.8e/crypto/engine/eng_cryptodev.c	2008-02-26 10:31:12.000000000 -0500
18384 +@@ -68,6 +68,16 @@
18385 + struct dev_crypto_state {
18386 + 	struct session_op d_sess;
18387 + 	int d_fd;
18388 ++
18389 ++#ifdef USE_CRYPTODEV_DIGESTS
18390 ++	char dummy_mac_key[20];
18391 ++
18392 ++	unsigned char digest_res[20];
18393 ++	char *mac_data;
18394 ++	int mac_len;
18395 ++
18396 ++	int copy;
18397 ++#endif
18398 + };
18399 + 
18400 + static u_int32_t cryptodev_asymfeat = 0;
18401 +@@ -75,9 +85,11 @@
18402 + static int get_asym_dev_crypto(void);
18403 + static int open_dev_crypto(void);
18404 + static int get_dev_crypto(void);
18405 ++#if 0
18406 + static int cryptodev_max_iv(int cipher);
18407 + static int cryptodev_key_length_valid(int cipher, int len);
18408 + static int cipher_nid_to_cryptodev(int nid);
18409 ++#endif
18410 + static int get_cryptodev_ciphers(const int **cnids);
18411 + static int get_cryptodev_digests(const int **cnids);
18412 + static int cryptodev_usable_ciphers(const int **nids);
18413 +@@ -100,7 +112,7 @@
18414 + static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
18415 +     const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
18416 + static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I,
18417 +-    RSA *rsa);
18418 ++    RSA *rsa, BN_CTX *ctx);
18419 + static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
18420 + static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
18421 +     const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
18422 +@@ -133,6 +145,7 @@
18423 + 	{ CRYPTO_DES_CBC,		NID_des_cbc,		8,	 8, },
18424 + 	{ CRYPTO_3DES_CBC,		NID_des_ede3_cbc,	8,	24, },
18425 + 	{ CRYPTO_AES_CBC,		NID_aes_128_cbc,	16,	16, },
18426 ++	{ CRYPTO_AES_CBC,		NID_aes_256_cbc,	16,	32, },
18427 + 	{ CRYPTO_BLF_CBC,		NID_bf_cbc,		8,	16, },
18428 + 	{ CRYPTO_CAST_CBC,		NID_cast5_cbc,		8,	16, },
18429 + 	{ CRYPTO_SKIPJACK_CBC,		NID_undef,		0,	 0, },
18430 +@@ -142,14 +155,15 @@
18431 + static struct {
18432 + 	int	id;
18433 + 	int	nid;
18434 ++	int 	keylen;
18435 + } digests[] = {
18436 +-	{ CRYPTO_SHA1_HMAC,		NID_hmacWithSHA1,	},
18437 +-	{ CRYPTO_RIPEMD160_HMAC,	NID_ripemd160,		},
18438 +-	{ CRYPTO_MD5_KPDK,		NID_undef,		},
18439 +-	{ CRYPTO_SHA1_KPDK,		NID_undef,		},
18440 +-	{ CRYPTO_MD5,			NID_md5,		},
18441 +-	{ CRYPTO_SHA1,			NID_undef,		},
18442 +-	{ 0,				NID_undef,		},
18443 ++	{ CRYPTO_SHA1_HMAC,		NID_hmacWithSHA1,	20},
18444 ++	{ CRYPTO_RIPEMD160_HMAC,	NID_ripemd160,		16/*?*/},
18445 ++	{ CRYPTO_MD5_KPDK,		NID_undef,		0},
18446 ++	{ CRYPTO_SHA1_KPDK,		NID_undef,		0},
18447 ++	{ CRYPTO_MD5,			NID_md5,		16},
18448 ++	{ CRYPTO_SHA1,			NID_sha1,		20},
18449 ++	{ 0,				NID_undef,		0},
18450 + };
18451 + 
18452 + /*
18453 +@@ -176,10 +190,17 @@
18454 + static int
18455 + get_dev_crypto(void)
18456 + {
18457 +-	int fd, retfd;
18458 ++	static int fd = -1;
18459 ++	int retfd;
18460 + 
18461 +-	if ((fd = open_dev_crypto()) == -1)
18462 +-		return (-1);
18463 ++	if (fd == -1) {
18464 ++		if ((fd = open_dev_crypto()) == -1)
18465 ++			return (-1);
18466 ++		if (fcntl(fd, F_SETFD, 1) == -1) {
18467 ++			close(fd);
18468 ++			return (-1);
18469 ++		}
18470 ++	}
18471 + 	if (ioctl(fd, CRIOGET, &retfd) == -1)
18472 + 		return (-1);
18473 + 
18474 +@@ -202,6 +223,7 @@
18475 + 	return fd;
18476 + }
18477 + 
18478 ++#if 0
18479 + /*
18480 +  * XXXX this needs to be set for each alg - and determined from
18481 +  * a running card.
18482 +@@ -245,6 +267,7 @@
18483 + 			return (ciphers[i].id);
18484 + 	return (0);
18485 + }
18486 ++#endif
18487 + 
18488 + /*
18489 +  * Find out what ciphers /dev/crypto will let us have a session for.
18490 +@@ -264,7 +287,7 @@
18491 + 		return (0);
18492 + 	}
18493 + 	memset(&sess, 0, sizeof(sess));
18494 +-	sess.key = (caddr_t)"123456781234567812345678";
18495 ++	sess.key = (caddr_t)"123456789abcdefghijklmno";
18496 + 
18497 + 	for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
18498 + 		if (ciphers[i].nid == NID_undef)
18499 +@@ -303,10 +326,12 @@
18500 + 		return (0);
18501 + 	}
18502 + 	memset(&sess, 0, sizeof(sess));
18503 ++	sess.mackey = (caddr_t)"123456789abcdefghijklmno";
18504 + 	for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
18505 + 		if (digests[i].nid == NID_undef)
18506 + 			continue;
18507 + 		sess.mac = digests[i].id;
18508 ++		sess.mackeylen = digests[i].keylen;
18509 + 		sess.cipher = 0;
18510 + 		if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
18511 + 		    ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
18512 +@@ -351,6 +376,9 @@
18513 + static int
18514 + cryptodev_usable_digests(const int **nids)
18515 + {
18516 ++#ifdef USE_CRYPTODEV_DIGESTS
18517 ++	return (get_cryptodev_digests(nids));
18518 ++#else
18519 + 	/*
18520 + 	 * XXXX just disable all digests for now, because it sucks.
18521 + 	 * we need a better way to decide this - i.e. I may not
18522 +@@ -365,6 +393,7 @@
18523 + 	 */
18524 + 	*nids = NULL;
18525 + 	return (0);
18526 ++#endif
18527 + }
18528 + 
18529 + static int
18530 +@@ -427,16 +456,20 @@
18531 + {
18532 + 	struct dev_crypto_state *state = ctx->cipher_data;
18533 + 	struct session_op *sess = &state->d_sess;
18534 +-	int cipher;
18535 +-
18536 +-	if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
18537 +-		return (0);
18538 ++	int cipher, i;
18539 + 
18540 +-	if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
18541 +-		return (0);
18542 ++	for (i = 0; ciphers[i].id; i++)
18543 ++		if (ctx->cipher->nid == ciphers[i].nid &&
18544 ++		    ctx->cipher->iv_len <= ciphers[i].ivmax &&
18545 ++		    ctx->key_len == ciphers[i].keylen) {
18546 ++			cipher = ciphers[i].id;
18547 ++			break;
18548 ++		}
18549 + 
18550 +-	if (!cryptodev_key_length_valid(cipher, ctx->key_len))
18551 ++	if (!ciphers[i].id) {
18552 ++		state->d_fd = -1;
18553 + 		return (0);
18554 ++	}
18555 + 
18556 + 	memset(sess, 0, sizeof(struct session_op));
18557 + 
18558 +@@ -563,6 +596,19 @@
18559 + 	NULL
18560 + };
18561 + 
18562 ++const EVP_CIPHER cryptodev_aes_256_cbc = {
18563 ++	NID_aes_256_cbc,
18564 ++	16, 32, 16,
18565 ++	EVP_CIPH_CBC_MODE,
18566 ++	cryptodev_init_key,
18567 ++	cryptodev_cipher,
18568 ++	cryptodev_cleanup,
18569 ++	sizeof(struct dev_crypto_state),
18570 ++	EVP_CIPHER_set_asn1_iv,
18571 ++	EVP_CIPHER_get_asn1_iv,
18572 ++	NULL
18573 ++};
18574 ++
18575 + /*
18576 +  * Registered by the ENGINE when used to find out how to deal with
18577 +  * a particular NID in the ENGINE. this says what we'll do at the
18578 +@@ -591,6 +637,9 @@
18579 + 	case NID_aes_128_cbc:
18580 + 		*cipher = &cryptodev_aes_cbc;
18581 + 		break;
18582 ++	case NID_aes_256_cbc:
18583 ++		*cipher = &cryptodev_aes_256_cbc;
18584 ++		break;
18585 + 	default:
18586 + 		*cipher = NULL;
18587 + 		break;
18588 +@@ -598,6 +647,234 @@
18589 + 	return (*cipher != NULL);
18590 + }
18591 + 
18592 ++
18593 ++#ifdef USE_CRYPTODEV_DIGESTS
18594 ++
18595 ++/* convert digest type to cryptodev */
18596 ++static int
18597 ++digest_nid_to_cryptodev(int nid)
18598 ++{
18599 ++	int i;
18600 ++
18601 ++	for (i = 0; digests[i].id; i++)
18602 ++		if (digests[i].nid == nid)
18603 ++			return (digests[i].id);
18604 ++	return (0);
18605 ++}
18606 ++
18607 ++
18608 ++static int
18609 ++digest_key_length(int nid)
18610 ++{
18611 ++	int i;
18612 ++
18613 ++	for (i = 0; digests[i].id; i++)
18614 ++		if (digests[i].nid == nid)
18615 ++			return digests[i].keylen;
18616 ++	return (0);
18617 ++}
18618 ++
18619 ++
18620 ++static int cryptodev_digest_init(EVP_MD_CTX *ctx)
18621 ++{
18622 ++	struct dev_crypto_state *state = ctx->md_data;
18623 ++	struct session_op *sess = &state->d_sess;
18624 ++	int digest;
18625 ++
18626 ++	if ((digest = digest_nid_to_cryptodev(ctx->digest->type)) == NID_undef){
18627 ++		printf("cryptodev_digest_init: Can't get digest \n");
18628 ++		return (0);
18629 ++	}
18630 ++
18631 ++	memset(state, 0, sizeof(struct dev_crypto_state));
18632 ++
18633 ++	if ((state->d_fd = get_dev_crypto()) < 0) {
18634 ++		printf("cryptodev_digest_init: Can't get Dev \n");
18635 ++		return (0);
18636 ++	}
18637 ++
18638 ++	sess->mackey = state->dummy_mac_key;
18639 ++	sess->mackeylen = digest_key_length(ctx->digest->type);
18640 ++	sess->mac = digest;
18641 ++
18642 ++	if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
18643 ++		close(state->d_fd);
18644 ++		state->d_fd = -1;
18645 ++		printf("cryptodev_digest_init: Open session failed\n");
18646 ++		return (0);
18647 ++	}
18648 ++
18649 ++	return (1);
18650 ++}
18651 ++
18652 ++static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
18653 ++		size_t count)
18654 ++{
18655 ++	struct crypt_op cryp;
18656 ++	struct dev_crypto_state *state = ctx->md_data;
18657 ++	struct session_op *sess = &state->d_sess;
18658 ++
18659 ++	if (!data || state->d_fd < 0) {
18660 ++		printf("cryptodev_digest_update: illegal inputs \n");
18661 ++		return (0);
18662 ++	}
18663 ++
18664 ++	if (!count) {
18665 ++		return (0);
18666 ++	}
18667 ++
18668 ++	if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) {
18669 ++		/* if application doesn't support one buffer */
18670 ++		state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count);
18671 ++
18672 ++		if (!state->mac_data) {
18673 ++			printf("cryptodev_digest_update: realloc failed\n");
18674 ++			return (0);
18675 ++		}
18676 ++
18677 ++		memcpy(state->mac_data + state->mac_len, data, count);
18678 ++   		state->mac_len += count;
18679 ++	
18680 ++		return (1);
18681 ++	}
18682 ++
18683 ++	memset(&cryp, 0, sizeof(cryp));
18684 ++
18685 ++	cryp.ses = sess->ses;
18686 ++	cryp.flags = 0;
18687 ++	cryp.len = count;
18688 ++	cryp.src = (caddr_t) data;
18689 ++	cryp.dst = NULL;
18690 ++	cryp.mac = state->digest_res;
18691 ++	if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
18692 ++		printf("cryptodev_digest_update: digest failed\n");
18693 ++		return (0);
18694 ++	}
18695 ++	return (1);
18696 ++}
18697 ++
18698 ++
18699 ++static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
18700 ++{
18701 ++	struct crypt_op cryp;
18702 ++	struct dev_crypto_state *state = ctx->md_data;
18703 ++	struct session_op *sess = &state->d_sess;
18704 ++
18705 ++	int ret = 1;
18706 ++
18707 ++	if (!md || state->d_fd < 0) {
18708 ++		printf("cryptodev_digest_final: illegal input\n");
18709 ++		return(0);
18710 ++	}
18711 ++
18712 ++	if (! (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) ) {
18713 ++		/* if application doesn't support one buffer */
18714 ++		memset(&cryp, 0, sizeof(cryp));
18715 ++
18716 ++		cryp.ses = sess->ses;
18717 ++		cryp.flags = 0;
18718 ++		cryp.len = state->mac_len;
18719 ++		cryp.src = state->mac_data;
18720 ++		cryp.dst = NULL;
18721 ++		cryp.mac = md;
18722 ++
18723 ++		if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
18724 ++			printf("cryptodev_digest_final: digest failed\n");
18725 ++			return (0);
18726 ++		}
18727 ++
18728 ++		return 1;
18729 ++	}
18730 ++
18731 ++	memcpy(md, state->digest_res, ctx->digest->md_size);
18732 ++
18733 ++	return (ret);
18734 ++}
18735 ++
18736 ++
18737 ++static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx)
18738 ++{
18739 ++	int ret = 1;
18740 ++	struct dev_crypto_state *state = ctx->md_data;
18741 ++	struct session_op *sess = &state->d_sess;
18742 ++
18743 ++	if (state->d_fd < 0) {
18744 ++		printf("cryptodev_digest_cleanup: illegal input\n");
18745 ++		return (0);
18746 ++	}
18747 ++
18748 ++	if (state->mac_data) {
18749 ++		OPENSSL_free(state->mac_data);
18750 ++		state->mac_data = NULL;
18751 ++		state->mac_len = 0;
18752 ++	}
18753 ++
18754 ++	if (state->copy)
18755 ++		return 1;
18756 ++
18757 ++	if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
18758 ++		printf("cryptodev_digest_cleanup: failed to close session\n");
18759 ++		ret = 0;
18760 ++	} else {
18761 ++		ret = 1;
18762 ++	}
18763 ++	close(state->d_fd);	
18764 ++	state->d_fd = -1;
18765 ++
18766 ++	return (ret);
18767 ++}
18768 ++
18769 ++static int cryptodev_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
18770 ++{
18771 ++	struct dev_crypto_state *fstate = from->md_data;
18772 ++	struct dev_crypto_state *dstate = to->md_data;
18773 ++
18774 ++	memcpy(dstate, fstate, sizeof(struct dev_crypto_state));
18775 ++
18776 ++	if (fstate->mac_len != 0) {
18777 ++		dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
18778 ++		memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
18779 ++	}
18780 ++
18781 ++	dstate->copy = 1;
18782 ++
18783 ++	return 1;
18784 ++}
18785 ++
18786 ++
18787 ++const EVP_MD cryptodev_sha1 = {
18788 ++	NID_sha1,
18789 ++	NID_undef, 
18790 ++	SHA_DIGEST_LENGTH, 
18791 ++	EVP_MD_FLAG_ONESHOT,
18792 ++	cryptodev_digest_init,
18793 ++	cryptodev_digest_update,
18794 ++	cryptodev_digest_final,
18795 ++	cryptodev_digest_copy,
18796 ++	cryptodev_digest_cleanup,
18797 ++	EVP_PKEY_NULL_method,
18798 ++	SHA_CBLOCK,
18799 ++	sizeof(struct dev_crypto_state),
18800 ++};
18801 ++
18802 ++const EVP_MD cryptodev_md5 = {
18803 ++	NID_md5,
18804 ++	NID_undef, 
18805 ++	16 /* MD5_DIGEST_LENGTH */, 
18806 ++	EVP_MD_FLAG_ONESHOT,
18807 ++	cryptodev_digest_init,
18808 ++	cryptodev_digest_update,
18809 ++	cryptodev_digest_final,
18810 ++	cryptodev_digest_copy,
18811 ++	cryptodev_digest_cleanup,
18812 ++	EVP_PKEY_NULL_method,
18813 ++	64 /* MD5_CBLOCK */,
18814 ++	sizeof(struct dev_crypto_state),
18815 ++};
18816 ++
18817 ++#endif /* USE_CRYPTODEV_DIGESTS */
18818 ++
18819 ++
18820 + static int
18821 + cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
18822 +     const int **nids, int nid)
18823 +@@ -606,10 +883,15 @@
18824 + 		return (cryptodev_usable_digests(nids));
18825 + 
18826 + 	switch (nid) {
18827 ++#ifdef USE_CRYPTODEV_DIGESTS
18828 + 	case NID_md5:
18829 +-		*digest = NULL; /* need to make a clean md5 critter */
18830 ++		*digest = &cryptodev_md5; 
18831 + 		break;
18832 ++	case NID_sha1:
18833 ++		*digest = &cryptodev_sha1;
18834 ++ 		break;
18835 + 	default:
18836 ++#endif /* USE_CRYPTODEV_DIGESTS */
18837 + 		*digest = NULL;
18838 + 		break;
18839 + 	}
18840 +@@ -625,7 +907,7 @@
18841 + bn2crparam(const BIGNUM *a, struct crparam *crp)
18842 + {
18843 + 	int i, j, k;
18844 +-	ssize_t words, bytes, bits;
18845 ++	ssize_t bytes, bits;
18846 + 	u_char *b;
18847 + 
18848 + 	crp->crp_p = NULL;
18849 +@@ -637,6 +919,7 @@
18850 + 	b = malloc(bytes);
18851 + 	if (b == NULL)
18852 + 		return (1);
18853 ++	memset(b, 0, bytes);
18854 + 
18855 + 	crp->crp_p = b;
18856 + 	crp->crp_nbits = bits;
18857 +@@ -681,7 +964,7 @@
18858 + {
18859 + 	int i;
18860 + 
18861 +-	for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
18862 ++	for (i = 0; i < kop->crk_iparams + kop->crk_oparams; i++) {
18863 + 		if (kop->crk_param[i].crp_p)
18864 + 			free(kop->crk_param[i].crp_p);
18865 + 		kop->crk_param[i].crp_p = NULL;
18866 +@@ -756,12 +1039,10 @@
18867 + }
18868 + 
18869 + static int
18870 +-cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
18871 ++cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
18872 + {
18873 + 	int r;
18874 +-	BN_CTX *ctx;
18875 +-
18876 +-	ctx = BN_CTX_new();
18877 ++	ctx = BN_CTX_new(); /* not sure why we reallocate this. DM */
18878 + 	r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL);
18879 + 	BN_CTX_free(ctx);
18880 + 	return (r);
18881 +diff -urN openssl-0.9.8e.old/crypto/engine/engine.h openssl-0.9.8e/crypto/engine/engine.h
18882 +--- openssl-0.9.8e.old/crypto/engine/engine.h	2008-02-26 10:30:37.000000000 -0500
18883 ++++ openssl-0.9.8e/crypto/engine/engine.h	2008-02-26 10:31:12.000000000 -0500
18884 +@@ -688,7 +688,7 @@
18885 +  * values. */
18886 + void *ENGINE_get_static_state(void);
18887 + 
18888 +-#if defined(__OpenBSD__) || defined(__FreeBSD__)
18889 ++#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
18890 + void ENGINE_setup_bsd_cryptodev(void);
18891 + #endif
18892 + 
18893 +diff -urN openssl-0.9.8e.old/crypto/engine/eng_table.c openssl-0.9.8e/crypto/engine/eng_table.c
18894 +--- openssl-0.9.8e.old/crypto/engine/eng_table.c	2008-02-26 10:30:37.000000000 -0500
18895 ++++ openssl-0.9.8e/crypto/engine/eng_table.c	2008-02-26 10:31:12.000000000 -0500
18896 +@@ -151,8 +151,6 @@
18897 + 		/* if 'setdefault', this ENGINE goes to the head of the list */
18898 + 		if(!sk_ENGINE_push(fnd->sk, e))
18899 + 			goto end;
18900 +-		/* "touch" this ENGINE_PILE */
18901 +-		fnd->uptodate = 1;
18902 + 		if(setdefault)
18903 + 			{
18904 + 			if(!engine_unlocked_init(e))
18905 +@@ -164,6 +162,8 @@
18906 + 			if(fnd->funct)
18907 + 				engine_unlocked_finish(fnd->funct, 0);
18908 + 			fnd->funct = e;
18909 ++			/* "touch" this ENGINE_PILE */
18910 ++			fnd->uptodate = 1;
18911 + 			}
18912 + 		nids++;
18913 + 		}
18914 +@@ -179,13 +179,13 @@
18915 + 	while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
18916 + 		{
18917 + 		sk_ENGINE_delete(pile->sk, n);
18918 +-		/* "touch" this ENGINE_CIPHER */
18919 +-		pile->uptodate = 1;
18920 + 		}
18921 + 	if(pile->funct == e)
18922 + 		{
18923 + 		engine_unlocked_finish(e, 0);
18924 + 		pile->funct = NULL;
18925 ++		/* "touch" this ENGINE_CIPHER */
18926 ++		pile->uptodate = 0;
18927 + 		}
18928 + 	}
18929 + static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
18930 +diff -urN openssl-0.9.8e.old/crypto/evp/c_all.c openssl-0.9.8e/crypto/evp/c_all.c
18931 +--- openssl-0.9.8e.old/crypto/evp/c_all.c	2008-02-26 10:30:37.000000000 -0500
18932 ++++ openssl-0.9.8e/crypto/evp/c_all.c	2008-02-26 10:31:12.000000000 -0500
18933 +@@ -83,7 +83,7 @@
18934 + 	OpenSSL_add_all_ciphers();
18935 + 	OpenSSL_add_all_digests();
18936 + #ifndef OPENSSL_NO_ENGINE
18937 +-# if defined(__OpenBSD__) || defined(__FreeBSD__)
18938 ++# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
18939 + 	ENGINE_setup_bsd_cryptodev();
18940 + # endif
18941 + #endif
18942 +diff -urN openssl-0.9.8e.old/crypto/evp/c_alld.c openssl-0.9.8e/crypto/evp/c_alld.c
18943 +--- openssl-0.9.8e.old/crypto/evp/c_alld.c	2008-02-26 10:30:37.000000000 -0500
18944 ++++ openssl-0.9.8e/crypto/evp/c_alld.c	2008-02-26 10:31:12.000000000 -0500
18945 +@@ -81,7 +81,7 @@
18946 + 	EVP_add_digest(EVP_dss());
18947 + #endif
18948 + #endif
18949 +-#ifndef OPENSSL_NO_SHA
18950 ++#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
18951 + 	EVP_add_digest(EVP_sha1());
18952 + 	EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
18953 + 	EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
18954 +diff -urN openssl-0.9.8e.old/engines/Makefile openssl-0.9.8e/engines/Makefile
18955 +--- openssl-0.9.8e.old/engines/Makefile	2008-02-26 10:30:37.000000000 -0500
18956 ++++ openssl-0.9.8e/engines/Makefile	2008-02-26 10:31:12.000000000 -0500
18957 +@@ -93,6 +93,7 @@
18958 + 			( echo installing $$l; \
18959 + 			  if [ "$(PLATFORM)" != "Cygwin" ]; then \
18960 + 				case "$(CFLAGS)" in \
18961 ++				*OPENSSL_NO_HW*)	continue;;	\
18962 + 				*DSO_DLFCN*)	sfx="so";;	\
18963 + 				*DSO_DL*)	sfx="sl";;	\
18964 + 				*)		sfx="bad";;	\
18965 +diff -urN openssl-0.9.8e.old/INSTALL openssl-0.9.8e/INSTALL
18966 +--- openssl-0.9.8e.old/INSTALL	2008-02-26 10:30:37.000000000 -0500
18967 ++++ openssl-0.9.8e/INSTALL	2008-02-26 10:31:12.000000000 -0500
18968 +@@ -103,6 +103,12 @@
18969 +                 define preprocessor symbols, specify additional libraries,
18970 +                 library directories or other compiler options.
18971 + 
18972 ++  --with-cryptodev Enabled the BSD cryptodev engine even if we are not using
18973 ++		BSD.  Useful if you are running ocf-linux or something
18974 ++		similar.  Once enabled you can also enable the use of
18975 ++		cryptodev digests,  with is usually slower unless you have
18976 ++		large amounts data.  Use --with-cryptodev-digests to force
18977 ++		it.
18978 + 
18979 +  Installation in Detail
18980 +  ----------------------
18981 +diff -urN openssl-0.9.8e.old/Makefile.org openssl-0.9.8e/Makefile.org
18982 +--- openssl-0.9.8e.old/Makefile.org	2008-02-26 10:30:37.000000000 -0500
18983 ++++ openssl-0.9.8e/Makefile.org	2008-02-26 10:31:12.000000000 -0500
18984 +@@ -367,7 +367,7 @@
18985 + 
18986 + links:
18987 + 	@$(PERL) $(TOP)/util/mkdir-p.pl include/openssl
18988 +-	@$(PERL) $(TOP)/util/mklink.pl include/openssl $(EXHEADER)
18989 ++	@$(PERL) $(TOP)/util/mklink.pl include/openssl $(HEADER) $(EXHEADER)
18990 + 	@set -e; target=links; $(RECURSIVE_BUILD_CMD)
18991 + 
18992 + gentests:
18993 +diff -urN openssl-0.9.8e.old/Makefile.shared openssl-0.9.8e/Makefile.shared
18994 +--- openssl-0.9.8e.old/Makefile.shared	2008-02-26 10:30:37.000000000 -0500
18995 ++++ openssl-0.9.8e/Makefile.shared	2008-02-26 10:31:12.000000000 -0500
18996 +@@ -6,13 +6,13 @@
18997 + # properly
18998 + 
18999 + # CC contains the current compiler.  This one MUST be defined
19000 +-CC=cc
19001 +-CFLAGS=$(CFLAG)
19002 ++CC?=cc
19003 ++CFLAGS?=$(CFLAG)
19004 + # LDFLAGS contains flags to be used when temporary object files (when building
19005 + # shared libraries) are created, or when an application is linked.
19006 + # SHARED_LDFLAGS contains flags to be used when the shared library is created.
19007 +-LDFLAGS=
19008 +-SHARED_LDFLAGS=
19009 ++LDFLAGS?=
19010 ++SHARED_LDFLAGS?=
19011 + 
19012 + # LIBNAME contains just the name of the library, without prefix ("lib"
19013 + # on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
19014 +diff -urN openssl-0.9.8e.old/util/domd openssl-0.9.8e/util/domd
19015 +--- openssl-0.9.8e.old/util/domd	2008-02-26 10:30:37.000000000 -0500
19016 ++++ openssl-0.9.8e/util/domd	2008-02-26 10:34:04.000000000 -0500
19017 +@@ -23,13 +23,17 @@
19018 +     done
19019 +     sed -e '/^# DO NOT DELETE.*/,$d' < Makefile > Makefile.tmp
19020 +     echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' >> Makefile.tmp
19021 +-    ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp
19022 ++    ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp && 
19023 +     ${PERL} $TOP/util/clean-depend.pl < Makefile.tmp > Makefile.new
19024 ++      RC=$?
19025 +     rm -f Makefile.tmp
19026 + else
19027 +-    ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND $@
19028 ++    ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND $@ &&
19029 +     ${PERL} $TOP/util/clean-depend.pl < Makefile > Makefile.new
19030 ++      RC=$?
19031 + fi
19032 + mv Makefile.new Makefile
19033 + # unfake the presence of Kerberos
19034 + rm $TOP/krb5.h
19035 ++
19036 ++exit $RC
19037 +diff -urN --exclude=.svn openssl-0.9.8e.old/crypto/engine/eng_cryptodev.c openssl-0.9.8e/crypto/engine/eng_cryptodev.c
19038 +--- openssl-0.9.8e.old/crypto/engine/eng_cryptodev.c	2008-02-27 20:05:09.000000000 -0500
19039 ++++ openssl-0.9.8e/crypto/engine/eng_cryptodev.c	2008-02-27 20:05:27.000000000 -0500
19040 +@@ -54,7 +54,7 @@
19041 + #else 
19042 +  
19043 + #include <sys/types.h>
19044 +-#include <crypto/cryptodev.h>
19045 ++#include <cryptodev.h>
19046 + #include <sys/ioctl.h>
19047 + #include <errno.h>
19048 + #include <stdio.h>
19049 diff -Nur kamikaze_7.09.orig/package/openvpn/files/openvpn.default kamikaze_7.09/package/openvpn/files/openvpn.default
19050 --- kamikaze_7.09.orig/package/openvpn/files/openvpn.default	1970-01-01 01:00:00.000000000 +0100
19051 +++ kamikaze_7.09/package/openvpn/files/openvpn.default	2008-06-19 17:34:17.000000000 +0200
19052 @@ -0,0 +1,2 @@
19053 +CONFIG="/etc/openvpn/server.conf"
19054 +OPTIONS="--config $CONFIG"
19055 diff -Nur kamikaze_7.09.orig/package/openvpn/files/openvpn.init kamikaze_7.09/package/openvpn/files/openvpn.init
19056 --- kamikaze_7.09.orig/package/openvpn/files/openvpn.init	1970-01-01 01:00:00.000000000 +0100
19057 +++ kamikaze_7.09/package/openvpn/files/openvpn.init	2008-06-19 17:34:17.000000000 +0200
19058 @@ -0,0 +1,18 @@
19059 +#!/bin/sh /etc/rc.common
19060 +# Copyright (C) 2007 OpenWrt.org
19061 +
19062 +START=70
19063 +BIN=openvpn
19064 +DEFAULT=/etc/default/$BIN
19065 +RUN_D=/var/run
19066 +PID_F=$RUN_D/$BIN.pid
19067 +
19068 +start() {
19069 +	[ -f $DEFAULT ] && . $DEFAULT
19070 +	mkdir -p $RUN_D
19071 +	$BIN --writepid $RUN_D/$BIN.pid --daemon $OPTIONS
19072 +}
19073 +
19074 +stop() {
19075 +	[ -f $PID_F ] && kill $(cat $PID_F)
19076 +}
19077 diff -Nur kamikaze_7.09.orig/package/openvpn/Makefile kamikaze_7.09/package/openvpn/Makefile
19078 --- kamikaze_7.09.orig/package/openvpn/Makefile	1970-01-01 01:00:00.000000000 +0100
19079 +++ kamikaze_7.09/package/openvpn/Makefile	2008-06-19 17:34:17.000000000 +0200
19080 @@ -0,0 +1,79 @@
19081 +#
19082 +# Copyright (C) 2006 OpenWrt.org
19083 +#
19084 +# This is free software, licensed under the GNU General Public License v2.
19085 +# See /LICENSE for more information.
19086 +#
19087 +# $Id: Makefile 9974 2007-12-28 13:31:04Z nix $
19088 +
19089 +include $(TOPDIR)/rules.mk
19090 +
19091 +PKG_NAME:=openvpn
19092 +PKG_VERSION:=2.0.9
19093 +PKG_RELEASE:=2
19094 +
19095 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
19096 +PKG_SOURCE_URL:=http://openvpn.net/release @SF/openvpn
19097 +PKG_MD5SUM:=60745008b90b7dbe25fe8337c550fec6
19098 +
19099 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
19100 +PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
19101 +
19102 +include $(INCLUDE_DIR)/package.mk
19103 +
19104 +define Package/openvpn
19105 +  SECTION:=net
19106 +  CATEGORY:=Network
19107 +  DEPENDS:=+kmod-tun +libopenssl
19108 +  TITLE:=Open source VPN solution using SSL
19109 +  URL:=http://openvpn.net
19110 +  SUBMENU:=VPN
19111 +endef
19112 +
19113 +define Package/openvpn/description
19114 +	 Open source VPN solution using SSL
19115 +endef
19116 +
19117 +define Package/openvpn-easy-rsa
19118 +  $(call Package/openvpn)
19119 +  DEPENDS:=openvpn +openssl-util
19120 +  TITLE:=Simple shell scripts to manage a Certificate Authority
19121 +endef
19122 +
19123 +define Build/Configure
19124 +	$(call Build/Configure/Default, \
19125 +		--disable-pthread \
19126 +		--disable-debug \
19127 +		--disable-plugins \
19128 +		--enable-management \
19129 +		--disable-socks \
19130 +                --disable-lzo \
19131 +		--enable-password-save \
19132 +	)
19133 +endef
19134 +
19135 +define Build/Compile	
19136 +	$(MAKE) -C $(PKG_BUILD_DIR) \
19137 +		DESTDIR="$(PKG_INSTALL_DIR)" \
19138 +		all install
19139 +endef
19140 +
19141 +define Package/openvpn/install	
19142 +	$(INSTALL_DIR) $(1)/usr/sbin
19143 +	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/openvpn $(1)/usr/sbin/
19144 +	$(INSTALL_DIR) $(1)/etc/init.d/
19145 +	$(INSTALL_BIN) files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
19146 +	$(INSTALL_DIR) $(1)/etc/default
19147 +	$(INSTALL_BIN) files/$(PKG_NAME).default $(1)/etc/default/$(PKG_NAME)
19148 +endef
19149 +
19150 +define Package/openvpn-easy-rsa/install	
19151 +	$(INSTALL_DIR) $(1)/usr/sbin
19152 +	$(CP) $(PKG_BUILD_DIR)/easy-rsa/2.0/{build-*,clean-all,inherit-inter,list-crl,pkitool,revoke-full,sign-req,whichopensslcnf} $(1)/usr/sbin/
19153 +	$(INSTALL_DIR) $(1)/etc/easy-rsa
19154 +	install -m 0644 $(PKG_BUILD_DIR)/easy-rsa/2.0/openssl.cnf $(1)/etc/easy-rsa/openssl.cnf
19155 +	install -m 0644 $(PKG_BUILD_DIR)/easy-rsa/2.0/vars $(1)/etc/easy-rsa/vars
19156 +endef
19157 +
19158 +$(eval $(call BuildPackage,openvpn))
19159 +$(eval $(call BuildPackage,openvpn-easy-rsa))
19160 diff -Nur kamikaze_7.09.orig/package/openvpn/patches/001-easy_rsa.patch kamikaze_7.09/package/openvpn/patches/001-easy_rsa.patch
19161 --- kamikaze_7.09.orig/package/openvpn/patches/001-easy_rsa.patch	1970-01-01 01:00:00.000000000 +0100
19162 +++ kamikaze_7.09/package/openvpn/patches/001-easy_rsa.patch	2008-06-19 17:34:17.000000000 +0200
19163 @@ -0,0 +1,249 @@
19164 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-ca openvpn-2.0.7/easy-rsa/2.0/build-ca
19165 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-ca	2005-11-02 19:42:38.000000000 +0100
19166 ++++ openvpn-2.0.7/easy-rsa/2.0/build-ca	2006-05-09 17:47:40.000000000 +0200
19167 +@@ -1,4 +1,4 @@
19168 +-#!/bin/bash
19169 ++#!/bin/sh
19170 + 
19171 + #
19172 + # Build a root certificate
19173 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-dh openvpn-2.0.7/easy-rsa/2.0/build-dh
19174 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-dh	2005-11-02 19:42:39.000000000 +0100
19175 ++++ openvpn-2.0.7/easy-rsa/2.0/build-dh	2006-05-09 17:47:40.000000000 +0200
19176 +@@ -1,4 +1,6 @@
19177 +-#!/bin/bash
19178 ++#!/bin/sh
19179 ++
19180 ++. /etc/easy-rsa/vars
19181 + 
19182 + # Build Diffie-Hellman parameters for the server side
19183 + # of an SSL/TLS connection.
19184 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-inter openvpn-2.0.7/easy-rsa/2.0/build-inter
19185 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-inter	2005-11-02 19:42:39.000000000 +0100
19186 ++++ openvpn-2.0.7/easy-rsa/2.0/build-inter	2006-05-09 17:47:40.000000000 +0200
19187 +@@ -1,4 +1,4 @@
19188 +-#!/bin/bash
19189 ++#!/bin/sh
19190 + 
19191 + # Make an intermediate CA certificate/private key pair using a locally generated
19192 + # root certificate.
19193 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-key openvpn-2.0.7/easy-rsa/2.0/build-key
19194 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-key	2005-11-02 19:42:39.000000000 +0100
19195 ++++ openvpn-2.0.7/easy-rsa/2.0/build-key	2006-05-09 17:47:40.000000000 +0200
19196 +@@ -1,4 +1,4 @@
19197 +-#!/bin/bash
19198 ++#!/bin/sh
19199 + 
19200 + # Make a certificate/private key pair using a locally generated
19201 + # root certificate.
19202 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-key-pass openvpn-2.0.7/easy-rsa/2.0/build-key-pass
19203 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-key-pass	2005-11-02 19:42:39.000000000 +0100
19204 ++++ openvpn-2.0.7/easy-rsa/2.0/build-key-pass	2006-05-09 17:47:40.000000000 +0200
19205 +@@ -1,4 +1,4 @@
19206 +-#!/bin/bash
19207 ++#!/bin/sh
19208 + 
19209 + # Similar to build-key, but protect the private key
19210 + # with a password.
19211 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-key-pkcs12 openvpn-2.0.7/easy-rsa/2.0/build-key-pkcs12
19212 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-key-pkcs12	2005-11-02 19:42:39.000000000 +0100
19213 ++++ openvpn-2.0.7/easy-rsa/2.0/build-key-pkcs12	2006-05-09 17:47:40.000000000 +0200
19214 +@@ -1,4 +1,4 @@
19215 +-#!/bin/bash
19216 ++#!/bin/sh
19217 + 
19218 + # Make a certificate/private key pair using a locally generated
19219 + # root certificate and convert it to a PKCS #12 file including the
19220 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-key-server openvpn-2.0.7/easy-rsa/2.0/build-key-server
19221 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-key-server	2005-11-02 19:42:39.000000000 +0100
19222 ++++ openvpn-2.0.7/easy-rsa/2.0/build-key-server	2006-05-09 17:47:40.000000000 +0200
19223 +@@ -1,4 +1,4 @@
19224 +-#!/bin/bash
19225 ++#!/bin/sh
19226 + 
19227 + # Make a certificate/private key pair using a locally generated
19228 + # root certificate.
19229 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-req openvpn-2.0.7/easy-rsa/2.0/build-req
19230 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-req	2005-11-02 19:42:38.000000000 +0100
19231 ++++ openvpn-2.0.7/easy-rsa/2.0/build-req	2006-05-09 17:47:40.000000000 +0200
19232 +@@ -1,4 +1,4 @@
19233 +-#!/bin/bash
19234 ++#!/bin/sh
19235 + 
19236 + # Build a certificate signing request and private key.  Use this
19237 + # when your root certificate and key is not available locally.
19238 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/build-req-pass openvpn-2.0.7/easy-rsa/2.0/build-req-pass
19239 +--- openvpn-2.0.7.orig/easy-rsa/2.0/build-req-pass	2005-11-02 19:42:39.000000000 +0100
19240 ++++ openvpn-2.0.7/easy-rsa/2.0/build-req-pass	2006-05-09 17:47:40.000000000 +0200
19241 +@@ -1,4 +1,4 @@
19242 +-#!/bin/bash
19243 ++#!/bin/sh
19244 + 
19245 + # Like build-req, but protect your private key
19246 + # with a password.
19247 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/clean-all openvpn-2.0.7/easy-rsa/2.0/clean-all
19248 +--- openvpn-2.0.7.orig/easy-rsa/2.0/clean-all	2005-11-02 19:42:39.000000000 +0100
19249 ++++ openvpn-2.0.7/easy-rsa/2.0/clean-all	2006-05-09 17:47:40.000000000 +0200
19250 +@@ -1,4 +1,6 @@
19251 +-#!/bin/bash
19252 ++#!/bin/sh
19253 ++
19254 ++. /etc/easy-rsa/vars
19255 + 
19256 + # Initialize the $KEY_DIR directory.
19257 + # Note that this script does a
19258 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/inherit-inter openvpn-2.0.7/easy-rsa/2.0/inherit-inter
19259 +--- openvpn-2.0.7.orig/easy-rsa/2.0/inherit-inter	2005-11-02 19:42:38.000000000 +0100
19260 ++++ openvpn-2.0.7/easy-rsa/2.0/inherit-inter	2006-05-09 17:47:40.000000000 +0200
19261 +@@ -1,4 +1,6 @@
19262 +-#!/bin/bash
19263 ++#!/bin/sh
19264 ++
19265 ++. /etc/easy-rsa/vars
19266 + 
19267 + # Build a new PKI which is rooted on an intermediate certificate generated
19268 + # by ./build-inter or ./pkitool --inter from a parent PKI.  The new PKI should
19269 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/list-crl openvpn-2.0.7/easy-rsa/2.0/list-crl
19270 +--- openvpn-2.0.7.orig/easy-rsa/2.0/list-crl	2005-11-02 19:42:39.000000000 +0100
19271 ++++ openvpn-2.0.7/easy-rsa/2.0/list-crl	2006-05-09 17:47:40.000000000 +0200
19272 +@@ -1,4 +1,6 @@
19273 +-#!/bin/bash
19274 ++#!/bin/sh
19275 ++
19276 ++. /etc/easy-rsa/vars
19277 + 
19278 + # list revoked certificates
19279 + 
19280 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/pkitool openvpn-2.0.7/easy-rsa/2.0/pkitool
19281 +--- openvpn-2.0.7.orig/easy-rsa/2.0/pkitool	2005-11-02 19:42:38.000000000 +0100
19282 ++++ openvpn-2.0.7/easy-rsa/2.0/pkitool	2006-05-09 17:47:40.000000000 +0200
19283 +@@ -1,5 +1,7 @@
19284 + #!/bin/sh
19285 + 
19286 ++. /etc/easy-rsa/vars
19287 ++
19288 + #  OpenVPN -- An application to securely tunnel IP networks
19289 + #             over a single TCP/UDP port, with support for SSL/TLS-based
19290 + #             session authentication and key exchange,
19291 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/revoke-full openvpn-2.0.7/easy-rsa/2.0/revoke-full
19292 +--- openvpn-2.0.7.orig/easy-rsa/2.0/revoke-full	2005-11-02 19:42:39.000000000 +0100
19293 ++++ openvpn-2.0.7/easy-rsa/2.0/revoke-full	2006-05-09 17:47:40.000000000 +0200
19294 +@@ -1,4 +1,6 @@
19295 +-#!/bin/bash
19296 ++#!/bin/sh
19297 ++
19298 ++. /etc/easy-rsa/vars
19299 + 
19300 + # revoke a certificate, regenerate CRL,
19301 + # and verify revocation
19302 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/sign-req openvpn-2.0.7/easy-rsa/2.0/sign-req
19303 +--- openvpn-2.0.7.orig/easy-rsa/2.0/sign-req	2005-11-02 19:42:39.000000000 +0100
19304 ++++ openvpn-2.0.7/easy-rsa/2.0/sign-req	2006-05-09 17:47:40.000000000 +0200
19305 +@@ -1,4 +1,4 @@
19306 +-#!/bin/bash
19307 ++#!/bin/sh
19308 + 
19309 + # Sign a certificate signing request (a .csr file)
19310 + # with a local root certificate and key.
19311 +diff -ur openvpn-2.0.7.orig/easy-rsa/2.0/vars openvpn-2.0.7/easy-rsa/2.0/vars
19312 +--- openvpn-2.0.7.orig/easy-rsa/2.0/vars	2005-11-02 19:42:39.000000000 +0100
19313 ++++ openvpn-2.0.7/easy-rsa/2.0/vars	2006-05-09 17:47:40.000000000 +0200
19314 +@@ -12,7 +12,7 @@
19315 + # This variable should point to
19316 + # the top level of the easy-rsa
19317 + # tree.
19318 +-export EASY_RSA="`pwd`"
19319 ++export EASY_RSA="/etc/easy-rsa"
19320 + 
19321 + #
19322 + # This variable should point to
19323 +@@ -26,7 +26,7 @@
19324 + # This variable should point to
19325 + # the openssl.cnf file included
19326 + # with easy-rsa.
19327 +-export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA`
19328 ++export KEY_CONFIG=`/usr/sbin/whichopensslcnf $EASY_RSA`
19329 + 
19330 + # Edit this variable to point to
19331 + # your soon-to-be-created key
19332 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-ca openvpn-2.0.9/easy-rsa/2.0/build-ca
19333 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-ca	2007-06-18 01:20:36.000000000 +0200
19334 ++++ openvpn-2.0.9/easy-rsa/2.0/build-ca	2007-06-18 01:21:07.000000000 +0200
19335 +@@ -5,4 +5,4 @@
19336 + #
19337 + 
19338 + export EASY_RSA="${EASY_RSA:-.}"
19339 +-"$EASY_RSA/pkitool" --interact --initca $*
19340 ++"/usr/sbin/pkitool" --interact --initca $*
19341 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-inter openvpn-2.0.9/easy-rsa/2.0/build-inter
19342 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-inter	2007-06-18 01:20:36.000000000 +0200
19343 ++++ openvpn-2.0.9/easy-rsa/2.0/build-inter	2007-06-18 01:21:19.000000000 +0200
19344 +@@ -4,4 +4,4 @@
19345 + # root certificate.
19346 + 
19347 + export EASY_RSA="${EASY_RSA:-.}"
19348 +-"$EASY_RSA/pkitool" --interact --inter $*
19349 ++"/usr/sbin/pkitool" --interact --inter $*
19350 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-key openvpn-2.0.9/easy-rsa/2.0/build-key
19351 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-key	2007-06-18 01:20:36.000000000 +0200
19352 ++++ openvpn-2.0.9/easy-rsa/2.0/build-key	2007-06-18 01:21:32.000000000 +0200
19353 +@@ -4,4 +4,4 @@
19354 + # root certificate.
19355 + 
19356 + export EASY_RSA="${EASY_RSA:-.}"
19357 +-"$EASY_RSA/pkitool" --interact $*
19358 ++"/usr/sbin/pkitool" --interact $*
19359 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-key-pass openvpn-2.0.9/easy-rsa/2.0/build-key-pass
19360 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-key-pass	2007-06-18 01:20:36.000000000 +0200
19361 ++++ openvpn-2.0.9/easy-rsa/2.0/build-key-pass	2007-06-18 01:21:45.000000000 +0200
19362 +@@ -4,4 +4,4 @@
19363 + # with a password.
19364 + 
19365 + export EASY_RSA="${EASY_RSA:-.}"
19366 +-"$EASY_RSA/pkitool" --interact --pass $*
19367 ++"/usr/sbin/pkitool" --interact --pass $*
19368 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-key-pkcs12 openvpn-2.0.9/easy-rsa/2.0/build-key-pkcs12
19369 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-key-pkcs12	2007-06-18 01:20:36.000000000 +0200
19370 ++++ openvpn-2.0.9/easy-rsa/2.0/build-key-pkcs12	2007-06-18 01:21:57.000000000 +0200
19371 +@@ -5,4 +5,4 @@
19372 + # the CA certificate as well.
19373 + 
19374 + export EASY_RSA="${EASY_RSA:-.}"
19375 +-"$EASY_RSA/pkitool" --interact --pkcs12 $*
19376 ++"/usr/sbin/pkitool" --interact --pkcs12 $*
19377 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-key-server openvpn-2.0.9/easy-rsa/2.0/build-key-server
19378 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-key-server	2007-06-18 01:20:36.000000000 +0200
19379 ++++ openvpn-2.0.9/easy-rsa/2.0/build-key-server	2007-06-18 01:22:09.000000000 +0200
19380 +@@ -7,4 +7,4 @@
19381 + # extension in the openssl.cnf file.
19382 + 
19383 + export EASY_RSA="${EASY_RSA:-.}"
19384 +-"$EASY_RSA/pkitool" --interact --server $*
19385 ++"/usr/sbin/pkitool" --interact --server $*
19386 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-req openvpn-2.0.9/easy-rsa/2.0/build-req
19387 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-req	2007-06-18 01:20:36.000000000 +0200
19388 ++++ openvpn-2.0.9/easy-rsa/2.0/build-req	2007-06-18 01:22:27.000000000 +0200
19389 +@@ -4,4 +4,4 @@
19390 + # when your root certificate and key is not available locally.
19391 + 
19392 + export EASY_RSA="${EASY_RSA:-.}"
19393 +-"$EASY_RSA/pkitool" --interact --csr $*
19394 ++"/usr/sbin/pkitool" --interact --csr $*
19395 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/build-req-pass openvpn-2.0.9/easy-rsa/2.0/build-req-pass
19396 +--- openvpn-2.0.9.orig/easy-rsa/2.0/build-req-pass	2007-06-18 01:20:36.000000000 +0200
19397 ++++ openvpn-2.0.9/easy-rsa/2.0/build-req-pass	2007-06-18 01:22:38.000000000 +0200
19398 +@@ -4,4 +4,4 @@
19399 + # with a password.
19400 + 
19401 + export EASY_RSA="${EASY_RSA:-.}"
19402 +-"$EASY_RSA/pkitool" --interact --csr --pass $*
19403 ++"/usr/sbin/pkitool" --interact --csr --pass $*
19404 +diff -urN openvpn-2.0.9.orig/easy-rsa/2.0/sign-req openvpn-2.0.9/easy-rsa/2.0/sign-req
19405 +--- openvpn-2.0.9.orig/easy-rsa/2.0/sign-req	2007-06-18 01:20:36.000000000 +0200
19406 ++++ openvpn-2.0.9/easy-rsa/2.0/sign-req	2007-06-18 01:22:53.000000000 +0200
19407 +@@ -4,4 +4,4 @@
19408 + # with a local root certificate and key.
19409 + 
19410 + export EASY_RSA="${EASY_RSA:-.}"
19411 +-"$EASY_RSA/pkitool" --interact --sign $*
19412 ++"/usr/sbin/pkitool" --interact --sign $*
19413 diff -Nur kamikaze_7.09.orig/package/screen/Makefile kamikaze_7.09/package/screen/Makefile
19414 --- kamikaze_7.09.orig/package/screen/Makefile	1970-01-01 01:00:00.000000000 +0100
19415 +++ kamikaze_7.09/package/screen/Makefile	2008-06-19 17:34:17.000000000 +0200
19416 @@ -0,0 +1,49 @@
19417 +#
19418 +# Copyright (C) 2006 OpenWrt.org
19419 +#
19420 +# This is free software, licensed under the GNU General Public License v2.
19421 +# See /LICENSE for more information.
19422 +#
19423 +# $Id: Makefile 9349 2007-10-18 18:46:37Z blogic $
19424 +
19425 +include $(TOPDIR)/rules.mk
19426 +
19427 +PKG_NAME:=screen
19428 +PKG_VERSION:=4.0.3
19429 +PKG_RELEASE:=1
19430 +
19431 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
19432 +PKG_SOURCE_URL:=ftp://ftp.uni-erlangen.de/pub/utilities/screen \
19433 +	@GNU/screen
19434 +PKG_MD5SUM:=8506fd205028a96c741e4037de6e3c42
19435 +
19436 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
19437 +PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
19438 +
19439 +include $(INCLUDE_DIR)/package.mk
19440 +
19441 +define Package/screen
19442 +  SECTION:=utils
19443 +  CATEGORY:=Utilities
19444 +  DEPENDS:=+libncurses
19445 +  TITLE:=Full-screen terminal window manager
19446 +  URL:=http://www.gnu.org/software/screen/
19447 +endef
19448 +
19449 +define Package/screen/description
19450 +	Screen is a full-screen window manager that multiplexes a physical
19451 +	terminal between several processes, typically interactive shells.
19452 +endef
19453 +
19454 +define Build/Configure
19455 +	$(call Build/Configure/Default,,\
19456 +		LIBS="-lcrypt" \
19457 +	)
19458 +endef
19459 +
19460 +define Package/screen/install	
19461 +	$(INSTALL_DIR) $(1)/usr/sbin
19462 +	$(INSTALL_BIN) $(PKG_BUILD_DIR)/screen $(1)/usr/sbin/
19463 +endef
19464 +
19465 +$(eval $(call BuildPackage,screen))
19466 diff -Nur kamikaze_7.09.orig/package/screen/patches/100-cross_compile_fix.patch kamikaze_7.09/package/screen/patches/100-cross_compile_fix.patch
19467 --- kamikaze_7.09.orig/package/screen/patches/100-cross_compile_fix.patch	1970-01-01 01:00:00.000000000 +0100
19468 +++ kamikaze_7.09/package/screen/patches/100-cross_compile_fix.patch	2008-06-19 17:34:17.000000000 +0200
19469 @@ -0,0 +1,530 @@
19470 +Binary files screen-4.0.2.old/.configure.swp and screen-4.0.2.dev/.configure.swp differ
19471 +diff -urN screen-4.0.2.old/configure screen-4.0.2.dev/configure
19472 +--- screen-4.0.2.old/configure	2003-12-05 14:46:53.000000000 +0100
19473 ++++ screen-4.0.2.dev/configure	2005-05-05 12:13:03.000000000 +0200
19474 +@@ -124,7 +124,7 @@
19475 +   fi
19476 +   if test ! -f "$as_myself"; then
19477 +     { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
19478 +-   { (exit 1); exit 1; }; }
19479 ++    }
19480 +   fi
19481 +   case $CONFIG_SHELL in
19482 +   '')
19483 +@@ -174,7 +174,7 @@
19484 +     ' >$as_me.lineno &&
19485 +   chmod +x $as_me.lineno ||
19486 +     { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
19487 +-   { (exit 1); exit 1; }; }
19488 ++    }
19489 + 
19490 +   # Don't try to exec as it changes $[0], causing all sort of problems
19491 +   # (the dirname of $[0] is not the place where we might find the
19492 +@@ -397,7 +397,7 @@
19493 +     # Reject names that are not valid shell variable names.
19494 +     expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
19495 +       { echo "$as_me: error: invalid feature name: $ac_feature" >&2
19496 +-   { (exit 1); exit 1; }; }
19497 ++    }
19498 +     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
19499 +     eval "enable_$ac_feature=no" ;;
19500 + 
19501 +@@ -406,7 +406,7 @@
19502 +     # Reject names that are not valid shell variable names.
19503 +     expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
19504 +       { echo "$as_me: error: invalid feature name: $ac_feature" >&2
19505 +-   { (exit 1); exit 1; }; }
19506 ++    }
19507 +     ac_feature=`echo $ac_feature | sed 's/-/_/g'`
19508 +     case $ac_option in
19509 +       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
19510 +@@ -588,7 +588,7 @@
19511 +     # Reject names that are not valid shell variable names.
19512 +     expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
19513 +       { echo "$as_me: error: invalid package name: $ac_package" >&2
19514 +-   { (exit 1); exit 1; }; }
19515 ++    }
19516 +     ac_package=`echo $ac_package| sed 's/-/_/g'`
19517 +     case $ac_option in
19518 +       *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
19519 +@@ -601,7 +601,7 @@
19520 +     # Reject names that are not valid shell variable names.
19521 +     expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
19522 +       { echo "$as_me: error: invalid package name: $ac_package" >&2
19523 +-   { (exit 1); exit 1; }; }
19524 ++    }
19525 +     ac_package=`echo $ac_package | sed 's/-/_/g'`
19526 +     eval "with_$ac_package=no" ;;
19527 + 
19528 +@@ -625,7 +625,7 @@
19529 + 
19530 +   -*) { echo "$as_me: error: unrecognized option: $ac_option
19531 + Try \`$0 --help' for more information." >&2
19532 +-   { (exit 1); exit 1; }; }
19533 ++    }
19534 +     ;;
19535 + 
19536 +   *=*)
19537 +@@ -633,7 +633,7 @@
19538 +     # Reject names that are not valid shell variable names.
19539 +     expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
19540 +       { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
19541 +-   { (exit 1); exit 1; }; }
19542 ++    }
19543 +     ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
19544 +     eval "$ac_envvar='$ac_optarg'"
19545 +     export $ac_envvar ;;
19546 +@@ -652,7 +652,7 @@
19547 + if test -n "$ac_prev"; then
19548 +   ac_option=--`echo $ac_prev | sed 's/_/-/g'`
19549 +   { echo "$as_me: error: missing argument to $ac_option" >&2
19550 +-   { (exit 1); exit 1; }; }
19551 ++    }
19552 + fi
19553 + 
19554 + # Be sure to have absolute paths.
19555 +@@ -662,7 +662,7 @@
19556 +   case $ac_val in
19557 +     [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
19558 +     *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
19559 +-   { (exit 1); exit 1; }; };;
19560 ++    };;
19561 +   esac
19562 + done
19563 + 
19564 +@@ -674,7 +674,7 @@
19565 +   case $ac_val in
19566 +     [\\/$]* | ?:[\\/]* ) ;;
19567 +     *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
19568 +-   { (exit 1); exit 1; }; };;
19569 ++    };;
19570 +   esac
19571 + done
19572 + 
19573 +@@ -728,15 +728,15 @@
19574 + if test ! -r $srcdir/$ac_unique_file; then
19575 +   if test "$ac_srcdir_defaulted" = yes; then
19576 +     { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
19577 +-   { (exit 1); exit 1; }; }
19578 ++    }
19579 +   else
19580 +     { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
19581 +-   { (exit 1); exit 1; }; }
19582 ++    }
19583 +   fi
19584 + fi
19585 + (cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
19586 +   { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
19587 +-   { (exit 1); exit 1; }; }
19588 ++    }
19589 + srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
19590 + ac_env_build_alias_set=${build_alias+set}
19591 + ac_env_build_alias_value=$build_alias
19592 +@@ -1243,7 +1243,7 @@
19593 + echo "$as_me: error: changes in the environment can compromise the build" >&2;}
19594 +   { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
19595 + echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
19596 +-   { (exit 1); exit 1; }; }
19597 ++    }
19598 + fi
19599 + 
19600 + ac_ext=c
19601 +@@ -1734,7 +1734,7 @@
19602 + See \`config.log' for more details." >&5
19603 + echo "$as_me: error: no acceptable C compiler found in \$PATH
19604 + See \`config.log' for more details." >&2;}
19605 +-   { (exit 1); exit 1; }; }
19606 ++    }
19607 + 
19608 + # Provide some information about the compiler.
19609 + echo "$as_me:$LINENO:" \
19610 +@@ -1856,7 +1856,7 @@
19611 + echo "$as_me: error: cannot run C compiled programs.
19612 + If you meant to cross compile, use \`--host'.
19613 + See \`config.log' for more details." >&2;}
19614 +-   { (exit 1); exit 1; }; }
19615 ++    }
19616 +     fi
19617 +   fi
19618 + fi
19619 +@@ -1898,7 +1898,7 @@
19620 + See \`config.log' for more details." >&5
19621 + echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
19622 + See \`config.log' for more details." >&2;}
19623 +-   { (exit 1); exit 1; }; }
19624 ++    }
19625 + fi
19626 + 
19627 + rm -f conftest$ac_cv_exeext
19628 +@@ -1950,7 +1950,7 @@
19629 + See \`config.log' for more details." >&5
19630 + echo "$as_me: error: cannot compute suffix of object files: cannot compile
19631 + See \`config.log' for more details." >&2;}
19632 +-   { (exit 1); exit 1; }; }
19633 ++    }
19634 + fi
19635 + 
19636 + rm -f conftest.$ac_cv_objext conftest.$ac_ext
19637 +@@ -2514,7 +2514,7 @@
19638 + See \`config.log' for more details." >&5
19639 + echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
19640 + See \`config.log' for more details." >&2;}
19641 +-   { (exit 1); exit 1; }; }
19642 ++    }
19643 + fi
19644 + 
19645 + ac_ext=c
19646 +@@ -2704,7 +2704,7 @@
19647 + See \`config.log' for more details." >&5
19648 + echo "$as_me: error: cannot run test program while cross compiling
19649 + See \`config.log' for more details." >&2;}
19650 +-   { (exit 1); exit 1; }; }
19651 ++    }
19652 + else
19653 +   cat >conftest.$ac_ext <<_ACEOF
19654 + #line $LINENO "configure"
19655 +@@ -2753,7 +2753,7 @@
19656 + See \`config.log' for more details." >&5
19657 + echo "$as_me: error: cannot run test program while cross compiling
19658 + See \`config.log' for more details." >&2;}
19659 +-   { (exit 1); exit 1; }; }
19660 ++  }
19661 + else
19662 +   cat >conftest.$ac_ext <<_ACEOF
19663 + #line $LINENO "configure"
19664 +@@ -2790,7 +2790,7 @@
19665 + 
19666 + { { echo "$as_me:$LINENO: error: Can't run the compiler - sorry" >&5
19667 + echo "$as_me: error: Can't run the compiler - sorry" >&2;}
19668 +-   { (exit 1); exit 1; }; }
19669 ++    }
19670 + fi
19671 + rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
19672 + fi
19673 +@@ -2800,7 +2800,7 @@
19674 + See \`config.log' for more details." >&5
19675 + echo "$as_me: error: cannot run test program while cross compiling
19676 + See \`config.log' for more details." >&2;}
19677 +-   { (exit 1); exit 1; }; }
19678 ++  }
19679 + else
19680 +   cat >conftest.$ac_ext <<_ACEOF
19681 + #line $LINENO "configure"
19682 +@@ -2830,7 +2830,7 @@
19683 +   (exit $ac_status); }; }; then
19684 +   { { echo "$as_me:$LINENO: error: Your compiler does not set the exit status - sorry" >&5
19685 + echo "$as_me: error: Your compiler does not set the exit status - sorry" >&2;}
19686 +-   { (exit 1); exit 1; }; }
19687 ++    }
19688 + else
19689 +   echo "$as_me: program exited with status $ac_status" >&5
19690 + echo "$as_me: failed program was:" >&5
19691 +@@ -2900,7 +2900,7 @@
19692 + if test -z "$ac_aux_dir"; then
19693 +   { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5
19694 + echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;}
19695 +-   { (exit 1); exit 1; }; }
19696 ++    }
19697 + fi
19698 + ac_config_guess="$SHELL $ac_aux_dir/config.guess"
19699 + ac_config_sub="$SHELL $ac_aux_dir/config.sub"
19700 +@@ -4149,7 +4149,7 @@
19701 + 
19702 + { { echo "$as_me:$LINENO: error: !!! no select - no screen" >&5
19703 + echo "$as_me: error: !!! no select - no screen" >&2;}
19704 +-   { (exit 1); exit 1; }; }
19705 ++    }
19706 + fi
19707 + rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
19708 + 
19709 +@@ -4163,7 +4163,7 @@
19710 + See \`config.log' for more details." >&5
19711 + echo "$as_me: error: cannot run test program while cross compiling
19712 + See \`config.log' for more details." >&2;}
19713 +-   { (exit 1); exit 1; }; }
19714 ++  }
19715 + else
19716 +   cat >conftest.$ac_ext <<_ACEOF
19717 + #line $LINENO "configure"
19718 +@@ -4272,7 +4272,7 @@
19719 + See \`config.log' for more details." >&5
19720 + echo "$as_me: error: cannot run test program while cross compiling
19721 + See \`config.log' for more details." >&2;}
19722 +-   { (exit 1); exit 1; }; }
19723 ++  }
19724 + else
19725 +   cat >conftest.$ac_ext <<_ACEOF
19726 + #line $LINENO "configure"
19727 +@@ -4365,7 +4365,7 @@
19728 + See \`config.log' for more details." >&5
19729 + echo "$as_me: error: cannot run test program while cross compiling
19730 + See \`config.log' for more details." >&2;}
19731 +-   { (exit 1); exit 1; }; }
19732 ++  }
19733 + else
19734 +   cat >conftest.$ac_ext <<_ACEOF
19735 + #line $LINENO "configure"
19736 +@@ -4460,7 +4460,7 @@
19737 + See \`config.log' for more details." >&5
19738 + echo "$as_me: error: cannot run test program while cross compiling
19739 + See \`config.log' for more details." >&2;}
19740 +-   { (exit 1); exit 1; }; }
19741 ++  }
19742 + else
19743 +   cat >conftest.$ac_ext <<_ACEOF
19744 + #line $LINENO "configure"
19745 +@@ -4562,7 +4562,7 @@
19746 + else
19747 +   { { echo "$as_me:$LINENO: error: you have neither usable sockets nor usable pipes -> no screen" >&5
19748 + echo "$as_me: error: you have neither usable sockets nor usable pipes -> no screen" >&2;}
19749 +-   { (exit 1); exit 1; }; }
19750 ++    }
19751 + fi
19752 + 
19753 + 
19754 +@@ -4573,7 +4573,7 @@
19755 + See \`config.log' for more details." >&5
19756 + echo "$as_me: error: cannot run test program while cross compiling
19757 + See \`config.log' for more details." >&2;}
19758 +-   { (exit 1); exit 1; }; }
19759 ++    }
19760 + else
19761 +   cat >conftest.$ac_ext <<_ACEOF
19762 + #line $LINENO "configure"
19763 +@@ -4898,7 +4898,7 @@
19764 + 
19765 + { { echo "$as_me:$LINENO: error: !!! no tgetent - no screen" >&5
19766 + echo "$as_me: error: !!! no tgetent - no screen" >&2;}
19767 +-   { (exit 1); exit 1; }; }
19768 ++    }
19769 + fi
19770 + rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
19771 + fi
19772 +@@ -4915,7 +4915,7 @@
19773 + See \`config.log' for more details." >&5
19774 + echo "$as_me: error: cannot run test program while cross compiling
19775 + See \`config.log' for more details." >&2;}
19776 +-   { (exit 1); exit 1; }; }
19777 ++    }
19778 + else
19779 +   cat >conftest.$ac_ext <<_ACEOF
19780 + #line $LINENO "configure"
19781 +@@ -5359,7 +5356,7 @@
19782 + See \`config.log' for more details." >&5
19783 + echo "$as_me: error: cannot run test program while cross compiling
19784 + See \`config.log' for more details." >&2;}
19785 +-   { (exit 1); exit 1; }; }
19786 ++    }
19787 + else
19788 +   cat >conftest.$ac_ext <<_ACEOF
19789 + #line $LINENO "configure"
19790 +@@ -6206,7 +6203,7 @@
19791 + See \`config.log' for more details." >&5
19792 + echo "$as_me: error: cannot run test program while cross compiling
19793 + See \`config.log' for more details." >&2;}
19794 +-   { (exit 1); exit 1; }; }
19795 ++    }
19796 + else
19797 +   cat >conftest.$ac_ext <<_ACEOF
19798 + #line $LINENO "configure"
19799 +@@ -6482,7 +6479,7 @@
19800 + See \`config.log' for more details." >&5
19801 + echo "$as_me: error: cannot run test program while cross compiling
19802 + See \`config.log' for more details." >&2;}
19803 +-   { (exit 1); exit 1; }; }
19804 ++    }
19805 + else
19806 +   cat >conftest.$ac_ext <<_ACEOF
19807 + #line $LINENO "configure"
19808 +@@ -7004,7 +7001,7 @@
19809 + See \`config.log' for more details." >&5
19810 + echo "$as_me: error: cannot run test program while cross compiling
19811 + See \`config.log' for more details." >&2;}
19812 +-   { (exit 1); exit 1; }; }
19813 ++    }
19814 + else
19815 +   cat >conftest.$ac_ext <<_ACEOF
19816 + #line $LINENO "configure"
19817 +@@ -7056,7 +7053,7 @@
19818 + See \`config.log' for more details." >&5
19819 + echo "$as_me: error: cannot run test program while cross compiling
19820 + See \`config.log' for more details." >&2;}
19821 +-   { (exit 1); exit 1; }; }
19822 ++    }
19823 + else
19824 +   cat >conftest.$ac_ext <<_ACEOF
19825 + #line $LINENO "configure"
19826 +@@ -7110,7 +7107,7 @@
19827 + See \`config.log' for more details." >&5
19828 + echo "$as_me: error: cannot run test program while cross compiling
19829 + See \`config.log' for more details." >&2;}
19830 +-   { (exit 1); exit 1; }; }
19831 ++    }
19832 + else
19833 +   cat >conftest.$ac_ext <<_ACEOF
19834 + #line $LINENO "configure"
19835 +@@ -7951,7 +7948,7 @@
19836 + See \`config.log' for more details." >&5
19837 + echo "$as_me: error: cannot run test program while cross compiling
19838 + See \`config.log' for more details." >&2;}
19839 +-   { (exit 1); exit 1; }; }
19840 ++    }
19841 + else
19842 +   cat >conftest.$ac_ext <<_ACEOF
19843 + #line $LINENO "configure"
19844 +@@ -7982,7 +7979,7 @@
19845 + ( exit $ac_status )
19846 + { { echo "$as_me:$LINENO: error: Can't run the compiler - internal error. Sorry." >&5
19847 + echo "$as_me: error: Can't run the compiler - internal error. Sorry." >&2;}
19848 +-   { (exit 1); exit 1; }; }
19849 ++    }
19850 + fi
19851 + rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
19852 + fi
19853 +@@ -8251,7 +8248,7 @@
19854 +   if test ! -f "$as_myself"; then
19855 +     { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
19856 + echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
19857 +-   { (exit 1); exit 1; }; }
19858 ++    }
19859 +   fi
19860 +   case $CONFIG_SHELL in
19861 +   '')
19862 +@@ -8302,7 +8299,7 @@
19863 +   chmod +x $as_me.lineno ||
19864 +     { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
19865 + echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
19866 +-   { (exit 1); exit 1; }; }
19867 ++    }
19868 + 
19869 +   # Don't try to exec as it changes $[0], causing all sort of problems
19870 +   # (the dirname of $[0] is not the place where we might find the
19871 +@@ -8494,7 +8491,7 @@
19872 + Try \`$0 --help' for more information." >&5
19873 + echo "$as_me: error: ambiguous option: $1
19874 + Try \`$0 --help' for more information." >&2;}
19875 +-   { (exit 1); exit 1; }; };;
19876 ++    };;
19877 +   --help | --hel | -h )
19878 +     echo "$ac_cs_usage"; exit 0 ;;
19879 +   --debug | --d* | -d )
19880 +@@ -8516,7 +8513,7 @@
19881 + Try \`$0 --help' for more information." >&5
19882 + echo "$as_me: error: unrecognized option: $1
19883 + Try \`$0 --help' for more information." >&2;}
19884 +-   { (exit 1); exit 1; }; } ;;
19885 ++    } ;;
19886 + 
19887 +   *) ac_config_targets="$ac_config_targets $1" ;;
19888 + 
19889 +@@ -8555,7 +8552,7 @@
19890 +   "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
19891 +   *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
19892 + echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
19893 +-   { (exit 1); exit 1; }; };;
19894 ++    };;
19895 +   esac
19896 + done
19897 + 
19898 +@@ -8750,7 +8747,7 @@
19899 +     test ! -n "$as_dirs" || mkdir $as_dirs
19900 +   fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
19901 + echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
19902 +-   { (exit 1); exit 1; }; }; }
19903 ++    }; }
19904 + 
19905 +   ac_builddir=.
19906 + 
19907 +@@ -8816,7 +8813,7 @@
19908 +          # Absolute (can't be DOS-style, as IFS=:)
19909 +          test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
19910 + echo "$as_me: error: cannot find input file: $f" >&2;}
19911 +-   { (exit 1); exit 1; }; }
19912 ++    }
19913 +          echo $f;;
19914 +       *) # Relative
19915 +          if test -f "$f"; then
19916 +@@ -8829,7 +8826,7 @@
19917 +            # /dev/null tree
19918 +            { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
19919 + echo "$as_me: error: cannot find input file: $f" >&2;}
19920 +-   { (exit 1); exit 1; }; }
19921 ++    }
19922 +          fi;;
19923 +       esac
19924 +     done` || { (exit 1); exit 1; }
19925 +@@ -8907,7 +8904,7 @@
19926 +          # Absolute (can't be DOS-style, as IFS=:)
19927 +          test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
19928 + echo "$as_me: error: cannot find input file: $f" >&2;}
19929 +-   { (exit 1); exit 1; }; }
19930 ++    }
19931 +          echo $f;;
19932 +       *) # Relative
19933 +          if test -f "$f"; then
19934 +@@ -8920,7 +8917,7 @@
19935 +            # /dev/null tree
19936 +            { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
19937 + echo "$as_me: error: cannot find input file: $f" >&2;}
19938 +-   { (exit 1); exit 1; }; }
19939 ++    }
19940 +          fi;;
19941 +       esac
19942 +     done` || { (exit 1); exit 1; }
19943 +@@ -9073,7 +9070,7 @@
19944 +     test ! -n "$as_dirs" || mkdir $as_dirs
19945 +   fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
19946 + echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
19947 +-   { (exit 1); exit 1; }; }; }
19948 ++    }; }
19949 + 
19950 +       rm -f $ac_file
19951 +       mv $tmp/config.h $ac_file
19952 +diff -urN screen-4.0.2.old/pty.c screen-4.0.2.dev/pty.c
19953 +--- screen-4.0.2.old/pty.c	2003-09-08 16:26:18.000000000 +0200
19954 ++++ screen-4.0.2.dev/pty.c	2005-05-05 12:32:20.000000000 +0200
19955 +@@ -34,9 +34,9 @@
19956 + #endif
19957 + 
19958 + /* for solaris 2.1, Unixware (SVR4.2) and possibly others */
19959 +-#ifdef HAVE_SVR4_PTYS
19960 +-# include <sys/stropts.h>
19961 +-#endif
19962 ++//#ifdef HAVE_SVR4_PTYS
19963 ++//# include <sys/stropts.h>
19964 ++//#endif
19965 + 
19966 + #if defined(sun) && defined(LOCKPTY) && !defined(TIOCEXCL)
19967 + # include <sys/ttold.h>
19968 +--- screen-4.0.2/configure.old	2005-05-24 18:49:30.000000000 +0200
19969 ++++ screen-4.0.2/configure	2005-05-24 18:49:54.000000000 +0200
19970 +@@ -6598,8 +6598,6 @@
19971 + LIBS="$oldlibs"
19972 + fi
19973 + rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
19974 +-test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
19975 +-test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
19976 + oldlibs="$LIBS"
19977 + LIBS="$LIBS -lsun"
19978 + { echo "$as_me:$LINENO: checking IRIX sun library..." >&5
19979 +diff -ur screen.old/sched.h screen.dev/sched.h
19980 +--- screen.old/sched.h	2002-01-08 16:42:43.000000000 +0100
19981 ++++ screen.dev/sched.h	2007-03-02 17:03:48.475830776 +0100
19982 +@@ -22,6 +22,11 @@
19983 +  * $Id: 100-cross_compile_fix.patch 6458 2007-03-02 16:12:30Z nbd $ FAU
19984 +  */
19985 + 
19986 ++#ifndef __SCHED_H
19987 ++#define __SCHED_H
19988 ++
19989 ++#include <sys/time.h>
19990 ++
19991 + struct event
19992 + {
19993 +   struct event *next;
19994 +@@ -41,3 +46,5 @@
19995 + #define EV_READ		1
19996 + #define EV_WRITE	2
19997 + #define EV_ALWAYS	3
19998 ++
19999 ++#endif
20000 diff -Nur kamikaze_7.09.orig/package/tcpdump/Makefile kamikaze_7.09/package/tcpdump/Makefile
20001 --- kamikaze_7.09.orig/package/tcpdump/Makefile	1970-01-01 01:00:00.000000000 +0100
20002 +++ kamikaze_7.09/package/tcpdump/Makefile	2008-06-19 17:34:17.000000000 +0200
20003 @@ -0,0 +1,58 @@
20004 +# 
20005 +# Copyright (C) 2007 OpenWrt.org
20006 +#
20007 +# This is free software, licensed under the GNU General Public License v2.
20008 +# See /LICENSE for more information.
20009 +#
20010 +# $Id: Makefile 9695 2007-12-09 18:59:01Z nbd $
20011 +
20012 +include $(TOPDIR)/rules.mk
20013 +
20014 +PKG_NAME:=tcpdump
20015 +PKG_VERSION:=3.9.8
20016 +PKG_RELEASE:=1
20017 +
20018 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
20019 +PKG_SOURCE_URL:=http://www.tcpdump.org/release/ \
20020 +	http://ftp.gwdg.de/pub/misc/tcpdump/ \
20021 +	http://www.at.tcpdump.org/ \
20022 +	http://www.br.tcpdump.org/
20023 +PKG_MD5SUM:=c491a78c52fe73f1f7271aa5d8c6ab2e
20024 +
20025 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
20026 +PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
20027 +
20028 +include $(INCLUDE_DIR)/package.mk
20029 +
20030 +define Package/tcpdump
20031 +  SECTION:=net
20032 +  CATEGORY:=Network
20033 +  DEPENDS:=+libpcap
20034 +  TITLE:=Network monitoring and data acquisition tool
20035 +  URL:=http://www.tcpdump.org/
20036 +endef
20037 +
20038 +define Build/Configure
20039 +	$(call Build/Configure/Default, \
20040 +		--enable-ipv6 \
20041 +		--without-crypto \
20042 +		, \
20043 +		BUILD_CC="$(TARGET_CC)" \
20044 +		HOSTCC="$(HOSTCC)" \
20045 +		td_cv_buggygetaddrinfo="no" \
20046 +	)
20047 +endef
20048 +
20049 +define Build/Compile
20050 +	$(MAKE) -C $(PKG_BUILD_DIR) \
20051 +		CCOPT="$(TARGET_CFLAGS)" INCLS="-I. -I$(STAGING_DIR)/usr/include" \
20052 +		DESTDIR="$(PKG_INSTALL_DIR)" \
20053 +		all install
20054 +endef
20055 +
20056 +define Package/tcpdump/install
20057 +	$(INSTALL_DIR) $(1)/usr/sbin
20058 +	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/tcpdump $(1)/usr/sbin/
20059 +endef
20060 +
20061 +$(eval $(call BuildPackage,tcpdump))
20062 diff -Nur kamikaze_7.09.orig/package/tcpdump/patches/001-remove_pcap_debug.patch kamikaze_7.09/package/tcpdump/patches/001-remove_pcap_debug.patch
20063 --- kamikaze_7.09.orig/package/tcpdump/patches/001-remove_pcap_debug.patch	1970-01-01 01:00:00.000000000 +0100
20064 +++ kamikaze_7.09/package/tcpdump/patches/001-remove_pcap_debug.patch	2008-06-19 17:34:17.000000000 +0200
20065 @@ -0,0 +1,24 @@
20066 +diff -urN tcpdump-3.9.4.orig/tcpdump.c tcpdump-3.9.4/tcpdump.c
20067 +--- tcpdump-3.9.4.orig/tcpdump.c	2005-08-23 12:29:41.000000000 +0200
20068 ++++ tcpdump-3.9.4/tcpdump.c	2006-02-05 17:52:37.000000000 +0100
20069 +@@ -762,20 +762,6 @@
20070 + 				error("invalid data link type %s", gndo->ndo_dltname);
20071 + 			break;
20072 + 
20073 +-#if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
20074 +-		case 'Y':
20075 +-			{
20076 +-			/* Undocumented flag */
20077 +-#ifdef HAVE_PCAP_DEBUG
20078 +-			extern int pcap_debug;
20079 +-			pcap_debug = 1;
20080 +-#else
20081 +-			extern int yydebug;
20082 +-			yydebug = 1;
20083 +-#endif
20084 +-			}
20085 +-			break;
20086 +-#endif
20087 + 		case 'Z':
20088 + 			if (optarg) {
20089 + 				username = strdup(optarg);
20090 diff -Nur kamikaze_7.09.orig/target/linux/generic-2.6/files/drivers/leds/leds-alix.c kamikaze_7.09/target/linux/generic-2.6/files/drivers/leds/leds-alix.c
20091 --- kamikaze_7.09.orig/target/linux/generic-2.6/files/drivers/leds/leds-alix.c	1970-01-01 01:00:00.000000000 +0100
20092 +++ kamikaze_7.09/target/linux/generic-2.6/files/drivers/leds/leds-alix.c	2008-06-19 17:34:17.000000000 +0200
20093 @@ -0,0 +1,172 @@
20094 +/*
20095 + * LEDs driver for PCEngines ALIX 2/3 series
20096 + *
20097 + * Copyright (C) 2007 Petr Leibman
20098 + *
20099 + * Based on leds-wrap.c
20100 + *
20101 + * This program is free software; you can redistribute it and/or modify
20102 + * it under the terms of the GNU General Public License version 2 as
20103 + * published by the Free Software Foundation.
20104 + */
20105 +
20106 +#include <linux/kernel.h>
20107 +#include <linux/init.h>
20108 +#include <linux/platform_device.h>
20109 +#include <linux/leds.h>
20110 +#include <linux/err.h>
20111 +#include <asm/io.h>
20112 +
20113 +#define DRVNAME "alix-led"
20114 +
20115 +#define ALIX_LED1_PORT		(0x6100)
20116 +#define ALIX_LED1_ON		(1<<22)
20117 +#define ALIX_LED1_OFF		(1<<6)
20118 +
20119 +#define ALIX_LED2_PORT		(0x6180)
20120 +#define ALIX_LED2_ON		(1<<25)
20121 +#define ALIX_LED2_OFF		(1<<9)
20122 +
20123 +#define ALIX_LED3_PORT		(0x6180)
20124 +#define ALIX_LED3_ON		(1<<27)
20125 +#define ALIX_LED3_OFF		(1<<11)
20126 +
20127 +
20128 +static struct platform_device *pdev;
20129 +
20130 +static void alix_led_set_1(struct led_classdev *led_cdev,
20131 +		enum led_brightness value)
20132 +{
20133 +	if (value)
20134 +		outl(ALIX_LED1_ON, ALIX_LED1_PORT);
20135 +	else
20136 +		outl(ALIX_LED1_OFF, ALIX_LED1_PORT);
20137 +}
20138 +
20139 +static void alix_led_set_2(struct led_classdev *led_cdev,
20140 +		enum led_brightness value)
20141 +{
20142 +	if (value)
20143 +		outl(ALIX_LED2_ON, ALIX_LED2_PORT);
20144 +	else
20145 +		outl(ALIX_LED2_OFF, ALIX_LED2_PORT);
20146 +}
20147 +
20148 +static void alix_led_set_3(struct led_classdev *led_cdev,
20149 +		enum led_brightness value)
20150 +{
20151 +	if (value)
20152 +		outl(ALIX_LED3_ON, ALIX_LED3_PORT);
20153 +	else
20154 +		outl(ALIX_LED3_OFF, ALIX_LED3_PORT);
20155 +}
20156 +
20157 +static struct led_classdev alix_led_1 = {
20158 +	.name		= "alix:1",
20159 +	.brightness_set	= alix_led_set_1,
20160 +};
20161 +
20162 +static struct led_classdev alix_led_2 = {
20163 +	.name		= "alix:2",
20164 +	.brightness_set	= alix_led_set_2,
20165 +};
20166 +
20167 +static struct led_classdev alix_led_3 = {
20168 +	.name		= "alix:3",
20169 +	.brightness_set	= alix_led_set_3,
20170 +};
20171 +
20172 +
20173 +#ifdef CONFIG_PM
20174 +static int alix_led_suspend(struct platform_device *dev,
20175 +		pm_message_t state)
20176 +{
20177 +	led_classdev_suspend(&alix_led_1);
20178 +	led_classdev_suspend(&alix_led_2);
20179 +	led_classdev_suspend(&alix_led_3);
20180 +	return 0;
20181 +}
20182 +
20183 +static int alix_led_resume(struct platform_device *dev)
20184 +{
20185 +	led_classdev_resume(&alix_led_1);
20186 +	led_classdev_resume(&alix_led_2);
20187 +	led_classdev_resume(&alix_led_3);
20188 +	return 0;
20189 +}
20190 +#else
20191 +#define alix_led_suspend NULL
20192 +#define alix_led_resume NULL
20193 +#endif
20194 +
20195 +static int alix_led_probe(struct platform_device *pdev)
20196 +{
20197 +	int ret;
20198 +
20199 +	ret = led_classdev_register(&pdev->dev, &alix_led_1);
20200 +	if (ret == 0)
20201 +	{
20202 +		ret = led_classdev_register(&pdev->dev, &alix_led_2);
20203 +		if (ret >= 0)
20204 +		{
20205 +			ret = led_classdev_register(&pdev->dev, &alix_led_3);
20206 +			if (ret < 0)
20207 +				led_classdev_unregister(&alix_led_2);
20208 +		}
20209 +		if (ret < 0)
20210 +			led_classdev_unregister(&alix_led_1);
20211 +	}
20212 +	return ret;
20213 +}
20214 +
20215 +static int alix_led_remove(struct platform_device *pdev)
20216 +{
20217 +	led_classdev_unregister(&alix_led_1);
20218 +	led_classdev_unregister(&alix_led_2);
20219 +	led_classdev_unregister(&alix_led_3);
20220 +	return 0;
20221 +}
20222 +
20223 +static struct platform_driver alix_led_driver = {
20224 +	.probe		= alix_led_probe,
20225 +	.remove		= alix_led_remove,
20226 +	.suspend	= alix_led_suspend,
20227 +	.resume		= alix_led_resume,
20228 +	.driver		= {
20229 +		.name		= DRVNAME,
20230 +		.owner		= THIS_MODULE,
20231 +	},
20232 +};
20233 +
20234 +static int __init alix_led_init(void)
20235 +{
20236 +	int ret;
20237 +
20238 +	ret = platform_driver_register(&alix_led_driver);
20239 +	if (ret < 0)
20240 +		goto out;
20241 +
20242 +	pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
20243 +	if (IS_ERR(pdev)) {
20244 +		ret = PTR_ERR(pdev);
20245 +		platform_driver_unregister(&alix_led_driver);
20246 +		goto out;
20247 +	}
20248 +
20249 +out:
20250 +	return ret;
20251 +}
20252 +
20253 +static void __exit alix_led_exit(void)
20254 +{
20255 +	platform_device_unregister(pdev);
20256 +	platform_driver_unregister(&alix_led_driver);
20257 +}
20258 +
20259 +module_init(alix_led_init);
20260 +module_exit(alix_led_exit);
20261 +
20262 +MODULE_AUTHOR("Petr Leibman");
20263 +MODULE_DESCRIPTION("PCEngines ALIX LED driver");
20264 +MODULE_LICENSE("GPL");
20265 +
20266 diff -Nur kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/401-led-alix.patch kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/401-led-alix.patch
20267 --- kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/401-led-alix.patch	1970-01-01 01:00:00.000000000 +0100
20268 +++ kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/401-led-alix.patch	2008-06-19 17:34:17.000000000 +0200
20269 @@ -0,0 +1,28 @@
20270 +diff -Nur linux-2.6.22.1.orig/drivers/leds/Kconfig linux-2.6.22.1/drivers/leds/Kconfig
20271 +--- linux-2.6.22.1.orig/drivers/leds/Kconfig	2006-10-12 12:43:44.000000000 -0400
20272 ++++ linux-2.6.22.1/drivers/leds/Kconfig	2006-10-31 02:36:22.000000000 -0400
20273 +@@ -83,6 +83,12 @@
20274 + 	help
20275 + 	  This option enables support for the PCEngines WRAP programmable LEDs.
20276 + 
20277 ++config LEDS_ALIX
20278 ++	tristate "LED Support for the ALIX 2/3 boards"
20279 ++	depends on LEDS_CLASS
20280 ++	help
20281 ++	  This option enables support for the three LEDs on the PCEngines ALIX 2/3 boards.
20282 ++
20283 + config LEDS_H1940
20284 + 	tristate "LED Support for iPAQ H1940 device"
20285 + 	depends LEDS_CLASS && ARCH_H1940
20286 +diff -Nur linux-2.6.22.1.orig/drivers/leds/Makefile linux-2.6.22.1/drivers/leds/Makefile
20287 +--- linux-2.6.22.1.orig/drivers/leds/Makefile	2006-10-12 12:43:44.000000000 -0400
20288 ++++ linux-2.6.22.1/drivers/leds/Makefile	2006-10-31 02:36:17.000000000 -0400
20289 +@@ -14,6 +14,7 @@
20290 + obj-$(CONFIG_LEDS_AMS_DELTA)		+= leds-ams-delta.o
20291 + obj-$(CONFIG_LEDS_NET48XX)		+= leds-net48xx.o
20292 + obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
20293 ++obj-$(CONFIG_LEDS_ALIX)			+= leds-alix.o
20294 + obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o
20295 + obj-$(CONFIG_LEDS_COBALT)		+= leds-cobalt.o
20296 + obj-$(CONFIG_LEDS_GPIO)			+= leds-gpio.o
20297 +
20298 diff -Nur kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/410-linux_ocf_kernel.patch kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/410-linux_ocf_kernel.patch
20299 --- kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/410-linux_ocf_kernel.patch	1970-01-01 01:00:00.000000000 +0100
20300 +++ kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/410-linux_ocf_kernel.patch	2008-06-19 17:34:17.000000000 +0200
20301 @@ -0,0 +1,19412 @@
20302 +diff -urN linux-2.6.23.16.old/crypto/Kconfig linux-2.6.23.16/crypto/Kconfig
20303 +--- linux-2.6.23.16.old/crypto/Kconfig	2008-02-26 09:26:41.000000000 -0500
20304 ++++ linux-2.6.23.16/crypto/Kconfig	2008-02-26 09:29:13.000000000 -0500
20305 +@@ -464,4 +464,6 @@
20306 + 
20307 + endif  # if CRYPTO
20308 + 
20309 ++source "crypto/ocf/Kconfig"
20310 ++
20311 + endmenu
20312 +diff -urN linux-2.6.23.16.old/crypto/Makefile linux-2.6.23.16/crypto/Makefile
20313 +--- linux-2.6.23.16.old/crypto/Makefile	2008-02-26 09:26:41.000000000 -0500
20314 ++++ linux-2.6.23.16/crypto/Makefile	2008-02-26 09:29:13.000000000 -0500
20315 +@@ -50,3 +50,5 @@
20316 + obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
20317 + 
20318 + obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
20319 ++
20320 ++obj-$(CONFIG_OCF_OCF) += ocf/
20321 +diff -urN linux-2.6.23.16.old/crypto/ocf/Config.in linux-2.6.23.16/crypto/ocf/Config.in
20322 +--- linux-2.6.23.16.old/crypto/ocf/Config.in	1969-12-31 19:00:00.000000000 -0500
20323 ++++ linux-2.6.23.16/crypto/ocf/Config.in	2008-02-26 09:29:13.000000000 -0500
20324 +@@ -0,0 +1,32 @@
20325 ++#############################################################################
20326 ++
20327 ++mainmenu_option next_comment
20328 ++comment 'OCF Configuration'
20329 ++tristate 'OCF (Open Cryptograhic Framework)' CONFIG_OCF_OCF
20330 ++dep_tristate '  enable fips RNG checks (fips check on RNG data before use)' \
20331 ++				CONFIG_OCF_FIPS $CONFIG_OCF_OCF
20332 ++dep_tristate '  enable harvesting entropy for /dev/random' \
20333 ++				CONFIG_OCF_RANDOMHARVEST $CONFIG_OCF_OCF
20334 ++dep_tristate '  cryptodev (user space support)' \
20335 ++				CONFIG_OCF_CRYPTODEV $CONFIG_OCF_OCF
20336 ++dep_tristate '  cryptosoft (software crypto engine)' \
20337 ++				CONFIG_OCF_CRYPTOSOFT $CONFIG_OCF_OCF
20338 ++dep_tristate '  safenet (HW crypto engine)' \
20339 ++				CONFIG_OCF_SAFE $CONFIG_OCF_OCF
20340 ++dep_tristate '  IXP4xx (HW crypto engine)' \
20341 ++				CONFIG_OCF_IXP4XX $CONFIG_OCF_OCF
20342 ++dep_mbool    '  Enable IXP4xx HW to perform SHA1 and MD5 hashing (very slow)' \
20343 ++				CONFIG_OCF_IXP4XX_SHA1_MD5 $CONFIG_OCF_IXP4XX
20344 ++dep_tristate '  hifn (HW crypto engine)' \
20345 ++				CONFIG_OCF_HIFN $CONFIG_OCF_OCF
20346 ++dep_tristate '  talitos (HW crypto engine)' \
20347 ++				CONFIG_OCF_TALITOS $CONFIG_OCF_OCF
20348 ++dep_tristate '  pasemi (HW crypto engine)' \
20349 ++				CONFIG_OCF_PASEMI $CONFIG_OCF_OCF
20350 ++dep_tristate '  ocfnull (does no crypto)' \
20351 ++				CONFIG_OCF_OCFNULL $CONFIG_OCF_OCF
20352 ++dep_tristate '  ocf-bench (HW crypto in-kernel benchmark)' \
20353 ++				CONFIG_OCF_BENCH $CONFIG_OCF_OCF
20354 ++endmenu
20355 ++
20356 ++#############################################################################
20357 +diff -urN linux-2.6.23.16.old/crypto/ocf/criov.c linux-2.6.23.16/crypto/ocf/criov.c
20358 +--- linux-2.6.23.16.old/crypto/ocf/criov.c	1969-12-31 19:00:00.000000000 -0500
20359 ++++ linux-2.6.23.16/crypto/ocf/criov.c	2008-02-26 09:29:13.000000000 -0500
20360 +@@ -0,0 +1,215 @@
20361 ++/*      $OpenBSD: criov.c,v 1.9 2002/01/29 15:48:29 jason Exp $	*/
20362 ++
20363 ++/*
20364 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
20365 ++ * Copyright (C) 2006-2007 David McCullough
20366 ++ * Copyright (C) 2004-2005 Intel Corporation.
20367 ++ * The license and original author are listed below.
20368 ++ *
20369 ++ * Copyright (c) 1999 Theo de Raadt
20370 ++ *
20371 ++ * Redistribution and use in source and binary forms, with or without
20372 ++ * modification, are permitted provided that the following conditions
20373 ++ * are met:
20374 ++ *
20375 ++ * 1. Redistributions of source code must retain the above copyright
20376 ++ *   notice, this list of conditions and the following disclaimer.
20377 ++ * 2. Redistributions in binary form must reproduce the above copyright
20378 ++ *   notice, this list of conditions and the following disclaimer in the
20379 ++ *   documentation and/or other materials provided with the distribution.
20380 ++ * 3. The name of the author may not be used to endorse or promote products
20381 ++ *   derived from this software without specific prior written permission.
20382 ++ *
20383 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20384 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20385 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20386 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20387 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20388 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20389 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20390 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20391 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20392 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20393 ++ *
20394 ++__FBSDID("$FreeBSD: src/sys/opencrypto/criov.c,v 1.5 2006/06/04 22:15:13 pjd Exp $");
20395 ++ */
20396 ++
20397 ++#ifndef AUTOCONF_INCLUDED
20398 ++#include <linux/config.h>
20399 ++#endif
20400 ++#include <linux/module.h>
20401 ++#include <linux/init.h>
20402 ++#include <linux/slab.h>
20403 ++#include <linux/uio.h>
20404 ++#include <linux/skbuff.h>
20405 ++#include <linux/kernel.h>
20406 ++#include <linux/mm.h>
20407 ++#include <asm/io.h>
20408 ++
20409 ++#include <uio.h>
20410 ++#include <cryptodev.h>
20411 ++
20412 ++/*
20413 ++ * This macro is only for avoiding code duplication, as we need to skip
20414 ++ * given number of bytes in the same way in three functions below.
20415 ++ */
20416 ++#define	CUIO_SKIP()	do {						\
20417 ++	KASSERT(off >= 0, ("%s: off %d < 0", __func__, off));		\
20418 ++	KASSERT(len >= 0, ("%s: len %d < 0", __func__, len));		\
20419 ++	while (off > 0) {						\
20420 ++		KASSERT(iol >= 0, ("%s: empty in skip", __func__));	\
20421 ++		if (off < iov->iov_len)					\
20422 ++			break;						\
20423 ++		off -= iov->iov_len;					\
20424 ++		iol--;							\
20425 ++		iov++;							\
20426 ++	}								\
20427 ++} while (0)
20428 ++
20429 ++void
20430 ++cuio_copydata(struct uio* uio, int off, int len, caddr_t cp)
20431 ++{
20432 ++	struct iovec *iov = uio->uio_iov;
20433 ++	int iol = uio->uio_iovcnt;
20434 ++	unsigned count;
20435 ++
20436 ++	CUIO_SKIP();
20437 ++	while (len > 0) {
20438 ++		KASSERT(iol >= 0, ("%s: empty", __func__));
20439 ++		count = min((int)(iov->iov_len - off), len);
20440 ++		memcpy(cp, ((caddr_t)iov->iov_base) + off, count);
20441 ++		len -= count;
20442 ++		cp += count;
20443 ++		off = 0;
20444 ++		iol--;
20445 ++		iov++;
20446 ++	}
20447 ++}
20448 ++
20449 ++void
20450 ++cuio_copyback(struct uio* uio, int off, int len, caddr_t cp)
20451 ++{
20452 ++	struct iovec *iov = uio->uio_iov;
20453 ++	int iol = uio->uio_iovcnt;
20454 ++	unsigned count;
20455 ++
20456 ++	CUIO_SKIP();
20457 ++	while (len > 0) {
20458 ++		KASSERT(iol >= 0, ("%s: empty", __func__));
20459 ++		count = min((int)(iov->iov_len - off), len);
20460 ++		memcpy(((caddr_t)iov->iov_base) + off, cp, count);
20461 ++		len -= count;
20462 ++		cp += count;
20463 ++		off = 0;
20464 ++		iol--;
20465 ++		iov++;
20466 ++	}
20467 ++}
20468 ++
20469 ++/*
20470 ++ * Return a pointer to iov/offset of location in iovec list.
20471 ++ */
20472 ++struct iovec *
20473 ++cuio_getptr(struct uio *uio, int loc, int *off)
20474 ++{
20475 ++	struct iovec *iov = uio->uio_iov;
20476 ++	int iol = uio->uio_iovcnt;
20477 ++
20478 ++	while (loc >= 0) {
20479 ++		/* Normal end of search */
20480 ++		if (loc < iov->iov_len) {
20481 ++	    		*off = loc;
20482 ++	    		return (iov);
20483 ++		}
20484 ++
20485 ++		loc -= iov->iov_len;
20486 ++		if (iol == 0) {
20487 ++			if (loc == 0) {
20488 ++				/* Point at the end of valid data */
20489 ++				*off = iov->iov_len;
20490 ++				return (iov);
20491 ++			} else
20492 ++				return (NULL);
20493 ++		} else {
20494 ++			iov++, iol--;
20495 ++		}
20496 ++    	}
20497 ++
20498 ++	return (NULL);
20499 ++}
20500 ++
20501 ++EXPORT_SYMBOL(cuio_copyback);
20502 ++EXPORT_SYMBOL(cuio_copydata);
20503 ++EXPORT_SYMBOL(cuio_getptr);
20504 ++
20505 ++
20506 ++static void
20507 ++skb_copy_bits_back(struct sk_buff *skb, int offset, caddr_t cp, int len)
20508 ++{
20509 ++	int i;
20510 ++	if (offset < skb_headlen(skb)) {
20511 ++		memcpy(skb->data + offset, cp, min_t(int, skb_headlen(skb), len));
20512 ++		len -= skb_headlen(skb);
20513 ++		cp += skb_headlen(skb);
20514 ++	}
20515 ++	offset -= skb_headlen(skb);
20516 ++	for (i = 0; len > 0 && i < skb_shinfo(skb)->nr_frags; i++) {
20517 ++		if (offset < skb_shinfo(skb)->frags[i].size) {
20518 ++			memcpy(page_address(skb_shinfo(skb)->frags[i].page) +
20519 ++					skb_shinfo(skb)->frags[i].page_offset,
20520 ++					cp, min_t(int, skb_shinfo(skb)->frags[i].size, len));
20521 ++			len -= skb_shinfo(skb)->frags[i].size;
20522 ++			cp += skb_shinfo(skb)->frags[i].size;
20523 ++		}
20524 ++		offset -= skb_shinfo(skb)->frags[i].size;
20525 ++	}
20526 ++}
20527 ++
20528 ++void
20529 ++crypto_copyback(int flags, caddr_t buf, int off, int size, caddr_t in)
20530 ++{
20531 ++
20532 ++	if ((flags & CRYPTO_F_SKBUF) != 0)
20533 ++		skb_copy_bits_back((struct sk_buff *)buf, off, in, size);
20534 ++	else if ((flags & CRYPTO_F_IOV) != 0)
20535 ++		cuio_copyback((struct uio *)buf, off, size, in);
20536 ++	else
20537 ++		bcopy(in, buf + off, size);
20538 ++}
20539 ++
20540 ++void
20541 ++crypto_copydata(int flags, caddr_t buf, int off, int size, caddr_t out)
20542 ++{
20543 ++
20544 ++	if ((flags & CRYPTO_F_SKBUF) != 0)
20545 ++		skb_copy_bits((struct sk_buff *)buf, off, out, size);
20546 ++	else if ((flags & CRYPTO_F_IOV) != 0)
20547 ++		cuio_copydata((struct uio *)buf, off, size, out);
20548 ++	else
20549 ++		bcopy(buf + off, out, size);
20550 ++}
20551 ++
20552 ++int
20553 ++crypto_apply(int flags, caddr_t buf, int off, int len,
20554 ++    int (*f)(void *, void *, u_int), void *arg)
20555 ++{
20556 ++#if 0
20557 ++	int error;
20558 ++
20559 ++	if ((flags & CRYPTO_F_SKBUF) != 0)
20560 ++		error = XXXXXX((struct mbuf *)buf, off, len, f, arg);
20561 ++	else if ((flags & CRYPTO_F_IOV) != 0)
20562 ++		error = cuio_apply((struct uio *)buf, off, len, f, arg);
20563 ++	else
20564 ++		error = (*f)(arg, buf + off, len);
20565 ++	return (error);
20566 ++#else
20567 ++	KASSERT(0, ("crypto_apply not implemented!\n"));
20568 ++#endif
20569 ++	return 0;
20570 ++}
20571 ++
20572 ++EXPORT_SYMBOL(crypto_copyback);
20573 ++EXPORT_SYMBOL(crypto_copydata);
20574 ++EXPORT_SYMBOL(crypto_apply);
20575 ++
20576 +diff -urN linux-2.6.23.16.old/crypto/ocf/crypto.c linux-2.6.23.16/crypto/ocf/crypto.c
20577 +--- linux-2.6.23.16.old/crypto/ocf/crypto.c	1969-12-31 19:00:00.000000000 -0500
20578 ++++ linux-2.6.23.16/crypto/ocf/crypto.c	2008-02-26 09:29:13.000000000 -0500
20579 +@@ -0,0 +1,1715 @@
20580 ++/*-
20581 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
20582 ++ * Copyright (C) 2006-2007 David McCullough
20583 ++ * Copyright (C) 2004-2005 Intel Corporation.
20584 ++ * The license and original author are listed below.
20585 ++ *
20586 ++ * Redistribution and use in source and binary forms, with or without
20587 ++ * Copyright (c) 2002-2006 Sam Leffler.  All rights reserved.
20588 ++ *
20589 ++ * modification, are permitted provided that the following conditions
20590 ++ * are met:
20591 ++ * 1. Redistributions of source code must retain the above copyright
20592 ++ *    notice, this list of conditions and the following disclaimer.
20593 ++ * 2. Redistributions in binary form must reproduce the above copyright
20594 ++ *    notice, this list of conditions and the following disclaimer in the
20595 ++ *    documentation and/or other materials provided with the distribution.
20596 ++ *
20597 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20598 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20599 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20600 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20601 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20602 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20603 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20604 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20605 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20606 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20607 ++ */
20608 ++
20609 ++#if 0
20610 ++#include <sys/cdefs.h>
20611 ++__FBSDID("$FreeBSD: src/sys/opencrypto/crypto.c,v 1.27 2007/03/21 03:42:51 sam Exp $");
20612 ++#endif
20613 ++
20614 ++/*
20615 ++ * Cryptographic Subsystem.
20616 ++ *
20617 ++ * This code is derived from the Openbsd Cryptographic Framework (OCF)
20618 ++ * that has the copyright shown below.  Very little of the original
20619 ++ * code remains.
20620 ++ */
20621 ++/*-
20622 ++ * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
20623 ++ *
20624 ++ * This code was written by Angelos D. Keromytis in Athens, Greece, in
20625 ++ * February 2000. Network Security Technologies Inc. (NSTI) kindly
20626 ++ * supported the development of this code.
20627 ++ *
20628 ++ * Copyright (c) 2000, 2001 Angelos D. Keromytis
20629 ++ *
20630 ++ * Permission to use, copy, and modify this software with or without fee
20631 ++ * is hereby granted, provided that this entire notice is included in
20632 ++ * all source code copies of any software which is or includes a copy or
20633 ++ * modification of this software.
20634 ++ *
20635 ++ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
20636 ++ * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
20637 ++ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
20638 ++ * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
20639 ++ * PURPOSE.
20640 ++ *
20641 ++__FBSDID("$FreeBSD: src/sys/opencrypto/crypto.c,v 1.16 2005/01/07 02:29:16 imp Exp $");
20642 ++ */
20643 ++
20644 ++
20645 ++#ifndef AUTOCONF_INCLUDED
20646 ++#include <linux/config.h>
20647 ++#endif
20648 ++#include <linux/module.h>
20649 ++#include <linux/init.h>
20650 ++#include <linux/list.h>
20651 ++#include <linux/slab.h>
20652 ++#include <linux/wait.h>
20653 ++#include <linux/sched.h>
20654 ++#include <linux/spinlock.h>
20655 ++#include <linux/version.h>
20656 ++#include <cryptodev.h>
20657 ++
20658 ++/*
20659 ++ * keep track of whether or not we have been initialised, a big
20660 ++ * issue if we are linked into the kernel and a driver gets started before
20661 ++ * us
20662 ++ */
20663 ++static int crypto_initted = 0;
20664 ++
20665 ++/*
20666 ++ * Crypto drivers register themselves by allocating a slot in the
20667 ++ * crypto_drivers table with crypto_get_driverid() and then registering
20668 ++ * each algorithm they support with crypto_register() and crypto_kregister().
20669 ++ */
20670 ++
20671 ++/*
20672 ++ * lock on driver table
20673 ++ * we track its state as spin_is_locked does not do anything on non-SMP boxes
20674 ++ */
20675 ++static spinlock_t	crypto_drivers_lock;
20676 ++static int			crypto_drivers_locked;		/* for non-SMP boxes */
20677 ++
20678 ++#define	CRYPTO_DRIVER_LOCK() \
20679 ++			({ \
20680 ++				spin_lock_irqsave(&crypto_drivers_lock, d_flags); \
20681 ++			 	crypto_drivers_locked = 1; \
20682 ++				dprintk("%s,%d: DRIVER_LOCK()\n", __FILE__, __LINE__); \
20683 ++			 })
20684 ++#define	CRYPTO_DRIVER_UNLOCK() \
20685 ++			({ \
20686 ++			 	dprintk("%s,%d: DRIVER_UNLOCK()\n", __FILE__, __LINE__); \
20687 ++			 	crypto_drivers_locked = 0; \
20688 ++				spin_unlock_irqrestore(&crypto_drivers_lock, d_flags); \
20689 ++			 })
20690 ++#define	CRYPTO_DRIVER_ASSERT() \
20691 ++			({ \
20692 ++			 	if (!crypto_drivers_locked) { \
20693 ++					dprintk("%s,%d: DRIVER_ASSERT!\n", __FILE__, __LINE__); \
20694 ++			 	} \
20695 ++			 })
20696 ++
20697 ++/*
20698 ++ * Crypto device/driver capabilities structure.
20699 ++ *
20700 ++ * Synchronization:
20701 ++ * (d) - protected by CRYPTO_DRIVER_LOCK()
20702 ++ * (q) - protected by CRYPTO_Q_LOCK()
20703 ++ * Not tagged fields are read-only.
20704 ++ */
20705 ++struct cryptocap {
20706 ++	device_t	cc_dev;			/* (d) device/driver */
20707 ++	u_int32_t	cc_sessions;		/* (d) # of sessions */
20708 ++	u_int32_t	cc_koperations;		/* (d) # os asym operations */
20709 ++	/*
20710 ++	 * Largest possible operator length (in bits) for each type of
20711 ++	 * encryption algorithm. XXX not used
20712 ++	 */
20713 ++	u_int16_t	cc_max_op_len[CRYPTO_ALGORITHM_MAX + 1];
20714 ++	u_int8_t	cc_alg[CRYPTO_ALGORITHM_MAX + 1];
20715 ++	u_int8_t	cc_kalg[CRK_ALGORITHM_MAX + 1];
20716 ++
20717 ++	int		cc_flags;		/* (d) flags */
20718 ++#define CRYPTOCAP_F_CLEANUP	0x80000000	/* needs resource cleanup */
20719 ++	int		cc_qblocked;		/* (q) symmetric q blocked */
20720 ++	int		cc_kqblocked;		/* (q) asymmetric q blocked */
20721 ++};
20722 ++static struct cryptocap *crypto_drivers = NULL;
20723 ++static int crypto_drivers_num = 0;
20724 ++
20725 ++/*
20726 ++ * There are two queues for crypto requests; one for symmetric (e.g.
20727 ++ * cipher) operations and one for asymmetric (e.g. MOD)operations.
20728 ++ * A single mutex is used to lock access to both queues.  We could
20729 ++ * have one per-queue but having one simplifies handling of block/unblock
20730 ++ * operations.
20731 ++ */
20732 ++static	int crp_sleep = 0;
20733 ++static LIST_HEAD(crp_q);		/* request queues */
20734 ++static LIST_HEAD(crp_kq);
20735 ++
20736 ++static spinlock_t crypto_q_lock;
20737 ++
20738 ++static int crypto_all_qblocked = 0;  /* protect with Q_LOCK */
20739 ++static int crypto_all_kqblocked = 0; /* protect with Q_LOCK */
20740 ++
20741 ++#define	CRYPTO_Q_LOCK() \
20742 ++			({ \
20743 ++				spin_lock_irqsave(&crypto_q_lock, q_flags); \
20744 ++			 	dprintk("%s,%d: Q_LOCK()\n", __FILE__, __LINE__); \
20745 ++			 })
20746 ++#define	CRYPTO_Q_UNLOCK() \
20747 ++			({ \
20748 ++			 	dprintk("%s,%d: Q_UNLOCK()\n", __FILE__, __LINE__); \
20749 ++				spin_unlock_irqrestore(&crypto_q_lock, q_flags); \
20750 ++			 })
20751 ++
20752 ++/*
20753 ++ * There are two queues for processing completed crypto requests; one
20754 ++ * for the symmetric and one for the asymmetric ops.  We only need one
20755 ++ * but have two to avoid type futzing (cryptop vs. cryptkop).  A single
20756 ++ * mutex is used to lock access to both queues.  Note that this lock
20757 ++ * must be separate from the lock on request queues to insure driver
20758 ++ * callbacks don't generate lock order reversals.
20759 ++ */
20760 ++static LIST_HEAD(crp_ret_q);		/* callback queues */
20761 ++static LIST_HEAD(crp_ret_kq);
20762 ++
20763 ++static spinlock_t crypto_ret_q_lock;
20764 ++#define	CRYPTO_RETQ_LOCK() \
20765 ++			({ \
20766 ++				spin_lock_irqsave(&crypto_ret_q_lock, r_flags); \
20767 ++				dprintk("%s,%d: RETQ_LOCK\n", __FILE__, __LINE__); \
20768 ++			 })
20769 ++#define	CRYPTO_RETQ_UNLOCK() \
20770 ++			({ \
20771 ++			 	dprintk("%s,%d: RETQ_UNLOCK\n", __FILE__, __LINE__); \
20772 ++				spin_unlock_irqrestore(&crypto_ret_q_lock, r_flags); \
20773 ++			 })
20774 ++#define	CRYPTO_RETQ_EMPTY()	(list_empty(&crp_ret_q) && list_empty(&crp_ret_kq))
20775 ++
20776 ++static struct kmem_cache *cryptop_zone;
20777 ++static struct kmem_cache *cryptodesc_zone;
20778 ++
20779 ++#define debug crypto_debug
20780 ++int crypto_debug = 0;
20781 ++module_param(crypto_debug, int, 0644);
20782 ++MODULE_PARM_DESC(crypto_debug, "Enable debug");
20783 ++EXPORT_SYMBOL(crypto_debug);
20784 ++
20785 ++/*
20786 ++ * Maximum number of outstanding crypto requests before we start
20787 ++ * failing requests.  We need this to prevent DOS when too many
20788 ++ * requests are arriving for us to keep up.  Otherwise we will
20789 ++ * run the system out of memory.  Since crypto is slow,  we are
20790 ++ * usually the bottleneck that needs to say, enough is enough.
20791 ++ *
20792 ++ * We cannot print errors when this condition occurs,  we are already too
20793 ++ * slow,  printing anything will just kill us
20794 ++ */
20795 ++
20796 ++static atomic_t crypto_q_cnt;
20797 ++static int crypto_q_max = 1000;
20798 ++module_param(crypto_q_max, int, 0644);
20799 ++MODULE_PARM_DESC(crypto_q_max,
20800 ++		"Maximum number of outstanding crypto requests");
20801 ++
20802 ++#define bootverbose crypto_verbose
20803 ++static int crypto_verbose = 0;
20804 ++module_param(crypto_verbose, int, 0644);
20805 ++MODULE_PARM_DESC(crypto_verbose,
20806 ++		"Enable verbose crypto startup");
20807 ++
20808 ++int	crypto_usercrypto = 1;	/* userland may do crypto reqs */
20809 ++module_param(crypto_usercrypto, int, 0644);
20810 ++MODULE_PARM_DESC(crypto_usercrypto,
20811 ++	   "Enable/disable user-mode access to crypto support");
20812 ++
20813 ++int	crypto_userasymcrypto = 1;	/* userland may do asym crypto reqs */
20814 ++module_param(crypto_userasymcrypto, int, 0644);
20815 ++MODULE_PARM_DESC(crypto_userasymcrypto,
20816 ++	   "Enable/disable user-mode access to asymmetric crypto support");
20817 ++
20818 ++int	crypto_devallowsoft = 0;	/* only use hardware crypto */
20819 ++module_param(crypto_devallowsoft, int, 0644);
20820 ++MODULE_PARM_DESC(crypto_devallowsoft,
20821 ++	   "Enable/disable use of software crypto support");
20822 ++
20823 ++static pid_t	cryptoproc = (pid_t) -1;
20824 ++static struct	completion cryptoproc_exited;
20825 ++static DECLARE_WAIT_QUEUE_HEAD(cryptoproc_wait);
20826 ++static pid_t	cryptoretproc = (pid_t) -1;
20827 ++static struct	completion cryptoretproc_exited;
20828 ++static DECLARE_WAIT_QUEUE_HEAD(cryptoretproc_wait);
20829 ++
20830 ++static	int crypto_proc(void *arg);
20831 ++static	int crypto_ret_proc(void *arg);
20832 ++static	int crypto_invoke(struct cryptocap *cap, struct cryptop *crp, int hint);
20833 ++static	int crypto_kinvoke(struct cryptkop *krp, int flags);
20834 ++static	void crypto_exit(void);
20835 ++static  int crypto_init(void);
20836 ++
20837 ++static	struct cryptostats cryptostats;
20838 ++
20839 ++static struct cryptocap *
20840 ++crypto_checkdriver(u_int32_t hid)
20841 ++{
20842 ++	if (crypto_drivers == NULL)
20843 ++		return NULL;
20844 ++	return (hid >= crypto_drivers_num ? NULL : &crypto_drivers[hid]);
20845 ++}
20846 ++
20847 ++/*
20848 ++ * Compare a driver's list of supported algorithms against another
20849 ++ * list; return non-zero if all algorithms are supported.
20850 ++ */
20851 ++static int
20852 ++driver_suitable(const struct cryptocap *cap, const struct cryptoini *cri)
20853 ++{
20854 ++	const struct cryptoini *cr;
20855 ++
20856 ++	/* See if all the algorithms are supported. */
20857 ++	for (cr = cri; cr; cr = cr->cri_next)
20858 ++		if (cap->cc_alg[cr->cri_alg] == 0)
20859 ++			return 0;
20860 ++	return 1;
20861 ++}
20862 ++
20863 ++/*
20864 ++ * Select a driver for a new session that supports the specified
20865 ++ * algorithms and, optionally, is constrained according to the flags.
20866 ++ * The algorithm we use here is pretty stupid; just use the
20867 ++ * first driver that supports all the algorithms we need. If there
20868 ++ * are multiple drivers we choose the driver with the fewest active
20869 ++ * sessions.  We prefer hardware-backed drivers to software ones.
20870 ++ *
20871 ++ * XXX We need more smarts here (in real life too, but that's
20872 ++ * XXX another story altogether).
20873 ++ */
20874 ++static struct cryptocap *
20875 ++crypto_select_driver(const struct cryptoini *cri, int flags)
20876 ++{
20877 ++	struct cryptocap *cap, *best;
20878 ++	int match, hid;
20879 ++
20880 ++	CRYPTO_DRIVER_ASSERT();
20881 ++
20882 ++	/*
20883 ++	 * Look first for hardware crypto devices if permitted.
20884 ++	 */
20885 ++	if (flags & CRYPTOCAP_F_HARDWARE)
20886 ++		match = CRYPTOCAP_F_HARDWARE;
20887 ++	else
20888 ++		match = CRYPTOCAP_F_SOFTWARE;
20889 ++	best = NULL;
20890 ++again:
20891 ++	for (hid = 0; hid < crypto_drivers_num; hid++) {
20892 ++		cap = &crypto_drivers[hid];
20893 ++		/*
20894 ++		 * If it's not initialized, is in the process of
20895 ++		 * going away, or is not appropriate (hardware
20896 ++		 * or software based on match), then skip.
20897 ++		 */
20898 ++		if (cap->cc_dev == NULL ||
20899 ++		    (cap->cc_flags & CRYPTOCAP_F_CLEANUP) ||
20900 ++		    (cap->cc_flags & match) == 0)
20901 ++			continue;
20902 ++
20903 ++		/* verify all the algorithms are supported. */
20904 ++		if (driver_suitable(cap, cri)) {
20905 ++			if (best == NULL ||
20906 ++			    cap->cc_sessions < best->cc_sessions)
20907 ++				best = cap;
20908 ++		}
20909 ++	}
20910 ++	if (best != NULL)
20911 ++		return best;
20912 ++	if (match == CRYPTOCAP_F_HARDWARE && (flags & CRYPTOCAP_F_SOFTWARE)) {
20913 ++		/* sort of an Algol 68-style for loop */
20914 ++		match = CRYPTOCAP_F_SOFTWARE;
20915 ++		goto again;
20916 ++	}
20917 ++	return best;
20918 ++}
20919 ++
20920 ++/*
20921 ++ * Create a new session.  The crid argument specifies a crypto
20922 ++ * driver to use or constraints on a driver to select (hardware
20923 ++ * only, software only, either).  Whatever driver is selected
20924 ++ * must be capable of the requested crypto algorithms.
20925 ++ */
20926 ++int
20927 ++crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int crid)
20928 ++{
20929 ++	struct cryptocap *cap;
20930 ++	u_int32_t hid, lid;
20931 ++	int err;
20932 ++	unsigned long d_flags;
20933 ++
20934 ++	CRYPTO_DRIVER_LOCK();
20935 ++	if ((crid & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
20936 ++		/*
20937 ++		 * Use specified driver; verify it is capable.
20938 ++		 */
20939 ++		cap = crypto_checkdriver(crid);
20940 ++		if (cap != NULL && !driver_suitable(cap, cri))
20941 ++			cap = NULL;
20942 ++	} else {
20943 ++		/*
20944 ++		 * No requested driver; select based on crid flags.
20945 ++		 */
20946 ++		cap = crypto_select_driver(cri, crid);
20947 ++		/*
20948 ++		 * if NULL then can't do everything in one session.
20949 ++		 * XXX Fix this. We need to inject a "virtual" session
20950 ++		 * XXX layer right about here.
20951 ++		 */
20952 ++	}
20953 ++	if (cap != NULL) {
20954 ++		/* Call the driver initialization routine. */
20955 ++		hid = cap - crypto_drivers;
20956 ++		lid = hid;		/* Pass the driver ID. */
20957 ++		cap->cc_sessions++;
20958 ++		CRYPTO_DRIVER_UNLOCK();
20959 ++		err = CRYPTODEV_NEWSESSION(cap->cc_dev, &lid, cri);
20960 ++		CRYPTO_DRIVER_LOCK();
20961 ++		if (err == 0) {
20962 ++			(*sid) = (cap->cc_flags & 0xff000000)
20963 ++			       | (hid & 0x00ffffff);
20964 ++			(*sid) <<= 32;
20965 ++			(*sid) |= (lid & 0xffffffff);
20966 ++		} else
20967 ++			cap->cc_sessions--;
20968 ++	} else
20969 ++		err = EINVAL;
20970 ++	CRYPTO_DRIVER_UNLOCK();
20971 ++	return err;
20972 ++}
20973 ++
20974 ++static void
20975 ++crypto_remove(struct cryptocap *cap)
20976 ++{
20977 ++	CRYPTO_DRIVER_ASSERT();
20978 ++	if (cap->cc_sessions == 0 && cap->cc_koperations == 0)
20979 ++		bzero(cap, sizeof(*cap));
20980 ++}
20981 ++
20982 ++/*
20983 ++ * Delete an existing session (or a reserved session on an unregistered
20984 ++ * driver).
20985 ++ */
20986 ++int
20987 ++crypto_freesession(u_int64_t sid)
20988 ++{
20989 ++	struct cryptocap *cap;
20990 ++	u_int32_t hid;
20991 ++	int err;
20992 ++	unsigned long d_flags;
20993 ++
20994 ++	dprintk("%s()\n", __FUNCTION__);
20995 ++	CRYPTO_DRIVER_LOCK();
20996 ++
20997 ++	if (crypto_drivers == NULL) {
20998 ++		err = EINVAL;
20999 ++		goto done;
21000 ++	}
21001 ++
21002 ++	/* Determine two IDs. */
21003 ++	hid = CRYPTO_SESID2HID(sid);
21004 ++
21005 ++	if (hid >= crypto_drivers_num) {
21006 ++		dprintk("%s - INVALID DRIVER NUM %d\n", __FUNCTION__, hid);
21007 ++		err = ENOENT;
21008 ++		err = ENOENT;
21009 ++		goto done;
21010 ++	}
21011 ++	cap = &crypto_drivers[hid];
21012 ++
21013 ++	if (cap->cc_dev) {
21014 ++		CRYPTO_DRIVER_UNLOCK();
21015 ++		/* Call the driver cleanup routine, if available, unlocked. */
21016 ++		err = CRYPTODEV_FREESESSION(cap->cc_dev, sid);
21017 ++		CRYPTO_DRIVER_LOCK();
21018 ++	}
21019 ++
21020 ++	if (cap->cc_sessions)
21021 ++		cap->cc_sessions--;
21022 ++
21023 ++	if (cap->cc_flags & CRYPTOCAP_F_CLEANUP)
21024 ++		crypto_remove(cap);
21025 ++
21026 ++done:
21027 ++	CRYPTO_DRIVER_UNLOCK();
21028 ++	return err;
21029 ++}
21030 ++
21031 ++/*
21032 ++ * Return an unused driver id.  Used by drivers prior to registering
21033 ++ * support for the algorithms they handle.
21034 ++ */
21035 ++int32_t
21036 ++crypto_get_driverid(device_t dev, int flags)
21037 ++{
21038 ++	struct cryptocap *newdrv;
21039 ++	int i;
21040 ++	unsigned long d_flags;
21041 ++
21042 ++	if ((flags & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
21043 ++		printf("%s: no flags specified when registering driver\n",
21044 ++		    device_get_nameunit(dev));
21045 ++		return -1;
21046 ++	}
21047 ++
21048 ++	CRYPTO_DRIVER_LOCK();
21049 ++
21050 ++	for (i = 0; i < crypto_drivers_num; i++) {
21051 ++		if (crypto_drivers[i].cc_dev == NULL &&
21052 ++		    (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) == 0) {
21053 ++			break;
21054 ++		}
21055 ++	}
21056 ++
21057 ++	/* Out of entries, allocate some more. */
21058 ++	if (i == crypto_drivers_num) {
21059 ++		/* Be careful about wrap-around. */
21060 ++		if (2 * crypto_drivers_num <= crypto_drivers_num) {
21061 ++			CRYPTO_DRIVER_UNLOCK();
21062 ++			printk("crypto: driver count wraparound!\n");
21063 ++			return -1;
21064 ++		}
21065 ++
21066 ++		newdrv = kmalloc(2 * crypto_drivers_num * sizeof(struct cryptocap),
21067 ++				GFP_KERNEL);
21068 ++		if (newdrv == NULL) {
21069 ++			CRYPTO_DRIVER_UNLOCK();
21070 ++			printk("crypto: no space to expand driver table!\n");
21071 ++			return -1;
21072 ++		}
21073 ++
21074 ++		memcpy(newdrv, crypto_drivers,
21075 ++				crypto_drivers_num * sizeof(struct cryptocap));
21076 ++		memset(&newdrv[crypto_drivers_num], 0,
21077 ++				crypto_drivers_num * sizeof(struct cryptocap));
21078 ++
21079 ++		crypto_drivers_num *= 2;
21080 ++
21081 ++		kfree(crypto_drivers);
21082 ++		crypto_drivers = newdrv;
21083 ++	}
21084 ++
21085 ++	/* NB: state is zero'd on free */
21086 ++	crypto_drivers[i].cc_sessions = 1;	/* Mark */
21087 ++	crypto_drivers[i].cc_dev = dev;
21088 ++	crypto_drivers[i].cc_flags = flags;
21089 ++	if (bootverbose)
21090 ++		printf("crypto: assign %s driver id %u, flags %u\n",
21091 ++		    device_get_nameunit(dev), i, flags);
21092 ++
21093 ++	CRYPTO_DRIVER_UNLOCK();
21094 ++
21095 ++	return i;
21096 ++}
21097 ++
21098 ++/*
21099 ++ * Lookup a driver by name.  We match against the full device
21100 ++ * name and unit, and against just the name.  The latter gives
21101 ++ * us a simple widlcarding by device name.  On success return the
21102 ++ * driver/hardware identifier; otherwise return -1.
21103 ++ */
21104 ++int
21105 ++crypto_find_driver(const char *match)
21106 ++{
21107 ++	int i, len = strlen(match);
21108 ++	unsigned long d_flags;
21109 ++
21110 ++	CRYPTO_DRIVER_LOCK();
21111 ++	for (i = 0; i < crypto_drivers_num; i++) {
21112 ++		device_t dev = crypto_drivers[i].cc_dev;
21113 ++		if (dev == NULL ||
21114 ++		    (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP))
21115 ++			continue;
21116 ++		if (strncmp(match, device_get_nameunit(dev), len) == 0 ||
21117 ++		    strncmp(match, device_get_name(dev), len) == 0)
21118 ++			break;
21119 ++	}
21120 ++	CRYPTO_DRIVER_UNLOCK();
21121 ++	return i < crypto_drivers_num ? i : -1;
21122 ++}
21123 ++
21124 ++/*
21125 ++ * Return the device_t for the specified driver or NULL
21126 ++ * if the driver identifier is invalid.
21127 ++ */
21128 ++device_t
21129 ++crypto_find_device_byhid(int hid)
21130 ++{
21131 ++	struct cryptocap *cap = crypto_checkdriver(hid);
21132 ++	return cap != NULL ? cap->cc_dev : NULL;
21133 ++}
21134 ++
21135 ++/*
21136 ++ * Return the device/driver capabilities.
21137 ++ */
21138 ++int
21139 ++crypto_getcaps(int hid)
21140 ++{
21141 ++	struct cryptocap *cap = crypto_checkdriver(hid);
21142 ++	return cap != NULL ? cap->cc_flags : 0;
21143 ++}
21144 ++
21145 ++/*
21146 ++ * Register support for a key-related algorithm.  This routine
21147 ++ * is called once for each algorithm supported a driver.
21148 ++ */
21149 ++int
21150 ++crypto_kregister(u_int32_t driverid, int kalg, u_int32_t flags)
21151 ++{
21152 ++	struct cryptocap *cap;
21153 ++	int err;
21154 ++	unsigned long d_flags;
21155 ++
21156 ++	dprintk("%s()\n", __FUNCTION__);
21157 ++	CRYPTO_DRIVER_LOCK();
21158 ++
21159 ++	cap = crypto_checkdriver(driverid);
21160 ++	if (cap != NULL &&
21161 ++	    (CRK_ALGORITM_MIN <= kalg && kalg <= CRK_ALGORITHM_MAX)) {
21162 ++		/*
21163 ++		 * XXX Do some performance testing to determine placing.
21164 ++		 * XXX We probably need an auxiliary data structure that
21165 ++		 * XXX describes relative performances.
21166 ++		 */
21167 ++
21168 ++		cap->cc_kalg[kalg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
21169 ++		if (bootverbose)
21170 ++			printf("crypto: %s registers key alg %u flags %u\n"
21171 ++				, device_get_nameunit(cap->cc_dev)
21172 ++				, kalg
21173 ++				, flags
21174 ++			);
21175 ++		err = 0;
21176 ++	} else
21177 ++		err = EINVAL;
21178 ++
21179 ++	CRYPTO_DRIVER_UNLOCK();
21180 ++	return err;
21181 ++}
21182 ++
21183 ++/*
21184 ++ * Register support for a non-key-related algorithm.  This routine
21185 ++ * is called once for each such algorithm supported by a driver.
21186 ++ */
21187 ++int
21188 ++crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
21189 ++    u_int32_t flags)
21190 ++{
21191 ++	struct cryptocap *cap;
21192 ++	int err;
21193 ++	unsigned long d_flags;
21194 ++
21195 ++	dprintk("%s(id=0x%x, alg=%d, maxoplen=%d, flags=0x%x)\n", __FUNCTION__,
21196 ++			driverid, alg, maxoplen, flags);
21197 ++
21198 ++	CRYPTO_DRIVER_LOCK();
21199 ++
21200 ++	cap = crypto_checkdriver(driverid);
21201 ++	/* NB: algorithms are in the range [1..max] */
21202 ++	if (cap != NULL &&
21203 ++	    (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX)) {
21204 ++		/*
21205 ++		 * XXX Do some performance testing to determine placing.
21206 ++		 * XXX We probably need an auxiliary data structure that
21207 ++		 * XXX describes relative performances.
21208 ++		 */
21209 ++
21210 ++		cap->cc_alg[alg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
21211 ++		cap->cc_max_op_len[alg] = maxoplen;
21212 ++		if (bootverbose)
21213 ++			printf("crypto: %s registers alg %u flags %u maxoplen %u\n"
21214 ++				, device_get_nameunit(cap->cc_dev)
21215 ++				, alg
21216 ++				, flags
21217 ++				, maxoplen
21218 ++			);
21219 ++		cap->cc_sessions = 0;		/* Unmark */
21220 ++		err = 0;
21221 ++	} else
21222 ++		err = EINVAL;
21223 ++
21224 ++	CRYPTO_DRIVER_UNLOCK();
21225 ++	return err;
21226 ++}
21227 ++
21228 ++static void
21229 ++driver_finis(struct cryptocap *cap)
21230 ++{
21231 ++	u_int32_t ses, kops;
21232 ++
21233 ++	CRYPTO_DRIVER_ASSERT();
21234 ++
21235 ++	ses = cap->cc_sessions;
21236 ++	kops = cap->cc_koperations;
21237 ++	bzero(cap, sizeof(*cap));
21238 ++	if (ses != 0 || kops != 0) {
21239 ++		/*
21240 ++		 * If there are pending sessions,
21241 ++		 * just mark as invalid.
21242 ++		 */
21243 ++		cap->cc_flags |= CRYPTOCAP_F_CLEANUP;
21244 ++		cap->cc_sessions = ses;
21245 ++		cap->cc_koperations = kops;
21246 ++	}
21247 ++}
21248 ++
21249 ++/*
21250 ++ * Unregister a crypto driver. If there are pending sessions using it,
21251 ++ * leave enough information around so that subsequent calls using those
21252 ++ * sessions will correctly detect the driver has been unregistered and
21253 ++ * reroute requests.
21254 ++ */
21255 ++int
21256 ++crypto_unregister(u_int32_t driverid, int alg)
21257 ++{
21258 ++	struct cryptocap *cap;
21259 ++	int i, err;
21260 ++	unsigned long d_flags;
21261 ++
21262 ++	dprintk("%s()\n", __FUNCTION__);
21263 ++	CRYPTO_DRIVER_LOCK();
21264 ++
21265 ++	cap = crypto_checkdriver(driverid);
21266 ++	if (cap != NULL &&
21267 ++	    (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX) &&
21268 ++	    cap->cc_alg[alg] != 0) {
21269 ++		cap->cc_alg[alg] = 0;
21270 ++		cap->cc_max_op_len[alg] = 0;
21271 ++
21272 ++		/* Was this the last algorithm ? */
21273 ++		for (i = 1; i <= CRYPTO_ALGORITHM_MAX; i++)
21274 ++			if (cap->cc_alg[i] != 0)
21275 ++				break;
21276 ++
21277 ++		if (i == CRYPTO_ALGORITHM_MAX + 1)
21278 ++			driver_finis(cap);
21279 ++		err = 0;
21280 ++	} else
21281 ++		err = EINVAL;
21282 ++	CRYPTO_DRIVER_UNLOCK();
21283 ++	return err;
21284 ++}
21285 ++
21286 ++/*
21287 ++ * Unregister all algorithms associated with a crypto driver.
21288 ++ * If there are pending sessions using it, leave enough information
21289 ++ * around so that subsequent calls using those sessions will
21290 ++ * correctly detect the driver has been unregistered and reroute
21291 ++ * requests.
21292 ++ */
21293 ++int
21294 ++crypto_unregister_all(u_int32_t driverid)
21295 ++{
21296 ++	struct cryptocap *cap;
21297 ++	int err;
21298 ++	unsigned long d_flags;
21299 ++
21300 ++	dprintk("%s()\n", __FUNCTION__);
21301 ++	CRYPTO_DRIVER_LOCK();
21302 ++	cap = crypto_checkdriver(driverid);
21303 ++	if (cap != NULL) {
21304 ++		driver_finis(cap);
21305 ++		err = 0;
21306 ++	} else
21307 ++		err = EINVAL;
21308 ++	CRYPTO_DRIVER_UNLOCK();
21309 ++
21310 ++	return err;
21311 ++}
21312 ++
21313 ++/*
21314 ++ * Clear blockage on a driver.  The what parameter indicates whether
21315 ++ * the driver is now ready for cryptop's and/or cryptokop's.
21316 ++ */
21317 ++int
21318 ++crypto_unblock(u_int32_t driverid, int what)
21319 ++{
21320 ++	struct cryptocap *cap;
21321 ++	int err;
21322 ++	unsigned long q_flags;
21323 ++
21324 ++	CRYPTO_Q_LOCK();
21325 ++	cap = crypto_checkdriver(driverid);
21326 ++	if (cap != NULL) {
21327 ++		if (what & CRYPTO_SYMQ) {
21328 ++			cap->cc_qblocked = 0;
21329 ++			crypto_all_qblocked = 0;
21330 ++		}
21331 ++		if (what & CRYPTO_ASYMQ) {
21332 ++			cap->cc_kqblocked = 0;
21333 ++			crypto_all_kqblocked = 0;
21334 ++		}
21335 ++		if (crp_sleep)
21336 ++			wake_up_interruptible(&cryptoproc_wait);
21337 ++		err = 0;
21338 ++	} else
21339 ++		err = EINVAL;
21340 ++	CRYPTO_Q_UNLOCK(); //DAVIDM should this be a driver lock
21341 ++
21342 ++	return err;
21343 ++}
21344 ++
21345 ++/*
21346 ++ * Add a crypto request to a queue, to be processed by the kernel thread.
21347 ++ */
21348 ++int
21349 ++crypto_dispatch(struct cryptop *crp)
21350 ++{
21351 ++	struct cryptocap *cap;
21352 ++	u_int32_t hid;
21353 ++	int result;
21354 ++	unsigned long q_flags;
21355 ++
21356 ++	dprintk("%s()\n", __FUNCTION__);
21357 ++
21358 ++	cryptostats.cs_ops++;
21359 ++
21360 ++	if (atomic_read(&crypto_q_cnt) >= crypto_q_max) {
21361 ++		cryptostats.cs_drops++;
21362 ++		return ENOMEM;
21363 ++	}
21364 ++	atomic_inc(&crypto_q_cnt);
21365 ++
21366 ++	hid = CRYPTO_SESID2HID(crp->crp_sid);
21367 ++
21368 ++	if ((crp->crp_flags & CRYPTO_F_BATCH) == 0) {
21369 ++		/*
21370 ++		 * Caller marked the request to be processed
21371 ++		 * immediately; dispatch it directly to the
21372 ++		 * driver unless the driver is currently blocked.
21373 ++		 */
21374 ++		cap = crypto_checkdriver(hid);
21375 ++		/* Driver cannot disappeared when there is an active session. */
21376 ++		KASSERT(cap != NULL, ("%s: Driver disappeared.", __func__));
21377 ++		if (!cap->cc_qblocked) {
21378 ++			result = crypto_invoke(cap, crp, 0);
21379 ++			if (result != ERESTART)
21380 ++				return (result);
21381 ++			/*
21382 ++			 * The driver ran out of resources, put the request on
21383 ++			 * the queue.
21384 ++			 */
21385 ++		}
21386 ++	}
21387 ++	CRYPTO_Q_LOCK();
21388 ++	TAILQ_INSERT_TAIL(&crp_q, crp, crp_next);
21389 ++	if (crp_sleep)
21390 ++		wake_up_interruptible(&cryptoproc_wait);
21391 ++	CRYPTO_Q_UNLOCK();
21392 ++	return 0;
21393 ++}
21394 ++
21395 ++/*
21396 ++ * Add an asymetric crypto request to a queue,
21397 ++ * to be processed by the kernel thread.
21398 ++ */
21399 ++int
21400 ++crypto_kdispatch(struct cryptkop *krp)
21401 ++{
21402 ++	int error;
21403 ++	unsigned long q_flags;
21404 ++
21405 ++	cryptostats.cs_kops++;
21406 ++
21407 ++	error = crypto_kinvoke(krp, krp->krp_crid);
21408 ++	if (error == ERESTART) {
21409 ++		CRYPTO_Q_LOCK();
21410 ++		TAILQ_INSERT_TAIL(&crp_kq, krp, krp_next);
21411 ++		if (crp_sleep)
21412 ++			wake_up_interruptible(&cryptoproc_wait);
21413 ++		CRYPTO_Q_UNLOCK();
21414 ++		error = 0;
21415 ++	}
21416 ++	return error;
21417 ++}
21418 ++
21419 ++/*
21420 ++ * Verify a driver is suitable for the specified operation.
21421 ++ */
21422 ++static __inline int
21423 ++kdriver_suitable(const struct cryptocap *cap, const struct cryptkop *krp)
21424 ++{
21425 ++	return (cap->cc_kalg[krp->krp_op] & CRYPTO_ALG_FLAG_SUPPORTED) != 0;
21426 ++}
21427 ++
21428 ++/*
21429 ++ * Select a driver for an asym operation.  The driver must
21430 ++ * support the necessary algorithm.  The caller can constrain
21431 ++ * which device is selected with the flags parameter.  The
21432 ++ * algorithm we use here is pretty stupid; just use the first
21433 ++ * driver that supports the algorithms we need. If there are
21434 ++ * multiple suitable drivers we choose the driver with the
21435 ++ * fewest active operations.  We prefer hardware-backed
21436 ++ * drivers to software ones when either may be used.
21437 ++ */
21438 ++static struct cryptocap *
21439 ++crypto_select_kdriver(const struct cryptkop *krp, int flags)
21440 ++{
21441 ++	struct cryptocap *cap, *best, *blocked;
21442 ++	int match, hid;
21443 ++
21444 ++	CRYPTO_DRIVER_ASSERT();
21445 ++
21446 ++	/*
21447 ++	 * Look first for hardware crypto devices if permitted.
21448 ++	 */
21449 ++	if (flags & CRYPTOCAP_F_HARDWARE)
21450 ++		match = CRYPTOCAP_F_HARDWARE;
21451 ++	else
21452 ++		match = CRYPTOCAP_F_SOFTWARE;
21453 ++	best = NULL;
21454 ++	blocked = NULL;
21455 ++again:
21456 ++	for (hid = 0; hid < crypto_drivers_num; hid++) {
21457 ++		cap = &crypto_drivers[hid];
21458 ++		/*
21459 ++		 * If it's not initialized, is in the process of
21460 ++		 * going away, or is not appropriate (hardware
21461 ++		 * or software based on match), then skip.
21462 ++		 */
21463 ++		if (cap->cc_dev == NULL ||
21464 ++		    (cap->cc_flags & CRYPTOCAP_F_CLEANUP) ||
21465 ++		    (cap->cc_flags & match) == 0)
21466 ++			continue;
21467 ++
21468 ++		/* verify all the algorithms are supported. */
21469 ++		if (kdriver_suitable(cap, krp)) {
21470 ++			if (best == NULL ||
21471 ++			    cap->cc_koperations < best->cc_koperations)
21472 ++				best = cap;
21473 ++		}
21474 ++	}
21475 ++	if (best != NULL)
21476 ++		return best;
21477 ++	if (match == CRYPTOCAP_F_HARDWARE && (flags & CRYPTOCAP_F_SOFTWARE)) {
21478 ++		/* sort of an Algol 68-style for loop */
21479 ++		match = CRYPTOCAP_F_SOFTWARE;
21480 ++		goto again;
21481 ++	}
21482 ++	return best;
21483 ++}
21484 ++
21485 ++/*
21486 ++ * Dispatch an assymetric crypto request.
21487 ++ */
21488 ++static int
21489 ++crypto_kinvoke(struct cryptkop *krp, int crid)
21490 ++{
21491 ++	struct cryptocap *cap = NULL;
21492 ++	int error;
21493 ++	unsigned long d_flags;
21494 ++
21495 ++	KASSERT(krp != NULL, ("%s: krp == NULL", __func__));
21496 ++	KASSERT(krp->krp_callback != NULL,
21497 ++	    ("%s: krp->crp_callback == NULL", __func__));
21498 ++
21499 ++	CRYPTO_DRIVER_LOCK();
21500 ++	if ((crid & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
21501 ++		cap = crypto_checkdriver(crid);
21502 ++		if (cap != NULL) {
21503 ++			/*
21504 ++			 * Driver present, it must support the necessary
21505 ++			 * algorithm and, if s/w drivers are excluded,
21506 ++			 * it must be registered as hardware-backed.
21507 ++			 */
21508 ++			if (!kdriver_suitable(cap, krp) ||
21509 ++			    (!crypto_devallowsoft &&
21510 ++			     (cap->cc_flags & CRYPTOCAP_F_HARDWARE) == 0))
21511 ++				cap = NULL;
21512 ++		}
21513 ++	} else {
21514 ++		/*
21515 ++		 * No requested driver; select based on crid flags.
21516 ++		 */
21517 ++		if (!crypto_devallowsoft)	/* NB: disallow s/w drivers */
21518 ++			crid &= ~CRYPTOCAP_F_SOFTWARE;
21519 ++		cap = crypto_select_kdriver(krp, crid);
21520 ++	}
21521 ++	if (cap != NULL && !cap->cc_kqblocked) {
21522 ++		krp->krp_hid = cap - crypto_drivers;
21523 ++		cap->cc_koperations++;
21524 ++		CRYPTO_DRIVER_UNLOCK();
21525 ++		error = CRYPTODEV_KPROCESS(cap->cc_dev, krp, 0);
21526 ++		CRYPTO_DRIVER_LOCK();
21527 ++		if (error == ERESTART) {
21528 ++			cap->cc_koperations--;
21529 ++			CRYPTO_DRIVER_UNLOCK();
21530 ++			return (error);
21531 ++		}
21532 ++		/* return the actual device used */
21533 ++		krp->krp_crid = krp->krp_hid;
21534 ++	} else {
21535 ++		/*
21536 ++		 * NB: cap is !NULL if device is blocked; in
21537 ++		 *     that case return ERESTART so the operation
21538 ++		 *     is resubmitted if possible.
21539 ++		 */
21540 ++		error = (cap == NULL) ? ENODEV : ERESTART;
21541 ++	}
21542 ++	CRYPTO_DRIVER_UNLOCK();
21543 ++
21544 ++	if (error) {
21545 ++		krp->krp_status = error;
21546 ++		crypto_kdone(krp);
21547 ++	}
21548 ++	return 0;
21549 ++}
21550 ++
21551 ++
21552 ++/*
21553 ++ * Dispatch a crypto request to the appropriate crypto devices.
21554 ++ */
21555 ++static int
21556 ++crypto_invoke(struct cryptocap *cap, struct cryptop *crp, int hint)
21557 ++{
21558 ++
21559 ++	KASSERT(crp != NULL, ("%s: crp == NULL", __func__));
21560 ++	KASSERT(crp->crp_callback != NULL,
21561 ++	    ("%s: crp->crp_callback == NULL", __func__));
21562 ++	KASSERT(crp->crp_desc != NULL, ("%s: crp->crp_desc == NULL", __func__));
21563 ++
21564 ++	dprintk("%s()\n", __FUNCTION__);
21565 ++
21566 ++#ifdef CRYPTO_TIMING
21567 ++	if (crypto_timing)
21568 ++		crypto_tstat(&cryptostats.cs_invoke, &crp->crp_tstamp);
21569 ++#endif
21570 ++	if (cap->cc_flags & CRYPTOCAP_F_CLEANUP) {
21571 ++		struct cryptodesc *crd;
21572 ++		u_int64_t nid;
21573 ++
21574 ++		/*
21575 ++		 * Driver has unregistered; migrate the session and return
21576 ++		 * an error to the caller so they'll resubmit the op.
21577 ++		 *
21578 ++		 * XXX: What if there are more already queued requests for this
21579 ++		 *      session?
21580 ++		 */
21581 ++		crypto_freesession(crp->crp_sid);
21582 ++
21583 ++		for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
21584 ++			crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
21585 ++
21586 ++		/* XXX propagate flags from initial session? */
21587 ++		if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI),
21588 ++		    CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE) == 0)
21589 ++			crp->crp_sid = nid;
21590 ++
21591 ++		crp->crp_etype = EAGAIN;
21592 ++		crypto_done(crp);
21593 ++		return 0;
21594 ++	} else {
21595 ++		/*
21596 ++		 * Invoke the driver to process the request.
21597 ++		 */
21598 ++		return CRYPTODEV_PROCESS(cap->cc_dev, crp, hint);
21599 ++	}
21600 ++}
21601 ++
21602 ++/*
21603 ++ * Release a set of crypto descriptors.
21604 ++ */
21605 ++void
21606 ++crypto_freereq(struct cryptop *crp)
21607 ++{
21608 ++	struct cryptodesc *crd;
21609 ++
21610 ++	if (crp == NULL)
21611 ++		return;
21612 ++
21613 ++#ifdef DIAGNOSTIC
21614 ++	{
21615 ++		struct cryptop *crp2;
21616 ++		unsigned long q_flags;
21617 ++
21618 ++		CRYPTO_Q_LOCK();
21619 ++		TAILQ_FOREACH(crp2, &crp_q, crp_next) {
21620 ++			KASSERT(crp2 != crp,
21621 ++			    ("Freeing cryptop from the crypto queue (%p).",
21622 ++			    crp));
21623 ++		}
21624 ++		CRYPTO_Q_UNLOCK();
21625 ++		CRYPTO_RETQ_LOCK();
21626 ++		TAILQ_FOREACH(crp2, &crp_ret_q, crp_next) {
21627 ++			KASSERT(crp2 != crp,
21628 ++			    ("Freeing cryptop from the return queue (%p).",
21629 ++			    crp));
21630 ++		}
21631 ++		CRYPTO_RETQ_UNLOCK();
21632 ++	}
21633 ++#endif
21634 ++
21635 ++	while ((crd = crp->crp_desc) != NULL) {
21636 ++		crp->crp_desc = crd->crd_next;
21637 ++		kmem_cache_free(cryptodesc_zone, crd);
21638 ++	}
21639 ++	kmem_cache_free(cryptop_zone, crp);
21640 ++}
21641 ++
21642 ++/*
21643 ++ * Acquire a set of crypto descriptors.
21644 ++ */
21645 ++struct cryptop *
21646 ++crypto_getreq(int num)
21647 ++{
21648 ++	struct cryptodesc *crd;
21649 ++	struct cryptop *crp;
21650 ++
21651 ++	crp = kmem_cache_alloc(cryptop_zone, SLAB_ATOMIC);
21652 ++	if (crp != NULL) {
21653 ++		memset(crp, 0, sizeof(*crp));
21654 ++		INIT_LIST_HEAD(&crp->crp_next);
21655 ++		init_waitqueue_head(&crp->crp_waitq);
21656 ++		while (num--) {
21657 ++			crd = kmem_cache_alloc(cryptodesc_zone, SLAB_ATOMIC);
21658 ++			if (crd == NULL) {
21659 ++				crypto_freereq(crp);
21660 ++				return NULL;
21661 ++			}
21662 ++			memset(crd, 0, sizeof(*crd));
21663 ++			crd->crd_next = crp->crp_desc;
21664 ++			crp->crp_desc = crd;
21665 ++		}
21666 ++	}
21667 ++	return crp;
21668 ++}
21669 ++
21670 ++/*
21671 ++ * Invoke the callback on behalf of the driver.
21672 ++ */
21673 ++void
21674 ++crypto_done(struct cryptop *crp)
21675 ++{
21676 ++	dprintk("%s()\n", __FUNCTION__);
21677 ++	if ((crp->crp_flags & CRYPTO_F_DONE) == 0) {
21678 ++		crp->crp_flags |= CRYPTO_F_DONE;
21679 ++		atomic_dec(&crypto_q_cnt);
21680 ++	} else
21681 ++		printk("crypto: crypto_done op already done, flags 0x%x",
21682 ++				crp->crp_flags);
21683 ++	if (crp->crp_etype != 0)
21684 ++		cryptostats.cs_errs++;
21685 ++	/*
21686 ++	 * CBIMM means unconditionally do the callback immediately;
21687 ++	 * CBIFSYNC means do the callback immediately only if the
21688 ++	 * operation was done synchronously.  Both are used to avoid
21689 ++	 * doing extraneous context switches; the latter is mostly
21690 ++	 * used with the software crypto driver.
21691 ++	 */
21692 ++	if ((crp->crp_flags & CRYPTO_F_CBIMM) ||
21693 ++	    ((crp->crp_flags & CRYPTO_F_CBIFSYNC) &&
21694 ++	     (CRYPTO_SESID2CAPS(crp->crp_sid) & CRYPTOCAP_F_SYNC))) {
21695 ++		/*
21696 ++		 * Do the callback directly.  This is ok when the
21697 ++		 * callback routine does very little (e.g. the
21698 ++		 * /dev/crypto callback method just does a wakeup).
21699 ++		 */
21700 ++		crp->crp_callback(crp);
21701 ++	} else {
21702 ++		unsigned long r_flags;
21703 ++		/*
21704 ++		 * Normal case; queue the callback for the thread.
21705 ++		 */
21706 ++		CRYPTO_RETQ_LOCK();
21707 ++		if (CRYPTO_RETQ_EMPTY())
21708 ++			wake_up_interruptible(&cryptoretproc_wait);/* shared wait channel */
21709 ++		TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next);
21710 ++		CRYPTO_RETQ_UNLOCK();
21711 ++	}
21712 ++}
21713 ++
21714 ++/*
21715 ++ * Invoke the callback on behalf of the driver.
21716 ++ */
21717 ++void
21718 ++crypto_kdone(struct cryptkop *krp)
21719 ++{
21720 ++	struct cryptocap *cap;
21721 ++	unsigned long d_flags;
21722 ++
21723 ++	if ((krp->krp_flags & CRYPTO_KF_DONE) != 0)
21724 ++		printk("crypto: crypto_kdone op already done, flags 0x%x",
21725 ++				krp->krp_flags);
21726 ++	krp->krp_flags |= CRYPTO_KF_DONE;
21727 ++	if (krp->krp_status != 0)
21728 ++		cryptostats.cs_kerrs++;
21729 ++
21730 ++	CRYPTO_DRIVER_LOCK();
21731 ++	/* XXX: What if driver is loaded in the meantime? */
21732 ++	if (krp->krp_hid < crypto_drivers_num) {
21733 ++		cap = &crypto_drivers[krp->krp_hid];
21734 ++		cap->cc_koperations--;
21735 ++		KASSERT(cap->cc_koperations >= 0, ("cc_koperations < 0"));
21736 ++		if (cap->cc_flags & CRYPTOCAP_F_CLEANUP)
21737 ++			crypto_remove(cap);
21738 ++	}
21739 ++	CRYPTO_DRIVER_UNLOCK();
21740 ++
21741 ++	/*
21742 ++	 * CBIMM means unconditionally do the callback immediately;
21743 ++	 * This is used to avoid doing extraneous context switches
21744 ++	 */
21745 ++	if ((krp->krp_flags & CRYPTO_KF_CBIMM)) {
21746 ++		/*
21747 ++		 * Do the callback directly.  This is ok when the
21748 ++		 * callback routine does very little (e.g. the
21749 ++		 * /dev/crypto callback method just does a wakeup).
21750 ++		 */
21751 ++		krp->krp_callback(krp);
21752 ++	} else {
21753 ++		unsigned long r_flags;
21754 ++		/*
21755 ++		 * Normal case; queue the callback for the thread.
21756 ++		 */
21757 ++		CRYPTO_RETQ_LOCK();
21758 ++		if (CRYPTO_RETQ_EMPTY())
21759 ++			wake_up_interruptible(&cryptoretproc_wait);/* shared wait channel */
21760 ++		TAILQ_INSERT_TAIL(&crp_ret_kq, krp, krp_next);
21761 ++		CRYPTO_RETQ_UNLOCK();
21762 ++	}
21763 ++}
21764 ++
21765 ++int
21766 ++crypto_getfeat(int *featp)
21767 ++{
21768 ++	int hid, kalg, feat = 0;
21769 ++	unsigned long d_flags;
21770 ++
21771 ++	CRYPTO_DRIVER_LOCK();
21772 ++	for (hid = 0; hid < crypto_drivers_num; hid++) {
21773 ++		const struct cryptocap *cap = &crypto_drivers[hid];
21774 ++
21775 ++		if ((cap->cc_flags & CRYPTOCAP_F_SOFTWARE) &&
21776 ++		    !crypto_devallowsoft) {
21777 ++			continue;
21778 ++		}
21779 ++		for (kalg = 0; kalg < CRK_ALGORITHM_MAX; kalg++)
21780 ++			if (cap->cc_kalg[kalg] & CRYPTO_ALG_FLAG_SUPPORTED)
21781 ++				feat |=  1 << kalg;
21782 ++	}
21783 ++	CRYPTO_DRIVER_UNLOCK();
21784 ++	*featp = feat;
21785 ++	return (0);
21786 ++}
21787 ++
21788 ++/*
21789 ++ * Crypto thread, dispatches crypto requests.
21790 ++ */
21791 ++static int
21792 ++crypto_proc(void *arg)
21793 ++{
21794 ++	struct cryptop *crp, *submit;
21795 ++	struct cryptkop *krp, *krpp;
21796 ++	struct cryptocap *cap;
21797 ++	u_int32_t hid;
21798 ++	int result, hint;
21799 ++	unsigned long q_flags;
21800 ++
21801 ++	ocf_daemonize("crypto");
21802 ++
21803 ++	CRYPTO_Q_LOCK();
21804 ++	for (;;) {
21805 ++		/*
21806 ++		 * we need to make sure we don't get into a busy loop with nothing
21807 ++		 * to do,  the two crypto_all_*blocked vars help us find out when
21808 ++		 * we are all full and can do nothing on any driver or Q.  If so we
21809 ++		 * wait for an unblock.
21810 ++		 */
21811 ++		crypto_all_qblocked  = !list_empty(&crp_q);
21812 ++
21813 ++		/*
21814 ++		 * Find the first element in the queue that can be
21815 ++		 * processed and look-ahead to see if multiple ops
21816 ++		 * are ready for the same driver.
21817 ++		 */
21818 ++		submit = NULL;
21819 ++		hint = 0;
21820 ++		list_for_each_entry(crp, &crp_q, crp_next) {
21821 ++			hid = CRYPTO_SESID2HID(crp->crp_sid);
21822 ++			cap = crypto_checkdriver(hid);
21823 ++			/*
21824 ++			 * Driver cannot disappeared when there is an active
21825 ++			 * session.
21826 ++			 */
21827 ++			KASSERT(cap != NULL, ("%s:%u Driver disappeared.",
21828 ++			    __func__, __LINE__));
21829 ++			if (cap == NULL || cap->cc_dev == NULL) {
21830 ++				/* Op needs to be migrated, process it. */
21831 ++				if (submit == NULL)
21832 ++					submit = crp;
21833 ++				break;
21834 ++			}
21835 ++			if (!cap->cc_qblocked) {
21836 ++				if (submit != NULL) {
21837 ++					/*
21838 ++					 * We stop on finding another op,
21839 ++					 * regardless whether its for the same
21840 ++					 * driver or not.  We could keep
21841 ++					 * searching the queue but it might be
21842 ++					 * better to just use a per-driver
21843 ++					 * queue instead.
21844 ++					 */
21845 ++					if (CRYPTO_SESID2HID(submit->crp_sid) == hid)
21846 ++						hint = CRYPTO_HINT_MORE;
21847 ++					break;
21848 ++				} else {
21849 ++					submit = crp;
21850 ++					if ((submit->crp_flags & CRYPTO_F_BATCH) == 0)
21851 ++						break;
21852 ++					/* keep scanning for more are q'd */
21853 ++				}
21854 ++			}
21855 ++		}
21856 ++		if (submit != NULL) {
21857 ++			crypto_all_qblocked = 0;
21858 ++			list_del(&submit->crp_next);
21859 ++			crypto_drivers[CRYPTO_SESID2HID(submit->crp_sid)].cc_qblocked = 1;
21860 ++			CRYPTO_Q_UNLOCK();
21861 ++			hid = CRYPTO_SESID2HID(submit->crp_sid);
21862 ++			cap = crypto_checkdriver(hid);
21863 ++			KASSERT(cap != NULL, ("%s:%u Driver disappeared.",
21864 ++			    __func__, __LINE__));
21865 ++			result = crypto_invoke(cap, submit, hint);
21866 ++			CRYPTO_Q_LOCK();
21867 ++			if (result == ERESTART) {
21868 ++				/*
21869 ++				 * The driver ran out of resources, mark the
21870 ++				 * driver ``blocked'' for cryptop's and put
21871 ++				 * the request back in the queue.  It would
21872 ++				 * best to put the request back where we got
21873 ++				 * it but that's hard so for now we put it
21874 ++				 * at the front.  This should be ok; putting
21875 ++				 * it at the end does not work.
21876 ++				 */
21877 ++				/* XXX validate sid again? */
21878 ++				list_add(&submit->crp_next, &crp_q);
21879 ++				cryptostats.cs_blocks++;
21880 ++			} else
21881 ++				crypto_drivers[CRYPTO_SESID2HID(submit->crp_sid)].cc_qblocked=0;
21882 ++		}
21883 ++
21884 ++		crypto_all_kqblocked = !list_empty(&crp_kq);
21885 ++
21886 ++		/* As above, but for key ops */
21887 ++		krp = NULL;
21888 ++		list_for_each_entry(krpp, &crp_kq, krp_next) {
21889 ++			cap = crypto_checkdriver(krpp->krp_hid);
21890 ++			if (cap == NULL || cap->cc_dev == NULL) {
21891 ++				/*
21892 ++				 * Operation needs to be migrated, invalidate
21893 ++				 * the assigned device so it will reselect a
21894 ++				 * new one below.  Propagate the original
21895 ++				 * crid selection flags if supplied.
21896 ++				 */
21897 ++				krp->krp_hid = krp->krp_crid &
21898 ++				    (CRYPTOCAP_F_SOFTWARE|CRYPTOCAP_F_HARDWARE);
21899 ++				if (krp->krp_hid == 0)
21900 ++					krp->krp_hid =
21901 ++				    CRYPTOCAP_F_SOFTWARE|CRYPTOCAP_F_HARDWARE;
21902 ++				break;
21903 ++			}
21904 ++			if (!cap->cc_kqblocked) {
21905 ++				krp = krpp;
21906 ++				break;
21907 ++			}
21908 ++		}
21909 ++		if (krp != NULL) {
21910 ++			crypto_all_kqblocked = 0;
21911 ++			list_del(&krp->krp_next);
21912 ++			crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
21913 ++			CRYPTO_Q_UNLOCK();
21914 ++			result = crypto_kinvoke(krp, krp->krp_hid);
21915 ++			CRYPTO_Q_LOCK();
21916 ++			if (result == ERESTART) {
21917 ++				/*
21918 ++				 * The driver ran out of resources, mark the
21919 ++				 * driver ``blocked'' for cryptkop's and put
21920 ++				 * the request back in the queue.  It would
21921 ++				 * best to put the request back where we got
21922 ++				 * it but that's hard so for now we put it
21923 ++				 * at the front.  This should be ok; putting
21924 ++				 * it at the end does not work.
21925 ++				 */
21926 ++				/* XXX validate sid again? */
21927 ++				list_add(&krp->krp_next, &crp_kq);
21928 ++				cryptostats.cs_kblocks++;
21929 ++			} else
21930 ++				crypto_drivers[krp->krp_hid].cc_kqblocked = 0;
21931 ++		}
21932 ++
21933 ++		if (submit == NULL && krp == NULL) {
21934 ++			/*
21935 ++			 * Nothing more to be processed.  Sleep until we're
21936 ++			 * woken because there are more ops to process.
21937 ++			 * This happens either by submission or by a driver
21938 ++			 * becoming unblocked and notifying us through
21939 ++			 * crypto_unblock.  Note that when we wakeup we
21940 ++			 * start processing each queue again from the
21941 ++			 * front. It's not clear that it's important to
21942 ++			 * preserve this ordering since ops may finish
21943 ++			 * out of order if dispatched to different devices
21944 ++			 * and some become blocked while others do not.
21945 ++			 */
21946 ++			dprintk("%s - sleeping (qe=%d qb=%d kqe=%d kqb=%d)\n",
21947 ++					__FUNCTION__,
21948 ++					list_empty(&crp_q), crypto_all_qblocked,
21949 ++					list_empty(&crp_kq), crypto_all_kqblocked);
21950 ++			CRYPTO_Q_UNLOCK();
21951 ++			crp_sleep = 1;
21952 ++			wait_event_interruptible(cryptoproc_wait,
21953 ++					!(list_empty(&crp_q) || crypto_all_qblocked) ||
21954 ++					!(list_empty(&crp_kq) || crypto_all_kqblocked) ||
21955 ++					cryptoproc == (pid_t) -1);
21956 ++			crp_sleep = 0;
21957 ++			if (signal_pending (current)) {
21958 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
21959 ++				spin_lock_irq(&current->sigmask_lock);
21960 ++#endif
21961 ++				flush_signals(current);
21962 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
21963 ++				spin_unlock_irq(&current->sigmask_lock);
21964 ++#endif
21965 ++			}
21966 ++			CRYPTO_Q_LOCK();
21967 ++			dprintk("%s - awake\n", __FUNCTION__);
21968 ++			if (cryptoproc == (pid_t) -1)
21969 ++				break;
21970 ++			cryptostats.cs_intrs++;
21971 ++		}
21972 ++	}
21973 ++	CRYPTO_Q_UNLOCK();
21974 ++	complete_and_exit(&cryptoproc_exited, 0);
21975 ++}
21976 ++
21977 ++/*
21978 ++ * Crypto returns thread, does callbacks for processed crypto requests.
21979 ++ * Callbacks are done here, rather than in the crypto drivers, because
21980 ++ * callbacks typically are expensive and would slow interrupt handling.
21981 ++ */
21982 ++static int
21983 ++crypto_ret_proc(void *arg)
21984 ++{
21985 ++	struct cryptop *crpt;
21986 ++	struct cryptkop *krpt;
21987 ++	unsigned long  r_flags;
21988 ++
21989 ++	ocf_daemonize("crypto_ret");
21990 ++
21991 ++	CRYPTO_RETQ_LOCK();
21992 ++	for (;;) {
21993 ++		/* Harvest return q's for completed ops */
21994 ++		crpt = NULL;
21995 ++		if (!list_empty(&crp_ret_q))
21996 ++			crpt = list_entry(crp_ret_q.next, typeof(*crpt), crp_next);
21997 ++		if (crpt != NULL)
21998 ++			list_del(&crpt->crp_next);
21999 ++
22000 ++		krpt = NULL;
22001 ++		if (!list_empty(&crp_ret_kq))
22002 ++			krpt = list_entry(crp_ret_kq.next, typeof(*krpt), krp_next);
22003 ++		if (krpt != NULL)
22004 ++			list_del(&krpt->krp_next);
22005 ++
22006 ++		if (crpt != NULL || krpt != NULL) {
22007 ++			CRYPTO_RETQ_UNLOCK();
22008 ++			/*
22009 ++			 * Run callbacks unlocked.
22010 ++			 */
22011 ++			if (crpt != NULL)
22012 ++				crpt->crp_callback(crpt);
22013 ++			if (krpt != NULL)
22014 ++				krpt->krp_callback(krpt);
22015 ++			CRYPTO_RETQ_LOCK();
22016 ++		} else {
22017 ++			/*
22018 ++			 * Nothing more to be processed.  Sleep until we're
22019 ++			 * woken because there are more returns to process.
22020 ++			 */
22021 ++			dprintk("%s - sleeping\n", __FUNCTION__);
22022 ++			CRYPTO_RETQ_UNLOCK();
22023 ++			wait_event_interruptible(cryptoretproc_wait,
22024 ++					cryptoretproc == (pid_t) -1 ||
22025 ++					!list_empty(&crp_ret_q) ||
22026 ++					!list_empty(&crp_ret_kq));
22027 ++			if (signal_pending (current)) {
22028 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
22029 ++				spin_lock_irq(&current->sigmask_lock);
22030 ++#endif
22031 ++				flush_signals(current);
22032 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
22033 ++				spin_unlock_irq(&current->sigmask_lock);
22034 ++#endif
22035 ++			}
22036 ++			CRYPTO_RETQ_LOCK();
22037 ++			dprintk("%s - awake\n", __FUNCTION__);
22038 ++			if (cryptoretproc == (pid_t) -1) {
22039 ++				dprintk("%s - EXITING!\n", __FUNCTION__);
22040 ++				break;
22041 ++			}
22042 ++			cryptostats.cs_rets++;
22043 ++		}
22044 ++	}
22045 ++	CRYPTO_RETQ_UNLOCK();
22046 ++	complete_and_exit(&cryptoretproc_exited, 0);
22047 ++}
22048 ++
22049 ++
22050 ++#if 0 /* should put this into /proc or something */
22051 ++static void
22052 ++db_show_drivers(void)
22053 ++{
22054 ++	int hid;
22055 ++
22056 ++	db_printf("%12s %4s %4s %8s %2s %2s\n"
22057 ++		, "Device"
22058 ++		, "Ses"
22059 ++		, "Kops"
22060 ++		, "Flags"
22061 ++		, "QB"
22062 ++		, "KB"
22063 ++	);
22064 ++	for (hid = 0; hid < crypto_drivers_num; hid++) {
22065 ++		const struct cryptocap *cap = &crypto_drivers[hid];
22066 ++		if (cap->cc_dev == NULL)
22067 ++			continue;
22068 ++		db_printf("%-12s %4u %4u %08x %2u %2u\n"
22069 ++		    , device_get_nameunit(cap->cc_dev)
22070 ++		    , cap->cc_sessions
22071 ++		    , cap->cc_koperations
22072 ++		    , cap->cc_flags
22073 ++		    , cap->cc_qblocked
22074 ++		    , cap->cc_kqblocked
22075 ++		);
22076 ++	}
22077 ++}
22078 ++
22079 ++DB_SHOW_COMMAND(crypto, db_show_crypto)
22080 ++{
22081 ++	struct cryptop *crp;
22082 ++
22083 ++	db_show_drivers();
22084 ++	db_printf("\n");
22085 ++
22086 ++	db_printf("%4s %8s %4s %4s %4s %4s %8s %8s\n",
22087 ++	    "HID", "Caps", "Ilen", "Olen", "Etype", "Flags",
22088 ++	    "Desc", "Callback");
22089 ++	TAILQ_FOREACH(crp, &crp_q, crp_next) {
22090 ++		db_printf("%4u %08x %4u %4u %4u %04x %8p %8p\n"
22091 ++		    , (int) CRYPTO_SESID2HID(crp->crp_sid)
22092 ++		    , (int) CRYPTO_SESID2CAPS(crp->crp_sid)
22093 ++		    , crp->crp_ilen, crp->crp_olen
22094 ++		    , crp->crp_etype
22095 ++		    , crp->crp_flags
22096 ++		    , crp->crp_desc
22097 ++		    , crp->crp_callback
22098 ++		);
22099 ++	}
22100 ++	if (!TAILQ_EMPTY(&crp_ret_q)) {
22101 ++		db_printf("\n%4s %4s %4s %8s\n",
22102 ++		    "HID", "Etype", "Flags", "Callback");
22103 ++		TAILQ_FOREACH(crp, &crp_ret_q, crp_next) {
22104 ++			db_printf("%4u %4u %04x %8p\n"
22105 ++			    , (int) CRYPTO_SESID2HID(crp->crp_sid)
22106 ++			    , crp->crp_etype
22107 ++			    , crp->crp_flags
22108 ++			    , crp->crp_callback
22109 ++			);
22110 ++		}
22111 ++	}
22112 ++}
22113 ++
22114 ++DB_SHOW_COMMAND(kcrypto, db_show_kcrypto)
22115 ++{
22116 ++	struct cryptkop *krp;
22117 ++
22118 ++	db_show_drivers();
22119 ++	db_printf("\n");
22120 ++
22121 ++	db_printf("%4s %5s %4s %4s %8s %4s %8s\n",
22122 ++	    "Op", "Status", "#IP", "#OP", "CRID", "HID", "Callback");
22123 ++	TAILQ_FOREACH(krp, &crp_kq, krp_next) {
22124 ++		db_printf("%4u %5u %4u %4u %08x %4u %8p\n"
22125 ++		    , krp->krp_op
22126 ++		    , krp->krp_status
22127 ++		    , krp->krp_iparams, krp->krp_oparams
22128 ++		    , krp->krp_crid, krp->krp_hid
22129 ++		    , krp->krp_callback
22130 ++		);
22131 ++	}
22132 ++	if (!TAILQ_EMPTY(&crp_ret_q)) {
22133 ++		db_printf("%4s %5s %8s %4s %8s\n",
22134 ++		    "Op", "Status", "CRID", "HID", "Callback");
22135 ++		TAILQ_FOREACH(krp, &crp_ret_kq, krp_next) {
22136 ++			db_printf("%4u %5u %08x %4u %8p\n"
22137 ++			    , krp->krp_op
22138 ++			    , krp->krp_status
22139 ++			    , krp->krp_crid, krp->krp_hid
22140 ++			    , krp->krp_callback
22141 ++			);
22142 ++		}
22143 ++	}
22144 ++}
22145 ++#endif
22146 ++
22147 ++
22148 ++static int
22149 ++crypto_init(void)
22150 ++{
22151 ++	int error;
22152 ++
22153 ++	dprintk("%s(0x%x)\n", __FUNCTION__, (int) crypto_init);
22154 ++
22155 ++	if (crypto_initted)
22156 ++		return 0;
22157 ++	crypto_initted = 1;
22158 ++
22159 ++	atomic_set(&crypto_q_cnt, 0);
22160 ++
22161 ++	spin_lock_init(&crypto_drivers_lock);
22162 ++	spin_lock_init(&crypto_q_lock);
22163 ++	spin_lock_init(&crypto_ret_q_lock);
22164 ++
22165 ++	cryptop_zone = kmem_cache_create("cryptop", sizeof(struct cryptop),
22166 ++				       0, SLAB_HWCACHE_ALIGN, NULL
22167 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
22168 ++				       , NULL
22169 ++#endif
22170 ++					);
22171 ++
22172 ++	cryptodesc_zone = kmem_cache_create("cryptodesc", sizeof(struct cryptodesc),
22173 ++				       0, SLAB_HWCACHE_ALIGN, NULL
22174 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
22175 ++				       , NULL
22176 ++#endif
22177 ++					);
22178 ++
22179 ++	if (cryptodesc_zone == NULL || cryptop_zone == NULL) {
22180 ++		printk("crypto: crypto_init cannot setup crypto zones\n");
22181 ++		error = ENOMEM;
22182 ++		goto bad;
22183 ++	}
22184 ++
22185 ++	crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
22186 ++	crypto_drivers = kmalloc(crypto_drivers_num * sizeof(struct cryptocap),
22187 ++			GFP_KERNEL);
22188 ++	if (crypto_drivers == NULL) {
22189 ++		printk("crypto: crypto_init cannot setup crypto drivers\n");
22190 ++		error = ENOMEM;
22191 ++		goto bad;
22192 ++	}
22193 ++
22194 ++	memset(crypto_drivers, 0, crypto_drivers_num * sizeof(struct cryptocap));
22195 ++
22196 ++	init_completion(&cryptoproc_exited);
22197 ++	init_completion(&cryptoretproc_exited);
22198 ++
22199 ++	cryptoproc = 0; /* to avoid race condition where proc runs first */
22200 ++	cryptoproc = kernel_thread(crypto_proc, NULL, CLONE_FS|CLONE_FILES);
22201 ++	if (cryptoproc < 0) {
22202 ++		error = cryptoproc;
22203 ++		printk("crypto: crypto_init cannot start crypto thread; error %d",
22204 ++			error);
22205 ++		goto bad;
22206 ++	}
22207 ++
22208 ++	cryptoretproc = 0; /* to avoid race condition where proc runs first */
22209 ++	cryptoretproc = kernel_thread(crypto_ret_proc, NULL, CLONE_FS|CLONE_FILES);
22210 ++	if (cryptoretproc < 0) {
22211 ++		error = cryptoretproc;
22212 ++		printk("crypto: crypto_init cannot start cryptoret thread; error %d",
22213 ++				error);
22214 ++		goto bad;
22215 ++	}
22216 ++
22217 ++	return 0;
22218 ++bad:
22219 ++	crypto_exit();
22220 ++	return error;
22221 ++}
22222 ++
22223 ++
22224 ++static void
22225 ++crypto_exit(void)
22226 ++{
22227 ++	pid_t p;
22228 ++	unsigned long d_flags;
22229 ++
22230 ++	dprintk("%s()\n", __FUNCTION__);
22231 ++
22232 ++	/*
22233 ++	 * Terminate any crypto threads.
22234 ++	 */
22235 ++
22236 ++	CRYPTO_DRIVER_LOCK();
22237 ++	p = cryptoproc;
22238 ++	cryptoproc = (pid_t) -1;
22239 ++	kill_proc(p, SIGTERM, 1);
22240 ++	wake_up_interruptible(&cryptoproc_wait);
22241 ++	CRYPTO_DRIVER_UNLOCK();
22242 ++
22243 ++	wait_for_completion(&cryptoproc_exited);
22244 ++
22245 ++	CRYPTO_DRIVER_LOCK();
22246 ++	p = cryptoretproc;
22247 ++	cryptoretproc = (pid_t) -1;
22248 ++	kill_proc(p, SIGTERM, 1);
22249 ++	wake_up_interruptible(&cryptoretproc_wait);
22250 ++	CRYPTO_DRIVER_UNLOCK();
22251 ++
22252 ++	wait_for_completion(&cryptoretproc_exited);
22253 ++
22254 ++	/* XXX flush queues??? */
22255 ++
22256 ++	/* 
22257 ++	 * Reclaim dynamically allocated resources.
22258 ++	 */
22259 ++	if (crypto_drivers != NULL)
22260 ++		kfree(crypto_drivers);
22261 ++
22262 ++	if (cryptodesc_zone != NULL)
22263 ++		kmem_cache_destroy(cryptodesc_zone);
22264 ++	if (cryptop_zone != NULL)
22265 ++		kmem_cache_destroy(cryptop_zone);
22266 ++}
22267 ++
22268 ++
22269 ++EXPORT_SYMBOL(crypto_newsession);
22270 ++EXPORT_SYMBOL(crypto_freesession);
22271 ++EXPORT_SYMBOL(crypto_get_driverid);
22272 ++EXPORT_SYMBOL(crypto_kregister);
22273 ++EXPORT_SYMBOL(crypto_register);
22274 ++EXPORT_SYMBOL(crypto_unregister);
22275 ++EXPORT_SYMBOL(crypto_unregister_all);
22276 ++EXPORT_SYMBOL(crypto_unblock);
22277 ++EXPORT_SYMBOL(crypto_dispatch);
22278 ++EXPORT_SYMBOL(crypto_kdispatch);
22279 ++EXPORT_SYMBOL(crypto_freereq);
22280 ++EXPORT_SYMBOL(crypto_getreq);
22281 ++EXPORT_SYMBOL(crypto_done);
22282 ++EXPORT_SYMBOL(crypto_kdone);
22283 ++EXPORT_SYMBOL(crypto_getfeat);
22284 ++EXPORT_SYMBOL(crypto_userasymcrypto);
22285 ++EXPORT_SYMBOL(crypto_getcaps);
22286 ++EXPORT_SYMBOL(crypto_find_driver);
22287 ++EXPORT_SYMBOL(crypto_find_device_byhid);
22288 ++
22289 ++module_init(crypto_init);
22290 ++module_exit(crypto_exit);
22291 ++
22292 ++MODULE_LICENSE("BSD");
22293 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
22294 ++MODULE_DESCRIPTION("OCF (OpenBSD Cryptographic Framework)");
22295 +diff -urN linux-2.6.23.16.old/crypto/ocf/cryptodev.c linux-2.6.23.16/crypto/ocf/cryptodev.c
22296 +--- linux-2.6.23.16.old/crypto/ocf/cryptodev.c	1969-12-31 19:00:00.000000000 -0500
22297 ++++ linux-2.6.23.16/crypto/ocf/cryptodev.c	2008-02-26 09:29:13.000000000 -0500
22298 +@@ -0,0 +1,1048 @@
22299 ++/*	$OpenBSD: cryptodev.c,v 1.52 2002/06/19 07:22:46 deraadt Exp $	*/
22300 ++
22301 ++/*-
22302 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
22303 ++ * Copyright (C) 2006-2007 David McCullough
22304 ++ * Copyright (C) 2004-2005 Intel Corporation.
22305 ++ * The license and original author are listed below.
22306 ++ *
22307 ++ * Copyright (c) 2001 Theo de Raadt
22308 ++ * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting
22309 ++ *
22310 ++ * Redistribution and use in source and binary forms, with or without
22311 ++ * modification, are permitted provided that the following conditions
22312 ++ * are met:
22313 ++ *
22314 ++ * 1. Redistributions of source code must retain the above copyright
22315 ++ *   notice, this list of conditions and the following disclaimer.
22316 ++ * 2. Redistributions in binary form must reproduce the above copyright
22317 ++ *   notice, this list of conditions and the following disclaimer in the
22318 ++ *   documentation and/or other materials provided with the distribution.
22319 ++ * 3. The name of the author may not be used to endorse or promote products
22320 ++ *   derived from this software without specific prior written permission.
22321 ++ *
22322 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22323 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22324 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22325 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22326 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22327 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22328 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22329 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22330 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22331 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22332 ++ *
22333 ++ * Effort sponsored in part by the Defense Advanced Research Projects
22334 ++ * Agency (DARPA) and Air Force Research Laboratory, Air Force
22335 ++ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
22336 ++ *
22337 ++__FBSDID("$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.34 2007/05/09 19:37:02 gnn Exp $");
22338 ++ */
22339 ++
22340 ++#ifndef AUTOCONF_INCLUDED
22341 ++#include <linux/config.h>
22342 ++#endif
22343 ++#include <linux/types.h>
22344 ++#include <linux/time.h>
22345 ++#include <linux/delay.h>
22346 ++#include <linux/list.h>
22347 ++#include <linux/init.h>
22348 ++#include <linux/sched.h>
22349 ++#include <linux/unistd.h>
22350 ++#include <linux/module.h>
22351 ++#include <linux/wait.h>
22352 ++#include <linux/slab.h>
22353 ++#include <linux/fs.h>
22354 ++#include <linux/dcache.h>
22355 ++#include <linux/file.h>
22356 ++#include <linux/mount.h>
22357 ++#include <linux/miscdevice.h>
22358 ++#include <linux/version.h>
22359 ++#include <asm/uaccess.h>
22360 ++
22361 ++#include <cryptodev.h>
22362 ++#include <uio.h>
22363 ++
22364 ++extern asmlinkage long sys_dup(unsigned int fildes);
22365 ++
22366 ++#define debug cryptodev_debug
22367 ++int cryptodev_debug = 0;
22368 ++module_param(cryptodev_debug, int, 0644);
22369 ++MODULE_PARM_DESC(cryptodev_debug, "Enable cryptodev debug");
22370 ++
22371 ++struct csession_info {
22372 ++	u_int16_t	blocksize;
22373 ++	u_int16_t	minkey, maxkey;
22374 ++
22375 ++	u_int16_t	keysize;
22376 ++	/* u_int16_t	hashsize;  */
22377 ++	u_int16_t	authsize;
22378 ++	/* u_int16_t	ctxsize; */
22379 ++};
22380 ++
22381 ++struct csession {
22382 ++	struct list_head	list;
22383 ++	u_int64_t	sid;
22384 ++	u_int32_t	ses;
22385 ++
22386 ++	wait_queue_head_t waitq;
22387 ++
22388 ++	u_int32_t	cipher;
22389 ++
22390 ++	u_int32_t	mac;
22391 ++
22392 ++	caddr_t		key;
22393 ++	int		keylen;
22394 ++	u_char		tmp_iv[EALG_MAX_BLOCK_LEN];
22395 ++
22396 ++	caddr_t		mackey;
22397 ++	int		mackeylen;
22398 ++
22399 ++	struct csession_info info;
22400 ++
22401 ++	struct iovec	iovec;
22402 ++	struct uio	uio;
22403 ++	int		error;
22404 ++};
22405 ++
22406 ++struct fcrypt {
22407 ++	struct list_head	csessions;
22408 ++	int		sesn;
22409 ++};
22410 ++
22411 ++static struct csession *csefind(struct fcrypt *, u_int);
22412 ++static int csedelete(struct fcrypt *, struct csession *);
22413 ++static struct csession *cseadd(struct fcrypt *, struct csession *);
22414 ++static struct csession *csecreate(struct fcrypt *, u_int64_t,
22415 ++		struct cryptoini *crie, struct cryptoini *cria, struct csession_info *);
22416 ++static int csefree(struct csession *);
22417 ++
22418 ++static	int cryptodev_op(struct csession *, struct crypt_op *);
22419 ++static	int cryptodev_key(struct crypt_kop *);
22420 ++static	int cryptodev_find(struct crypt_find_op *);
22421 ++
22422 ++static int cryptodev_cb(void *);
22423 ++static int cryptodev_open(struct inode *inode, struct file *filp);
22424 ++
22425 ++/*
22426 ++ * Check a crypto identifier to see if it requested
22427 ++ * a valid crid and it's capabilities match.
22428 ++ */
22429 ++static int
22430 ++checkcrid(int crid)
22431 ++{
22432 ++	int hid = crid & ~(CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_HARDWARE);
22433 ++	int typ = crid & (CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_HARDWARE);
22434 ++	int caps = 0;
22435 ++	
22436 ++	/* if the user hasn't selected a driver, then just call newsession */
22437 ++	if (hid == 0 && typ != 0)
22438 ++		return 0;
22439 ++
22440 ++	caps = crypto_getcaps(hid);
22441 ++
22442 ++	/* didn't find anything with capabilities */
22443 ++	if (caps == 0) {
22444 ++		dprintk("%s: hid=%x typ=%x not matched\n", __FUNCTION__, hid, typ);
22445 ++		return EINVAL;
22446 ++	}
22447 ++	
22448 ++	/* the user didn't specify SW or HW, so the driver is ok */
22449 ++	if (typ == 0)
22450 ++		return 0;
22451 ++
22452 ++	/* if the type specified didn't match */
22453 ++	if (typ != (caps & (CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_HARDWARE))) {
22454 ++		dprintk("%s: hid=%x typ=%x caps=%x not matched\n", __FUNCTION__,
22455 ++				hid, typ, caps);
22456 ++		return EINVAL;
22457 ++	}
22458 ++
22459 ++	return 0;
22460 ++}
22461 ++
22462 ++static int
22463 ++cryptodev_op(struct csession *cse, struct crypt_op *cop)
22464 ++{
22465 ++	struct cryptop *crp = NULL;
22466 ++	struct cryptodesc *crde = NULL, *crda = NULL;
22467 ++	int error = 0;
22468 ++
22469 ++	dprintk("%s()\n", __FUNCTION__);
22470 ++	if (cop->len > CRYPTO_MAX_DATA_LEN) {
22471 ++		dprintk("%s: %d > %d\n", __FUNCTION__, cop->len, CRYPTO_MAX_DATA_LEN);
22472 ++		return (E2BIG);
22473 ++	}
22474 ++
22475 ++	if (cse->info.blocksize && (cop->len % cse->info.blocksize) != 0) {
22476 ++		dprintk("%s: blocksize=%d len=%d\n", __FUNCTION__, cse->info.blocksize,
22477 ++				cop->len);
22478 ++		return (EINVAL);
22479 ++	}
22480 ++
22481 ++	cse->uio.uio_iov = &cse->iovec;
22482 ++	cse->uio.uio_iovcnt = 1;
22483 ++	cse->uio.uio_offset = 0;
22484 ++#if 0
22485 ++	cse->uio.uio_resid = cop->len;
22486 ++	cse->uio.uio_segflg = UIO_SYSSPACE;
22487 ++	cse->uio.uio_rw = UIO_WRITE;
22488 ++	cse->uio.uio_td = td;
22489 ++#endif
22490 ++	cse->uio.uio_iov[0].iov_len = cop->len;
22491 ++	if (cse->info.authsize)
22492 ++		cse->uio.uio_iov[0].iov_len += cse->info.authsize;
22493 ++	cse->uio.uio_iov[0].iov_base = kmalloc(cse->uio.uio_iov[0].iov_len,
22494 ++			GFP_KERNEL);
22495 ++
22496 ++	if (cse->uio.uio_iov[0].iov_base == NULL) {
22497 ++		dprintk("%s: iov_base kmalloc(%d) failed\n", __FUNCTION__,
22498 ++				cse->uio.uio_iov[0].iov_len);
22499 ++		return (ENOMEM);
22500 ++	}
22501 ++
22502 ++	crp = crypto_getreq((cse->info.blocksize != 0) + (cse->info.authsize != 0));
22503 ++	if (crp == NULL) {
22504 ++		dprintk("%s: ENOMEM\n", __FUNCTION__);
22505 ++		error = ENOMEM;
22506 ++		goto bail;
22507 ++	}
22508 ++
22509 ++	if (cse->info.authsize) {
22510 ++		crda = crp->crp_desc;
22511 ++		if (cse->info.blocksize)
22512 ++			crde = crda->crd_next;
22513 ++	} else {
22514 ++		if (cse->info.blocksize)
22515 ++			crde = crp->crp_desc;
22516 ++		else {
22517 ++			dprintk("%s: bad request\n", __FUNCTION__);
22518 ++			error = EINVAL;
22519 ++			goto bail;
22520 ++		}
22521 ++	}
22522 ++
22523 ++	if ((error = copy_from_user(cse->uio.uio_iov[0].iov_base, cop->src,
22524 ++					cop->len))) {
22525 ++		dprintk("%s: bad copy\n", __FUNCTION__);
22526 ++		goto bail;
22527 ++	}
22528 ++
22529 ++	if (crda) {
22530 ++		crda->crd_skip = 0;
22531 ++		crda->crd_len = cop->len;
22532 ++		crda->crd_inject = cop->len;
22533 ++
22534 ++		crda->crd_alg = cse->mac;
22535 ++		crda->crd_key = cse->mackey;
22536 ++		crda->crd_klen = cse->mackeylen * 8;
22537 ++	}
22538 ++
22539 ++	if (crde) {
22540 ++		if (cop->op == COP_ENCRYPT)
22541 ++			crde->crd_flags |= CRD_F_ENCRYPT;
22542 ++		else
22543 ++			crde->crd_flags &= ~CRD_F_ENCRYPT;
22544 ++		crde->crd_len = cop->len;
22545 ++		crde->crd_inject = 0;
22546 ++
22547 ++		crde->crd_alg = cse->cipher;
22548 ++		crde->crd_key = cse->key;
22549 ++		crde->crd_klen = cse->keylen * 8;
22550 ++	}
22551 ++
22552 ++	crp->crp_ilen = cse->uio.uio_iov[0].iov_len;
22553 ++	crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_CBIMM
22554 ++		       | (cop->flags & COP_F_BATCH);
22555 ++	crp->crp_buf = (caddr_t)&cse->uio;
22556 ++	crp->crp_callback = (int (*) (struct cryptop *)) cryptodev_cb;
22557 ++	crp->crp_sid = cse->sid;
22558 ++	crp->crp_opaque = (void *)cse;
22559 ++
22560 ++	if (cop->iv) {
22561 ++		if (crde == NULL) {
22562 ++			error = EINVAL;
22563 ++			dprintk("%s no crde\n", __FUNCTION__);
22564 ++			goto bail;
22565 ++		}
22566 ++		if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
22567 ++			error = EINVAL;
22568 ++			dprintk("%s arc4 with IV\n", __FUNCTION__);
22569 ++			goto bail;
22570 ++		}
22571 ++		if ((error = copy_from_user(cse->tmp_iv, cop->iv,
22572 ++						cse->info.blocksize))) {
22573 ++			dprintk("%s bad iv copy\n", __FUNCTION__);
22574 ++			goto bail;
22575 ++		}
22576 ++		memcpy(crde->crd_iv, cse->tmp_iv, cse->info.blocksize);
22577 ++		crde->crd_flags |= CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT;
22578 ++		crde->crd_skip = 0;
22579 ++	} else if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
22580 ++		crde->crd_skip = 0;
22581 ++	} else if (crde) {
22582 ++		crde->crd_flags |= CRD_F_IV_PRESENT;
22583 ++		crde->crd_skip = cse->info.blocksize;
22584 ++		crde->crd_len -= cse->info.blocksize;
22585 ++	}
22586 ++
22587 ++	if (cop->mac && crda == NULL) {
22588 ++		error = EINVAL;
22589 ++		dprintk("%s no crda\n", __FUNCTION__);
22590 ++		goto bail;
22591 ++	}
22592 ++
22593 ++	/*
22594 ++	 * Let the dispatch run unlocked, then, interlock against the
22595 ++	 * callback before checking if the operation completed and going
22596 ++	 * to sleep.  This insures drivers don't inherit our lock which
22597 ++	 * results in a lock order reversal between crypto_dispatch forced
22598 ++	 * entry and the crypto_done callback into us.
22599 ++	 */
22600 ++	error = crypto_dispatch(crp);
22601 ++	if (error == 0) {
22602 ++		dprintk("%s about to WAIT\n", __FUNCTION__);
22603 ++		/*
22604 ++		 * we really need to wait for driver to complete to maintain
22605 ++		 * state,  luckily interrupts will be remembered
22606 ++		 */
22607 ++		do {
22608 ++			error = wait_event_interruptible(crp->crp_waitq,
22609 ++					((crp->crp_flags & CRYPTO_F_DONE) != 0));
22610 ++			/*
22611 ++			 * we can't break out of this loop or we will leave behind
22612 ++			 * a huge mess,  however,  staying here means if your driver
22613 ++			 * is broken user applications can hang and not be killed.
22614 ++			 * The solution,  fix your driver :-)
22615 ++			 */
22616 ++			if (error) {
22617 ++				schedule();
22618 ++				error = 0;
22619 ++			}
22620 ++		} while ((crp->crp_flags & CRYPTO_F_DONE) == 0);
22621 ++		dprintk("%s finished WAITING error=%d\n", __FUNCTION__, error);
22622 ++	}
22623 ++
22624 ++	if (crp->crp_etype != 0) {
22625 ++		error = crp->crp_etype;
22626 ++		dprintk("%s error in crp processing\n", __FUNCTION__);
22627 ++		goto bail;
22628 ++	}
22629 ++
22630 ++	if (cse->error) {
22631 ++		error = cse->error;
22632 ++		dprintk("%s error in cse processing\n", __FUNCTION__);
22633 ++		goto bail;
22634 ++	}
22635 ++
22636 ++	if (cop->dst && (error = copy_to_user(cop->dst,
22637 ++					cse->uio.uio_iov[0].iov_base, cop->len))) {
22638 ++		dprintk("%s bad dst copy\n", __FUNCTION__);
22639 ++		goto bail;
22640 ++	}
22641 ++
22642 ++	if (cop->mac &&
22643 ++			(error=copy_to_user(cop->mac,
22644 ++				(caddr_t)cse->uio.uio_iov[0].iov_base + cop->len,
22645 ++				cse->info.authsize))) {
22646 ++		dprintk("%s bad mac copy\n", __FUNCTION__);
22647 ++		goto bail;
22648 ++	}
22649 ++
22650 ++bail:
22651 ++	if (crp)
22652 ++		crypto_freereq(crp);
22653 ++	if (cse->uio.uio_iov[0].iov_base)
22654 ++		kfree(cse->uio.uio_iov[0].iov_base);
22655 ++
22656 ++	return (error);
22657 ++}
22658 ++
22659 ++static int
22660 ++cryptodev_cb(void *op)
22661 ++{
22662 ++	struct cryptop *crp = (struct cryptop *) op;
22663 ++	struct csession *cse = (struct csession *)crp->crp_opaque;
22664 ++	int error;
22665 ++
22666 ++	dprintk("%s()\n", __FUNCTION__);
22667 ++	error = crp->crp_etype;
22668 ++	if (error == EAGAIN) {
22669 ++		crp->crp_flags &= ~CRYPTO_F_DONE;
22670 ++#ifdef NOTYET
22671 ++		/*
22672 ++		 * DAVIDM I am fairly sure that we should turn this into a batch
22673 ++		 * request to stop bad karma/lockup, revisit
22674 ++		 */
22675 ++		crp->crp_flags |= CRYPTO_F_BATCH;
22676 ++#endif
22677 ++		return crypto_dispatch(crp);
22678 ++	}
22679 ++	if (error != 0 || (crp->crp_flags & CRYPTO_F_DONE)) {
22680 ++		cse->error = error;
22681 ++		wake_up_interruptible(&crp->crp_waitq);
22682 ++	}
22683 ++	return (0);
22684 ++}
22685 ++
22686 ++static int
22687 ++cryptodevkey_cb(void *op)
22688 ++{
22689 ++	struct cryptkop *krp = (struct cryptkop *) op;
22690 ++	dprintk("%s()\n", __FUNCTION__);
22691 ++	wake_up_interruptible(&krp->krp_waitq);
22692 ++	return (0);
22693 ++}
22694 ++
22695 ++static int
22696 ++cryptodev_key(struct crypt_kop *kop)
22697 ++{
22698 ++	struct cryptkop *krp = NULL;
22699 ++	int error = EINVAL;
22700 ++	int in, out, size, i;
22701 ++
22702 ++	dprintk("%s()\n", __FUNCTION__);
22703 ++	if (kop->crk_iparams + kop->crk_oparams > CRK_MAXPARAM) {
22704 ++		dprintk("%s params too big\n", __FUNCTION__);
22705 ++		return (EFBIG);
22706 ++	}
22707 ++
22708 ++	in = kop->crk_iparams;
22709 ++	out = kop->crk_oparams;
22710 ++	switch (kop->crk_op) {
22711 ++	case CRK_MOD_EXP:
22712 ++		if (in == 3 && out == 1)
22713 ++			break;
22714 ++		return (EINVAL);
22715 ++	case CRK_MOD_EXP_CRT:
22716 ++		if (in == 6 && out == 1)
22717 ++			break;
22718 ++		return (EINVAL);
22719 ++	case CRK_DSA_SIGN:
22720 ++		if (in == 5 && out == 2)
22721 ++			break;
22722 ++		return (EINVAL);
22723 ++	case CRK_DSA_VERIFY:
22724 ++		if (in == 7 && out == 0)
22725 ++			break;
22726 ++		return (EINVAL);
22727 ++	case CRK_DH_COMPUTE_KEY:
22728 ++		if (in == 3 && out == 1)
22729 ++			break;
22730 ++		return (EINVAL);
22731 ++	default:
22732 ++		return (EINVAL);
22733 ++	}
22734 ++
22735 ++	krp = (struct cryptkop *)kmalloc(sizeof *krp, GFP_KERNEL);
22736 ++	if (!krp)
22737 ++		return (ENOMEM);
22738 ++	bzero(krp, sizeof *krp);
22739 ++	krp->krp_op = kop->crk_op;
22740 ++	krp->krp_status = kop->crk_status;
22741 ++	krp->krp_iparams = kop->crk_iparams;
22742 ++	krp->krp_oparams = kop->crk_oparams;
22743 ++	krp->krp_crid = kop->crk_crid;
22744 ++	krp->krp_status = 0;
22745 ++	krp->krp_flags = CRYPTO_KF_CBIMM;
22746 ++	krp->krp_callback = (int (*) (struct cryptkop *)) cryptodevkey_cb;
22747 ++	init_waitqueue_head(&krp->krp_waitq);
22748 ++
22749 ++	for (i = 0; i < CRK_MAXPARAM; i++)
22750 ++		krp->krp_param[i].crp_nbits = kop->crk_param[i].crp_nbits;
22751 ++	for (i = 0; i < krp->krp_iparams + krp->krp_oparams; i++) {
22752 ++		size = (krp->krp_param[i].crp_nbits + 7) / 8;
22753 ++		if (size == 0)
22754 ++			continue;
22755 ++		krp->krp_param[i].crp_p = (caddr_t) kmalloc(size, GFP_KERNEL);
22756 ++		if (i >= krp->krp_iparams)
22757 ++			continue;
22758 ++		error = copy_from_user(krp->krp_param[i].crp_p,
22759 ++				kop->crk_param[i].crp_p, size);
22760 ++		if (error)
22761 ++			goto fail;
22762 ++	}
22763 ++
22764 ++	error = crypto_kdispatch(krp);
22765 ++	if (error)
22766 ++		goto fail;
22767 ++
22768 ++	do {
22769 ++		error = wait_event_interruptible(krp->krp_waitq,
22770 ++				((krp->krp_flags & CRYPTO_KF_DONE) != 0));
22771 ++		/*
22772 ++		 * we can't break out of this loop or we will leave behind
22773 ++		 * a huge mess,  however,  staying here means if your driver
22774 ++		 * is broken user applications can hang and not be killed.
22775 ++		 * The solution,  fix your driver :-)
22776 ++		 */
22777 ++		if (error) {
22778 ++			schedule();
22779 ++			error = 0;
22780 ++		}
22781 ++	} while ((krp->krp_flags & CRYPTO_KF_DONE) == 0);
22782 ++
22783 ++	dprintk("%s finished WAITING error=%d\n", __FUNCTION__, error);
22784 ++	
22785 ++	kop->crk_crid = krp->krp_crid;		/* device that did the work */
22786 ++	if (krp->krp_status != 0) {
22787 ++		error = krp->krp_status;
22788 ++		goto fail;
22789 ++	}
22790 ++
22791 ++	for (i = krp->krp_iparams; i < krp->krp_iparams + krp->krp_oparams; i++) {
22792 ++		size = (krp->krp_param[i].crp_nbits + 7) / 8;
22793 ++		if (size == 0)
22794 ++			continue;
22795 ++		error = copy_to_user(kop->crk_param[i].crp_p, krp->krp_param[i].crp_p,
22796 ++				size);
22797 ++		if (error)
22798 ++			goto fail;
22799 ++	}
22800 ++
22801 ++fail:
22802 ++	if (krp) {
22803 ++		kop->crk_status = krp->krp_status;
22804 ++		for (i = 0; i < CRK_MAXPARAM; i++) {
22805 ++			if (krp->krp_param[i].crp_p)
22806 ++				kfree(krp->krp_param[i].crp_p);
22807 ++		}
22808 ++		kfree(krp);
22809 ++	}
22810 ++	return (error);
22811 ++}
22812 ++
22813 ++static int
22814 ++cryptodev_find(struct crypt_find_op *find)
22815 ++{
22816 ++	device_t dev;
22817 ++
22818 ++	if (find->crid != -1) {
22819 ++		dev = crypto_find_device_byhid(find->crid);
22820 ++		if (dev == NULL)
22821 ++			return (ENOENT);
22822 ++		strlcpy(find->name, device_get_nameunit(dev),
22823 ++		    sizeof(find->name));
22824 ++	} else {
22825 ++		find->crid = crypto_find_driver(find->name);
22826 ++		if (find->crid == -1)
22827 ++			return (ENOENT);
22828 ++	}
22829 ++	return (0);
22830 ++}
22831 ++
22832 ++static struct csession *
22833 ++csefind(struct fcrypt *fcr, u_int ses)
22834 ++{
22835 ++	struct csession *cse;
22836 ++
22837 ++	dprintk("%s()\n", __FUNCTION__);
22838 ++	list_for_each_entry(cse, &fcr->csessions, list)
22839 ++		if (cse->ses == ses)
22840 ++			return (cse);
22841 ++	return (NULL);
22842 ++}
22843 ++
22844 ++static int
22845 ++csedelete(struct fcrypt *fcr, struct csession *cse_del)
22846 ++{
22847 ++	struct csession *cse;
22848 ++
22849 ++	dprintk("%s()\n", __FUNCTION__);
22850 ++	list_for_each_entry(cse, &fcr->csessions, list) {
22851 ++		if (cse == cse_del) {
22852 ++			list_del(&cse->list);
22853 ++			return (1);
22854 ++		}
22855 ++	}
22856 ++	return (0);
22857 ++}
22858 ++	
22859 ++static struct csession *
22860 ++cseadd(struct fcrypt *fcr, struct csession *cse)
22861 ++{
22862 ++	dprintk("%s()\n", __FUNCTION__);
22863 ++	list_add_tail(&cse->list, &fcr->csessions);
22864 ++	cse->ses = fcr->sesn++;
22865 ++	return (cse);
22866 ++}
22867 ++
22868 ++static struct csession *
22869 ++csecreate(struct fcrypt *fcr, u_int64_t sid, struct cryptoini *crie,
22870 ++	struct cryptoini *cria, struct csession_info *info)
22871 ++{
22872 ++	struct csession *cse;
22873 ++
22874 ++	dprintk("%s()\n", __FUNCTION__);
22875 ++	cse = (struct csession *) kmalloc(sizeof(struct csession), GFP_KERNEL);
22876 ++	if (cse == NULL)
22877 ++		return NULL;
22878 ++	memset(cse, 0, sizeof(struct csession));
22879 ++
22880 ++	INIT_LIST_HEAD(&cse->list);
22881 ++	init_waitqueue_head(&cse->waitq);
22882 ++
22883 ++	cse->key = crie->cri_key;
22884 ++	cse->keylen = crie->cri_klen/8;
22885 ++	cse->mackey = cria->cri_key;
22886 ++	cse->mackeylen = cria->cri_klen/8;
22887 ++	cse->sid = sid;
22888 ++	cse->cipher = crie->cri_alg;
22889 ++	cse->mac = cria->cri_alg;
22890 ++	cse->info = *info;
22891 ++	cseadd(fcr, cse);
22892 ++	return (cse);
22893 ++}
22894 ++
22895 ++static int
22896 ++csefree(struct csession *cse)
22897 ++{
22898 ++	int error;
22899 ++
22900 ++	dprintk("%s()\n", __FUNCTION__);
22901 ++	error = crypto_freesession(cse->sid);
22902 ++	if (cse->key)
22903 ++		kfree(cse->key);
22904 ++	if (cse->mackey)
22905 ++		kfree(cse->mackey);
22906 ++	kfree(cse);
22907 ++	return(error);
22908 ++}
22909 ++
22910 ++static int
22911 ++cryptodev_ioctl(
22912 ++	struct inode *inode,
22913 ++	struct file *filp,
22914 ++	unsigned int cmd,
22915 ++	unsigned long arg)
22916 ++{
22917 ++	struct cryptoini cria, crie;
22918 ++	struct fcrypt *fcr = filp->private_data;
22919 ++	struct csession *cse;
22920 ++	struct csession_info info;
22921 ++	struct session2_op sop;
22922 ++	struct crypt_op cop;
22923 ++	struct crypt_kop kop;
22924 ++	struct crypt_find_op fop;
22925 ++	u_int64_t sid;
22926 ++	u_int32_t ses;
22927 ++	int feat, fd, error = 0, crid;
22928 ++	mm_segment_t fs;
22929 ++
22930 ++	dprintk("%s(cmd=%x arg=%lx)\n", __FUNCTION__, cmd, arg);
22931 ++
22932 ++	switch (cmd) {
22933 ++
22934 ++	case CRIOGET: {
22935 ++		dprintk("%s(CRIOGET)\n", __FUNCTION__);
22936 ++		fs = get_fs();
22937 ++		set_fs(get_ds());
22938 ++		for (fd = 0; fd < files_fdtable(current->files)->max_fds; fd++)
22939 ++			if (files_fdtable(current->files)->fd[fd] == filp)
22940 ++				break;
22941 ++		fd = sys_dup(fd);
22942 ++		set_fs(fs);
22943 ++		put_user(fd, (int *) arg);
22944 ++		return IS_ERR_VALUE(fd) ? fd : 0;
22945 ++		}
22946 ++
22947 ++#define	CIOCGSESSSTR	(cmd == CIOCGSESSION ? "CIOCGSESSION" : "CIOCGSESSION2")
22948 ++	case CIOCGSESSION:
22949 ++	case CIOCGSESSION2:
22950 ++		dprintk("%s(%s)\n", __FUNCTION__, CIOCGSESSSTR);
22951 ++		memset(&crie, 0, sizeof(crie));
22952 ++		memset(&cria, 0, sizeof(cria));
22953 ++		memset(&info, 0, sizeof(info));
22954 ++		memset(&sop, 0, sizeof(sop));
22955 ++
22956 ++		if (copy_from_user(&sop, (void*)arg, (cmd == CIOCGSESSION) ?
22957 ++					sizeof(struct session_op) : sizeof(sop))) {
22958 ++			dprintk("%s(%s) - bad copy\n", __FUNCTION__, CIOCGSESSSTR);
22959 ++			error = EFAULT;
22960 ++			goto bail;
22961 ++		}
22962 ++
22963 ++		switch (sop.cipher) {
22964 ++		case 0:
22965 ++			dprintk("%s(%s) - no cipher\n", __FUNCTION__, CIOCGSESSSTR);
22966 ++			break;
22967 ++		case CRYPTO_NULL_CBC:
22968 ++			info.blocksize = NULL_BLOCK_LEN;
22969 ++			info.minkey = NULL_MIN_KEY_LEN;
22970 ++			info.maxkey = NULL_MAX_KEY_LEN;
22971 ++			break;
22972 ++		case CRYPTO_DES_CBC:
22973 ++			info.blocksize = DES_BLOCK_LEN;
22974 ++			info.minkey = DES_MIN_KEY_LEN;
22975 ++			info.maxkey = DES_MAX_KEY_LEN;
22976 ++			break;
22977 ++		case CRYPTO_3DES_CBC:
22978 ++			info.blocksize = DES3_BLOCK_LEN;
22979 ++			info.minkey = DES3_MIN_KEY_LEN;
22980 ++			info.maxkey = DES3_MAX_KEY_LEN;
22981 ++			break;
22982 ++		case CRYPTO_BLF_CBC:
22983 ++			info.blocksize = BLOWFISH_BLOCK_LEN;
22984 ++			info.minkey = BLOWFISH_MIN_KEY_LEN;
22985 ++			info.maxkey = BLOWFISH_MAX_KEY_LEN;
22986 ++			break;
22987 ++		case CRYPTO_CAST_CBC:
22988 ++			info.blocksize = CAST128_BLOCK_LEN;
22989 ++			info.minkey = CAST128_MIN_KEY_LEN;
22990 ++			info.maxkey = CAST128_MAX_KEY_LEN;
22991 ++			break;
22992 ++		case CRYPTO_SKIPJACK_CBC:
22993 ++			info.blocksize = SKIPJACK_BLOCK_LEN;
22994 ++			info.minkey = SKIPJACK_MIN_KEY_LEN;
22995 ++			info.maxkey = SKIPJACK_MAX_KEY_LEN;
22996 ++			break;
22997 ++		case CRYPTO_AES_CBC:
22998 ++			info.blocksize = AES_BLOCK_LEN;
22999 ++			info.minkey = AES_MIN_KEY_LEN;
23000 ++			info.maxkey = AES_MAX_KEY_LEN;
23001 ++			break;
23002 ++		case CRYPTO_ARC4:
23003 ++			info.blocksize = ARC4_BLOCK_LEN;
23004 ++			info.minkey = ARC4_MIN_KEY_LEN;
23005 ++			info.maxkey = ARC4_MAX_KEY_LEN;
23006 ++			break;
23007 ++		case CRYPTO_CAMELLIA_CBC:
23008 ++			info.blocksize = CAMELLIA_BLOCK_LEN;
23009 ++			info.minkey = CAMELLIA_MIN_KEY_LEN;
23010 ++			info.maxkey = CAMELLIA_MAX_KEY_LEN;
23011 ++			break;
23012 ++		default:
23013 ++			dprintk("%s(%s) - bad cipher\n", __FUNCTION__, CIOCGSESSSTR);
23014 ++			error = EINVAL;
23015 ++			goto bail;
23016 ++		}
23017 ++
23018 ++		switch (sop.mac) {
23019 ++		case 0:
23020 ++			dprintk("%s(%s) - no mac\n", __FUNCTION__, CIOCGSESSSTR);
23021 ++			break;
23022 ++		case CRYPTO_NULL_HMAC:
23023 ++			info.authsize = NULL_HASH_LEN;
23024 ++			break;
23025 ++		case CRYPTO_MD5:
23026 ++			info.authsize = MD5_HASH_LEN;
23027 ++			break;
23028 ++		case CRYPTO_SHA1:
23029 ++			info.authsize = SHA1_HASH_LEN;
23030 ++			break;
23031 ++		case CRYPTO_SHA2_256:
23032 ++			info.authsize = SHA2_256_HASH_LEN;
23033 ++			break;
23034 ++		case CRYPTO_SHA2_384:
23035 ++			info.authsize = SHA2_384_HASH_LEN;
23036 ++  			break;
23037 ++		case CRYPTO_SHA2_512:
23038 ++			info.authsize = SHA2_512_HASH_LEN;
23039 ++			break;
23040 ++		case CRYPTO_RIPEMD160:
23041 ++			info.authsize = RIPEMD160_HASH_LEN;
23042 ++			break;
23043 ++		case CRYPTO_MD5_HMAC:
23044 ++			info.authsize = MD5_HASH_LEN;
23045 ++			break;
23046 ++		case CRYPTO_SHA1_HMAC:
23047 ++			info.authsize = SHA1_HASH_LEN;
23048 ++			break;
23049 ++		case CRYPTO_SHA2_256_HMAC:
23050 ++			info.authsize = SHA2_256_HASH_LEN;
23051 ++			break;
23052 ++		case CRYPTO_SHA2_384_HMAC:
23053 ++			info.authsize = SHA2_384_HASH_LEN;
23054 ++  			break;
23055 ++		case CRYPTO_SHA2_512_HMAC:
23056 ++			info.authsize = SHA2_512_HASH_LEN;
23057 ++			break;
23058 ++		case CRYPTO_RIPEMD160_HMAC:
23059 ++			info.authsize = RIPEMD160_HASH_LEN;
23060 ++			break;
23061 ++		default:
23062 ++			dprintk("%s(%s) - bad mac\n", __FUNCTION__, CIOCGSESSSTR);
23063 ++			error = EINVAL;
23064 ++			goto bail;
23065 ++		}
23066 ++
23067 ++		if (info.blocksize) {
23068 ++			crie.cri_alg = sop.cipher;
23069 ++			crie.cri_klen = sop.keylen * 8;
23070 ++			if ((info.maxkey && sop.keylen > info.maxkey) ||
23071 ++				   	sop.keylen < info.minkey) {
23072 ++				dprintk("%s(%s) - bad key\n", __FUNCTION__, CIOCGSESSSTR);
23073 ++				error = EINVAL;
23074 ++				goto bail;
23075 ++			}
23076 ++
23077 ++			crie.cri_key = (u_int8_t *) kmalloc(crie.cri_klen/8+1, GFP_KERNEL);
23078 ++			if (copy_from_user(crie.cri_key, sop.key,
23079 ++							crie.cri_klen/8)) {
23080 ++				dprintk("%s(%s) - bad copy\n", __FUNCTION__, CIOCGSESSSTR);
23081 ++				error = EFAULT;
23082 ++				goto bail;
23083 ++			}
23084 ++			if (info.authsize)
23085 ++				crie.cri_next = &cria;
23086 ++		}
23087 ++
23088 ++		if (info.authsize) {
23089 ++			cria.cri_alg = sop.mac;
23090 ++			cria.cri_klen = sop.mackeylen * 8;
23091 ++			if ((info.maxkey && sop.mackeylen > info.maxkey) ||
23092 ++					sop.keylen < info.minkey) {
23093 ++				dprintk("%s(%s) - mackeylen %d\n", __FUNCTION__, CIOCGSESSSTR,
23094 ++						sop.mackeylen);
23095 ++				error = EINVAL;
23096 ++				goto bail;
23097 ++			}
23098 ++
23099 ++			if (cria.cri_klen) {
23100 ++				cria.cri_key = (u_int8_t *) kmalloc(cria.cri_klen/8,GFP_KERNEL);
23101 ++				if (copy_from_user(cria.cri_key, sop.mackey,
23102 ++								cria.cri_klen / 8)) {
23103 ++					dprintk("%s(%s) - bad copy\n", __FUNCTION__, CIOCGSESSSTR);
23104 ++					error = EFAULT;
23105 ++					goto bail;
23106 ++				}
23107 ++			}
23108 ++		}
23109 ++
23110 ++		/* NB: CIOGSESSION2 has the crid */
23111 ++		if (cmd == CIOCGSESSION2) {
23112 ++			crid = sop.crid;
23113 ++			error = checkcrid(crid);
23114 ++			if (error) {
23115 ++				dprintk("%s(%s) - checkcrid %x\n", __FUNCTION__,
23116 ++						CIOCGSESSSTR, error);
23117 ++				goto bail;
23118 ++			}
23119 ++		} else {
23120 ++			/* allow either HW or SW to be used */
23121 ++			crid = CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE;
23122 ++		}
23123 ++		error = crypto_newsession(&sid, (info.blocksize ? &crie : &cria), crid);
23124 ++		if (error) {
23125 ++			dprintk("%s(%s) - newsession %d\n",__FUNCTION__,CIOCGSESSSTR,error);
23126 ++			goto bail;
23127 ++		}
23128 ++
23129 ++		cse = csecreate(fcr, sid, &crie, &cria, &info);
23130 ++		if (cse == NULL) {
23131 ++			crypto_freesession(sid);
23132 ++			error = EINVAL;
23133 ++			dprintk("%s(%s) - csecreate failed\n", __FUNCTION__, CIOCGSESSSTR);
23134 ++			goto bail;
23135 ++		}
23136 ++		sop.ses = cse->ses;
23137 ++
23138 ++		if (cmd == CIOCGSESSION2) {
23139 ++			/* return hardware/driver id */
23140 ++			sop.crid = CRYPTO_SESID2HID(cse->sid);
23141 ++		}
23142 ++
23143 ++		if (copy_to_user((void*)arg, &sop, (cmd == CIOCGSESSION) ?
23144 ++					sizeof(struct session_op) : sizeof(sop))) {
23145 ++			dprintk("%s(%s) - bad copy\n", __FUNCTION__, CIOCGSESSSTR);
23146 ++			error = EFAULT;
23147 ++		}
23148 ++bail:
23149 ++		if (error) {
23150 ++			dprintk("%s(%s) - bail %d\n", __FUNCTION__, CIOCGSESSSTR, error);
23151 ++			if (crie.cri_key)
23152 ++				kfree(crie.cri_key);
23153 ++			if (cria.cri_key)
23154 ++				kfree(cria.cri_key);
23155 ++		}
23156 ++		break;
23157 ++	case CIOCFSESSION:
23158 ++		dprintk("%s(CIOCFSESSION)\n", __FUNCTION__);
23159 ++		get_user(ses, (uint32_t*)arg);
23160 ++		cse = csefind(fcr, ses);
23161 ++		if (cse == NULL) {
23162 ++			error = EINVAL;
23163 ++			dprintk("%s(CIOCFSESSION) - Fail %d\n", __FUNCTION__, error);
23164 ++			break;
23165 ++		}
23166 ++		csedelete(fcr, cse);
23167 ++		error = csefree(cse);
23168 ++		break;
23169 ++	case CIOCCRYPT:
23170 ++		dprintk("%s(CIOCCRYPT)\n", __FUNCTION__);
23171 ++		if(copy_from_user(&cop, (void*)arg, sizeof(cop))) {
23172 ++			dprintk("%s(CIOCCRYPT) - bad copy\n", __FUNCTION__);
23173 ++			error = EFAULT;
23174 ++			goto bail;
23175 ++		}
23176 ++		cse = csefind(fcr, cop.ses);
23177 ++		if (cse == NULL) {
23178 ++			error = EINVAL;
23179 ++			dprintk("%s(CIOCCRYPT) - Fail %d\n", __FUNCTION__, error);
23180 ++			break;
23181 ++		}
23182 ++		error = cryptodev_op(cse, &cop);
23183 ++		if(copy_to_user((void*)arg, &cop, sizeof(cop))) {
23184 ++			dprintk("%s(CIOCCRYPT) - bad return copy\n", __FUNCTION__);
23185 ++			error = EFAULT;
23186 ++			goto bail;
23187 ++		}
23188 ++		break;
23189 ++	case CIOCKEY:
23190 ++	case CIOCKEY2:
23191 ++		dprintk("%s(CIOCKEY)\n", __FUNCTION__);
23192 ++		if (!crypto_userasymcrypto)
23193 ++			return (EPERM);		/* XXX compat? */
23194 ++		if(copy_from_user(&kop, (void*)arg, sizeof(kop))) {
23195 ++			dprintk("%s(CIOCKEY) - bad copy\n", __FUNCTION__);
23196 ++			error = EFAULT;
23197 ++			goto bail;
23198 ++		}
23199 ++		if (cmd == CIOCKEY) {
23200 ++			/* NB: crypto core enforces s/w driver use */
23201 ++			kop.crk_crid =
23202 ++			    CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE;
23203 ++		}
23204 ++		error = cryptodev_key(&kop);
23205 ++		if(copy_to_user((void*)arg, &kop, sizeof(kop))) {
23206 ++			dprintk("%s(CIOCGKEY) - bad return copy\n", __FUNCTION__);
23207 ++			error = EFAULT;
23208 ++			goto bail;
23209 ++		}
23210 ++		break;
23211 ++	case CIOCASYMFEAT:
23212 ++		dprintk("%s(CIOCASYMFEAT)\n", __FUNCTION__);
23213 ++		if (!crypto_userasymcrypto) {
23214 ++			/*
23215 ++			 * NB: if user asym crypto operations are
23216 ++			 * not permitted return "no algorithms"
23217 ++			 * so well-behaved applications will just
23218 ++			 * fallback to doing them in software.
23219 ++			 */
23220 ++			feat = 0;
23221 ++		} else
23222 ++			error = crypto_getfeat(&feat);
23223 ++		if (!error) {
23224 ++		  error = copy_to_user((void*)arg, &feat, sizeof(feat));
23225 ++		}
23226 ++		break;
23227 ++	case CIOCFINDDEV:
23228 ++		if (copy_from_user(&fop, (void*)arg, sizeof(fop))) {
23229 ++			dprintk("%s(CIOCFINDDEV) - bad copy\n", __FUNCTION__);
23230 ++			error = EFAULT;
23231 ++			goto bail;
23232 ++		}
23233 ++		error = cryptodev_find(&fop);
23234 ++		if (copy_to_user((void*)arg, &fop, sizeof(fop))) {
23235 ++			dprintk("%s(CIOCFINDDEV) - bad return copy\n", __FUNCTION__);
23236 ++			error = EFAULT;
23237 ++			goto bail;
23238 ++		}
23239 ++		break;
23240 ++	default:
23241 ++		dprintk("%s(unknown ioctl 0x%x)\n", __FUNCTION__, cmd);
23242 ++		error = EINVAL;
23243 ++		break;
23244 ++	}
23245 ++	return(-error);
23246 ++}
23247 ++
23248 ++#ifdef HAVE_UNLOCKED_IOCTL
23249 ++static long
23250 ++cryptodev_unlocked_ioctl(
23251 ++	struct file *filp,
23252 ++	unsigned int cmd,
23253 ++	unsigned long arg)
23254 ++{
23255 ++	return cryptodev_ioctl(NULL, filp, cmd, arg);
23256 ++}
23257 ++#endif
23258 ++
23259 ++static int
23260 ++cryptodev_open(struct inode *inode, struct file *filp)
23261 ++{
23262 ++	struct fcrypt *fcr;
23263 ++
23264 ++	dprintk("%s()\n", __FUNCTION__);
23265 ++	if (filp->private_data) {
23266 ++		printk("cryptodev: Private data already exists !\n");
23267 ++		return(0);
23268 ++	}
23269 ++
23270 ++	fcr = kmalloc(sizeof(*fcr), GFP_KERNEL);
23271 ++	if (!fcr) {
23272 ++		dprintk("%s() - malloc failed\n", __FUNCTION__);
23273 ++		return(-ENOMEM);
23274 ++	}
23275 ++	memset(fcr, 0, sizeof(*fcr));
23276 ++
23277 ++	INIT_LIST_HEAD(&fcr->csessions);
23278 ++	filp->private_data = fcr;
23279 ++	return(0);
23280 ++}
23281 ++
23282 ++static int
23283 ++cryptodev_release(struct inode *inode, struct file *filp)
23284 ++{
23285 ++	struct fcrypt *fcr = filp->private_data;
23286 ++	struct csession *cse, *tmp;
23287 ++
23288 ++	dprintk("%s()\n", __FUNCTION__);
23289 ++	if (!filp) {
23290 ++		printk("cryptodev: No private data on release\n");
23291 ++		return(0);
23292 ++	}
23293 ++
23294 ++	list_for_each_entry_safe(cse, tmp, &fcr->csessions, list) {
23295 ++		list_del(&cse->list);
23296 ++		(void)csefree(cse);
23297 ++	}
23298 ++	filp->private_data = NULL;
23299 ++	kfree(fcr);
23300 ++	return(0);
23301 ++}
23302 ++
23303 ++static struct file_operations cryptodev_fops = {
23304 ++	.owner = THIS_MODULE,
23305 ++	.open = cryptodev_open,
23306 ++	.release = cryptodev_release,
23307 ++	.ioctl = cryptodev_ioctl,
23308 ++#ifdef HAVE_UNLOCKED_IOCTL
23309 ++	.unlocked_ioctl = cryptodev_unlocked_ioctl,
23310 ++#endif
23311 ++};
23312 ++
23313 ++static struct miscdevice cryptodev = {
23314 ++	.minor = CRYPTODEV_MINOR,
23315 ++	.name = "crypto",
23316 ++	.fops = &cryptodev_fops,
23317 ++};
23318 ++
23319 ++static int __init
23320 ++cryptodev_init(void)
23321 ++{
23322 ++	int rc;
23323 ++
23324 ++	dprintk("%s(%p)\n", __FUNCTION__, cryptodev_init);
23325 ++	rc = misc_register(&cryptodev);
23326 ++	if (rc) {
23327 ++		printk(KERN_ERR "cryptodev: registration of /dev/crypto failed\n");
23328 ++		return(rc);
23329 ++	}
23330 ++
23331 ++	return(0);
23332 ++}
23333 ++
23334 ++static void __exit
23335 ++cryptodev_exit(void)
23336 ++{
23337 ++	dprintk("%s()\n", __FUNCTION__);
23338 ++	misc_deregister(&cryptodev);
23339 ++}
23340 ++
23341 ++module_init(cryptodev_init);
23342 ++module_exit(cryptodev_exit);
23343 ++
23344 ++MODULE_LICENSE("BSD");
23345 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
23346 ++MODULE_DESCRIPTION("Cryptodev (user interface to OCF)");
23347 +diff -urN linux-2.6.23.16.old/crypto/ocf/cryptodev.h linux-2.6.23.16/crypto/ocf/cryptodev.h
23348 +--- linux-2.6.23.16.old/crypto/ocf/cryptodev.h	1969-12-31 19:00:00.000000000 -0500
23349 ++++ linux-2.6.23.16/crypto/ocf/cryptodev.h	2008-02-26 09:29:13.000000000 -0500
23350 +@@ -0,0 +1,478 @@
23351 ++/*	$FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.25 2007/05/09 19:37:02 gnn Exp $	*/
23352 ++/*	$OpenBSD: cryptodev.h,v 1.31 2002/06/11 11:14:29 beck Exp $	*/
23353 ++
23354 ++/*-
23355 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
23356 ++ * Copyright (C) 2006-2007 David McCullough
23357 ++ * Copyright (C) 2004-2005 Intel Corporation.
23358 ++ * The license and original author are listed below.
23359 ++ *
23360 ++ * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
23361 ++ * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting
23362 ++ *
23363 ++ * This code was written by Angelos D. Keromytis in Athens, Greece, in
23364 ++ * February 2000. Network Security Technologies Inc. (NSTI) kindly
23365 ++ * supported the development of this code.
23366 ++ *
23367 ++ * Copyright (c) 2000 Angelos D. Keromytis
23368 ++ *
23369 ++ * Permission to use, copy, and modify this software with or without fee
23370 ++ * is hereby granted, provided that this entire notice is included in
23371 ++ * all source code copies of any software which is or includes a copy or
23372 ++ * modification of this software.
23373 ++ *
23374 ++ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
23375 ++ * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
23376 ++ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
23377 ++ * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
23378 ++ * PURPOSE.
23379 ++ *
23380 ++ * Copyright (c) 2001 Theo de Raadt
23381 ++ *
23382 ++ * Redistribution and use in source and binary forms, with or without
23383 ++ * modification, are permitted provided that the following conditions
23384 ++ * are met:
23385 ++ *
23386 ++ * 1. Redistributions of source code must retain the above copyright
23387 ++ *   notice, this list of conditions and the following disclaimer.
23388 ++ * 2. Redistributions in binary form must reproduce the above copyright
23389 ++ *   notice, this list of conditions and the following disclaimer in the
23390 ++ *   documentation and/or other materials provided with the distribution.
23391 ++ * 3. The name of the author may not be used to endorse or promote products
23392 ++ *   derived from this software without specific prior written permission.
23393 ++ *
23394 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23395 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23396 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23397 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23398 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23399 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23400 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23401 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23402 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23403 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23404 ++ *
23405 ++ * Effort sponsored in part by the Defense Advanced Research Projects
23406 ++ * Agency (DARPA) and Air Force Research Laboratory, Air Force
23407 ++ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
23408 ++ *
23409 ++ */
23410 ++
23411 ++#ifndef _CRYPTO_CRYPTO_H_
23412 ++#define _CRYPTO_CRYPTO_H_
23413 ++
23414 ++/* Some initial values */
23415 ++#define CRYPTO_DRIVERS_INITIAL	4
23416 ++#define CRYPTO_SW_SESSIONS	32
23417 ++
23418 ++/* Hash values */
23419 ++#define NULL_HASH_LEN		0
23420 ++#define MD5_HASH_LEN		16
23421 ++#define SHA1_HASH_LEN		20
23422 ++#define RIPEMD160_HASH_LEN	20
23423 ++#define SHA2_256_HASH_LEN	32
23424 ++#define SHA2_384_HASH_LEN	48
23425 ++#define SHA2_512_HASH_LEN	64
23426 ++#define MD5_KPDK_HASH_LEN	16
23427 ++#define SHA1_KPDK_HASH_LEN	20
23428 ++/* Maximum hash algorithm result length */
23429 ++#define HASH_MAX_LEN		SHA2_512_HASH_LEN /* Keep this updated */
23430 ++
23431 ++/* HMAC values */
23432 ++#define NULL_HMAC_BLOCK_LEN			1
23433 ++#define MD5_HMAC_BLOCK_LEN			64
23434 ++#define SHA1_HMAC_BLOCK_LEN			64
23435 ++#define RIPEMD160_HMAC_BLOCK_LEN	64
23436 ++#define SHA2_256_HMAC_BLOCK_LEN		64
23437 ++#define SHA2_384_HMAC_BLOCK_LEN		128
23438 ++#define SHA2_512_HMAC_BLOCK_LEN		128
23439 ++/* Maximum HMAC block length */
23440 ++#define HMAC_MAX_BLOCK_LEN		SHA2_512_HMAC_BLOCK_LEN /* Keep this updated */
23441 ++#define HMAC_IPAD_VAL			0x36
23442 ++#define HMAC_OPAD_VAL			0x5C
23443 ++
23444 ++/* Encryption algorithm block sizes */
23445 ++#define NULL_BLOCK_LEN			1
23446 ++#define DES_BLOCK_LEN			8
23447 ++#define DES3_BLOCK_LEN			8
23448 ++#define BLOWFISH_BLOCK_LEN		8
23449 ++#define SKIPJACK_BLOCK_LEN		8
23450 ++#define CAST128_BLOCK_LEN		8
23451 ++#define RIJNDAEL128_BLOCK_LEN	16
23452 ++#define AES_BLOCK_LEN			RIJNDAEL128_BLOCK_LEN
23453 ++#define CAMELLIA_BLOCK_LEN		16
23454 ++#define ARC4_BLOCK_LEN			1
23455 ++#define EALG_MAX_BLOCK_LEN		AES_BLOCK_LEN /* Keep this updated */
23456 ++
23457 ++/* Encryption algorithm min and max key sizes */
23458 ++#define NULL_MIN_KEY_LEN		0
23459 ++#define NULL_MAX_KEY_LEN		0
23460 ++#define DES_MIN_KEY_LEN			8
23461 ++#define DES_MAX_KEY_LEN			8
23462 ++#define DES3_MIN_KEY_LEN		24
23463 ++#define DES3_MAX_KEY_LEN		24
23464 ++#define BLOWFISH_MIN_KEY_LEN	4
23465 ++#define BLOWFISH_MAX_KEY_LEN	56
23466 ++#define SKIPJACK_MIN_KEY_LEN	10
23467 ++#define SKIPJACK_MAX_KEY_LEN	10
23468 ++#define CAST128_MIN_KEY_LEN		5
23469 ++#define CAST128_MAX_KEY_LEN		16
23470 ++#define RIJNDAEL128_MIN_KEY_LEN	16
23471 ++#define RIJNDAEL128_MAX_KEY_LEN	32
23472 ++#define AES_MIN_KEY_LEN			RIJNDAEL128_MIN_KEY_LEN
23473 ++#define AES_MAX_KEY_LEN			RIJNDAEL128_MAX_KEY_LEN
23474 ++#define CAMELLIA_MIN_KEY_LEN	16
23475 ++#define CAMELLIA_MAX_KEY_LEN	32
23476 ++#define ARC4_MIN_KEY_LEN		1
23477 ++#define ARC4_MAX_KEY_LEN		256
23478 ++
23479 ++/* Max size of data that can be processed */
23480 ++#define CRYPTO_MAX_DATA_LEN		64*1024 - 1
23481 ++
23482 ++#define CRYPTO_ALGORITHM_MIN	1
23483 ++#define CRYPTO_DES_CBC			1
23484 ++#define CRYPTO_3DES_CBC			2
23485 ++#define CRYPTO_BLF_CBC			3
23486 ++#define CRYPTO_CAST_CBC			4
23487 ++#define CRYPTO_SKIPJACK_CBC		5
23488 ++#define CRYPTO_MD5_HMAC			6
23489 ++#define CRYPTO_SHA1_HMAC		7
23490 ++#define CRYPTO_RIPEMD160_HMAC	8
23491 ++#define CRYPTO_MD5_KPDK			9
23492 ++#define CRYPTO_SHA1_KPDK		10
23493 ++#define CRYPTO_RIJNDAEL128_CBC	11 /* 128 bit blocksize */
23494 ++#define CRYPTO_AES_CBC			11 /* 128 bit blocksize -- the same as above */
23495 ++#define CRYPTO_ARC4				12
23496 ++#define CRYPTO_MD5				13
23497 ++#define CRYPTO_SHA1				14
23498 ++#define CRYPTO_NULL_HMAC		15
23499 ++#define CRYPTO_NULL_CBC			16
23500 ++#define CRYPTO_DEFLATE_COMP		17 /* Deflate compression algorithm */
23501 ++#define CRYPTO_SHA2_256_HMAC	18
23502 ++#define CRYPTO_SHA2_384_HMAC	19
23503 ++#define CRYPTO_SHA2_512_HMAC	20
23504 ++#define CRYPTO_CAMELLIA_CBC		21
23505 ++#define CRYPTO_SHA2_256			22
23506 ++#define CRYPTO_SHA2_384			23
23507 ++#define CRYPTO_SHA2_512			24
23508 ++#define CRYPTO_RIPEMD160		25
23509 ++#define CRYPTO_ALGORITHM_MAX	25 /* Keep updated - see below */
23510 ++
23511 ++/* Algorithm flags */
23512 ++#define CRYPTO_ALG_FLAG_SUPPORTED	0x01 /* Algorithm is supported */
23513 ++#define CRYPTO_ALG_FLAG_RNG_ENABLE	0x02 /* Has HW RNG for DH/DSA */
23514 ++#define CRYPTO_ALG_FLAG_DSA_SHA		0x04 /* Can do SHA on msg */
23515 ++
23516 ++/*
23517 ++ * Crypto driver/device flags.  They can set in the crid
23518 ++ * parameter when creating a session or submitting a key
23519 ++ * op to affect the device/driver assigned.  If neither
23520 ++ * of these are specified then the crid is assumed to hold
23521 ++ * the driver id of an existing (and suitable) device that
23522 ++ * must be used to satisfy the request.
23523 ++ */
23524 ++#define CRYPTO_FLAG_HARDWARE	0x01000000	/* hardware accelerated */
23525 ++#define CRYPTO_FLAG_SOFTWARE	0x02000000	/* software implementation */
23526 ++
23527 ++/* NB: deprecated */
23528 ++struct session_op {
23529 ++	u_int32_t	cipher;		/* ie. CRYPTO_DES_CBC */
23530 ++	u_int32_t	mac;		/* ie. CRYPTO_MD5_HMAC */
23531 ++
23532 ++	u_int32_t	keylen;		/* cipher key */
23533 ++	caddr_t		key;
23534 ++	int		mackeylen;	/* mac key */
23535 ++	caddr_t		mackey;
23536 ++
23537 ++  	u_int32_t	ses;		/* returns: session # */ 
23538 ++};
23539 ++
23540 ++struct session2_op {
23541 ++	u_int32_t	cipher;		/* ie. CRYPTO_DES_CBC */
23542 ++	u_int32_t	mac;		/* ie. CRYPTO_MD5_HMAC */
23543 ++
23544 ++	u_int32_t	keylen;		/* cipher key */
23545 ++	caddr_t		key;
23546 ++	int		mackeylen;	/* mac key */
23547 ++	caddr_t		mackey;
23548 ++
23549 ++  	u_int32_t	ses;		/* returns: session # */ 
23550 ++	int		crid;		/* driver id + flags (rw) */
23551 ++	int		pad[4];		/* for future expansion */
23552 ++};
23553 ++
23554 ++struct crypt_op {
23555 ++	u_int32_t	ses;
23556 ++	u_int16_t	op;		/* i.e. COP_ENCRYPT */
23557 ++#define COP_NONE	0
23558 ++#define COP_ENCRYPT	1
23559 ++#define COP_DECRYPT	2
23560 ++	u_int16_t	flags;
23561 ++#define	COP_F_BATCH	0x0008		/* Batch op if possible */
23562 ++	u_int		len;
23563 ++	caddr_t		src, dst;	/* become iov[] inside kernel */
23564 ++	caddr_t		mac;		/* must be big enough for chosen MAC */
23565 ++	caddr_t		iv;
23566 ++};
23567 ++
23568 ++/*
23569 ++ * Parameters for looking up a crypto driver/device by
23570 ++ * device name or by id.  The latter are returned for
23571 ++ * created sessions (crid) and completed key operations.
23572 ++ */
23573 ++struct crypt_find_op {
23574 ++	int		crid;		/* driver id + flags */
23575 ++	char		name[32];	/* device/driver name */
23576 ++};
23577 ++
23578 ++/* bignum parameter, in packed bytes, ... */
23579 ++struct crparam {
23580 ++	caddr_t		crp_p;
23581 ++	u_int		crp_nbits;
23582 ++};
23583 ++
23584 ++#define CRK_MAXPARAM	8
23585 ++
23586 ++struct crypt_kop {
23587 ++	u_int		crk_op;		/* ie. CRK_MOD_EXP or other */
23588 ++	u_int		crk_status;	/* return status */
23589 ++	u_short		crk_iparams;	/* # of input parameters */
23590 ++	u_short		crk_oparams;	/* # of output parameters */
23591 ++	u_int		crk_crid;	/* NB: only used by CIOCKEY2 (rw) */
23592 ++	struct crparam	crk_param[CRK_MAXPARAM];
23593 ++};
23594 ++#define CRK_ALGORITM_MIN	0
23595 ++#define CRK_MOD_EXP		0
23596 ++#define CRK_MOD_EXP_CRT		1
23597 ++#define CRK_DSA_SIGN		2
23598 ++#define CRK_DSA_VERIFY		3
23599 ++#define CRK_DH_COMPUTE_KEY	4
23600 ++#define CRK_ALGORITHM_MAX	4 /* Keep updated - see below */
23601 ++
23602 ++#define CRF_MOD_EXP		(1 << CRK_MOD_EXP)
23603 ++#define CRF_MOD_EXP_CRT		(1 << CRK_MOD_EXP_CRT)
23604 ++#define CRF_DSA_SIGN		(1 << CRK_DSA_SIGN)
23605 ++#define CRF_DSA_VERIFY		(1 << CRK_DSA_VERIFY)
23606 ++#define CRF_DH_COMPUTE_KEY	(1 << CRK_DH_COMPUTE_KEY)
23607 ++
23608 ++/*
23609 ++ * done against open of /dev/crypto, to get a cloned descriptor.
23610 ++ * Please use F_SETFD against the cloned descriptor.
23611 ++ */
23612 ++#define CRIOGET		_IOWR('c', 100, u_int32_t)
23613 ++#define CRIOASYMFEAT	CIOCASYMFEAT
23614 ++#define CRIOFINDDEV	CIOCFINDDEV
23615 ++
23616 ++/* the following are done against the cloned descriptor */
23617 ++#define CIOCGSESSION	_IOWR('c', 101, struct session_op)
23618 ++#define CIOCFSESSION	_IOW('c', 102, u_int32_t)
23619 ++#define CIOCCRYPT	_IOWR('c', 103, struct crypt_op)
23620 ++#define CIOCKEY		_IOWR('c', 104, struct crypt_kop)
23621 ++#define CIOCASYMFEAT	_IOR('c', 105, u_int32_t)
23622 ++#define CIOCGSESSION2	_IOWR('c', 106, struct session2_op)
23623 ++#define CIOCKEY2	_IOWR('c', 107, struct crypt_kop)
23624 ++#define CIOCFINDDEV	_IOWR('c', 108, struct crypt_find_op)
23625 ++
23626 ++struct cryptotstat {
23627 ++	struct timespec	acc;		/* total accumulated time */
23628 ++	struct timespec	min;		/* min time */
23629 ++	struct timespec	max;		/* max time */
23630 ++	u_int32_t	count;		/* number of observations */
23631 ++};
23632 ++
23633 ++struct cryptostats {
23634 ++	u_int32_t	cs_ops;		/* symmetric crypto ops submitted */
23635 ++	u_int32_t	cs_errs;	/* symmetric crypto ops that failed */
23636 ++	u_int32_t	cs_kops;	/* asymetric/key ops submitted */
23637 ++	u_int32_t	cs_kerrs;	/* asymetric/key ops that failed */
23638 ++	u_int32_t	cs_intrs;	/* crypto swi thread activations */
23639 ++	u_int32_t	cs_rets;	/* crypto return thread activations */
23640 ++	u_int32_t	cs_blocks;	/* symmetric op driver block */
23641 ++	u_int32_t	cs_kblocks;	/* symmetric op driver block */
23642 ++	/*
23643 ++	 * When CRYPTO_TIMING is defined at compile time and the
23644 ++	 * sysctl debug.crypto is set to 1, the crypto system will
23645 ++	 * accumulate statistics about how long it takes to process
23646 ++	 * crypto requests at various points during processing.
23647 ++	 */
23648 ++	struct cryptotstat cs_invoke;	/* crypto_dipsatch -> crypto_invoke */
23649 ++	struct cryptotstat cs_done;	/* crypto_invoke -> crypto_done */
23650 ++	struct cryptotstat cs_cb;	/* crypto_done -> callback */
23651 ++	struct cryptotstat cs_finis;	/* callback -> callback return */
23652 ++
23653 ++	u_int32_t	cs_drops;		/* crypto ops dropped due to congestion */
23654 ++};
23655 ++
23656 ++#ifdef __KERNEL__
23657 ++
23658 ++/* Standard initialization structure beginning */
23659 ++struct cryptoini {
23660 ++	int		cri_alg;	/* Algorithm to use */
23661 ++	int		cri_klen;	/* Key length, in bits */
23662 ++	int		cri_mlen;	/* Number of bytes we want from the
23663 ++					   entire hash. 0 means all. */
23664 ++	caddr_t		cri_key;	/* key to use */
23665 ++	u_int8_t	cri_iv[EALG_MAX_BLOCK_LEN];	/* IV to use */
23666 ++	struct cryptoini *cri_next;
23667 ++};
23668 ++
23669 ++/* Describe boundaries of a single crypto operation */
23670 ++struct cryptodesc {
23671 ++	int		crd_skip;	/* How many bytes to ignore from start */
23672 ++	int		crd_len;	/* How many bytes to process */
23673 ++	int		crd_inject;	/* Where to inject results, if applicable */
23674 ++	int		crd_flags;
23675 ++
23676 ++#define CRD_F_ENCRYPT		0x01	/* Set when doing encryption */
23677 ++#define CRD_F_IV_PRESENT	0x02	/* When encrypting, IV is already in
23678 ++					   place, so don't copy. */
23679 ++#define CRD_F_IV_EXPLICIT	0x04	/* IV explicitly provided */
23680 ++#define CRD_F_DSA_SHA_NEEDED	0x08	/* Compute SHA-1 of buffer for DSA */
23681 ++#define CRD_F_KEY_EXPLICIT	0x10	/* Key explicitly provided */
23682 ++#define CRD_F_COMP		0x0f    /* Set when doing compression */
23683 ++
23684 ++	struct cryptoini	CRD_INI; /* Initialization/context data */
23685 ++#define crd_iv		CRD_INI.cri_iv
23686 ++#define crd_key		CRD_INI.cri_key
23687 ++#define crd_alg		CRD_INI.cri_alg
23688 ++#define crd_klen	CRD_INI.cri_klen
23689 ++
23690 ++	struct cryptodesc *crd_next;
23691 ++};
23692 ++
23693 ++/* Structure describing complete operation */
23694 ++struct cryptop {
23695 ++	struct list_head crp_next;
23696 ++	wait_queue_head_t crp_waitq;
23697 ++
23698 ++	u_int64_t	crp_sid;	/* Session ID */
23699 ++	int		crp_ilen;	/* Input data total length */
23700 ++	int		crp_olen;	/* Result total length */
23701 ++
23702 ++	int		crp_etype;	/*
23703 ++					 * Error type (zero means no error).
23704 ++					 * All error codes except EAGAIN
23705 ++					 * indicate possible data corruption (as in,
23706 ++					 * the data have been touched). On all
23707 ++					 * errors, the crp_sid may have changed
23708 ++					 * (reset to a new one), so the caller
23709 ++					 * should always check and use the new
23710 ++					 * value on future requests.
23711 ++					 */
23712 ++	int		crp_flags;
23713 ++
23714 ++#define CRYPTO_F_SKBUF		0x0001	/* Input/output are skbuf chains */
23715 ++#define CRYPTO_F_IOV		0x0002	/* Input/output are uio */
23716 ++#define CRYPTO_F_REL		0x0004	/* Must return data in same place */
23717 ++#define CRYPTO_F_BATCH		0x0008	/* Batch op if possible */
23718 ++#define CRYPTO_F_CBIMM		0x0010	/* Do callback immediately */
23719 ++#define CRYPTO_F_DONE		0x0020	/* Operation completed */
23720 ++#define CRYPTO_F_CBIFSYNC	0x0040	/* Do CBIMM if op is synchronous */
23721 ++
23722 ++	caddr_t		crp_buf;	/* Data to be processed */
23723 ++	caddr_t		crp_opaque;	/* Opaque pointer, passed along */
23724 ++	struct cryptodesc *crp_desc;	/* Linked list of processing descriptors */
23725 ++
23726 ++	int (*crp_callback)(struct cryptop *); /* Callback function */
23727 ++};
23728 ++
23729 ++#define CRYPTO_BUF_CONTIG	0x0
23730 ++#define CRYPTO_BUF_IOV		0x1
23731 ++#define CRYPTO_BUF_SKBUF		0x2
23732 ++
23733 ++#define CRYPTO_OP_DECRYPT	0x0
23734 ++#define CRYPTO_OP_ENCRYPT	0x1
23735 ++
23736 ++/*
23737 ++ * Hints passed to process methods.
23738 ++ */
23739 ++#define CRYPTO_HINT_MORE	0x1	/* more ops coming shortly */
23740 ++
23741 ++struct cryptkop {
23742 ++	struct list_head krp_next;
23743 ++	wait_queue_head_t krp_waitq;
23744 ++
23745 ++	int		krp_flags;
23746 ++#define CRYPTO_KF_DONE		0x0001	/* Operation completed */
23747 ++#define CRYPTO_KF_CBIMM		0x0002	/* Do callback immediately */
23748 ++
23749 ++	u_int		krp_op;		/* ie. CRK_MOD_EXP or other */
23750 ++	u_int		krp_status;	/* return status */
23751 ++	u_short		krp_iparams;	/* # of input parameters */
23752 ++	u_short		krp_oparams;	/* # of output parameters */
23753 ++	u_int		krp_crid;	/* desired device, etc. */
23754 ++	u_int32_t	krp_hid;
23755 ++	struct crparam	krp_param[CRK_MAXPARAM];	/* kvm */
23756 ++	int		(*krp_callback)(struct cryptkop *);
23757 ++};
23758 ++
23759 ++#include <ocf-compat.h>
23760 ++
23761 ++/*
23762 ++ * Session ids are 64 bits.  The lower 32 bits contain a "local id" which
23763 ++ * is a driver-private session identifier.  The upper 32 bits contain a
23764 ++ * "hardware id" used by the core crypto code to identify the driver and
23765 ++ * a copy of the driver's capabilities that can be used by client code to
23766 ++ * optimize operation.
23767 ++ */
23768 ++#define CRYPTO_SESID2HID(_sid)	(((_sid) >> 32) & 0x00ffffff)
23769 ++#define CRYPTO_SESID2CAPS(_sid)	(((_sid) >> 32) & 0xff000000)
23770 ++#define CRYPTO_SESID2LID(_sid)	(((u_int32_t) (_sid)) & 0xffffffff)
23771 ++
23772 ++extern	int crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard);
23773 ++extern	int crypto_freesession(u_int64_t sid);
23774 ++#define CRYPTOCAP_F_HARDWARE	CRYPTO_FLAG_HARDWARE
23775 ++#define CRYPTOCAP_F_SOFTWARE	CRYPTO_FLAG_SOFTWARE
23776 ++#define CRYPTOCAP_F_SYNC	0x04000000	/* operates synchronously */
23777 ++extern	int32_t crypto_get_driverid(device_t dev, int flags);
23778 ++extern	int crypto_find_driver(const char *);
23779 ++extern	device_t crypto_find_device_byhid(int hid);
23780 ++extern	int crypto_getcaps(int hid);
23781 ++extern	int crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
23782 ++	    u_int32_t flags);
23783 ++extern	int crypto_kregister(u_int32_t, int, u_int32_t);
23784 ++extern	int crypto_unregister(u_int32_t driverid, int alg);
23785 ++extern	int crypto_unregister_all(u_int32_t driverid);
23786 ++extern	int crypto_dispatch(struct cryptop *crp);
23787 ++extern	int crypto_kdispatch(struct cryptkop *);
23788 ++#define CRYPTO_SYMQ	0x1
23789 ++#define CRYPTO_ASYMQ	0x2
23790 ++extern	int crypto_unblock(u_int32_t, int);
23791 ++extern	void crypto_done(struct cryptop *crp);
23792 ++extern	void crypto_kdone(struct cryptkop *);
23793 ++extern	int crypto_getfeat(int *);
23794 ++
23795 ++extern	void crypto_freereq(struct cryptop *crp);
23796 ++extern	struct cryptop *crypto_getreq(int num);
23797 ++
23798 ++extern  int crypto_usercrypto;      /* userland may do crypto requests */
23799 ++extern  int crypto_userasymcrypto;  /* userland may do asym crypto reqs */
23800 ++extern  int crypto_devallowsoft;    /* only use hardware crypto */
23801 ++
23802 ++/*
23803 ++ * random number support,  crypto_unregister_all will unregister
23804 ++ */
23805 ++extern int crypto_rregister(u_int32_t driverid,
23806 ++		int (*read_random)(void *arg, u_int32_t *buf, int len), void *arg);
23807 ++extern int crypto_runregister_all(u_int32_t driverid);
23808 ++
23809 ++/*
23810 ++ * Crypto-related utility routines used mainly by drivers.
23811 ++ *
23812 ++ * XXX these don't really belong here; but for now they're
23813 ++ *     kept apart from the rest of the system.
23814 ++ */
23815 ++struct uio;
23816 ++extern	void cuio_copydata(struct uio* uio, int off, int len, caddr_t cp);
23817 ++extern	void cuio_copyback(struct uio* uio, int off, int len, caddr_t cp);
23818 ++extern	struct iovec *cuio_getptr(struct uio *uio, int loc, int *off);
23819 ++
23820 ++extern	void crypto_copyback(int flags, caddr_t buf, int off, int size,
23821 ++	    caddr_t in);
23822 ++extern	void crypto_copydata(int flags, caddr_t buf, int off, int size,
23823 ++	    caddr_t out);
23824 ++extern	int crypto_apply(int flags, caddr_t buf, int off, int len,
23825 ++	    int (*f)(void *, void *, u_int), void *arg);
23826 ++
23827 ++#endif /* __KERNEL__ */
23828 ++#endif /* _CRYPTO_CRYPTO_H_ */
23829 +diff -urN linux-2.6.23.16.old/crypto/ocf/cryptosoft.c linux-2.6.23.16/crypto/ocf/cryptosoft.c
23830 +--- linux-2.6.23.16.old/crypto/ocf/cryptosoft.c	1969-12-31 19:00:00.000000000 -0500
23831 ++++ linux-2.6.23.16/crypto/ocf/cryptosoft.c	2008-02-26 09:29:13.000000000 -0500
23832 +@@ -0,0 +1,900 @@
23833 ++/*
23834 ++ * An OCF module that uses the linux kernel cryptoapi, based on the
23835 ++ * original cryptosoft for BSD by Angelos D. Keromytis (angelos@cis.upenn.edu)
23836 ++ * but is mostly unrecognisable,
23837 ++ *
23838 ++ * Written by David McCullough <david_mccullough@securecomputing.com>
23839 ++ * Copyright (C) 2004-2007 David McCullough
23840 ++ * Copyright (C) 2004-2005 Intel Corporation.
23841 ++ *
23842 ++ * LICENSE TERMS
23843 ++ *
23844 ++ * The free distribution and use of this software in both source and binary
23845 ++ * form is allowed (with or without changes) provided that:
23846 ++ *
23847 ++ *   1. distributions of this source code include the above copyright
23848 ++ *      notice, this list of conditions and the following disclaimer;
23849 ++ *
23850 ++ *   2. distributions in binary form include the above copyright
23851 ++ *      notice, this list of conditions and the following disclaimer
23852 ++ *      in the documentation and/or other associated materials;
23853 ++ *
23854 ++ *   3. the copyright holder's name is not used to endorse products
23855 ++ *      built using this software without specific written permission.
23856 ++ *
23857 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
23858 ++ * may be distributed under the terms of the GNU General Public License (GPL),
23859 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
23860 ++ *
23861 ++ * DISCLAIMER
23862 ++ *
23863 ++ * This software is provided 'as is' with no explicit or implied warranties
23864 ++ * in respect of its properties, including, but not limited to, correctness
23865 ++ * and/or fitness for purpose.
23866 ++ * ---------------------------------------------------------------------------
23867 ++ */
23868 ++
23869 ++#ifndef AUTOCONF_INCLUDED
23870 ++#include <linux/config.h>
23871 ++#endif
23872 ++#include <linux/module.h>
23873 ++#include <linux/init.h>
23874 ++#include <linux/list.h>
23875 ++#include <linux/slab.h>
23876 ++#include <linux/sched.h>
23877 ++#include <linux/wait.h>
23878 ++#include <linux/crypto.h>
23879 ++#include <linux/mm.h>
23880 ++#include <linux/skbuff.h>
23881 ++#include <linux/random.h>
23882 ++#include <asm/scatterlist.h>
23883 ++
23884 ++#include <cryptodev.h>
23885 ++#include <uio.h>
23886 ++
23887 ++struct {
23888 ++	softc_device_decl	sc_dev;
23889 ++} swcr_softc;
23890 ++
23891 ++#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
23892 ++
23893 ++/* Software session entry */
23894 ++
23895 ++#define SW_TYPE_CIPHER		0
23896 ++#define SW_TYPE_HMAC		1
23897 ++#define SW_TYPE_AUTH2		2
23898 ++#define SW_TYPE_HASH		3
23899 ++#define SW_TYPE_COMP		4
23900 ++#define SW_TYPE_BLKCIPHER	5
23901 ++
23902 ++struct swcr_data {
23903 ++	int					sw_type;
23904 ++	int					sw_alg;
23905 ++	struct crypto_tfm	*sw_tfm;
23906 ++	union {
23907 ++		struct {
23908 ++			char *sw_key;
23909 ++			int  sw_klen;
23910 ++			int  sw_mlen;
23911 ++		} hmac;
23912 ++		void *sw_comp_buf;
23913 ++	} u;
23914 ++	struct swcr_data	*sw_next;
23915 ++};
23916 ++
23917 ++#ifndef CRYPTO_TFM_MODE_CBC
23918 ++/*
23919 ++ * As of linux-2.6.21 this is no longer defined, and presumably no longer
23920 ++ * needed to be passed into the crypto core code.
23921 ++ */
23922 ++#define	CRYPTO_TFM_MODE_CBC	0
23923 ++#define	CRYPTO_TFM_MODE_ECB	0
23924 ++#endif
23925 ++
23926 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
23927 ++	/*
23928 ++	 * Linux 2.6.19 introduced a new Crypto API, setup macro's to convert new
23929 ++	 * API into old API.
23930 ++	 */
23931 ++
23932 ++	/* Symmetric/Block Cipher */
23933 ++	struct blkcipher_desc
23934 ++	{
23935 ++		struct crypto_tfm *tfm;
23936 ++		void *info;
23937 ++	};
23938 ++	#define ecb(X)								#X
23939 ++	#define cbc(X)								#X
23940 ++	#define crypto_has_blkcipher(X, Y, Z)		crypto_alg_available(X, 0)
23941 ++	#define crypto_blkcipher_cast(X)			X
23942 ++	#define crypto_blkcipher_tfm(X)				X
23943 ++	#define crypto_alloc_blkcipher(X, Y, Z)		crypto_alloc_tfm(X, mode)
23944 ++	#define crypto_blkcipher_ivsize(X)			crypto_tfm_alg_ivsize(X)
23945 ++	#define crypto_blkcipher_blocksize(X)		crypto_tfm_alg_blocksize(X)
23946 ++	#define crypto_blkcipher_setkey(X, Y, Z)	crypto_cipher_setkey(X, Y, Z)
23947 ++	#define crypto_blkcipher_encrypt_iv(W, X, Y, Z)	\
23948 ++				crypto_cipher_encrypt_iv((W)->tfm, X, Y, Z, (u8 *)((W)->info))
23949 ++	#define crypto_blkcipher_decrypt_iv(W, X, Y, Z)	\
23950 ++				crypto_cipher_decrypt_iv((W)->tfm, X, Y, Z, (u8 *)((W)->info))
23951 ++
23952 ++	/* Hash/HMAC/Digest */
23953 ++	struct hash_desc
23954 ++	{
23955 ++		struct crypto_tfm *tfm;
23956 ++	};
23957 ++	#define hmac(X)							#X
23958 ++	#define crypto_has_hash(X, Y, Z)		crypto_alg_available(X, 0)
23959 ++	#define crypto_hash_cast(X)				X
23960 ++	#define crypto_hash_tfm(X)				X
23961 ++	#define crypto_alloc_hash(X, Y, Z)		crypto_alloc_tfm(X, mode)
23962 ++	#define crypto_hash_digestsize(X)		crypto_tfm_alg_digestsize(X)
23963 ++	#define crypto_hash_digest(W, X, Y, Z)	\
23964 ++				crypto_digest_digest((W)->tfm, X, sg_num, Z)
23965 ++
23966 ++	/* Asymmetric Cipher */
23967 ++	#define crypto_has_cipher(X, Y, Z)		crypto_alg_available(X, 0)
23968 ++
23969 ++	/* Compression */
23970 ++	#define crypto_has_comp(X, Y, Z)		crypto_alg_available(X, 0)
23971 ++	#define crypto_comp_tfm(X)				X
23972 ++	#define crypto_comp_cast(X)				X
23973 ++	#define crypto_alloc_comp(X, Y, Z)		crypto_alloc_tfm(X, mode)
23974 ++#else
23975 ++	#define ecb(X)	"ecb(" #X ")"
23976 ++	#define cbc(X)	"cbc(" #X ")"
23977 ++	#define hmac(X)	"hmac(" #X ")"
23978 ++#endif /* if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) */
23979 ++
23980 ++struct crypto_details
23981 ++{
23982 ++	char *alg_name;
23983 ++	int mode;
23984 ++	int sw_type;
23985 ++};
23986 ++
23987 ++/*
23988 ++ * This needs to be kept updated with CRYPTO_xxx list (cryptodev.h).
23989 ++ * If the Algorithm is not supported, then insert a {NULL, 0, 0} entry.
23990 ++ *
23991 ++ * IMPORTANT: The index to the array IS CRYPTO_xxx.
23992 ++ */
23993 ++static struct crypto_details crypto_details[CRYPTO_ALGORITHM_MAX + 1] = {
23994 ++	{ NULL,              0,                   0 },
23995 ++	/* CRYPTO_xxx index starts at 1 */
23996 ++	{ cbc(des),          CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
23997 ++	{ cbc(des3_ede),     CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
23998 ++	{ cbc(blowfish),     CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
23999 ++	{ cbc(cast5),        CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
24000 ++	{ cbc(skipjack),     CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
24001 ++	{ hmac(md5),         0,                   SW_TYPE_HMAC },
24002 ++	{ hmac(sha1),        0,                   SW_TYPE_HMAC },
24003 ++	{ hmac(ripemd160),   0,                   SW_TYPE_HMAC },
24004 ++	{ "md5-kpdk??",      0,                   SW_TYPE_HASH },
24005 ++	{ "sha1-kpdk??",     0,                   SW_TYPE_HASH },
24006 ++	{ cbc(aes),          CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
24007 ++	{ ecb(arc4),         CRYPTO_TFM_MODE_ECB, SW_TYPE_BLKCIPHER },
24008 ++	{ "md5",             0,                   SW_TYPE_HASH },
24009 ++	{ "sha1",            0,                   SW_TYPE_HASH },
24010 ++	{ hmac(digest_null), 0,                   SW_TYPE_HMAC },
24011 ++	{ cbc(cipher_null),  CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
24012 ++	{ "deflate",         0,                   SW_TYPE_COMP },
24013 ++	{ hmac(sha256),      0,                   SW_TYPE_HMAC },
24014 ++	{ hmac(sha384),      0,                   SW_TYPE_HMAC },
24015 ++	{ hmac(sha512),      0,                   SW_TYPE_HMAC },
24016 ++	{ cbc(camellia),     CRYPTO_TFM_MODE_CBC, SW_TYPE_BLKCIPHER },
24017 ++	{ "sha256",          0,                   SW_TYPE_HASH },
24018 ++	{ "sha384",          0,                   SW_TYPE_HASH },
24019 ++	{ "sha512",          0,                   SW_TYPE_HASH },
24020 ++	{ "ripemd160",       0,                   SW_TYPE_HASH },
24021 ++};
24022 ++
24023 ++int32_t swcr_id = -1;
24024 ++module_param(swcr_id, int, 0444);
24025 ++MODULE_PARM_DESC(swcr_id, "Read-Only OCF ID for cryptosoft driver");
24026 ++
24027 ++int swcr_fail_if_compression_grows = 1;
24028 ++module_param(swcr_fail_if_compression_grows, int, 0644);
24029 ++MODULE_PARM_DESC(swcr_fail_if_compression_grows,
24030 ++                "Treat compression that results in more data as a failure");
24031 ++
24032 ++static struct swcr_data **swcr_sessions = NULL;
24033 ++static u_int32_t swcr_sesnum = 0;
24034 ++
24035 ++static	int swcr_process(device_t, struct cryptop *, int);
24036 ++static	int swcr_newsession(device_t, u_int32_t *, struct cryptoini *);
24037 ++static	int swcr_freesession(device_t, u_int64_t);
24038 ++
24039 ++static device_method_t swcr_methods = {
24040 ++	/* crypto device methods */
24041 ++	DEVMETHOD(cryptodev_newsession,	swcr_newsession),
24042 ++	DEVMETHOD(cryptodev_freesession,swcr_freesession),
24043 ++	DEVMETHOD(cryptodev_process,	swcr_process),
24044 ++};
24045 ++
24046 ++#define debug swcr_debug
24047 ++int swcr_debug = 0;
24048 ++module_param(swcr_debug, int, 0644);
24049 ++MODULE_PARM_DESC(swcr_debug, "Enable debug");
24050 ++
24051 ++/*
24052 ++ * Generate a new software session.
24053 ++ */
24054 ++static int
24055 ++swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri)
24056 ++{
24057 ++	struct swcr_data **swd;
24058 ++	u_int32_t i;
24059 ++	int error;
24060 ++	char *algo;
24061 ++	int mode, sw_type;
24062 ++
24063 ++	dprintk("%s()\n", __FUNCTION__);
24064 ++	if (sid == NULL || cri == NULL) {
24065 ++		dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
24066 ++		return EINVAL;
24067 ++	}
24068 ++
24069 ++	if (swcr_sessions) {
24070 ++		for (i = 1; i < swcr_sesnum; i++)
24071 ++			if (swcr_sessions[i] == NULL)
24072 ++				break;
24073 ++	} else
24074 ++		i = 1;		/* NB: to silence compiler warning */
24075 ++
24076 ++	if (swcr_sessions == NULL || i == swcr_sesnum) {
24077 ++		if (swcr_sessions == NULL) {
24078 ++			i = 1; /* We leave swcr_sessions[0] empty */
24079 ++			swcr_sesnum = CRYPTO_SW_SESSIONS;
24080 ++		} else
24081 ++			swcr_sesnum *= 2;
24082 ++
24083 ++		swd = kmalloc(swcr_sesnum * sizeof(struct swcr_data *), SLAB_ATOMIC);
24084 ++		if (swd == NULL) {
24085 ++			/* Reset session number */
24086 ++			if (swcr_sesnum == CRYPTO_SW_SESSIONS)
24087 ++				swcr_sesnum = 0;
24088 ++			else
24089 ++				swcr_sesnum /= 2;
24090 ++			dprintk("%s,%d: ENOBUFS\n", __FILE__, __LINE__);
24091 ++			return ENOBUFS;
24092 ++		}
24093 ++		memset(swd, 0, swcr_sesnum * sizeof(struct swcr_data *));
24094 ++
24095 ++		/* Copy existing sessions */
24096 ++		if (swcr_sessions) {
24097 ++			memcpy(swd, swcr_sessions,
24098 ++			    (swcr_sesnum / 2) * sizeof(struct swcr_data *));
24099 ++			kfree(swcr_sessions);
24100 ++		}
24101 ++
24102 ++		swcr_sessions = swd;
24103 ++	}
24104 ++
24105 ++	swd = &swcr_sessions[i];
24106 ++	*sid = i;
24107 ++
24108 ++	while (cri) {
24109 ++		*swd = (struct swcr_data *) kmalloc(sizeof(struct swcr_data),
24110 ++				SLAB_ATOMIC);
24111 ++		if (*swd == NULL) {
24112 ++			swcr_freesession(NULL, i);
24113 ++			dprintk("%s,%d: ENOBUFS\n", __FILE__, __LINE__);
24114 ++			return ENOBUFS;
24115 ++		}
24116 ++		memset(*swd, 0, sizeof(struct swcr_data));
24117 ++
24118 ++		if (cri->cri_alg > CRYPTO_ALGORITHM_MAX) {
24119 ++			printk("cryptosoft: Unknown algorithm 0x%x\n", cri->cri_alg);
24120 ++			swcr_freesession(NULL, i);
24121 ++			return EINVAL;
24122 ++		}
24123 ++
24124 ++		algo = crypto_details[cri->cri_alg].alg_name;
24125 ++		if (!algo || !*algo) {
24126 ++			printk("cryptosoft: Unsupported algorithm 0x%x\n", cri->cri_alg);
24127 ++			swcr_freesession(NULL, i);
24128 ++			return EINVAL;
24129 ++		}
24130 ++
24131 ++		mode = crypto_details[cri->cri_alg].mode;
24132 ++		sw_type = crypto_details[cri->cri_alg].sw_type;
24133 ++
24134 ++		/* Algorithm specific configuration */
24135 ++		switch (cri->cri_alg) {
24136 ++		case CRYPTO_NULL_CBC:
24137 ++			cri->cri_klen = 0; /* make it work with crypto API */
24138 ++			break;
24139 ++		default:
24140 ++			break;
24141 ++		}
24142 ++
24143 ++		if (sw_type == SW_TYPE_BLKCIPHER) {
24144 ++			dprintk("%s crypto_alloc_blkcipher(%s, 0x%x)\n", __FUNCTION__,
24145 ++					algo, mode);
24146 ++
24147 ++			(*swd)->sw_tfm = crypto_blkcipher_tfm(
24148 ++								crypto_alloc_blkcipher(algo, 0,
24149 ++									CRYPTO_ALG_ASYNC));
24150 ++			if (!(*swd)->sw_tfm) {
24151 ++				dprintk("cryptosoft: crypto_alloc_blkcipher failed(%s,0x%x)\n",
24152 ++						algo,mode);
24153 ++				swcr_freesession(NULL, i);
24154 ++				return EINVAL;
24155 ++			}
24156 ++
24157 ++			if (debug) {
24158 ++				dprintk("%s key:cri->cri_klen=%d,(cri->cri_klen + 7)/8=%d",
24159 ++						__FUNCTION__,cri->cri_klen,(cri->cri_klen + 7)/8);
24160 ++				for (i = 0; i < (cri->cri_klen + 7) / 8; i++)
24161 ++				{
24162 ++					dprintk("%s0x%x", (i % 8) ? " " : "\n    ",cri->cri_key[i]);
24163 ++				}
24164 ++				dprintk("\n");
24165 ++			}
24166 ++			error = crypto_blkcipher_setkey(
24167 ++						crypto_blkcipher_cast((*swd)->sw_tfm), cri->cri_key,
24168 ++							(cri->cri_klen + 7) / 8);
24169 ++			if (error) {
24170 ++				printk("cryptosoft: setkey failed %d (crt_flags=0x%x)\n", error,
24171 ++						(*swd)->sw_tfm->crt_flags);
24172 ++				swcr_freesession(NULL, i);
24173 ++				return error;
24174 ++			}
24175 ++		} else if (sw_type == SW_TYPE_HMAC || sw_type == SW_TYPE_HASH) {
24176 ++			dprintk("%s crypto_alloc_hash(%s, 0x%x)\n", __FUNCTION__,
24177 ++					algo, mode);
24178 ++
24179 ++			(*swd)->sw_tfm = crypto_hash_tfm(
24180 ++								crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC));
24181 ++
24182 ++			if (!(*swd)->sw_tfm) {
24183 ++				dprintk("cryptosoft: crypto_alloc_hash failed(%s,0x%x)\n",
24184 ++						algo, mode);
24185 ++				swcr_freesession(NULL, i);
24186 ++				return EINVAL;
24187 ++			}
24188 ++
24189 ++			(*swd)->u.hmac.sw_klen = (cri->cri_klen + 7) / 8;
24190 ++			(*swd)->u.hmac.sw_key = (char *)kmalloc((*swd)->u.hmac.sw_klen,
24191 ++				SLAB_ATOMIC);
24192 ++			if ((*swd)->u.hmac.sw_key == NULL) {
24193 ++				swcr_freesession(NULL, i);
24194 ++				dprintk("%s,%d: ENOBUFS\n", __FILE__, __LINE__);
24195 ++				return ENOBUFS;
24196 ++			}
24197 ++			memcpy((*swd)->u.hmac.sw_key, cri->cri_key, (*swd)->u.hmac.sw_klen);
24198 ++			if (cri->cri_mlen) {
24199 ++				(*swd)->u.hmac.sw_mlen = cri->cri_mlen;
24200 ++			} else {
24201 ++				(*swd)->u.hmac.sw_mlen =
24202 ++						crypto_hash_digestsize(
24203 ++								crypto_hash_cast((*swd)->sw_tfm));
24204 ++			}
24205 ++		} else if (sw_type == SW_TYPE_COMP) {
24206 ++			(*swd)->sw_tfm = crypto_comp_tfm(
24207 ++					crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC));
24208 ++			if (!(*swd)->sw_tfm) {
24209 ++				dprintk("cryptosoft: crypto_alloc_comp failed(%s,0x%x)\n",
24210 ++						algo, mode);
24211 ++				swcr_freesession(NULL, i);
24212 ++				return EINVAL;
24213 ++			}
24214 ++			(*swd)->u.sw_comp_buf = kmalloc(CRYPTO_MAX_DATA_LEN, SLAB_ATOMIC);
24215 ++			if ((*swd)->u.sw_comp_buf == NULL) {
24216 ++				swcr_freesession(NULL, i);
24217 ++				dprintk("%s,%d: ENOBUFS\n", __FILE__, __LINE__);
24218 ++				return ENOBUFS;
24219 ++			}
24220 ++		} else {
24221 ++			printk("cryptosoft: Unhandled sw_type %d\n", sw_type);
24222 ++			swcr_freesession(NULL, i);
24223 ++			return EINVAL;
24224 ++		}
24225 ++
24226 ++		(*swd)->sw_alg = cri->cri_alg;
24227 ++		(*swd)->sw_type = sw_type;
24228 ++
24229 ++		cri = cri->cri_next;
24230 ++		swd = &((*swd)->sw_next);
24231 ++	}
24232 ++	return 0;
24233 ++}
24234 ++
24235 ++/*
24236 ++ * Free a session.
24237 ++ */
24238 ++static int
24239 ++swcr_freesession(device_t dev, u_int64_t tid)
24240 ++{
24241 ++	struct swcr_data *swd;
24242 ++	u_int32_t sid = CRYPTO_SESID2LID(tid);
24243 ++
24244 ++	dprintk("%s()\n", __FUNCTION__);
24245 ++	if (sid > swcr_sesnum || swcr_sessions == NULL ||
24246 ++			swcr_sessions[sid] == NULL) {
24247 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24248 ++		return(EINVAL);
24249 ++	}
24250 ++
24251 ++	/* Silently accept and return */
24252 ++	if (sid == 0)
24253 ++		return(0);
24254 ++
24255 ++	while ((swd = swcr_sessions[sid]) != NULL) {
24256 ++		swcr_sessions[sid] = swd->sw_next;
24257 ++		if (swd->sw_tfm)
24258 ++			crypto_free_tfm(swd->sw_tfm);
24259 ++		if (swd->sw_type == SW_TYPE_COMP) {
24260 ++			if (swd->u.sw_comp_buf)
24261 ++				kfree(swd->u.sw_comp_buf);
24262 ++		} else {
24263 ++			if (swd->u.hmac.sw_key)
24264 ++				kfree(swd->u.hmac.sw_key);
24265 ++		}
24266 ++		kfree(swd);
24267 ++	}
24268 ++	return 0;
24269 ++}
24270 ++
24271 ++/*
24272 ++ * Process a software request.
24273 ++ */
24274 ++static int
24275 ++swcr_process(device_t dev, struct cryptop *crp, int hint)
24276 ++{
24277 ++	struct cryptodesc *crd;
24278 ++	struct swcr_data *sw;
24279 ++	u_int32_t lid;
24280 ++#define SCATTERLIST_MAX 16
24281 ++	struct scatterlist sg[SCATTERLIST_MAX];
24282 ++	int sg_num, sg_len, skip;
24283 ++	struct sk_buff *skb = NULL;
24284 ++	struct uio *uiop = NULL;
24285 ++
24286 ++	dprintk("%s()\n", __FUNCTION__);
24287 ++	/* Sanity check */
24288 ++	if (crp == NULL) {
24289 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24290 ++		return EINVAL;
24291 ++	}
24292 ++
24293 ++	crp->crp_etype = 0;
24294 ++
24295 ++	if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
24296 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24297 ++		crp->crp_etype = EINVAL;
24298 ++		goto done;
24299 ++	}
24300 ++
24301 ++	lid = crp->crp_sid & 0xffffffff;
24302 ++	if (lid >= swcr_sesnum || lid == 0 || swcr_sessions == NULL ||
24303 ++			swcr_sessions[lid] == NULL) {
24304 ++		crp->crp_etype = ENOENT;
24305 ++		dprintk("%s,%d: ENOENT\n", __FILE__, __LINE__);
24306 ++		goto done;
24307 ++	}
24308 ++
24309 ++	/*
24310 ++	 * do some error checking outside of the loop for SKB and IOV processing
24311 ++	 * this leaves us with valid skb or uiop pointers for later
24312 ++	 */
24313 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
24314 ++		skb = (struct sk_buff *) crp->crp_buf;
24315 ++		if (skb_shinfo(skb)->nr_frags >= SCATTERLIST_MAX) {
24316 ++			printk("%s,%d: %d nr_frags > SCATTERLIST_MAX", __FILE__, __LINE__,
24317 ++					skb_shinfo(skb)->nr_frags);
24318 ++			goto done;
24319 ++		}
24320 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
24321 ++		uiop = (struct uio *) crp->crp_buf;
24322 ++		if (uiop->uio_iovcnt > SCATTERLIST_MAX) {
24323 ++			printk("%s,%d: %d uio_iovcnt > SCATTERLIST_MAX", __FILE__, __LINE__,
24324 ++					uiop->uio_iovcnt);
24325 ++			goto done;
24326 ++		}
24327 ++	}
24328 ++
24329 ++	/* Go through crypto descriptors, processing as we go */
24330 ++	for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
24331 ++		/*
24332 ++		 * Find the crypto context.
24333 ++		 *
24334 ++		 * XXX Note that the logic here prevents us from having
24335 ++		 * XXX the same algorithm multiple times in a session
24336 ++		 * XXX (or rather, we can but it won't give us the right
24337 ++		 * XXX results). To do that, we'd need some way of differentiating
24338 ++		 * XXX between the various instances of an algorithm (so we can
24339 ++		 * XXX locate the correct crypto context).
24340 ++		 */
24341 ++		for (sw = swcr_sessions[lid]; sw && sw->sw_alg != crd->crd_alg;
24342 ++				sw = sw->sw_next)
24343 ++			;
24344 ++
24345 ++		/* No such context ? */
24346 ++		if (sw == NULL) {
24347 ++			crp->crp_etype = EINVAL;
24348 ++			dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24349 ++			goto done;
24350 ++		}
24351 ++
24352 ++		skip = crd->crd_skip;
24353 ++
24354 ++		/*
24355 ++		 * setup the SG list skip from the start of the buffer
24356 ++		 */
24357 ++		memset(sg, 0, sizeof(sg));
24358 ++		if (crp->crp_flags & CRYPTO_F_SKBUF) {
24359 ++			int i, len;
24360 ++
24361 ++			sg_num = 0;
24362 ++			sg_len = 0;
24363 ++
24364 ++			if (skip < skb_headlen(skb)) {
24365 ++				sg[sg_num].page   = virt_to_page(skb->data + skip);
24366 ++				sg[sg_num].offset = offset_in_page(skb->data + skip);
24367 ++				len = skb_headlen(skb) - skip;
24368 ++				if (len + sg_len > crd->crd_len)
24369 ++					len = crd->crd_len - sg_len;
24370 ++				sg[sg_num].length = len;
24371 ++				sg_len += sg[sg_num].length;
24372 ++				sg_num++;
24373 ++				skip = 0;
24374 ++			} else
24375 ++				skip -= skb_headlen(skb);
24376 ++
24377 ++			for (i = 0; sg_len < crd->crd_len &&
24378 ++						i < skb_shinfo(skb)->nr_frags &&
24379 ++						sg_num < SCATTERLIST_MAX; i++) {
24380 ++				if (skip < skb_shinfo(skb)->frags[i].size) {
24381 ++					sg[sg_num].page   = skb_shinfo(skb)->frags[i].page;
24382 ++					sg[sg_num].offset = skb_shinfo(skb)->frags[i].page_offset +
24383 ++							skip;
24384 ++					len = skb_shinfo(skb)->frags[i].size - skip;
24385 ++					if (len + sg_len > crd->crd_len)
24386 ++						len = crd->crd_len - sg_len;
24387 ++					sg[sg_num].length = len;
24388 ++					sg_len += sg[sg_num].length;
24389 ++					sg_num++;
24390 ++					skip = 0;
24391 ++				} else
24392 ++					skip -= skb_shinfo(skb)->frags[i].size;
24393 ++			}
24394 ++		} else if (crp->crp_flags & CRYPTO_F_IOV) {
24395 ++			int len;
24396 ++
24397 ++			sg_len = 0;
24398 ++			for (sg_num = 0; sg_len <= crd->crd_len &&
24399 ++					sg_num < uiop->uio_iovcnt &&
24400 ++					sg_num < SCATTERLIST_MAX; sg_num++) {
24401 ++				if (skip <= uiop->uio_iov[sg_num].iov_len) {
24402 ++					sg[sg_num].page   =
24403 ++							virt_to_page(uiop->uio_iov[sg_num].iov_base+skip);
24404 ++					sg[sg_num].offset =
24405 ++							offset_in_page(uiop->uio_iov[sg_num].iov_base+skip);
24406 ++					len = uiop->uio_iov[sg_num].iov_len - skip;
24407 ++					if (len + sg_len > crd->crd_len)
24408 ++						len = crd->crd_len - sg_len;
24409 ++					sg[sg_num].length = len;
24410 ++					sg_len += sg[sg_num].length;
24411 ++					skip = 0;
24412 ++				} else 
24413 ++					skip -= uiop->uio_iov[sg_num].iov_len;
24414 ++			}
24415 ++		} else {
24416 ++			sg[0].page   = virt_to_page(crp->crp_buf + skip);
24417 ++			sg[0].offset = offset_in_page(crp->crp_buf + skip);
24418 ++			sg_len = (crp->crp_ilen - skip);
24419 ++			if (sg_len > crd->crd_len)
24420 ++				sg_len = crd->crd_len;
24421 ++			sg[0].length = sg_len;
24422 ++			sg_num = 1;
24423 ++		}
24424 ++
24425 ++
24426 ++		switch (sw->sw_type) {
24427 ++		case SW_TYPE_BLKCIPHER: {
24428 ++			unsigned char iv[EALG_MAX_BLOCK_LEN];
24429 ++			unsigned char *ivp = iv;
24430 ++			int ivsize = 
24431 ++				crypto_blkcipher_ivsize(crypto_blkcipher_cast(sw->sw_tfm));
24432 ++			struct blkcipher_desc desc;
24433 ++
24434 ++			if (sg_len < crypto_blkcipher_blocksize(
24435 ++					crypto_blkcipher_cast(sw->sw_tfm))) {
24436 ++				crp->crp_etype = EINVAL;
24437 ++				dprintk("%s,%d: EINVAL len %d < %d\n", __FILE__, __LINE__,
24438 ++						sg_len, crypto_blkcipher_blocksize(
24439 ++							crypto_blkcipher_cast(sw->sw_tfm)));
24440 ++				goto done;
24441 ++			}
24442 ++
24443 ++			if (ivsize > sizeof(iv)) {
24444 ++				crp->crp_etype = EINVAL;
24445 ++				dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24446 ++				goto done;
24447 ++			}
24448 ++
24449 ++			if (crd->crd_flags & CRD_F_KEY_EXPLICIT) {
24450 ++				int i, error;
24451 ++
24452 ++				if (debug) {
24453 ++					dprintk("%s key:", __FUNCTION__);
24454 ++					for (i = 0; i < (crd->crd_klen + 7) / 8; i++)
24455 ++						dprintk("%s0x%x", (i % 8) ? " " : "\n    ",
24456 ++								crd->crd_key[i]);
24457 ++					dprintk("\n");
24458 ++				}
24459 ++				error = crypto_blkcipher_setkey(
24460 ++							crypto_blkcipher_cast(sw->sw_tfm), crd->crd_key,
24461 ++							(crd->crd_klen + 7) / 8);
24462 ++				if (error) {
24463 ++					dprintk("cryptosoft: setkey failed %d (crt_flags=0x%x)\n",
24464 ++							error, sw->sw_tfm->crt_flags);
24465 ++					crp->crp_etype = -error;
24466 ++				}
24467 ++			}
24468 ++
24469 ++			memset(&desc, 0, sizeof(desc));
24470 ++			desc.tfm = crypto_blkcipher_cast(sw->sw_tfm);
24471 ++
24472 ++			if (crd->crd_flags & CRD_F_ENCRYPT) { /* encrypt */
24473 ++
24474 ++				if (crd->crd_flags & CRD_F_IV_EXPLICIT) {
24475 ++					ivp = crd->crd_iv;
24476 ++				} else {
24477 ++					get_random_bytes(ivp, ivsize);
24478 ++				}
24479 ++				/*
24480 ++				 * do we have to copy the IV back to the buffer ?
24481 ++				 */
24482 ++				if ((crd->crd_flags & CRD_F_IV_PRESENT) == 0) {
24483 ++					crypto_copyback(crp->crp_flags, crp->crp_buf,
24484 ++							crd->crd_inject, ivsize, (caddr_t)ivp);
24485 ++				}
24486 ++				desc.info = ivp;
24487 ++				crypto_blkcipher_encrypt_iv(&desc, sg, sg, sg_len);
24488 ++
24489 ++			} else { /*decrypt */
24490 ++
24491 ++				if (crd->crd_flags & CRD_F_IV_EXPLICIT) {
24492 ++					ivp = crd->crd_iv;
24493 ++				} else {
24494 ++					crypto_copydata(crp->crp_flags, crp->crp_buf,
24495 ++							crd->crd_inject, ivsize, (caddr_t)ivp);
24496 ++				}
24497 ++				desc.info = ivp;
24498 ++				crypto_blkcipher_decrypt_iv(&desc, sg, sg, sg_len);
24499 ++			}
24500 ++			} break;
24501 ++		case SW_TYPE_HMAC:
24502 ++		case SW_TYPE_HASH:
24503 ++			{
24504 ++			char result[HASH_MAX_LEN];
24505 ++			struct hash_desc desc;
24506 ++
24507 ++			/* check we have room for the result */
24508 ++			if (crp->crp_ilen - crd->crd_inject < sw->u.hmac.sw_mlen) {
24509 ++				dprintk(
24510 ++			"cryptosoft: EINVAL crp_ilen=%d, len=%d, inject=%d digestsize=%d\n",
24511 ++						crp->crp_ilen, crd->crd_skip + sg_len, crd->crd_inject,
24512 ++						sw->u.hmac.sw_mlen);
24513 ++				crp->crp_etype = EINVAL;
24514 ++				goto done;
24515 ++			}
24516 ++
24517 ++			memset(&desc, 0, sizeof(desc));
24518 ++			desc.tfm = crypto_hash_cast(sw->sw_tfm);
24519 ++
24520 ++			memset(result, 0, sizeof(result));
24521 ++
24522 ++			if (sw->sw_type == SW_TYPE_HMAC) {
24523 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
24524 ++				crypto_hmac(sw->sw_tfm, sw->u.hmac.sw_key, &sw->u.hmac.sw_klen,
24525 ++						sg, sg_num, result);
24526 ++#else
24527 ++				crypto_hash_setkey(desc.tfm, sw->u.hmac.sw_key,
24528 ++						sw->u.hmac.sw_klen);
24529 ++				crypto_hash_digest(&desc, sg, sg_len, result);
24530 ++#endif /* #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) */
24531 ++				
24532 ++			} else { /* SW_TYPE_HASH */
24533 ++				crypto_hash_digest(&desc, sg, sg_len, result);
24534 ++			}
24535 ++
24536 ++			crypto_copyback(crp->crp_flags, crp->crp_buf,
24537 ++					crd->crd_inject, sw->u.hmac.sw_mlen, result);
24538 ++			}
24539 ++			break;
24540 ++
24541 ++		case SW_TYPE_COMP: {
24542 ++			void *ibuf = NULL;
24543 ++			void *obuf = sw->u.sw_comp_buf;
24544 ++			int ilen = sg_len, olen = CRYPTO_MAX_DATA_LEN;
24545 ++			int ret = 0;
24546 ++
24547 ++			/*
24548 ++			 * we need to use an additional copy if there is more than one
24549 ++			 * input chunk since the kernel comp routines do not handle
24550 ++			 * SG yet.  Otherwise we just use the input buffer as is.
24551 ++			 * Rather than allocate another buffer we just split the tmp
24552 ++			 * buffer we already have.
24553 ++			 * Perhaps we should just use zlib directly ?
24554 ++			 */
24555 ++			if (sg_num > 1) {
24556 ++				int blk;
24557 ++
24558 ++				ibuf = obuf;
24559 ++				for (blk = 0; blk < sg_num; blk++) {
24560 ++					memcpy(obuf, page_address(sg[blk].page) + sg[blk].offset,
24561 ++							sg[blk].length);
24562 ++					obuf += sg[blk].length;
24563 ++				}
24564 ++				olen -= sg_len;
24565 ++			} else
24566 ++				ibuf = page_address(sg[0].page) + sg[0].offset;
24567 ++
24568 ++			if (crd->crd_flags & CRD_F_ENCRYPT) { /* compress */
24569 ++				ret = crypto_comp_compress(crypto_comp_cast(sw->sw_tfm),
24570 ++						ibuf, ilen, obuf, &olen);
24571 ++				if (!ret && olen > crd->crd_len) {
24572 ++					dprintk("cryptosoft: ERANGE compress %d into %d\n",
24573 ++							crd->crd_len, olen);
24574 ++					if (swcr_fail_if_compression_grows)
24575 ++						ret = ERANGE;
24576 ++				}
24577 ++			} else { /* decompress */
24578 ++				ret = crypto_comp_decompress(crypto_comp_cast(sw->sw_tfm),
24579 ++						ibuf, ilen, obuf, &olen);
24580 ++				if (!ret && (olen + crd->crd_inject) > crp->crp_olen) {
24581 ++					dprintk("cryptosoft: ETOOSMALL decompress %d into %d, "
24582 ++							"space for %d,at offset %d\n",
24583 ++							crd->crd_len, olen, crp->crp_olen, crd->crd_inject);
24584 ++					ret = ETOOSMALL;
24585 ++				}
24586 ++			}
24587 ++			if (ret)
24588 ++				dprintk("%s,%d: ret = %d\n", __FILE__, __LINE__, ret);
24589 ++
24590 ++			/*
24591 ++			 * on success copy result back,
24592 ++			 * linux crpyto API returns -errno,  we need to fix that
24593 ++			 */
24594 ++			crp->crp_etype = ret < 0 ? -ret : ret;
24595 ++			if (ret == 0) {
24596 ++				/* copy back the result and return it's size */
24597 ++				crypto_copyback(crp->crp_flags, crp->crp_buf,
24598 ++						crd->crd_inject, olen, obuf);
24599 ++				crp->crp_olen = olen;
24600 ++			}
24601 ++
24602 ++
24603 ++			} break;
24604 ++
24605 ++		default:
24606 ++			/* Unknown/unsupported algorithm */
24607 ++			dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
24608 ++			crp->crp_etype = EINVAL;
24609 ++			goto done;
24610 ++		}
24611 ++	}
24612 ++
24613 ++done:
24614 ++	crypto_done(crp);
24615 ++	return 0;
24616 ++}
24617 ++
24618 ++static int
24619 ++cryptosoft_init(void)
24620 ++{
24621 ++	int i, sw_type, mode;
24622 ++	char *algo;
24623 ++
24624 ++	dprintk("%s(%p)\n", __FUNCTION__, cryptosoft_init);
24625 ++
24626 ++	softc_device_init(&swcr_softc, "cryptosoft", 0, swcr_methods);
24627 ++
24628 ++	swcr_id = crypto_get_driverid(softc_get_device(&swcr_softc),
24629 ++			CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_SYNC);
24630 ++	if (swcr_id < 0) {
24631 ++		printk("Software crypto device cannot initialize!");
24632 ++		return -ENODEV;
24633 ++	}
24634 ++
24635 ++#define	REGISTER(alg) \
24636 ++		crypto_register(swcr_id, alg, 0,0);
24637 ++
24638 ++	for (i = CRYPTO_ALGORITHM_MIN; i <= CRYPTO_ALGORITHM_MAX; ++i)
24639 ++	{
24640 ++		
24641 ++		algo = crypto_details[i].alg_name;
24642 ++		if (!algo || !*algo)
24643 ++		{
24644 ++			dprintk("%s:Algorithm %d not supported\n", __FUNCTION__, i);
24645 ++			continue;
24646 ++		}
24647 ++
24648 ++		mode = crypto_details[i].mode;
24649 ++		sw_type = crypto_details[i].sw_type;
24650 ++
24651 ++		switch (sw_type)
24652 ++		{
24653 ++			case SW_TYPE_CIPHER:
24654 ++				if (crypto_has_cipher(algo, 0, CRYPTO_ALG_ASYNC))
24655 ++				{
24656 ++					REGISTER(i);
24657 ++				}
24658 ++				else
24659 ++				{
24660 ++					dprintk("%s:CIPHER algorithm %d:'%s' not supported\n",
24661 ++								__FUNCTION__, i, algo);
24662 ++				}
24663 ++				break;
24664 ++			case SW_TYPE_HMAC:
24665 ++				if (crypto_has_hash(algo, 0, CRYPTO_ALG_ASYNC))
24666 ++				{
24667 ++					REGISTER(i);
24668 ++				}
24669 ++				else
24670 ++				{
24671 ++					dprintk("%s:HMAC algorithm %d:'%s' not supported\n",
24672 ++								__FUNCTION__, i, algo);
24673 ++				}
24674 ++				break;
24675 ++			case SW_TYPE_HASH:
24676 ++				if (crypto_has_hash(algo, 0, CRYPTO_ALG_ASYNC))
24677 ++				{
24678 ++					REGISTER(i);
24679 ++				}
24680 ++				else
24681 ++				{
24682 ++					dprintk("%s:HASH algorithm %d:'%s' not supported\n",
24683 ++								__FUNCTION__, i, algo);
24684 ++				}
24685 ++				break;
24686 ++			case SW_TYPE_COMP:
24687 ++				if (crypto_has_comp(algo, 0, CRYPTO_ALG_ASYNC))
24688 ++				{
24689 ++					REGISTER(i);
24690 ++				}
24691 ++				else
24692 ++				{
24693 ++					dprintk("%s:COMP algorithm %d:'%s' not supported\n",
24694 ++								__FUNCTION__, i, algo);
24695 ++				}
24696 ++				break;
24697 ++			case SW_TYPE_BLKCIPHER:
24698 ++				if (crypto_has_blkcipher(algo, 0, CRYPTO_ALG_ASYNC))
24699 ++				{
24700 ++					REGISTER(i);
24701 ++				}
24702 ++				else
24703 ++				{
24704 ++					dprintk("%s:BLKCIPHER algorithm %d:'%s' not supported\n",
24705 ++								__FUNCTION__, i, algo);
24706 ++				}
24707 ++				break;
24708 ++			default:
24709 ++				dprintk(
24710 ++				"%s:Algorithm Type %d not supported (algorithm %d:'%s')\n",
24711 ++					__FUNCTION__, sw_type, i, algo);
24712 ++				break;
24713 ++		}
24714 ++	}
24715 ++
24716 ++	return(0);
24717 ++}
24718 ++
24719 ++static void
24720 ++cryptosoft_exit(void)
24721 ++{
24722 ++	dprintk("%s()\n", __FUNCTION__);
24723 ++	crypto_unregister_all(swcr_id);
24724 ++	swcr_id = -1;
24725 ++}
24726 ++
24727 ++module_init(cryptosoft_init);
24728 ++module_exit(cryptosoft_exit);
24729 ++
24730 ++MODULE_LICENSE("Dual BSD/GPL");
24731 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
24732 ++MODULE_DESCRIPTION("Cryptosoft (OCF module for kernel crypto)");
24733 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751.c linux-2.6.23.16/crypto/ocf/hifn/hifn7751.c
24734 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751.c	1969-12-31 19:00:00.000000000 -0500
24735 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifn7751.c	2008-02-26 09:29:13.000000000 -0500
24736 +@@ -0,0 +1,2969 @@
24737 ++/*	$OpenBSD: hifn7751.c,v 1.120 2002/05/17 00:33:34 deraadt Exp $	*/
24738 ++
24739 ++/*-
24740 ++ * Invertex AEON / Hifn 7751 driver
24741 ++ * Copyright (c) 1999 Invertex Inc. All rights reserved.
24742 ++ * Copyright (c) 1999 Theo de Raadt
24743 ++ * Copyright (c) 2000-2001 Network Security Technologies, Inc.
24744 ++ *			http://www.netsec.net
24745 ++ * Copyright (c) 2003 Hifn Inc.
24746 ++ *
24747 ++ * This driver is based on a previous driver by Invertex, for which they
24748 ++ * requested:  Please send any comments, feedback, bug-fixes, or feature
24749 ++ * requests to software@invertex.com.
24750 ++ *
24751 ++ * Redistribution and use in source and binary forms, with or without
24752 ++ * modification, are permitted provided that the following conditions
24753 ++ * are met:
24754 ++ *
24755 ++ * 1. Redistributions of source code must retain the above copyright
24756 ++ *   notice, this list of conditions and the following disclaimer.
24757 ++ * 2. Redistributions in binary form must reproduce the above copyright
24758 ++ *   notice, this list of conditions and the following disclaimer in the
24759 ++ *   documentation and/or other materials provided with the distribution.
24760 ++ * 3. The name of the author may not be used to endorse or promote products
24761 ++ *   derived from this software without specific prior written permission.
24762 ++ *
24763 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24764 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24765 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24766 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24767 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24768 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24769 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24770 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24771 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24772 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24773 ++ *
24774 ++ * Effort sponsored in part by the Defense Advanced Research Projects
24775 ++ * Agency (DARPA) and Air Force Research Laboratory, Air Force
24776 ++ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
24777 ++ *
24778 ++ *
24779 ++__FBSDID("$FreeBSD: src/sys/dev/hifn/hifn7751.c,v 1.40 2007/03/21 03:42:49 sam Exp $");
24780 ++ */
24781 ++
24782 ++/*
24783 ++ * Driver for various Hifn encryption processors.
24784 ++ */
24785 ++#ifndef AUTOCONF_INCLUDED
24786 ++#include <linux/config.h>
24787 ++#endif
24788 ++#include <linux/module.h>
24789 ++#include <linux/init.h>
24790 ++#include <linux/list.h>
24791 ++#include <linux/slab.h>
24792 ++#include <linux/wait.h>
24793 ++#include <linux/sched.h>
24794 ++#include <linux/pci.h>
24795 ++#include <linux/delay.h>
24796 ++#include <linux/interrupt.h>
24797 ++#include <linux/spinlock.h>
24798 ++#include <linux/random.h>
24799 ++#include <linux/version.h>
24800 ++#include <linux/skbuff.h>
24801 ++#include <asm/io.h>
24802 ++
24803 ++#include <cryptodev.h>
24804 ++#include <uio.h>
24805 ++#include <hifn/hifn7751reg.h>
24806 ++#include <hifn/hifn7751var.h>
24807 ++
24808 ++#if 1
24809 ++#define	DPRINTF(a...)	if (hifn_debug) { \
24810 ++							printk("%s: ", sc ? \
24811 ++								device_get_nameunit(sc->sc_dev) : "hifn"); \
24812 ++							printk(a); \
24813 ++						} else
24814 ++#else
24815 ++#define	DPRINTF(a...)
24816 ++#endif
24817 ++
24818 ++static inline int
24819 ++pci_get_revid(struct pci_dev *dev)
24820 ++{
24821 ++	u8 rid = 0;
24822 ++	pci_read_config_byte(dev, PCI_REVISION_ID, &rid);
24823 ++	return rid;
24824 ++}
24825 ++
24826 ++static	struct hifn_stats hifnstats;
24827 ++
24828 ++#define	debug hifn_debug
24829 ++int hifn_debug = 0;
24830 ++module_param(hifn_debug, int, 0644);
24831 ++MODULE_PARM_DESC(hifn_debug, "Enable debug");
24832 ++
24833 ++int hifn_maxbatch = 1;
24834 ++module_param(hifn_maxbatch, int, 0644);
24835 ++MODULE_PARM_DESC(hifn_maxbatch, "max ops to batch w/o interrupt");
24836 ++
24837 ++#ifdef MODULE_PARM
24838 ++char *hifn_pllconfig = NULL;
24839 ++MODULE_PARM(hifn_pllconfig, "s");
24840 ++#else
24841 ++char hifn_pllconfig[32]; /* This setting is RO after loading */
24842 ++module_param_string(hifn_pllconfig, hifn_pllconfig, 32, 0444);
24843 ++#endif
24844 ++MODULE_PARM_DESC(hifn_pllconfig, "PLL config, ie., pci66, ext33, ...");
24845 ++
24846 ++#ifdef HIFN_VULCANDEV
24847 ++#include <sys/conf.h>
24848 ++#include <sys/uio.h>
24849 ++
24850 ++static struct cdevsw vulcanpk_cdevsw; /* forward declaration */
24851 ++#endif
24852 ++
24853 ++/*
24854 ++ * Prototypes and count for the pci_device structure
24855 ++ */
24856 ++static	int  hifn_probe(struct pci_dev *dev, const struct pci_device_id *ent);
24857 ++static	void hifn_remove(struct pci_dev *dev);
24858 ++
24859 ++static	int hifn_newsession(device_t, u_int32_t *, struct cryptoini *);
24860 ++static	int hifn_freesession(device_t, u_int64_t);
24861 ++static	int hifn_process(device_t, struct cryptop *, int);
24862 ++
24863 ++static device_method_t hifn_methods = {
24864 ++	/* crypto device methods */
24865 ++	DEVMETHOD(cryptodev_newsession,	hifn_newsession),
24866 ++	DEVMETHOD(cryptodev_freesession,hifn_freesession),
24867 ++	DEVMETHOD(cryptodev_process,	hifn_process),
24868 ++};
24869 ++
24870 ++static	void hifn_reset_board(struct hifn_softc *, int);
24871 ++static	void hifn_reset_puc(struct hifn_softc *);
24872 ++static	void hifn_puc_wait(struct hifn_softc *);
24873 ++static	int hifn_enable_crypto(struct hifn_softc *);
24874 ++static	void hifn_set_retry(struct hifn_softc *sc);
24875 ++static	void hifn_init_dma(struct hifn_softc *);
24876 ++static	void hifn_init_pci_registers(struct hifn_softc *);
24877 ++static	int hifn_sramsize(struct hifn_softc *);
24878 ++static	int hifn_dramsize(struct hifn_softc *);
24879 ++static	int hifn_ramtype(struct hifn_softc *);
24880 ++static	void hifn_sessions(struct hifn_softc *);
24881 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
24882 ++static irqreturn_t hifn_intr(int irq, void *arg);
24883 ++#else
24884 ++static irqreturn_t hifn_intr(int irq, void *arg, struct pt_regs *regs);
24885 ++#endif
24886 ++static	u_int hifn_write_command(struct hifn_command *, u_int8_t *);
24887 ++static	u_int32_t hifn_next_signature(u_int32_t a, u_int cnt);
24888 ++static	void hifn_callback(struct hifn_softc *, struct hifn_command *, u_int8_t *);
24889 ++static	int hifn_crypto(struct hifn_softc *, struct hifn_command *, struct cryptop *, int);
24890 ++static	int hifn_readramaddr(struct hifn_softc *, int, u_int8_t *);
24891 ++static	int hifn_writeramaddr(struct hifn_softc *, int, u_int8_t *);
24892 ++static	int hifn_dmamap_load_src(struct hifn_softc *, struct hifn_command *);
24893 ++static	int hifn_dmamap_load_dst(struct hifn_softc *, struct hifn_command *);
24894 ++static	int hifn_init_pubrng(struct hifn_softc *);
24895 ++static	void hifn_tick(unsigned long arg);
24896 ++static	void hifn_abort(struct hifn_softc *);
24897 ++static	void hifn_alloc_slot(struct hifn_softc *, int *, int *, int *, int *);
24898 ++
24899 ++static	void hifn_write_reg_0(struct hifn_softc *, bus_size_t, u_int32_t);
24900 ++static	void hifn_write_reg_1(struct hifn_softc *, bus_size_t, u_int32_t);
24901 ++
24902 ++#ifdef CONFIG_OCF_RANDOMHARVEST
24903 ++static	int hifn_read_random(void *arg, u_int32_t *buf, int len);
24904 ++#endif
24905 ++
24906 ++#define HIFN_MAX_CHIPS	8
24907 ++static struct hifn_softc *hifn_chip_idx[HIFN_MAX_CHIPS];
24908 ++
24909 ++static __inline u_int32_t
24910 ++READ_REG_0(struct hifn_softc *sc, bus_size_t reg)
24911 ++{
24912 ++	u_int32_t v = readl(sc->sc_bar0 + reg);
24913 ++	sc->sc_bar0_lastreg = (bus_size_t) -1;
24914 ++	return (v);
24915 ++}
24916 ++#define	WRITE_REG_0(sc, reg, val)	hifn_write_reg_0(sc, reg, val)
24917 ++
24918 ++static __inline u_int32_t
24919 ++READ_REG_1(struct hifn_softc *sc, bus_size_t reg)
24920 ++{
24921 ++	u_int32_t v = readl(sc->sc_bar1 + reg);
24922 ++	sc->sc_bar1_lastreg = (bus_size_t) -1;
24923 ++	return (v);
24924 ++}
24925 ++#define	WRITE_REG_1(sc, reg, val)	hifn_write_reg_1(sc, reg, val)
24926 ++
24927 ++/*
24928 ++ * map in a given buffer (great on some arches :-)
24929 ++ */
24930 ++
24931 ++static int
24932 ++pci_map_uio(struct hifn_softc *sc, struct hifn_operand *buf, struct uio *uio)
24933 ++{
24934 ++	struct iovec *iov = uio->uio_iov;
24935 ++
24936 ++	DPRINTF("%s()\n", __FUNCTION__);
24937 ++
24938 ++	buf->mapsize = 0;
24939 ++	for (buf->nsegs = 0; buf->nsegs < uio->uio_iovcnt; ) {
24940 ++		buf->segs[buf->nsegs].ds_addr = pci_map_single(sc->sc_pcidev,
24941 ++				iov->iov_base, iov->iov_len,
24942 ++				PCI_DMA_BIDIRECTIONAL);
24943 ++		buf->segs[buf->nsegs].ds_len = iov->iov_len;
24944 ++		buf->mapsize += iov->iov_len;
24945 ++		iov++;
24946 ++		buf->nsegs++;
24947 ++	}
24948 ++	/* identify this buffer by the first segment */
24949 ++	buf->map = (void *) buf->segs[0].ds_addr;
24950 ++	return(0);
24951 ++}
24952 ++
24953 ++/*
24954 ++ * map in a given sk_buff
24955 ++ */
24956 ++
24957 ++static int
24958 ++pci_map_skb(struct hifn_softc *sc,struct hifn_operand *buf,struct sk_buff *skb)
24959 ++{
24960 ++	int i;
24961 ++
24962 ++	DPRINTF("%s()\n", __FUNCTION__);
24963 ++
24964 ++	buf->mapsize = 0;
24965 ++
24966 ++	buf->segs[0].ds_addr = pci_map_single(sc->sc_pcidev,
24967 ++			skb->data, skb_headlen(skb), PCI_DMA_BIDIRECTIONAL);
24968 ++	buf->segs[0].ds_len = skb_headlen(skb);
24969 ++	buf->mapsize += buf->segs[0].ds_len;
24970 ++
24971 ++	buf->nsegs = 1;
24972 ++
24973 ++	for (i = 0; i < skb_shinfo(skb)->nr_frags; ) {
24974 ++		buf->segs[buf->nsegs].ds_len = skb_shinfo(skb)->frags[i].size;
24975 ++		buf->segs[buf->nsegs].ds_addr = pci_map_single(sc->sc_pcidev,
24976 ++				page_address(skb_shinfo(skb)->frags[i].page) +
24977 ++					skb_shinfo(skb)->frags[i].page_offset,
24978 ++				buf->segs[buf->nsegs].ds_len, PCI_DMA_BIDIRECTIONAL);
24979 ++		buf->mapsize += buf->segs[buf->nsegs].ds_len;
24980 ++		buf->nsegs++;
24981 ++	}
24982 ++
24983 ++	/* identify this buffer by the first segment */
24984 ++	buf->map = (void *) buf->segs[0].ds_addr;
24985 ++	return(0);
24986 ++}
24987 ++
24988 ++/*
24989 ++ * map in a given contiguous buffer
24990 ++ */
24991 ++
24992 ++static int
24993 ++pci_map_buf(struct hifn_softc *sc,struct hifn_operand *buf, void *b, int len)
24994 ++{
24995 ++	DPRINTF("%s()\n", __FUNCTION__);
24996 ++
24997 ++	buf->mapsize = 0;
24998 ++	buf->segs[0].ds_addr = pci_map_single(sc->sc_pcidev,
24999 ++			b, len, PCI_DMA_BIDIRECTIONAL);
25000 ++	buf->segs[0].ds_len = len;
25001 ++	buf->mapsize += buf->segs[0].ds_len;
25002 ++	buf->nsegs = 1;
25003 ++
25004 ++	/* identify this buffer by the first segment */
25005 ++	buf->map = (void *) buf->segs[0].ds_addr;
25006 ++	return(0);
25007 ++}
25008 ++
25009 ++#if 0 /* not needed at this time */
25010 ++static void
25011 ++pci_sync_iov(struct hifn_softc *sc, struct hifn_operand *buf)
25012 ++{
25013 ++	int i;
25014 ++
25015 ++	DPRINTF("%s()\n", __FUNCTION__);
25016 ++	for (i = 0; i < buf->nsegs; i++)
25017 ++		pci_dma_sync_single_for_cpu(sc->sc_pcidev, buf->segs[i].ds_addr,
25018 ++				buf->segs[i].ds_len, PCI_DMA_BIDIRECTIONAL);
25019 ++}
25020 ++#endif
25021 ++
25022 ++static void
25023 ++pci_unmap_buf(struct hifn_softc *sc, struct hifn_operand *buf)
25024 ++{
25025 ++	int i;
25026 ++	DPRINTF("%s()\n", __FUNCTION__);
25027 ++	for (i = 0; i < buf->nsegs; i++) {
25028 ++		pci_unmap_single(sc->sc_pcidev, buf->segs[i].ds_addr,
25029 ++				buf->segs[i].ds_len, PCI_DMA_BIDIRECTIONAL);
25030 ++		buf->segs[i].ds_addr = 0;
25031 ++		buf->segs[i].ds_len = 0;
25032 ++	}
25033 ++	buf->nsegs = 0;
25034 ++	buf->mapsize = 0;
25035 ++	buf->map = 0;
25036 ++}
25037 ++
25038 ++static const char*
25039 ++hifn_partname(struct hifn_softc *sc)
25040 ++{
25041 ++	/* XXX sprintf numbers when not decoded */
25042 ++	switch (pci_get_vendor(sc->sc_pcidev)) {
25043 ++	case PCI_VENDOR_HIFN:
25044 ++		switch (pci_get_device(sc->sc_pcidev)) {
25045 ++		case PCI_PRODUCT_HIFN_6500:	return "Hifn 6500";
25046 ++		case PCI_PRODUCT_HIFN_7751:	return "Hifn 7751";
25047 ++		case PCI_PRODUCT_HIFN_7811:	return "Hifn 7811";
25048 ++		case PCI_PRODUCT_HIFN_7951:	return "Hifn 7951";
25049 ++		case PCI_PRODUCT_HIFN_7955:	return "Hifn 7955";
25050 ++		case PCI_PRODUCT_HIFN_7956:	return "Hifn 7956";
25051 ++		}
25052 ++		return "Hifn unknown-part";
25053 ++	case PCI_VENDOR_INVERTEX:
25054 ++		switch (pci_get_device(sc->sc_pcidev)) {
25055 ++		case PCI_PRODUCT_INVERTEX_AEON:	return "Invertex AEON";
25056 ++		}
25057 ++		return "Invertex unknown-part";
25058 ++	case PCI_VENDOR_NETSEC:
25059 ++		switch (pci_get_device(sc->sc_pcidev)) {
25060 ++		case PCI_PRODUCT_NETSEC_7751:	return "NetSec 7751";
25061 ++		}
25062 ++		return "NetSec unknown-part";
25063 ++	}
25064 ++	return "Unknown-vendor unknown-part";
25065 ++}
25066 ++
25067 ++static u_int
25068 ++checkmaxmin(struct pci_dev *dev, const char *what, u_int v, u_int min, u_int max)
25069 ++{
25070 ++	struct hifn_softc *sc = pci_get_drvdata(dev);
25071 ++	if (v > max) {
25072 ++		device_printf(sc->sc_dev, "Warning, %s %u out of range, "
25073 ++			"using max %u\n", what, v, max);
25074 ++		v = max;
25075 ++	} else if (v < min) {
25076 ++		device_printf(sc->sc_dev, "Warning, %s %u out of range, "
25077 ++			"using min %u\n", what, v, min);
25078 ++		v = min;
25079 ++	}
25080 ++	return v;
25081 ++}
25082 ++
25083 ++/*
25084 ++ * Select PLL configuration for 795x parts.  This is complicated in
25085 ++ * that we cannot determine the optimal parameters without user input.
25086 ++ * The reference clock is derived from an external clock through a
25087 ++ * multiplier.  The external clock is either the host bus (i.e. PCI)
25088 ++ * or an external clock generator.  When using the PCI bus we assume
25089 ++ * the clock is either 33 or 66 MHz; for an external source we cannot
25090 ++ * tell the speed.
25091 ++ *
25092 ++ * PLL configuration is done with a string: "pci" for PCI bus, or "ext"
25093 ++ * for an external source, followed by the frequency.  We calculate
25094 ++ * the appropriate multiplier and PLL register contents accordingly.
25095 ++ * When no configuration is given we default to "pci66" since that
25096 ++ * always will allow the card to work.  If a card is using the PCI
25097 ++ * bus clock and in a 33MHz slot then it will be operating at half
25098 ++ * speed until the correct information is provided.
25099 ++ *
25100 ++ * We use a default setting of "ext66" because according to Mike Ham
25101 ++ * of HiFn, almost every board in existence has an external crystal
25102 ++ * populated at 66Mhz. Using PCI can be a problem on modern motherboards,
25103 ++ * because PCI33 can have clocks from 0 to 33Mhz, and some have
25104 ++ * non-PCI-compliant spread-spectrum clocks, which can confuse the pll.
25105 ++ */
25106 ++static void
25107 ++hifn_getpllconfig(struct pci_dev *dev, u_int *pll)
25108 ++{
25109 ++	const char *pllspec = hifn_pllconfig;
25110 ++	u_int freq, mul, fl, fh;
25111 ++	u_int32_t pllconfig;
25112 ++	char *nxt;
25113 ++
25114 ++	if (pllspec == NULL)
25115 ++		pllspec = "ext66";
25116 ++	fl = 33, fh = 66;
25117 ++	pllconfig = 0;
25118 ++	if (strncmp(pllspec, "ext", 3) == 0) {
25119 ++		pllspec += 3;
25120 ++		pllconfig |= HIFN_PLL_REF_SEL;
25121 ++		switch (pci_get_device(dev)) {
25122 ++		case PCI_PRODUCT_HIFN_7955:
25123 ++		case PCI_PRODUCT_HIFN_7956:
25124 ++			fl = 20, fh = 100;
25125 ++			break;
25126 ++#ifdef notyet
25127 ++		case PCI_PRODUCT_HIFN_7954:
25128 ++			fl = 20, fh = 66;
25129 ++			break;
25130 ++#endif
25131 ++		}
25132 ++	} else if (strncmp(pllspec, "pci", 3) == 0)
25133 ++		pllspec += 3;
25134 ++	freq = strtoul(pllspec, &nxt, 10);
25135 ++	if (nxt == pllspec)
25136 ++		freq = 66;
25137 ++	else
25138 ++		freq = checkmaxmin(dev, "frequency", freq, fl, fh);
25139 ++	/*
25140 ++	 * Calculate multiplier.  We target a Fck of 266 MHz,
25141 ++	 * allowing only even values, possibly rounded down.
25142 ++	 * Multipliers > 8 must set the charge pump current.
25143 ++	 */
25144 ++	mul = checkmaxmin(dev, "PLL divisor", (266 / freq) &~ 1, 2, 12);
25145 ++	pllconfig |= (mul / 2 - 1) << HIFN_PLL_ND_SHIFT;
25146 ++	if (mul > 8)
25147 ++		pllconfig |= HIFN_PLL_IS;
25148 ++	*pll = pllconfig;
25149 ++}
25150 ++
25151 ++/*
25152 ++ * Attach an interface that successfully probed.
25153 ++ */
25154 ++static int
25155 ++hifn_probe(struct pci_dev *dev, const struct pci_device_id *ent)
25156 ++{
25157 ++	struct hifn_softc *sc = NULL;
25158 ++	char rbase;
25159 ++	u_int16_t ena, rev;
25160 ++	int rseg, rc;
25161 ++	unsigned long mem_start, mem_len;
25162 ++	static int num_chips = 0;
25163 ++
25164 ++	DPRINTF("%s()\n", __FUNCTION__);
25165 ++
25166 ++	if (pci_enable_device(dev) < 0)
25167 ++		return(-ENODEV);
25168 ++
25169 ++	if (pci_set_mwi(dev))
25170 ++		return(-ENODEV);
25171 ++
25172 ++	if (!dev->irq) {
25173 ++		printk("hifn: found device with no IRQ assigned. check BIOS settings!");
25174 ++		pci_disable_device(dev);
25175 ++		return(-ENODEV);
25176 ++	}
25177 ++
25178 ++	sc = (struct hifn_softc *) kmalloc(sizeof(*sc), GFP_KERNEL);
25179 ++	if (!sc)
25180 ++		return(-ENOMEM);
25181 ++	memset(sc, 0, sizeof(*sc));
25182 ++
25183 ++	softc_device_init(sc, "hifn", num_chips, hifn_methods);
25184 ++
25185 ++	sc->sc_pcidev = dev;
25186 ++	sc->sc_irq = -1;
25187 ++	sc->sc_cid = -1;
25188 ++	sc->sc_num = num_chips++;
25189 ++	if (sc->sc_num < HIFN_MAX_CHIPS)
25190 ++		hifn_chip_idx[sc->sc_num] = sc;
25191 ++
25192 ++	pci_set_drvdata(sc->sc_pcidev, sc);
25193 ++
25194 ++	spin_lock_init(&sc->sc_mtx);
25195 ++
25196 ++	/* XXX handle power management */
25197 ++
25198 ++	/*
25199 ++	 * The 7951 and 795x have a random number generator and
25200 ++	 * public key support; note this.
25201 ++	 */
25202 ++	if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
25203 ++	    (pci_get_device(dev) == PCI_PRODUCT_HIFN_7951 ||
25204 ++	     pci_get_device(dev) == PCI_PRODUCT_HIFN_7955 ||
25205 ++	     pci_get_device(dev) == PCI_PRODUCT_HIFN_7956))
25206 ++		sc->sc_flags = HIFN_HAS_RNG | HIFN_HAS_PUBLIC;
25207 ++	/*
25208 ++	 * The 7811 has a random number generator and
25209 ++	 * we also note it's identity 'cuz of some quirks.
25210 ++	 */
25211 ++	if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
25212 ++	    pci_get_device(dev) == PCI_PRODUCT_HIFN_7811)
25213 ++		sc->sc_flags |= HIFN_IS_7811 | HIFN_HAS_RNG;
25214 ++
25215 ++	/*
25216 ++	 * The 795x parts support AES.
25217 ++	 */
25218 ++	if (pci_get_vendor(dev) == PCI_VENDOR_HIFN &&
25219 ++	    (pci_get_device(dev) == PCI_PRODUCT_HIFN_7955 ||
25220 ++	     pci_get_device(dev) == PCI_PRODUCT_HIFN_7956)) {
25221 ++		sc->sc_flags |= HIFN_IS_7956 | HIFN_HAS_AES;
25222 ++		/*
25223 ++		 * Select PLL configuration.  This depends on the
25224 ++		 * bus and board design and must be manually configured
25225 ++		 * if the default setting is unacceptable.
25226 ++		 */
25227 ++		hifn_getpllconfig(dev, &sc->sc_pllconfig);
25228 ++	}
25229 ++
25230 ++	/*
25231 ++	 * Setup PCI resources. Note that we record the bus
25232 ++	 * tag and handle for each register mapping, this is
25233 ++	 * used by the READ_REG_0, WRITE_REG_0, READ_REG_1,
25234 ++	 * and WRITE_REG_1 macros throughout the driver.
25235 ++	 */
25236 ++	mem_start = pci_resource_start(sc->sc_pcidev, 0);
25237 ++	mem_len   = pci_resource_len(sc->sc_pcidev, 0);
25238 ++	sc->sc_bar0 = (ocf_iomem_t) ioremap(mem_start, mem_len);
25239 ++	if (!sc->sc_bar0) {
25240 ++		device_printf(sc->sc_dev, "cannot map bar%d register space\n", 0);
25241 ++		goto fail;
25242 ++	}
25243 ++	sc->sc_bar0_lastreg = (bus_size_t) -1;
25244 ++
25245 ++	mem_start = pci_resource_start(sc->sc_pcidev, 1);
25246 ++	mem_len   = pci_resource_len(sc->sc_pcidev, 1);
25247 ++	sc->sc_bar1 = (ocf_iomem_t) ioremap(mem_start, mem_len);
25248 ++	if (!sc->sc_bar1) {
25249 ++		device_printf(sc->sc_dev, "cannot map bar%d register space\n", 1);
25250 ++		goto fail;
25251 ++	}
25252 ++	sc->sc_bar1_lastreg = (bus_size_t) -1;
25253 ++
25254 ++	/* fix up the bus size */
25255 ++	if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
25256 ++		device_printf(sc->sc_dev, "No usable DMA configuration, aborting.\n");
25257 ++		goto fail;
25258 ++	}
25259 ++	if (pci_set_consistent_dma_mask(dev, DMA_32BIT_MASK)) {
25260 ++		device_printf(sc->sc_dev,
25261 ++				"No usable consistent DMA configuration, aborting.\n");
25262 ++		goto fail;
25263 ++	}
25264 ++
25265 ++	hifn_set_retry(sc);
25266 ++
25267 ++	/*
25268 ++	 * Setup the area where the Hifn DMA's descriptors
25269 ++	 * and associated data structures.
25270 ++	 */
25271 ++	sc->sc_dma = (struct hifn_dma *) pci_alloc_consistent(dev,
25272 ++			sizeof(*sc->sc_dma),
25273 ++			&sc->sc_dma_physaddr);
25274 ++	if (!sc->sc_dma) {
25275 ++		device_printf(sc->sc_dev, "cannot alloc sc_dma\n");
25276 ++		goto fail;
25277 ++	}
25278 ++	bzero(sc->sc_dma, sizeof(*sc->sc_dma));
25279 ++
25280 ++	/*
25281 ++	 * Reset the board and do the ``secret handshake''
25282 ++	 * to enable the crypto support.  Then complete the
25283 ++	 * initialization procedure by setting up the interrupt
25284 ++	 * and hooking in to the system crypto support so we'll
25285 ++	 * get used for system services like the crypto device,
25286 ++	 * IPsec, RNG device, etc.
25287 ++	 */
25288 ++	hifn_reset_board(sc, 0);
25289 ++
25290 ++	if (hifn_enable_crypto(sc) != 0) {
25291 ++		device_printf(sc->sc_dev, "crypto enabling failed\n");
25292 ++		goto fail;
25293 ++	}
25294 ++	hifn_reset_puc(sc);
25295 ++
25296 ++	hifn_init_dma(sc);
25297 ++	hifn_init_pci_registers(sc);
25298 ++
25299 ++	pci_set_master(sc->sc_pcidev);
25300 ++
25301 ++	/* XXX can't dynamically determine ram type for 795x; force dram */
25302 ++	if (sc->sc_flags & HIFN_IS_7956)
25303 ++		sc->sc_drammodel = 1;
25304 ++	else if (hifn_ramtype(sc))
25305 ++		goto fail;
25306 ++
25307 ++	if (sc->sc_drammodel == 0)
25308 ++		hifn_sramsize(sc);
25309 ++	else
25310 ++		hifn_dramsize(sc);
25311 ++
25312 ++	/*
25313 ++	 * Workaround for NetSec 7751 rev A: half ram size because two
25314 ++	 * of the address lines were left floating
25315 ++	 */
25316 ++	if (pci_get_vendor(dev) == PCI_VENDOR_NETSEC &&
25317 ++	    pci_get_device(dev) == PCI_PRODUCT_NETSEC_7751 &&
25318 ++	    pci_get_revid(dev) == 0x61)	/*XXX???*/
25319 ++		sc->sc_ramsize >>= 1;
25320 ++
25321 ++	/*
25322 ++	 * Arrange the interrupt line.
25323 ++	 */
25324 ++	rc = request_irq(dev->irq, hifn_intr, IRQF_SHARED, "hifn", sc);
25325 ++	if (rc) {
25326 ++		device_printf(sc->sc_dev, "could not map interrupt: %d\n", rc);
25327 ++		goto fail;
25328 ++	}
25329 ++	sc->sc_irq = dev->irq;
25330 ++
25331 ++	hifn_sessions(sc);
25332 ++
25333 ++	/*
25334 ++	 * NB: Keep only the low 16 bits; this masks the chip id
25335 ++	 *     from the 7951.
25336 ++	 */
25337 ++	rev = READ_REG_1(sc, HIFN_1_REVID) & 0xffff;
25338 ++
25339 ++	rseg = sc->sc_ramsize / 1024;
25340 ++	rbase = 'K';
25341 ++	if (sc->sc_ramsize >= (1024 * 1024)) {
25342 ++		rbase = 'M';
25343 ++		rseg /= 1024;
25344 ++	}
25345 ++	device_printf(sc->sc_dev, "%s, rev %u, %d%cB %cram",
25346 ++		hifn_partname(sc), rev,
25347 ++		rseg, rbase, sc->sc_drammodel ? 'd' : 's');
25348 ++	if (sc->sc_flags & HIFN_IS_7956)
25349 ++		printf(", pll=0x%x<%s clk, %ux mult>",
25350 ++			sc->sc_pllconfig,
25351 ++			sc->sc_pllconfig & HIFN_PLL_REF_SEL ? "ext" : "pci",
25352 ++			2 + 2*((sc->sc_pllconfig & HIFN_PLL_ND) >> 11));
25353 ++	printf("\n");
25354 ++
25355 ++	sc->sc_cid = crypto_get_driverid(softc_get_device(sc),CRYPTOCAP_F_HARDWARE);
25356 ++	if (sc->sc_cid < 0) {
25357 ++		device_printf(sc->sc_dev, "could not get crypto driver id\n");
25358 ++		goto fail;
25359 ++	}
25360 ++
25361 ++	WRITE_REG_0(sc, HIFN_0_PUCNFG,
25362 ++	    READ_REG_0(sc, HIFN_0_PUCNFG) | HIFN_PUCNFG_CHIPID);
25363 ++	ena = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
25364 ++
25365 ++	switch (ena) {
25366 ++	case HIFN_PUSTAT_ENA_2:
25367 ++		crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
25368 ++		crypto_register(sc->sc_cid, CRYPTO_ARC4, 0, 0);
25369 ++		if (sc->sc_flags & HIFN_HAS_AES)
25370 ++			crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0);
25371 ++		/*FALLTHROUGH*/
25372 ++	case HIFN_PUSTAT_ENA_1:
25373 ++		crypto_register(sc->sc_cid, CRYPTO_MD5, 0, 0);
25374 ++		crypto_register(sc->sc_cid, CRYPTO_SHA1, 0, 0);
25375 ++		crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0);
25376 ++		crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0);
25377 ++		crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0);
25378 ++		break;
25379 ++	}
25380 ++
25381 ++	if (sc->sc_flags & (HIFN_HAS_PUBLIC | HIFN_HAS_RNG))
25382 ++		hifn_init_pubrng(sc);
25383 ++
25384 ++	init_timer(&sc->sc_tickto);
25385 ++	sc->sc_tickto.function = hifn_tick;
25386 ++	sc->sc_tickto.data = (unsigned long) sc->sc_num;
25387 ++	mod_timer(&sc->sc_tickto, jiffies + HZ);
25388 ++
25389 ++	return (0);
25390 ++
25391 ++fail:
25392 ++    if (sc->sc_cid >= 0)
25393 ++        crypto_unregister_all(sc->sc_cid);
25394 ++    if (sc->sc_irq != -1)
25395 ++        free_irq(sc->sc_irq, sc);
25396 ++    if (sc->sc_dma) {
25397 ++		/* Turn off DMA polling */
25398 ++		WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
25399 ++			HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
25400 ++
25401 ++        pci_free_consistent(sc->sc_pcidev,
25402 ++				sizeof(*sc->sc_dma),
25403 ++                sc->sc_dma, sc->sc_dma_physaddr);
25404 ++	}
25405 ++    kfree(sc);
25406 ++	return (-ENXIO);
25407 ++}
25408 ++
25409 ++/*
25410 ++ * Detach an interface that successfully probed.
25411 ++ */
25412 ++static void
25413 ++hifn_remove(struct pci_dev *dev)
25414 ++{
25415 ++	struct hifn_softc *sc = pci_get_drvdata(dev);
25416 ++	unsigned long l_flags;
25417 ++
25418 ++	DPRINTF("%s()\n", __FUNCTION__);
25419 ++
25420 ++	KASSERT(sc != NULL, ("hifn_detach: null software carrier!"));
25421 ++
25422 ++	/* disable interrupts */
25423 ++	HIFN_LOCK(sc);
25424 ++	WRITE_REG_1(sc, HIFN_1_DMA_IER, 0);
25425 ++	HIFN_UNLOCK(sc);
25426 ++
25427 ++	/*XXX other resources */
25428 ++	del_timer_sync(&sc->sc_tickto);
25429 ++
25430 ++	/* Turn off DMA polling */
25431 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
25432 ++	    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
25433 ++
25434 ++	crypto_unregister_all(sc->sc_cid);
25435 ++
25436 ++	free_irq(sc->sc_irq, sc);
25437 ++
25438 ++	pci_free_consistent(sc->sc_pcidev, sizeof(*sc->sc_dma),
25439 ++                sc->sc_dma, sc->sc_dma_physaddr);
25440 ++}
25441 ++
25442 ++
25443 ++static int
25444 ++hifn_init_pubrng(struct hifn_softc *sc)
25445 ++{
25446 ++	int i;
25447 ++
25448 ++	DPRINTF("%s()\n", __FUNCTION__);
25449 ++
25450 ++	if ((sc->sc_flags & HIFN_IS_7811) == 0) {
25451 ++		/* Reset 7951 public key/rng engine */
25452 ++		WRITE_REG_1(sc, HIFN_1_PUB_RESET,
25453 ++		    READ_REG_1(sc, HIFN_1_PUB_RESET) | HIFN_PUBRST_RESET);
25454 ++
25455 ++		for (i = 0; i < 100; i++) {
25456 ++			DELAY(1000);
25457 ++			if ((READ_REG_1(sc, HIFN_1_PUB_RESET) &
25458 ++			    HIFN_PUBRST_RESET) == 0)
25459 ++				break;
25460 ++		}
25461 ++
25462 ++		if (i == 100) {
25463 ++			device_printf(sc->sc_dev, "public key init failed\n");
25464 ++			return (1);
25465 ++		}
25466 ++	}
25467 ++
25468 ++	/* Enable the rng, if available */
25469 ++#ifdef CONFIG_OCF_RANDOMHARVEST
25470 ++	if (sc->sc_flags & HIFN_HAS_RNG) {
25471 ++		if (sc->sc_flags & HIFN_IS_7811) {
25472 ++			u_int32_t r;
25473 ++			r = READ_REG_1(sc, HIFN_1_7811_RNGENA);
25474 ++			if (r & HIFN_7811_RNGENA_ENA) {
25475 ++				r &= ~HIFN_7811_RNGENA_ENA;
25476 ++				WRITE_REG_1(sc, HIFN_1_7811_RNGENA, r);
25477 ++			}
25478 ++			WRITE_REG_1(sc, HIFN_1_7811_RNGCFG,
25479 ++			    HIFN_7811_RNGCFG_DEFL);
25480 ++			r |= HIFN_7811_RNGENA_ENA;
25481 ++			WRITE_REG_1(sc, HIFN_1_7811_RNGENA, r);
25482 ++		} else
25483 ++			WRITE_REG_1(sc, HIFN_1_RNG_CONFIG,
25484 ++			    READ_REG_1(sc, HIFN_1_RNG_CONFIG) |
25485 ++			    HIFN_RNGCFG_ENA);
25486 ++
25487 ++		sc->sc_rngfirst = 1;
25488 ++		crypto_rregister(sc->sc_cid, hifn_read_random, sc);
25489 ++	}
25490 ++#endif
25491 ++
25492 ++	/* Enable public key engine, if available */
25493 ++	if (sc->sc_flags & HIFN_HAS_PUBLIC) {
25494 ++		WRITE_REG_1(sc, HIFN_1_PUB_IEN, HIFN_PUBIEN_DONE);
25495 ++		sc->sc_dmaier |= HIFN_DMAIER_PUBDONE;
25496 ++		WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
25497 ++#ifdef HIFN_VULCANDEV
25498 ++		sc->sc_pkdev = make_dev(&vulcanpk_cdevsw, 0, 
25499 ++					UID_ROOT, GID_WHEEL, 0666,
25500 ++					"vulcanpk");
25501 ++		sc->sc_pkdev->si_drv1 = sc;
25502 ++#endif
25503 ++	}
25504 ++
25505 ++	return (0);
25506 ++}
25507 ++
25508 ++#ifdef CONFIG_OCF_RANDOMHARVEST
25509 ++static int
25510 ++hifn_read_random(void *arg, u_int32_t *buf, int len)
25511 ++{
25512 ++	struct hifn_softc *sc = (struct hifn_softc *) arg;
25513 ++	u_int32_t sts;
25514 ++	int i, rc = 0;
25515 ++
25516 ++	if (len <= 0)
25517 ++		return rc;
25518 ++
25519 ++	if (sc->sc_flags & HIFN_IS_7811) {
25520 ++		/* ONLY VALID ON 7811!!!! */
25521 ++		for (i = 0; i < 5; i++) {
25522 ++			sts = READ_REG_1(sc, HIFN_1_7811_RNGSTS);
25523 ++			if (sts & HIFN_7811_RNGSTS_UFL) {
25524 ++				device_printf(sc->sc_dev,
25525 ++					      "RNG underflow: disabling\n");
25526 ++				/* DAVIDM perhaps return -1 */
25527 ++				break;
25528 ++			}
25529 ++			if ((sts & HIFN_7811_RNGSTS_RDY) == 0)
25530 ++				break;
25531 ++
25532 ++			/*
25533 ++			 * There are at least two words in the RNG FIFO
25534 ++			 * at this point.
25535 ++			 */
25536 ++			if (rc < len)
25537 ++				buf[rc++] = READ_REG_1(sc, HIFN_1_7811_RNGDAT);
25538 ++			if (rc < len)
25539 ++				buf[rc++] = READ_REG_1(sc, HIFN_1_7811_RNGDAT);
25540 ++		}
25541 ++	} else
25542 ++		buf[rc++] = READ_REG_1(sc, HIFN_1_RNG_DATA);
25543 ++
25544 ++	/* NB: discard first data read */
25545 ++	if (sc->sc_rngfirst) {
25546 ++		sc->sc_rngfirst = 0;
25547 ++		rc = 0;
25548 ++	}
25549 ++
25550 ++	return(rc);
25551 ++}
25552 ++#endif /* CONFIG_OCF_RANDOMHARVEST */
25553 ++
25554 ++static void
25555 ++hifn_puc_wait(struct hifn_softc *sc)
25556 ++{
25557 ++	int i;
25558 ++	int reg = HIFN_0_PUCTRL;
25559 ++
25560 ++	if (sc->sc_flags & HIFN_IS_7956) {
25561 ++		reg = HIFN_0_PUCTRL2;
25562 ++	}
25563 ++
25564 ++	for (i = 5000; i > 0; i--) {
25565 ++		DELAY(1);
25566 ++		if (!(READ_REG_0(sc, reg) & HIFN_PUCTRL_RESET))
25567 ++			break;
25568 ++	}
25569 ++	if (!i)
25570 ++		device_printf(sc->sc_dev, "proc unit did not reset(0x%x)\n",
25571 ++				READ_REG_0(sc, HIFN_0_PUCTRL));
25572 ++}
25573 ++
25574 ++/*
25575 ++ * Reset the processing unit.
25576 ++ */
25577 ++static void
25578 ++hifn_reset_puc(struct hifn_softc *sc)
25579 ++{
25580 ++	/* Reset processing unit */
25581 ++	int reg = HIFN_0_PUCTRL;
25582 ++
25583 ++	if (sc->sc_flags & HIFN_IS_7956) {
25584 ++		reg = HIFN_0_PUCTRL2;
25585 ++	}
25586 ++	WRITE_REG_0(sc, reg, HIFN_PUCTRL_DMAENA);
25587 ++
25588 ++	hifn_puc_wait(sc);
25589 ++}
25590 ++
25591 ++/*
25592 ++ * Set the Retry and TRDY registers; note that we set them to
25593 ++ * zero because the 7811 locks up when forced to retry (section
25594 ++ * 3.6 of "Specification Update SU-0014-04".  Not clear if we
25595 ++ * should do this for all Hifn parts, but it doesn't seem to hurt.
25596 ++ */
25597 ++static void
25598 ++hifn_set_retry(struct hifn_softc *sc)
25599 ++{
25600 ++	DPRINTF("%s()\n", __FUNCTION__);
25601 ++	/* NB: RETRY only responds to 8-bit reads/writes */
25602 ++	pci_write_config_byte(sc->sc_pcidev, HIFN_RETRY_TIMEOUT, 0);
25603 ++	pci_write_config_dword(sc->sc_pcidev, HIFN_TRDY_TIMEOUT, 0);
25604 ++}
25605 ++
25606 ++/*
25607 ++ * Resets the board.  Values in the regesters are left as is
25608 ++ * from the reset (i.e. initial values are assigned elsewhere).
25609 ++ */
25610 ++static void
25611 ++hifn_reset_board(struct hifn_softc *sc, int full)
25612 ++{
25613 ++	u_int32_t reg;
25614 ++
25615 ++	DPRINTF("%s()\n", __FUNCTION__);
25616 ++	/*
25617 ++	 * Set polling in the DMA configuration register to zero.  0x7 avoids
25618 ++	 * resetting the board and zeros out the other fields.
25619 ++	 */
25620 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
25621 ++	    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
25622 ++
25623 ++	/*
25624 ++	 * Now that polling has been disabled, we have to wait 1 ms
25625 ++	 * before resetting the board.
25626 ++	 */
25627 ++	DELAY(1000);
25628 ++
25629 ++	/* Reset the DMA unit */
25630 ++	if (full) {
25631 ++		WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MODE);
25632 ++		DELAY(1000);
25633 ++	} else {
25634 ++		WRITE_REG_1(sc, HIFN_1_DMA_CNFG,
25635 ++		    HIFN_DMACNFG_MODE | HIFN_DMACNFG_MSTRESET);
25636 ++		hifn_reset_puc(sc);
25637 ++	}
25638 ++
25639 ++	KASSERT(sc->sc_dma != NULL, ("hifn_reset_board: null DMA tag!"));
25640 ++	bzero(sc->sc_dma, sizeof(*sc->sc_dma));
25641 ++
25642 ++	/* Bring dma unit out of reset */
25643 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
25644 ++	    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
25645 ++
25646 ++	hifn_puc_wait(sc);
25647 ++	hifn_set_retry(sc);
25648 ++
25649 ++	if (sc->sc_flags & HIFN_IS_7811) {
25650 ++		for (reg = 0; reg < 1000; reg++) {
25651 ++			if (READ_REG_1(sc, HIFN_1_7811_MIPSRST) &
25652 ++			    HIFN_MIPSRST_CRAMINIT)
25653 ++				break;
25654 ++			DELAY(1000);
25655 ++		}
25656 ++		if (reg == 1000)
25657 ++			device_printf(sc->sc_dev, ": cram init timeout\n");
25658 ++	} else {
25659 ++	  /* set up DMA configuration register #2 */
25660 ++	  /* turn off all PK and BAR0 swaps */
25661 ++	  WRITE_REG_1(sc, HIFN_1_DMA_CNFG2,
25662 ++		      (3 << HIFN_DMACNFG2_INIT_WRITE_BURST_SHIFT)|
25663 ++		      (3 << HIFN_DMACNFG2_INIT_READ_BURST_SHIFT)|
25664 ++		      (2 << HIFN_DMACNFG2_TGT_WRITE_BURST_SHIFT)|
25665 ++		      (2 << HIFN_DMACNFG2_TGT_READ_BURST_SHIFT));
25666 ++	}
25667 ++}
25668 ++
25669 ++static u_int32_t
25670 ++hifn_next_signature(u_int32_t a, u_int cnt)
25671 ++{
25672 ++	int i;
25673 ++	u_int32_t v;
25674 ++
25675 ++	for (i = 0; i < cnt; i++) {
25676 ++
25677 ++		/* get the parity */
25678 ++		v = a & 0x80080125;
25679 ++		v ^= v >> 16;
25680 ++		v ^= v >> 8;
25681 ++		v ^= v >> 4;
25682 ++		v ^= v >> 2;
25683 ++		v ^= v >> 1;
25684 ++
25685 ++		a = (v & 1) ^ (a << 1);
25686 ++	}
25687 ++
25688 ++	return a;
25689 ++}
25690 ++
25691 ++
25692 ++/*
25693 ++ * Checks to see if crypto is already enabled.  If crypto isn't enable,
25694 ++ * "hifn_enable_crypto" is called to enable it.  The check is important,
25695 ++ * as enabling crypto twice will lock the board.
25696 ++ */
25697 ++static int 
25698 ++hifn_enable_crypto(struct hifn_softc *sc)
25699 ++{
25700 ++	u_int32_t dmacfg, ramcfg, encl, addr, i;
25701 ++	char offtbl[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25702 ++					  0x00, 0x00, 0x00, 0x00 };
25703 ++
25704 ++	DPRINTF("%s()\n", __FUNCTION__);
25705 ++
25706 ++	ramcfg = READ_REG_0(sc, HIFN_0_PUCNFG);
25707 ++	dmacfg = READ_REG_1(sc, HIFN_1_DMA_CNFG);
25708 ++
25709 ++	/*
25710 ++	 * The RAM config register's encrypt level bit needs to be set before
25711 ++	 * every read performed on the encryption level register.
25712 ++	 */
25713 ++	WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg | HIFN_PUCNFG_CHIPID);
25714 ++
25715 ++	encl = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
25716 ++
25717 ++	/*
25718 ++	 * Make sure we don't re-unlock.  Two unlocks kills chip until the
25719 ++	 * next reboot.
25720 ++	 */
25721 ++	if (encl == HIFN_PUSTAT_ENA_1 || encl == HIFN_PUSTAT_ENA_2) {
25722 ++#ifdef HIFN_DEBUG
25723 ++		if (hifn_debug)
25724 ++			device_printf(sc->sc_dev,
25725 ++			    "Strong crypto already enabled!\n");
25726 ++#endif
25727 ++		goto report;
25728 ++	}
25729 ++
25730 ++	if (encl != 0 && encl != HIFN_PUSTAT_ENA_0) {
25731 ++#ifdef HIFN_DEBUG
25732 ++		if (hifn_debug)
25733 ++			device_printf(sc->sc_dev,
25734 ++			      "Unknown encryption level 0x%x\n", encl);
25735 ++#endif
25736 ++		return 1;
25737 ++	}
25738 ++
25739 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_UNLOCK |
25740 ++	    HIFN_DMACNFG_MSTRESET | HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
25741 ++	DELAY(1000);
25742 ++	addr = READ_REG_1(sc, HIFN_UNLOCK_SECRET1);
25743 ++	DELAY(1000);
25744 ++	WRITE_REG_1(sc, HIFN_UNLOCK_SECRET2, 0);
25745 ++	DELAY(1000);
25746 ++
25747 ++	for (i = 0; i <= 12; i++) {
25748 ++		addr = hifn_next_signature(addr, offtbl[i] + 0x101);
25749 ++		WRITE_REG_1(sc, HIFN_UNLOCK_SECRET2, addr);
25750 ++
25751 ++		DELAY(1000);
25752 ++	}
25753 ++
25754 ++	WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg | HIFN_PUCNFG_CHIPID);
25755 ++	encl = READ_REG_0(sc, HIFN_0_PUSTAT) & HIFN_PUSTAT_CHIPENA;
25756 ++
25757 ++#ifdef HIFN_DEBUG
25758 ++	if (hifn_debug) {
25759 ++		if (encl != HIFN_PUSTAT_ENA_1 && encl != HIFN_PUSTAT_ENA_2)
25760 ++			device_printf(sc->sc_dev, "Engine is permanently "
25761 ++				"locked until next system reset!\n");
25762 ++		else
25763 ++			device_printf(sc->sc_dev, "Engine enabled "
25764 ++				"successfully!\n");
25765 ++	}
25766 ++#endif
25767 ++
25768 ++report:
25769 ++	WRITE_REG_0(sc, HIFN_0_PUCNFG, ramcfg);
25770 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, dmacfg);
25771 ++
25772 ++	switch (encl) {
25773 ++	case HIFN_PUSTAT_ENA_1:
25774 ++	case HIFN_PUSTAT_ENA_2:
25775 ++		break;
25776 ++	case HIFN_PUSTAT_ENA_0:
25777 ++	default:
25778 ++		device_printf(sc->sc_dev, "disabled\n");
25779 ++		break;
25780 ++	}
25781 ++
25782 ++	return 0;
25783 ++}
25784 ++
25785 ++/*
25786 ++ * Give initial values to the registers listed in the "Register Space"
25787 ++ * section of the HIFN Software Development reference manual.
25788 ++ */
25789 ++static void 
25790 ++hifn_init_pci_registers(struct hifn_softc *sc)
25791 ++{
25792 ++	DPRINTF("%s()\n", __FUNCTION__);
25793 ++
25794 ++	/* write fixed values needed by the Initialization registers */
25795 ++	WRITE_REG_0(sc, HIFN_0_PUCTRL, HIFN_PUCTRL_DMAENA);
25796 ++	WRITE_REG_0(sc, HIFN_0_FIFOCNFG, HIFN_FIFOCNFG_THRESHOLD);
25797 ++	WRITE_REG_0(sc, HIFN_0_PUIER, HIFN_PUIER_DSTOVER);
25798 ++
25799 ++	/* write all 4 ring address registers */
25800 ++	WRITE_REG_1(sc, HIFN_1_DMA_CRAR, sc->sc_dma_physaddr +
25801 ++	    offsetof(struct hifn_dma, cmdr[0]));
25802 ++	WRITE_REG_1(sc, HIFN_1_DMA_SRAR, sc->sc_dma_physaddr +
25803 ++	    offsetof(struct hifn_dma, srcr[0]));
25804 ++	WRITE_REG_1(sc, HIFN_1_DMA_DRAR, sc->sc_dma_physaddr +
25805 ++	    offsetof(struct hifn_dma, dstr[0]));
25806 ++	WRITE_REG_1(sc, HIFN_1_DMA_RRAR, sc->sc_dma_physaddr +
25807 ++	    offsetof(struct hifn_dma, resr[0]));
25808 ++
25809 ++	DELAY(2000);
25810 ++
25811 ++	/* write status register */
25812 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR,
25813 ++	    HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS |
25814 ++	    HIFN_DMACSR_S_CTRL_DIS | HIFN_DMACSR_C_CTRL_DIS |
25815 ++	    HIFN_DMACSR_D_ABORT | HIFN_DMACSR_D_DONE | HIFN_DMACSR_D_LAST |
25816 ++	    HIFN_DMACSR_D_WAIT | HIFN_DMACSR_D_OVER |
25817 ++	    HIFN_DMACSR_R_ABORT | HIFN_DMACSR_R_DONE | HIFN_DMACSR_R_LAST |
25818 ++	    HIFN_DMACSR_R_WAIT | HIFN_DMACSR_R_OVER |
25819 ++	    HIFN_DMACSR_S_ABORT | HIFN_DMACSR_S_DONE | HIFN_DMACSR_S_LAST |
25820 ++	    HIFN_DMACSR_S_WAIT |
25821 ++	    HIFN_DMACSR_C_ABORT | HIFN_DMACSR_C_DONE | HIFN_DMACSR_C_LAST |
25822 ++	    HIFN_DMACSR_C_WAIT |
25823 ++	    HIFN_DMACSR_ENGINE |
25824 ++	    ((sc->sc_flags & HIFN_HAS_PUBLIC) ?
25825 ++		HIFN_DMACSR_PUBDONE : 0) |
25826 ++	    ((sc->sc_flags & HIFN_IS_7811) ?
25827 ++		HIFN_DMACSR_ILLW | HIFN_DMACSR_ILLR : 0));
25828 ++
25829 ++	sc->sc_d_busy = sc->sc_r_busy = sc->sc_s_busy = sc->sc_c_busy = 0;
25830 ++	sc->sc_dmaier |= HIFN_DMAIER_R_DONE | HIFN_DMAIER_C_ABORT |
25831 ++	    HIFN_DMAIER_D_OVER | HIFN_DMAIER_R_OVER |
25832 ++	    HIFN_DMAIER_S_ABORT | HIFN_DMAIER_D_ABORT | HIFN_DMAIER_R_ABORT |
25833 ++	    ((sc->sc_flags & HIFN_IS_7811) ?
25834 ++		HIFN_DMAIER_ILLW | HIFN_DMAIER_ILLR : 0);
25835 ++	sc->sc_dmaier &= ~HIFN_DMAIER_C_WAIT;
25836 ++	WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
25837 ++
25838 ++
25839 ++	if (sc->sc_flags & HIFN_IS_7956) {
25840 ++		u_int32_t pll;
25841 ++
25842 ++		WRITE_REG_0(sc, HIFN_0_PUCNFG, HIFN_PUCNFG_COMPSING |
25843 ++		    HIFN_PUCNFG_TCALLPHASES |
25844 ++		    HIFN_PUCNFG_TCDRVTOTEM | HIFN_PUCNFG_BUS32);
25845 ++
25846 ++		/* turn off the clocks and insure bypass is set */
25847 ++		pll = READ_REG_1(sc, HIFN_1_PLL);
25848 ++		pll = (pll &~ (HIFN_PLL_PK_CLK_SEL | HIFN_PLL_PE_CLK_SEL))
25849 ++		  | HIFN_PLL_BP | HIFN_PLL_MBSET;
25850 ++		WRITE_REG_1(sc, HIFN_1_PLL, pll);
25851 ++		DELAY(10*1000);		/* 10ms */
25852 ++
25853 ++		/* change configuration */
25854 ++		pll = (pll &~ HIFN_PLL_CONFIG) | sc->sc_pllconfig;
25855 ++		WRITE_REG_1(sc, HIFN_1_PLL, pll);
25856 ++		DELAY(10*1000);		/* 10ms */
25857 ++
25858 ++		/* disable bypass */
25859 ++		pll &= ~HIFN_PLL_BP;
25860 ++		WRITE_REG_1(sc, HIFN_1_PLL, pll);
25861 ++		/* enable clocks with new configuration */
25862 ++		pll |= HIFN_PLL_PK_CLK_SEL | HIFN_PLL_PE_CLK_SEL;
25863 ++		WRITE_REG_1(sc, HIFN_1_PLL, pll);
25864 ++	} else {
25865 ++		WRITE_REG_0(sc, HIFN_0_PUCNFG, HIFN_PUCNFG_COMPSING |
25866 ++		    HIFN_PUCNFG_DRFR_128 | HIFN_PUCNFG_TCALLPHASES |
25867 ++		    HIFN_PUCNFG_TCDRVTOTEM | HIFN_PUCNFG_BUS32 |
25868 ++		    (sc->sc_drammodel ? HIFN_PUCNFG_DRAM : HIFN_PUCNFG_SRAM));
25869 ++	}
25870 ++
25871 ++	WRITE_REG_0(sc, HIFN_0_PUISR, HIFN_PUISR_DSTOVER);
25872 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
25873 ++	    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE | HIFN_DMACNFG_LAST |
25874 ++	    ((HIFN_POLL_FREQUENCY << 16 ) & HIFN_DMACNFG_POLLFREQ) |
25875 ++	    ((HIFN_POLL_SCALAR << 8) & HIFN_DMACNFG_POLLINVAL));
25876 ++}
25877 ++
25878 ++/*
25879 ++ * The maximum number of sessions supported by the card
25880 ++ * is dependent on the amount of context ram, which
25881 ++ * encryption algorithms are enabled, and how compression
25882 ++ * is configured.  This should be configured before this
25883 ++ * routine is called.
25884 ++ */
25885 ++static void
25886 ++hifn_sessions(struct hifn_softc *sc)
25887 ++{
25888 ++	u_int32_t pucnfg;
25889 ++	int ctxsize;
25890 ++
25891 ++	DPRINTF("%s()\n", __FUNCTION__);
25892 ++
25893 ++	pucnfg = READ_REG_0(sc, HIFN_0_PUCNFG);
25894 ++
25895 ++	if (pucnfg & HIFN_PUCNFG_COMPSING) {
25896 ++		if (pucnfg & HIFN_PUCNFG_ENCCNFG)
25897 ++			ctxsize = 128;
25898 ++		else
25899 ++			ctxsize = 512;
25900 ++		/*
25901 ++		 * 7955/7956 has internal context memory of 32K
25902 ++		 */
25903 ++		if (sc->sc_flags & HIFN_IS_7956)
25904 ++			sc->sc_maxses = 32768 / ctxsize;
25905 ++		else
25906 ++			sc->sc_maxses = 1 +
25907 ++			    ((sc->sc_ramsize - 32768) / ctxsize);
25908 ++	} else
25909 ++		sc->sc_maxses = sc->sc_ramsize / 16384;
25910 ++
25911 ++	if (sc->sc_maxses > 2048)
25912 ++		sc->sc_maxses = 2048;
25913 ++}
25914 ++
25915 ++/*
25916 ++ * Determine ram type (sram or dram).  Board should be just out of a reset
25917 ++ * state when this is called.
25918 ++ */
25919 ++static int
25920 ++hifn_ramtype(struct hifn_softc *sc)
25921 ++{
25922 ++	u_int8_t data[8], dataexpect[8];
25923 ++	int i;
25924 ++
25925 ++	for (i = 0; i < sizeof(data); i++)
25926 ++		data[i] = dataexpect[i] = 0x55;
25927 ++	if (hifn_writeramaddr(sc, 0, data))
25928 ++		return (-1);
25929 ++	if (hifn_readramaddr(sc, 0, data))
25930 ++		return (-1);
25931 ++	if (bcmp(data, dataexpect, sizeof(data)) != 0) {
25932 ++		sc->sc_drammodel = 1;
25933 ++		return (0);
25934 ++	}
25935 ++
25936 ++	for (i = 0; i < sizeof(data); i++)
25937 ++		data[i] = dataexpect[i] = 0xaa;
25938 ++	if (hifn_writeramaddr(sc, 0, data))
25939 ++		return (-1);
25940 ++	if (hifn_readramaddr(sc, 0, data))
25941 ++		return (-1);
25942 ++	if (bcmp(data, dataexpect, sizeof(data)) != 0) {
25943 ++		sc->sc_drammodel = 1;
25944 ++		return (0);
25945 ++	}
25946 ++
25947 ++	return (0);
25948 ++}
25949 ++
25950 ++#define	HIFN_SRAM_MAX		(32 << 20)
25951 ++#define	HIFN_SRAM_STEP_SIZE	16384
25952 ++#define	HIFN_SRAM_GRANULARITY	(HIFN_SRAM_MAX / HIFN_SRAM_STEP_SIZE)
25953 ++
25954 ++static int
25955 ++hifn_sramsize(struct hifn_softc *sc)
25956 ++{
25957 ++	u_int32_t a;
25958 ++	u_int8_t data[8];
25959 ++	u_int8_t dataexpect[sizeof(data)];
25960 ++	int32_t i;
25961 ++
25962 ++	for (i = 0; i < sizeof(data); i++)
25963 ++		data[i] = dataexpect[i] = i ^ 0x5a;
25964 ++
25965 ++	for (i = HIFN_SRAM_GRANULARITY - 1; i >= 0; i--) {
25966 ++		a = i * HIFN_SRAM_STEP_SIZE;
25967 ++		bcopy(&i, data, sizeof(i));
25968 ++		hifn_writeramaddr(sc, a, data);
25969 ++	}
25970 ++
25971 ++	for (i = 0; i < HIFN_SRAM_GRANULARITY; i++) {
25972 ++		a = i * HIFN_SRAM_STEP_SIZE;
25973 ++		bcopy(&i, dataexpect, sizeof(i));
25974 ++		if (hifn_readramaddr(sc, a, data) < 0)
25975 ++			return (0);
25976 ++		if (bcmp(data, dataexpect, sizeof(data)) != 0)
25977 ++			return (0);
25978 ++		sc->sc_ramsize = a + HIFN_SRAM_STEP_SIZE;
25979 ++	}
25980 ++
25981 ++	return (0);
25982 ++}
25983 ++
25984 ++/*
25985 ++ * XXX For dram boards, one should really try all of the
25986 ++ * HIFN_PUCNFG_DSZ_*'s.  This just assumes that PUCNFG
25987 ++ * is already set up correctly.
25988 ++ */
25989 ++static int
25990 ++hifn_dramsize(struct hifn_softc *sc)
25991 ++{
25992 ++	u_int32_t cnfg;
25993 ++
25994 ++	if (sc->sc_flags & HIFN_IS_7956) {
25995 ++		/*
25996 ++		 * 7955/7956 have a fixed internal ram of only 32K.
25997 ++		 */
25998 ++		sc->sc_ramsize = 32768;
25999 ++	} else {
26000 ++		cnfg = READ_REG_0(sc, HIFN_0_PUCNFG) &
26001 ++		    HIFN_PUCNFG_DRAMMASK;
26002 ++		sc->sc_ramsize = 1 << ((cnfg >> 13) + 18);
26003 ++	}
26004 ++	return (0);
26005 ++}
26006 ++
26007 ++static void
26008 ++hifn_alloc_slot(struct hifn_softc *sc, int *cmdp, int *srcp, int *dstp, int *resp)
26009 ++{
26010 ++	struct hifn_dma *dma = sc->sc_dma;
26011 ++
26012 ++	DPRINTF("%s()\n", __FUNCTION__);
26013 ++
26014 ++	if (dma->cmdi == HIFN_D_CMD_RSIZE) {
26015 ++		dma->cmdi = 0;
26016 ++		dma->cmdr[HIFN_D_CMD_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26017 ++		wmb();
26018 ++		dma->cmdr[HIFN_D_CMD_RSIZE].l |= htole32(HIFN_D_VALID);
26019 ++		HIFN_CMDR_SYNC(sc, HIFN_D_CMD_RSIZE,
26020 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26021 ++	}
26022 ++	*cmdp = dma->cmdi++;
26023 ++	dma->cmdk = dma->cmdi;
26024 ++
26025 ++	if (dma->srci == HIFN_D_SRC_RSIZE) {
26026 ++		dma->srci = 0;
26027 ++		dma->srcr[HIFN_D_SRC_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26028 ++		wmb();
26029 ++		dma->srcr[HIFN_D_SRC_RSIZE].l |= htole32(HIFN_D_VALID);
26030 ++		HIFN_SRCR_SYNC(sc, HIFN_D_SRC_RSIZE,
26031 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26032 ++	}
26033 ++	*srcp = dma->srci++;
26034 ++	dma->srck = dma->srci;
26035 ++
26036 ++	if (dma->dsti == HIFN_D_DST_RSIZE) {
26037 ++		dma->dsti = 0;
26038 ++		dma->dstr[HIFN_D_DST_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26039 ++		wmb();
26040 ++		dma->dstr[HIFN_D_DST_RSIZE].l |= htole32(HIFN_D_VALID);
26041 ++		HIFN_DSTR_SYNC(sc, HIFN_D_DST_RSIZE,
26042 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26043 ++	}
26044 ++	*dstp = dma->dsti++;
26045 ++	dma->dstk = dma->dsti;
26046 ++
26047 ++	if (dma->resi == HIFN_D_RES_RSIZE) {
26048 ++		dma->resi = 0;
26049 ++		dma->resr[HIFN_D_RES_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26050 ++		wmb();
26051 ++		dma->resr[HIFN_D_RES_RSIZE].l |= htole32(HIFN_D_VALID);
26052 ++		HIFN_RESR_SYNC(sc, HIFN_D_RES_RSIZE,
26053 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26054 ++	}
26055 ++	*resp = dma->resi++;
26056 ++	dma->resk = dma->resi;
26057 ++}
26058 ++
26059 ++static int
26060 ++hifn_writeramaddr(struct hifn_softc *sc, int addr, u_int8_t *data)
26061 ++{
26062 ++	struct hifn_dma *dma = sc->sc_dma;
26063 ++	hifn_base_command_t wc;
26064 ++	const u_int32_t masks = HIFN_D_VALID | HIFN_D_LAST | HIFN_D_MASKDONEIRQ;
26065 ++	int r, cmdi, resi, srci, dsti;
26066 ++
26067 ++	DPRINTF("%s()\n", __FUNCTION__);
26068 ++
26069 ++	wc.masks = htole16(3 << 13);
26070 ++	wc.session_num = htole16(addr >> 14);
26071 ++	wc.total_source_count = htole16(8);
26072 ++	wc.total_dest_count = htole16(addr & 0x3fff);
26073 ++
26074 ++	hifn_alloc_slot(sc, &cmdi, &srci, &dsti, &resi);
26075 ++
26076 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR,
26077 ++	    HIFN_DMACSR_C_CTRL_ENA | HIFN_DMACSR_S_CTRL_ENA |
26078 ++	    HIFN_DMACSR_D_CTRL_ENA | HIFN_DMACSR_R_CTRL_ENA);
26079 ++
26080 ++	/* build write command */
26081 ++	bzero(dma->command_bufs[cmdi], HIFN_MAX_COMMAND);
26082 ++	*(hifn_base_command_t *)dma->command_bufs[cmdi] = wc;
26083 ++	bcopy(data, &dma->test_src, sizeof(dma->test_src));
26084 ++
26085 ++	dma->srcr[srci].p = htole32(sc->sc_dma_physaddr
26086 ++	    + offsetof(struct hifn_dma, test_src));
26087 ++	dma->dstr[dsti].p = htole32(sc->sc_dma_physaddr
26088 ++	    + offsetof(struct hifn_dma, test_dst));
26089 ++
26090 ++	dma->cmdr[cmdi].l = htole32(16 | masks);
26091 ++	dma->srcr[srci].l = htole32(8 | masks);
26092 ++	dma->dstr[dsti].l = htole32(4 | masks);
26093 ++	dma->resr[resi].l = htole32(4 | masks);
26094 ++
26095 ++	for (r = 10000; r >= 0; r--) {
26096 ++		DELAY(10);
26097 ++		if ((dma->resr[resi].l & htole32(HIFN_D_VALID)) == 0)
26098 ++			break;
26099 ++	}
26100 ++	if (r == 0) {
26101 ++		device_printf(sc->sc_dev, "writeramaddr -- "
26102 ++		    "result[%d](addr %d) still valid\n", resi, addr);
26103 ++		r = -1;
26104 ++		return (-1);
26105 ++	} else
26106 ++		r = 0;
26107 ++
26108 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR,
26109 ++	    HIFN_DMACSR_C_CTRL_DIS | HIFN_DMACSR_S_CTRL_DIS |
26110 ++	    HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS);
26111 ++
26112 ++	return (r);
26113 ++}
26114 ++
26115 ++static int
26116 ++hifn_readramaddr(struct hifn_softc *sc, int addr, u_int8_t *data)
26117 ++{
26118 ++	struct hifn_dma *dma = sc->sc_dma;
26119 ++	hifn_base_command_t rc;
26120 ++	const u_int32_t masks = HIFN_D_VALID | HIFN_D_LAST | HIFN_D_MASKDONEIRQ;
26121 ++	int r, cmdi, srci, dsti, resi;
26122 ++
26123 ++	DPRINTF("%s()\n", __FUNCTION__);
26124 ++
26125 ++	rc.masks = htole16(2 << 13);
26126 ++	rc.session_num = htole16(addr >> 14);
26127 ++	rc.total_source_count = htole16(addr & 0x3fff);
26128 ++	rc.total_dest_count = htole16(8);
26129 ++
26130 ++	hifn_alloc_slot(sc, &cmdi, &srci, &dsti, &resi);
26131 ++
26132 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR,
26133 ++	    HIFN_DMACSR_C_CTRL_ENA | HIFN_DMACSR_S_CTRL_ENA |
26134 ++	    HIFN_DMACSR_D_CTRL_ENA | HIFN_DMACSR_R_CTRL_ENA);
26135 ++
26136 ++	bzero(dma->command_bufs[cmdi], HIFN_MAX_COMMAND);
26137 ++	*(hifn_base_command_t *)dma->command_bufs[cmdi] = rc;
26138 ++
26139 ++	dma->srcr[srci].p = htole32(sc->sc_dma_physaddr +
26140 ++	    offsetof(struct hifn_dma, test_src));
26141 ++	dma->test_src = 0;
26142 ++	dma->dstr[dsti].p =  htole32(sc->sc_dma_physaddr +
26143 ++	    offsetof(struct hifn_dma, test_dst));
26144 ++	dma->test_dst = 0;
26145 ++	dma->cmdr[cmdi].l = htole32(8 | masks);
26146 ++	dma->srcr[srci].l = htole32(8 | masks);
26147 ++	dma->dstr[dsti].l = htole32(8 | masks);
26148 ++	dma->resr[resi].l = htole32(HIFN_MAX_RESULT | masks);
26149 ++
26150 ++	for (r = 10000; r >= 0; r--) {
26151 ++		DELAY(10);
26152 ++		if ((dma->resr[resi].l & htole32(HIFN_D_VALID)) == 0)
26153 ++			break;
26154 ++	}
26155 ++	if (r == 0) {
26156 ++		device_printf(sc->sc_dev, "readramaddr -- "
26157 ++		    "result[%d](addr %d) still valid\n", resi, addr);
26158 ++		r = -1;
26159 ++	} else {
26160 ++		r = 0;
26161 ++		bcopy(&dma->test_dst, data, sizeof(dma->test_dst));
26162 ++	}
26163 ++
26164 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR,
26165 ++	    HIFN_DMACSR_C_CTRL_DIS | HIFN_DMACSR_S_CTRL_DIS |
26166 ++	    HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS);
26167 ++
26168 ++	return (r);
26169 ++}
26170 ++
26171 ++/*
26172 ++ * Initialize the descriptor rings.
26173 ++ */
26174 ++static void 
26175 ++hifn_init_dma(struct hifn_softc *sc)
26176 ++{
26177 ++	struct hifn_dma *dma = sc->sc_dma;
26178 ++	int i;
26179 ++
26180 ++	DPRINTF("%s()\n", __FUNCTION__);
26181 ++
26182 ++	hifn_set_retry(sc);
26183 ++
26184 ++	/* initialize static pointer values */
26185 ++	for (i = 0; i < HIFN_D_CMD_RSIZE; i++)
26186 ++		dma->cmdr[i].p = htole32(sc->sc_dma_physaddr +
26187 ++		    offsetof(struct hifn_dma, command_bufs[i][0]));
26188 ++	for (i = 0; i < HIFN_D_RES_RSIZE; i++)
26189 ++		dma->resr[i].p = htole32(sc->sc_dma_physaddr +
26190 ++		    offsetof(struct hifn_dma, result_bufs[i][0]));
26191 ++
26192 ++	dma->cmdr[HIFN_D_CMD_RSIZE].p =
26193 ++	    htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, cmdr[0]));
26194 ++	dma->srcr[HIFN_D_SRC_RSIZE].p =
26195 ++	    htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, srcr[0]));
26196 ++	dma->dstr[HIFN_D_DST_RSIZE].p =
26197 ++	    htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, dstr[0]));
26198 ++	dma->resr[HIFN_D_RES_RSIZE].p =
26199 ++	    htole32(sc->sc_dma_physaddr + offsetof(struct hifn_dma, resr[0]));
26200 ++
26201 ++	dma->cmdu = dma->srcu = dma->dstu = dma->resu = 0;
26202 ++	dma->cmdi = dma->srci = dma->dsti = dma->resi = 0;
26203 ++	dma->cmdk = dma->srck = dma->dstk = dma->resk = 0;
26204 ++}
26205 ++
26206 ++/*
26207 ++ * Writes out the raw command buffer space.  Returns the
26208 ++ * command buffer size.
26209 ++ */
26210 ++static u_int
26211 ++hifn_write_command(struct hifn_command *cmd, u_int8_t *buf)
26212 ++{
26213 ++	struct hifn_softc *sc = NULL;
26214 ++	u_int8_t *buf_pos;
26215 ++	hifn_base_command_t *base_cmd;
26216 ++	hifn_mac_command_t *mac_cmd;
26217 ++	hifn_crypt_command_t *cry_cmd;
26218 ++	int using_mac, using_crypt, len, ivlen;
26219 ++	u_int32_t dlen, slen;
26220 ++
26221 ++	DPRINTF("%s()\n", __FUNCTION__);
26222 ++
26223 ++	buf_pos = buf;
26224 ++	using_mac = cmd->base_masks & HIFN_BASE_CMD_MAC;
26225 ++	using_crypt = cmd->base_masks & HIFN_BASE_CMD_CRYPT;
26226 ++
26227 ++	base_cmd = (hifn_base_command_t *)buf_pos;
26228 ++	base_cmd->masks = htole16(cmd->base_masks);
26229 ++	slen = cmd->src_mapsize;
26230 ++	if (cmd->sloplen)
26231 ++		dlen = cmd->dst_mapsize - cmd->sloplen + sizeof(u_int32_t);
26232 ++	else
26233 ++		dlen = cmd->dst_mapsize;
26234 ++	base_cmd->total_source_count = htole16(slen & HIFN_BASE_CMD_LENMASK_LO);
26235 ++	base_cmd->total_dest_count = htole16(dlen & HIFN_BASE_CMD_LENMASK_LO);
26236 ++	dlen >>= 16;
26237 ++	slen >>= 16;
26238 ++	base_cmd->session_num = htole16(
26239 ++	    ((slen << HIFN_BASE_CMD_SRCLEN_S) & HIFN_BASE_CMD_SRCLEN_M) |
26240 ++	    ((dlen << HIFN_BASE_CMD_DSTLEN_S) & HIFN_BASE_CMD_DSTLEN_M));
26241 ++	buf_pos += sizeof(hifn_base_command_t);
26242 ++
26243 ++	if (using_mac) {
26244 ++		mac_cmd = (hifn_mac_command_t *)buf_pos;
26245 ++		dlen = cmd->maccrd->crd_len;
26246 ++		mac_cmd->source_count = htole16(dlen & 0xffff);
26247 ++		dlen >>= 16;
26248 ++		mac_cmd->masks = htole16(cmd->mac_masks |
26249 ++		    ((dlen << HIFN_MAC_CMD_SRCLEN_S) & HIFN_MAC_CMD_SRCLEN_M));
26250 ++		mac_cmd->header_skip = htole16(cmd->maccrd->crd_skip);
26251 ++		mac_cmd->reserved = 0;
26252 ++		buf_pos += sizeof(hifn_mac_command_t);
26253 ++	}
26254 ++
26255 ++	if (using_crypt) {
26256 ++		cry_cmd = (hifn_crypt_command_t *)buf_pos;
26257 ++		dlen = cmd->enccrd->crd_len;
26258 ++		cry_cmd->source_count = htole16(dlen & 0xffff);
26259 ++		dlen >>= 16;
26260 ++		cry_cmd->masks = htole16(cmd->cry_masks |
26261 ++		    ((dlen << HIFN_CRYPT_CMD_SRCLEN_S) & HIFN_CRYPT_CMD_SRCLEN_M));
26262 ++		cry_cmd->header_skip = htole16(cmd->enccrd->crd_skip);
26263 ++		cry_cmd->reserved = 0;
26264 ++		buf_pos += sizeof(hifn_crypt_command_t);
26265 ++	}
26266 ++
26267 ++	if (using_mac && cmd->mac_masks & HIFN_MAC_CMD_NEW_KEY) {
26268 ++		bcopy(cmd->mac, buf_pos, HIFN_MAC_KEY_LENGTH);
26269 ++		buf_pos += HIFN_MAC_KEY_LENGTH;
26270 ++	}
26271 ++
26272 ++	if (using_crypt && cmd->cry_masks & HIFN_CRYPT_CMD_NEW_KEY) {
26273 ++		switch (cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) {
26274 ++		case HIFN_CRYPT_CMD_ALG_3DES:
26275 ++			bcopy(cmd->ck, buf_pos, HIFN_3DES_KEY_LENGTH);
26276 ++			buf_pos += HIFN_3DES_KEY_LENGTH;
26277 ++			break;
26278 ++		case HIFN_CRYPT_CMD_ALG_DES:
26279 ++			bcopy(cmd->ck, buf_pos, HIFN_DES_KEY_LENGTH);
26280 ++			buf_pos += HIFN_DES_KEY_LENGTH;
26281 ++			break;
26282 ++		case HIFN_CRYPT_CMD_ALG_RC4:
26283 ++			len = 256;
26284 ++			do {
26285 ++				int clen;
26286 ++
26287 ++				clen = MIN(cmd->cklen, len);
26288 ++				bcopy(cmd->ck, buf_pos, clen);
26289 ++				len -= clen;
26290 ++				buf_pos += clen;
26291 ++			} while (len > 0);
26292 ++			bzero(buf_pos, 4);
26293 ++			buf_pos += 4;
26294 ++			break;
26295 ++		case HIFN_CRYPT_CMD_ALG_AES:
26296 ++			/*
26297 ++			 * AES keys are variable 128, 192 and
26298 ++			 * 256 bits (16, 24 and 32 bytes).
26299 ++			 */
26300 ++			bcopy(cmd->ck, buf_pos, cmd->cklen);
26301 ++			buf_pos += cmd->cklen;
26302 ++			break;
26303 ++		}
26304 ++	}
26305 ++
26306 ++	if (using_crypt && cmd->cry_masks & HIFN_CRYPT_CMD_NEW_IV) {
26307 ++		switch (cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) {
26308 ++		case HIFN_CRYPT_CMD_ALG_AES:
26309 ++			ivlen = HIFN_AES_IV_LENGTH;
26310 ++			break;
26311 ++		default:
26312 ++			ivlen = HIFN_IV_LENGTH;
26313 ++			break;
26314 ++		}
26315 ++		bcopy(cmd->iv, buf_pos, ivlen);
26316 ++		buf_pos += ivlen;
26317 ++	}
26318 ++
26319 ++	if ((cmd->base_masks & (HIFN_BASE_CMD_MAC|HIFN_BASE_CMD_CRYPT)) == 0) {
26320 ++		bzero(buf_pos, 8);
26321 ++		buf_pos += 8;
26322 ++	}
26323 ++
26324 ++	return (buf_pos - buf);
26325 ++}
26326 ++
26327 ++static int
26328 ++hifn_dmamap_aligned(struct hifn_operand *op)
26329 ++{
26330 ++	struct hifn_softc *sc = NULL;
26331 ++	int i;
26332 ++
26333 ++	DPRINTF("%s()\n", __FUNCTION__);
26334 ++
26335 ++	for (i = 0; i < op->nsegs; i++) {
26336 ++		if (op->segs[i].ds_addr & 3)
26337 ++			return (0);
26338 ++		if ((i != (op->nsegs - 1)) && (op->segs[i].ds_len & 3))
26339 ++			return (0);
26340 ++	}
26341 ++	return (1);
26342 ++}
26343 ++
26344 ++static __inline int
26345 ++hifn_dmamap_dstwrap(struct hifn_softc *sc, int idx)
26346 ++{
26347 ++	struct hifn_dma *dma = sc->sc_dma;
26348 ++
26349 ++	if (++idx == HIFN_D_DST_RSIZE) {
26350 ++		dma->dstr[idx].l = htole32(HIFN_D_VALID | HIFN_D_JUMP |
26351 ++		    HIFN_D_MASKDONEIRQ);
26352 ++		HIFN_DSTR_SYNC(sc, idx,
26353 ++		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26354 ++		idx = 0;
26355 ++	}
26356 ++	return (idx);
26357 ++}
26358 ++
26359 ++static int
26360 ++hifn_dmamap_load_dst(struct hifn_softc *sc, struct hifn_command *cmd)
26361 ++{
26362 ++	struct hifn_dma *dma = sc->sc_dma;
26363 ++	struct hifn_operand *dst = &cmd->dst;
26364 ++	u_int32_t p, l;
26365 ++	int idx, used = 0, i;
26366 ++
26367 ++	DPRINTF("%s()\n", __FUNCTION__);
26368 ++
26369 ++	idx = dma->dsti;
26370 ++	for (i = 0; i < dst->nsegs - 1; i++) {
26371 ++		dma->dstr[idx].p = htole32(dst->segs[i].ds_addr);
26372 ++		dma->dstr[idx].l = htole32(HIFN_D_MASKDONEIRQ | dst->segs[i].ds_len);
26373 ++		wmb();
26374 ++		dma->dstr[idx].l |= htole32(HIFN_D_VALID);
26375 ++		HIFN_DSTR_SYNC(sc, idx,
26376 ++		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26377 ++		used++;
26378 ++
26379 ++		idx = hifn_dmamap_dstwrap(sc, idx);
26380 ++	}
26381 ++
26382 ++	if (cmd->sloplen == 0) {
26383 ++		p = dst->segs[i].ds_addr;
26384 ++		l = HIFN_D_MASKDONEIRQ | HIFN_D_LAST |
26385 ++		    dst->segs[i].ds_len;
26386 ++	} else {
26387 ++		p = sc->sc_dma_physaddr +
26388 ++		    offsetof(struct hifn_dma, slop[cmd->slopidx]);
26389 ++		l = HIFN_D_MASKDONEIRQ | HIFN_D_LAST |
26390 ++		    sizeof(u_int32_t);
26391 ++
26392 ++		if ((dst->segs[i].ds_len - cmd->sloplen) != 0) {
26393 ++			dma->dstr[idx].p = htole32(dst->segs[i].ds_addr);
26394 ++			dma->dstr[idx].l = htole32(HIFN_D_MASKDONEIRQ |
26395 ++			    (dst->segs[i].ds_len - cmd->sloplen));
26396 ++			wmb();
26397 ++			dma->dstr[idx].l |= htole32(HIFN_D_VALID);
26398 ++			HIFN_DSTR_SYNC(sc, idx,
26399 ++			    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26400 ++			used++;
26401 ++
26402 ++			idx = hifn_dmamap_dstwrap(sc, idx);
26403 ++		}
26404 ++	}
26405 ++	dma->dstr[idx].p = htole32(p);
26406 ++	dma->dstr[idx].l = htole32(l);
26407 ++	wmb();
26408 ++	dma->dstr[idx].l |= htole32(HIFN_D_VALID);
26409 ++	HIFN_DSTR_SYNC(sc, idx, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26410 ++	used++;
26411 ++
26412 ++	idx = hifn_dmamap_dstwrap(sc, idx);
26413 ++
26414 ++	dma->dsti = idx;
26415 ++	dma->dstu += used;
26416 ++	return (idx);
26417 ++}
26418 ++
26419 ++static __inline int
26420 ++hifn_dmamap_srcwrap(struct hifn_softc *sc, int idx)
26421 ++{
26422 ++	struct hifn_dma *dma = sc->sc_dma;
26423 ++
26424 ++	if (++idx == HIFN_D_SRC_RSIZE) {
26425 ++		dma->srcr[idx].l = htole32(HIFN_D_VALID |
26426 ++		    HIFN_D_JUMP | HIFN_D_MASKDONEIRQ);
26427 ++		HIFN_SRCR_SYNC(sc, HIFN_D_SRC_RSIZE,
26428 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26429 ++		idx = 0;
26430 ++	}
26431 ++	return (idx);
26432 ++}
26433 ++
26434 ++static int
26435 ++hifn_dmamap_load_src(struct hifn_softc *sc, struct hifn_command *cmd)
26436 ++{
26437 ++	struct hifn_dma *dma = sc->sc_dma;
26438 ++	struct hifn_operand *src = &cmd->src;
26439 ++	int idx, i;
26440 ++	u_int32_t last = 0;
26441 ++
26442 ++	DPRINTF("%s()\n", __FUNCTION__);
26443 ++
26444 ++	idx = dma->srci;
26445 ++	for (i = 0; i < src->nsegs; i++) {
26446 ++		if (i == src->nsegs - 1)
26447 ++			last = HIFN_D_LAST;
26448 ++
26449 ++		dma->srcr[idx].p = htole32(src->segs[i].ds_addr);
26450 ++		dma->srcr[idx].l = htole32(src->segs[i].ds_len |
26451 ++		    HIFN_D_MASKDONEIRQ | last);
26452 ++		wmb();
26453 ++		dma->srcr[idx].l |= htole32(HIFN_D_VALID);
26454 ++		HIFN_SRCR_SYNC(sc, idx,
26455 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26456 ++
26457 ++		idx = hifn_dmamap_srcwrap(sc, idx);
26458 ++	}
26459 ++	dma->srci = idx;
26460 ++	dma->srcu += src->nsegs;
26461 ++	return (idx);
26462 ++} 
26463 ++
26464 ++
26465 ++static int 
26466 ++hifn_crypto(
26467 ++	struct hifn_softc *sc,
26468 ++	struct hifn_command *cmd,
26469 ++	struct cryptop *crp,
26470 ++	int hint)
26471 ++{
26472 ++	struct	hifn_dma *dma = sc->sc_dma;
26473 ++	u_int32_t cmdlen, csr;
26474 ++	int cmdi, resi, err = 0;
26475 ++	unsigned long l_flags;
26476 ++
26477 ++	DPRINTF("%s()\n", __FUNCTION__);
26478 ++
26479 ++	/*
26480 ++	 * need 1 cmd, and 1 res
26481 ++	 *
26482 ++	 * NB: check this first since it's easy.
26483 ++	 */
26484 ++	HIFN_LOCK(sc);
26485 ++	if ((dma->cmdu + 1) > HIFN_D_CMD_RSIZE ||
26486 ++	    (dma->resu + 1) > HIFN_D_RES_RSIZE) {
26487 ++#ifdef HIFN_DEBUG
26488 ++		if (hifn_debug) {
26489 ++			device_printf(sc->sc_dev,
26490 ++				"cmd/result exhaustion, cmdu %u resu %u\n",
26491 ++				dma->cmdu, dma->resu);
26492 ++		}
26493 ++#endif
26494 ++		hifnstats.hst_nomem_cr++;
26495 ++		sc->sc_needwakeup |= CRYPTO_SYMQ;
26496 ++		HIFN_UNLOCK(sc);
26497 ++		return (ERESTART);
26498 ++	}
26499 ++
26500 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
26501 ++		if (pci_map_skb(sc, &cmd->src, cmd->src_skb)) {
26502 ++			hifnstats.hst_nomem_load++;
26503 ++			err = ENOMEM;
26504 ++			goto err_srcmap1;
26505 ++		}
26506 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
26507 ++		if (pci_map_uio(sc, &cmd->src, cmd->src_io)) {
26508 ++			hifnstats.hst_nomem_load++;
26509 ++			err = ENOMEM;
26510 ++			goto err_srcmap1;
26511 ++		}
26512 ++	} else {
26513 ++		if (pci_map_buf(sc, &cmd->src, cmd->src_buf, crp->crp_ilen)) {
26514 ++			hifnstats.hst_nomem_load++;
26515 ++			err = ENOMEM;
26516 ++			goto err_srcmap1;
26517 ++		}
26518 ++	}
26519 ++
26520 ++	if (hifn_dmamap_aligned(&cmd->src)) {
26521 ++		cmd->sloplen = cmd->src_mapsize & 3;
26522 ++		cmd->dst = cmd->src;
26523 ++	} else {
26524 ++		if (crp->crp_flags & CRYPTO_F_IOV) {
26525 ++			DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
26526 ++			err = EINVAL;
26527 ++			goto err_srcmap;
26528 ++		} else if (crp->crp_flags & CRYPTO_F_SKBUF) {
26529 ++#ifdef NOTYET
26530 ++			int totlen, len;
26531 ++			struct mbuf *m, *m0, *mlast;
26532 ++
26533 ++			KASSERT(cmd->dst_m == cmd->src_m,
26534 ++				("hifn_crypto: dst_m initialized improperly"));
26535 ++			hifnstats.hst_unaligned++;
26536 ++			/*
26537 ++			 * Source is not aligned on a longword boundary.
26538 ++			 * Copy the data to insure alignment.  If we fail
26539 ++			 * to allocate mbufs or clusters while doing this
26540 ++			 * we return ERESTART so the operation is requeued
26541 ++			 * at the crypto later, but only if there are
26542 ++			 * ops already posted to the hardware; otherwise we
26543 ++			 * have no guarantee that we'll be re-entered.
26544 ++			 */
26545 ++			totlen = cmd->src_mapsize;
26546 ++			if (cmd->src_m->m_flags & M_PKTHDR) {
26547 ++				len = MHLEN;
26548 ++				MGETHDR(m0, M_DONTWAIT, MT_DATA);
26549 ++				if (m0 && !m_dup_pkthdr(m0, cmd->src_m, M_DONTWAIT)) {
26550 ++					m_free(m0);
26551 ++					m0 = NULL;
26552 ++				}
26553 ++			} else {
26554 ++				len = MLEN;
26555 ++				MGET(m0, M_DONTWAIT, MT_DATA);
26556 ++			}
26557 ++			if (m0 == NULL) {
26558 ++				hifnstats.hst_nomem_mbuf++;
26559 ++				err = dma->cmdu ? ERESTART : ENOMEM;
26560 ++				goto err_srcmap;
26561 ++			}
26562 ++			if (totlen >= MINCLSIZE) {
26563 ++				MCLGET(m0, M_DONTWAIT);
26564 ++				if ((m0->m_flags & M_EXT) == 0) {
26565 ++					hifnstats.hst_nomem_mcl++;
26566 ++					err = dma->cmdu ? ERESTART : ENOMEM;
26567 ++					m_freem(m0);
26568 ++					goto err_srcmap;
26569 ++				}
26570 ++				len = MCLBYTES;
26571 ++			}
26572 ++			totlen -= len;
26573 ++			m0->m_pkthdr.len = m0->m_len = len;
26574 ++			mlast = m0;
26575 ++
26576 ++			while (totlen > 0) {
26577 ++				MGET(m, M_DONTWAIT, MT_DATA);
26578 ++				if (m == NULL) {
26579 ++					hifnstats.hst_nomem_mbuf++;
26580 ++					err = dma->cmdu ? ERESTART : ENOMEM;
26581 ++					m_freem(m0);
26582 ++					goto err_srcmap;
26583 ++				}
26584 ++				len = MLEN;
26585 ++				if (totlen >= MINCLSIZE) {
26586 ++					MCLGET(m, M_DONTWAIT);
26587 ++					if ((m->m_flags & M_EXT) == 0) {
26588 ++						hifnstats.hst_nomem_mcl++;
26589 ++						err = dma->cmdu ? ERESTART : ENOMEM;
26590 ++						mlast->m_next = m;
26591 ++						m_freem(m0);
26592 ++						goto err_srcmap;
26593 ++					}
26594 ++					len = MCLBYTES;
26595 ++				}
26596 ++
26597 ++				m->m_len = len;
26598 ++				m0->m_pkthdr.len += len;
26599 ++				totlen -= len;
26600 ++
26601 ++				mlast->m_next = m;
26602 ++				mlast = m;
26603 ++			}
26604 ++			cmd->dst_m = m0;
26605 ++#else
26606 ++			device_printf(sc->sc_dev,
26607 ++					"%s,%d: CRYPTO_F_SKBUF unaligned not implemented\n",
26608 ++					__FILE__, __LINE__);
26609 ++			err = EINVAL;
26610 ++			goto err_srcmap;
26611 ++#endif
26612 ++		} else {
26613 ++			device_printf(sc->sc_dev,
26614 ++					"%s,%d: unaligned contig buffers not implemented\n",
26615 ++					__FILE__, __LINE__);
26616 ++			err = EINVAL;
26617 ++			goto err_srcmap;
26618 ++		}
26619 ++	}
26620 ++
26621 ++	if (cmd->dst_map == NULL) {
26622 ++		if (crp->crp_flags & CRYPTO_F_SKBUF) {
26623 ++			if (pci_map_skb(sc, &cmd->dst, cmd->dst_skb)) {
26624 ++				hifnstats.hst_nomem_map++;
26625 ++				err = ENOMEM;
26626 ++				goto err_dstmap1;
26627 ++			}
26628 ++		} else if (crp->crp_flags & CRYPTO_F_IOV) {
26629 ++			if (pci_map_uio(sc, &cmd->dst, cmd->dst_io)) {
26630 ++				hifnstats.hst_nomem_load++;
26631 ++				err = ENOMEM;
26632 ++				goto err_dstmap1;
26633 ++			}
26634 ++		} else {
26635 ++			if (pci_map_buf(sc, &cmd->dst, cmd->dst_buf, crp->crp_ilen)) {
26636 ++				hifnstats.hst_nomem_load++;
26637 ++				err = ENOMEM;
26638 ++				goto err_dstmap1;
26639 ++			}
26640 ++		}
26641 ++	}
26642 ++
26643 ++#ifdef HIFN_DEBUG
26644 ++	if (hifn_debug) {
26645 ++		device_printf(sc->sc_dev,
26646 ++		    "Entering cmd: stat %8x ien %8x u %d/%d/%d/%d n %d/%d\n",
26647 ++		    READ_REG_1(sc, HIFN_1_DMA_CSR),
26648 ++		    READ_REG_1(sc, HIFN_1_DMA_IER),
26649 ++		    dma->cmdu, dma->srcu, dma->dstu, dma->resu,
26650 ++		    cmd->src_nsegs, cmd->dst_nsegs);
26651 ++	}
26652 ++#endif
26653 ++
26654 ++#if 0
26655 ++	if (cmd->src_map == cmd->dst_map) {
26656 ++		bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
26657 ++		    BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
26658 ++	} else {
26659 ++		bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
26660 ++		    BUS_DMASYNC_PREWRITE);
26661 ++		bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
26662 ++		    BUS_DMASYNC_PREREAD);
26663 ++	}
26664 ++#endif
26665 ++
26666 ++	/*
26667 ++	 * need N src, and N dst
26668 ++	 */
26669 ++	if ((dma->srcu + cmd->src_nsegs) > HIFN_D_SRC_RSIZE ||
26670 ++	    (dma->dstu + cmd->dst_nsegs + 1) > HIFN_D_DST_RSIZE) {
26671 ++#ifdef HIFN_DEBUG
26672 ++		if (hifn_debug) {
26673 ++			device_printf(sc->sc_dev,
26674 ++				"src/dst exhaustion, srcu %u+%u dstu %u+%u\n",
26675 ++				dma->srcu, cmd->src_nsegs,
26676 ++				dma->dstu, cmd->dst_nsegs);
26677 ++		}
26678 ++#endif
26679 ++		hifnstats.hst_nomem_sd++;
26680 ++		err = ERESTART;
26681 ++		goto err_dstmap;
26682 ++	}
26683 ++
26684 ++	if (dma->cmdi == HIFN_D_CMD_RSIZE) {
26685 ++		dma->cmdi = 0;
26686 ++		dma->cmdr[HIFN_D_CMD_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26687 ++		wmb();
26688 ++		dma->cmdr[HIFN_D_CMD_RSIZE].l |= htole32(HIFN_D_VALID);
26689 ++		HIFN_CMDR_SYNC(sc, HIFN_D_CMD_RSIZE,
26690 ++		    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26691 ++	}
26692 ++	cmdi = dma->cmdi++;
26693 ++	cmdlen = hifn_write_command(cmd, dma->command_bufs[cmdi]);
26694 ++	HIFN_CMD_SYNC(sc, cmdi, BUS_DMASYNC_PREWRITE);
26695 ++
26696 ++	/* .p for command/result already set */
26697 ++	dma->cmdr[cmdi].l = htole32(cmdlen | HIFN_D_LAST |
26698 ++	    HIFN_D_MASKDONEIRQ);
26699 ++	wmb();
26700 ++	dma->cmdr[cmdi].l |= htole32(HIFN_D_VALID);
26701 ++	HIFN_CMDR_SYNC(sc, cmdi,
26702 ++	    BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
26703 ++	dma->cmdu++;
26704 ++
26705 ++	/*
26706 ++	 * We don't worry about missing an interrupt (which a "command wait"
26707 ++	 * interrupt salvages us from), unless there is more than one command
26708 ++	 * in the queue.
26709 ++	 */
26710 ++	if (dma->cmdu > 1) {
26711 ++		sc->sc_dmaier |= HIFN_DMAIER_C_WAIT;
26712 ++		WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
26713 ++	}
26714 ++
26715 ++	hifnstats.hst_ipackets++;
26716 ++	hifnstats.hst_ibytes += cmd->src_mapsize;
26717 ++
26718 ++	hifn_dmamap_load_src(sc, cmd);
26719 ++
26720 ++	/*
26721 ++	 * Unlike other descriptors, we don't mask done interrupt from
26722 ++	 * result descriptor.
26723 ++	 */
26724 ++#ifdef HIFN_DEBUG
26725 ++	if (hifn_debug)
26726 ++		device_printf(sc->sc_dev, "load res\n");
26727 ++#endif
26728 ++	if (dma->resi == HIFN_D_RES_RSIZE) {
26729 ++		dma->resi = 0;
26730 ++		dma->resr[HIFN_D_RES_RSIZE].l = htole32(HIFN_D_JUMP|HIFN_D_MASKDONEIRQ);
26731 ++		wmb();
26732 ++		dma->resr[HIFN_D_RES_RSIZE].l |= htole32(HIFN_D_VALID);
26733 ++		HIFN_RESR_SYNC(sc, HIFN_D_RES_RSIZE,
26734 ++		    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26735 ++	}
26736 ++	resi = dma->resi++;
26737 ++	KASSERT(dma->hifn_commands[resi] == NULL,
26738 ++		("hifn_crypto: command slot %u busy", resi));
26739 ++	dma->hifn_commands[resi] = cmd;
26740 ++	HIFN_RES_SYNC(sc, resi, BUS_DMASYNC_PREREAD);
26741 ++	if ((hint & CRYPTO_HINT_MORE) && sc->sc_curbatch < hifn_maxbatch) {
26742 ++		dma->resr[resi].l = htole32(HIFN_MAX_RESULT |
26743 ++		    HIFN_D_LAST | HIFN_D_MASKDONEIRQ);
26744 ++		wmb();
26745 ++		dma->resr[resi].l |= htole32(HIFN_D_VALID);
26746 ++		sc->sc_curbatch++;
26747 ++		if (sc->sc_curbatch > hifnstats.hst_maxbatch)
26748 ++			hifnstats.hst_maxbatch = sc->sc_curbatch;
26749 ++		hifnstats.hst_totbatch++;
26750 ++	} else {
26751 ++		dma->resr[resi].l = htole32(HIFN_MAX_RESULT | HIFN_D_LAST);
26752 ++		wmb();
26753 ++		dma->resr[resi].l |= htole32(HIFN_D_VALID);
26754 ++		sc->sc_curbatch = 0;
26755 ++	}
26756 ++	HIFN_RESR_SYNC(sc, resi,
26757 ++	    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26758 ++	dma->resu++;
26759 ++
26760 ++	if (cmd->sloplen)
26761 ++		cmd->slopidx = resi;
26762 ++
26763 ++	hifn_dmamap_load_dst(sc, cmd);
26764 ++
26765 ++	csr = 0;
26766 ++	if (sc->sc_c_busy == 0) {
26767 ++		csr |= HIFN_DMACSR_C_CTRL_ENA;
26768 ++		sc->sc_c_busy = 1;
26769 ++	}
26770 ++	if (sc->sc_s_busy == 0) {
26771 ++		csr |= HIFN_DMACSR_S_CTRL_ENA;
26772 ++		sc->sc_s_busy = 1;
26773 ++	}
26774 ++	if (sc->sc_r_busy == 0) {
26775 ++		csr |= HIFN_DMACSR_R_CTRL_ENA;
26776 ++		sc->sc_r_busy = 1;
26777 ++	}
26778 ++	if (sc->sc_d_busy == 0) {
26779 ++		csr |= HIFN_DMACSR_D_CTRL_ENA;
26780 ++		sc->sc_d_busy = 1;
26781 ++	}
26782 ++	if (csr)
26783 ++		WRITE_REG_1(sc, HIFN_1_DMA_CSR, csr);
26784 ++
26785 ++#ifdef HIFN_DEBUG
26786 ++	if (hifn_debug) {
26787 ++		device_printf(sc->sc_dev, "command: stat %8x ier %8x\n",
26788 ++		    READ_REG_1(sc, HIFN_1_DMA_CSR),
26789 ++		    READ_REG_1(sc, HIFN_1_DMA_IER));
26790 ++	}
26791 ++#endif
26792 ++
26793 ++	sc->sc_active = 5;
26794 ++	HIFN_UNLOCK(sc);
26795 ++	KASSERT(err == 0, ("hifn_crypto: success with error %u", err));
26796 ++	return (err);		/* success */
26797 ++
26798 ++err_dstmap:
26799 ++	if (cmd->src_map != cmd->dst_map)
26800 ++		pci_unmap_buf(sc, &cmd->dst);
26801 ++err_dstmap1:
26802 ++err_srcmap:
26803 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
26804 ++		if (cmd->src_skb != cmd->dst_skb)
26805 ++#ifdef NOTYET
26806 ++			m_freem(cmd->dst_m);
26807 ++#else
26808 ++			device_printf(sc->sc_dev,
26809 ++					"%s,%d: CRYPTO_F_SKBUF src != dst not implemented\n",
26810 ++					__FILE__, __LINE__);
26811 ++#endif
26812 ++	}
26813 ++	pci_unmap_buf(sc, &cmd->src);
26814 ++err_srcmap1:
26815 ++	HIFN_UNLOCK(sc);
26816 ++	return (err);
26817 ++}
26818 ++
26819 ++static void
26820 ++hifn_tick(unsigned long arg)
26821 ++{
26822 ++	struct hifn_softc *sc;
26823 ++	unsigned long l_flags;
26824 ++
26825 ++	if (arg >= HIFN_MAX_CHIPS)
26826 ++		return;
26827 ++	sc = hifn_chip_idx[arg];
26828 ++	if (!sc)
26829 ++		return;
26830 ++
26831 ++	HIFN_LOCK(sc);
26832 ++	if (sc->sc_active == 0) {
26833 ++		struct hifn_dma *dma = sc->sc_dma;
26834 ++		u_int32_t r = 0;
26835 ++
26836 ++		if (dma->cmdu == 0 && sc->sc_c_busy) {
26837 ++			sc->sc_c_busy = 0;
26838 ++			r |= HIFN_DMACSR_C_CTRL_DIS;
26839 ++		}
26840 ++		if (dma->srcu == 0 && sc->sc_s_busy) {
26841 ++			sc->sc_s_busy = 0;
26842 ++			r |= HIFN_DMACSR_S_CTRL_DIS;
26843 ++		}
26844 ++		if (dma->dstu == 0 && sc->sc_d_busy) {
26845 ++			sc->sc_d_busy = 0;
26846 ++			r |= HIFN_DMACSR_D_CTRL_DIS;
26847 ++		}
26848 ++		if (dma->resu == 0 && sc->sc_r_busy) {
26849 ++			sc->sc_r_busy = 0;
26850 ++			r |= HIFN_DMACSR_R_CTRL_DIS;
26851 ++		}
26852 ++		if (r)
26853 ++			WRITE_REG_1(sc, HIFN_1_DMA_CSR, r);
26854 ++	} else
26855 ++		sc->sc_active--;
26856 ++	HIFN_UNLOCK(sc);
26857 ++	mod_timer(&sc->sc_tickto, jiffies + HZ);
26858 ++}
26859 ++
26860 ++static irqreturn_t
26861 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
26862 ++hifn_intr(int irq, void *arg)
26863 ++#else
26864 ++hifn_intr(int irq, void *arg, struct pt_regs *regs)
26865 ++#endif
26866 ++{
26867 ++	struct hifn_softc *sc = arg;
26868 ++	struct hifn_dma *dma;
26869 ++	u_int32_t dmacsr, restart;
26870 ++	int i, u;
26871 ++	unsigned long l_flags;
26872 ++
26873 ++	dmacsr = READ_REG_1(sc, HIFN_1_DMA_CSR);
26874 ++
26875 ++	/* Nothing in the DMA unit interrupted */
26876 ++	if ((dmacsr & sc->sc_dmaier) == 0)
26877 ++		return IRQ_NONE;
26878 ++
26879 ++	HIFN_LOCK(sc);
26880 ++
26881 ++	dma = sc->sc_dma;
26882 ++
26883 ++#ifdef HIFN_DEBUG
26884 ++	if (hifn_debug) {
26885 ++		device_printf(sc->sc_dev,
26886 ++		    "irq: stat %08x ien %08x damier %08x i %d/%d/%d/%d k %d/%d/%d/%d u %d/%d/%d/%d\n",
26887 ++		    dmacsr, READ_REG_1(sc, HIFN_1_DMA_IER), sc->sc_dmaier,
26888 ++		    dma->cmdi, dma->srci, dma->dsti, dma->resi,
26889 ++		    dma->cmdk, dma->srck, dma->dstk, dma->resk,
26890 ++		    dma->cmdu, dma->srcu, dma->dstu, dma->resu);
26891 ++	}
26892 ++#endif
26893 ++
26894 ++	WRITE_REG_1(sc, HIFN_1_DMA_CSR, dmacsr & sc->sc_dmaier);
26895 ++
26896 ++	if ((sc->sc_flags & HIFN_HAS_PUBLIC) &&
26897 ++	    (dmacsr & HIFN_DMACSR_PUBDONE))
26898 ++		WRITE_REG_1(sc, HIFN_1_PUB_STATUS,
26899 ++		    READ_REG_1(sc, HIFN_1_PUB_STATUS) | HIFN_PUBSTS_DONE);
26900 ++
26901 ++	restart = dmacsr & (HIFN_DMACSR_D_OVER | HIFN_DMACSR_R_OVER);
26902 ++	if (restart)
26903 ++		device_printf(sc->sc_dev, "overrun %x\n", dmacsr);
26904 ++
26905 ++	if (sc->sc_flags & HIFN_IS_7811) {
26906 ++		if (dmacsr & HIFN_DMACSR_ILLR)
26907 ++			device_printf(sc->sc_dev, "illegal read\n");
26908 ++		if (dmacsr & HIFN_DMACSR_ILLW)
26909 ++			device_printf(sc->sc_dev, "illegal write\n");
26910 ++	}
26911 ++
26912 ++	restart = dmacsr & (HIFN_DMACSR_C_ABORT | HIFN_DMACSR_S_ABORT |
26913 ++	    HIFN_DMACSR_D_ABORT | HIFN_DMACSR_R_ABORT);
26914 ++	if (restart) {
26915 ++		device_printf(sc->sc_dev, "abort, resetting.\n");
26916 ++		hifnstats.hst_abort++;
26917 ++		hifn_abort(sc);
26918 ++		HIFN_UNLOCK(sc);
26919 ++		return IRQ_HANDLED;
26920 ++	}
26921 ++
26922 ++	if ((dmacsr & HIFN_DMACSR_C_WAIT) && (dma->cmdu == 0)) {
26923 ++		/*
26924 ++		 * If no slots to process and we receive a "waiting on
26925 ++		 * command" interrupt, we disable the "waiting on command"
26926 ++		 * (by clearing it).
26927 ++		 */
26928 ++		sc->sc_dmaier &= ~HIFN_DMAIER_C_WAIT;
26929 ++		WRITE_REG_1(sc, HIFN_1_DMA_IER, sc->sc_dmaier);
26930 ++	}
26931 ++
26932 ++	/* clear the rings */
26933 ++	i = dma->resk; u = dma->resu;
26934 ++	while (u != 0) {
26935 ++		HIFN_RESR_SYNC(sc, i,
26936 ++		    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
26937 ++		if (dma->resr[i].l & htole32(HIFN_D_VALID)) {
26938 ++			HIFN_RESR_SYNC(sc, i,
26939 ++			    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26940 ++			break;
26941 ++		}
26942 ++
26943 ++		if (i != HIFN_D_RES_RSIZE) {
26944 ++			struct hifn_command *cmd;
26945 ++			u_int8_t *macbuf = NULL;
26946 ++
26947 ++			HIFN_RES_SYNC(sc, i, BUS_DMASYNC_POSTREAD);
26948 ++			cmd = dma->hifn_commands[i];
26949 ++			KASSERT(cmd != NULL,
26950 ++				("hifn_intr: null command slot %u", i));
26951 ++			dma->hifn_commands[i] = NULL;
26952 ++
26953 ++			if (cmd->base_masks & HIFN_BASE_CMD_MAC) {
26954 ++				macbuf = dma->result_bufs[i];
26955 ++				macbuf += 12;
26956 ++			}
26957 ++
26958 ++			hifn_callback(sc, cmd, macbuf);
26959 ++			hifnstats.hst_opackets++;
26960 ++			u--;
26961 ++		}
26962 ++
26963 ++		if (++i == (HIFN_D_RES_RSIZE + 1))
26964 ++			i = 0;
26965 ++	}
26966 ++	dma->resk = i; dma->resu = u;
26967 ++
26968 ++	i = dma->srck; u = dma->srcu;
26969 ++	while (u != 0) {
26970 ++		if (i == HIFN_D_SRC_RSIZE)
26971 ++			i = 0;
26972 ++		HIFN_SRCR_SYNC(sc, i,
26973 ++		    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
26974 ++		if (dma->srcr[i].l & htole32(HIFN_D_VALID)) {
26975 ++			HIFN_SRCR_SYNC(sc, i,
26976 ++			    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26977 ++			break;
26978 ++		}
26979 ++		i++, u--;
26980 ++	}
26981 ++	dma->srck = i; dma->srcu = u;
26982 ++
26983 ++	i = dma->cmdk; u = dma->cmdu;
26984 ++	while (u != 0) {
26985 ++		HIFN_CMDR_SYNC(sc, i,
26986 ++		    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
26987 ++		if (dma->cmdr[i].l & htole32(HIFN_D_VALID)) {
26988 ++			HIFN_CMDR_SYNC(sc, i,
26989 ++			    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
26990 ++			break;
26991 ++		}
26992 ++		if (i != HIFN_D_CMD_RSIZE) {
26993 ++			u--;
26994 ++			HIFN_CMD_SYNC(sc, i, BUS_DMASYNC_POSTWRITE);
26995 ++		}
26996 ++		if (++i == (HIFN_D_CMD_RSIZE + 1))
26997 ++			i = 0;
26998 ++	}
26999 ++	dma->cmdk = i; dma->cmdu = u;
27000 ++
27001 ++	HIFN_UNLOCK(sc);
27002 ++
27003 ++	if (sc->sc_needwakeup) {		/* XXX check high watermark */
27004 ++		int wakeup = sc->sc_needwakeup & (CRYPTO_SYMQ|CRYPTO_ASYMQ);
27005 ++#ifdef HIFN_DEBUG
27006 ++		if (hifn_debug)
27007 ++			device_printf(sc->sc_dev,
27008 ++				"wakeup crypto (%x) u %d/%d/%d/%d\n",
27009 ++				sc->sc_needwakeup,
27010 ++				dma->cmdu, dma->srcu, dma->dstu, dma->resu);
27011 ++#endif
27012 ++		sc->sc_needwakeup &= ~wakeup;
27013 ++		crypto_unblock(sc->sc_cid, wakeup);
27014 ++	}
27015 ++
27016 ++	return IRQ_HANDLED;
27017 ++}
27018 ++
27019 ++/*
27020 ++ * Allocate a new 'session' and return an encoded session id.  'sidp'
27021 ++ * contains our registration id, and should contain an encoded session
27022 ++ * id on successful allocation.
27023 ++ */
27024 ++static int
27025 ++hifn_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
27026 ++{
27027 ++	struct hifn_softc *sc = device_get_softc(dev);
27028 ++	struct cryptoini *c;
27029 ++	int mac = 0, cry = 0, sesn;
27030 ++	struct hifn_session *ses = NULL;
27031 ++	unsigned long l_flags;
27032 ++
27033 ++	DPRINTF("%s()\n", __FUNCTION__);
27034 ++
27035 ++	KASSERT(sc != NULL, ("hifn_newsession: null softc"));
27036 ++	if (sidp == NULL || cri == NULL || sc == NULL) {
27037 ++		DPRINTF("%s,%d: %s - EINVAL\n", __FILE__, __LINE__, __FUNCTION__);
27038 ++		return (EINVAL);
27039 ++	}
27040 ++
27041 ++	HIFN_LOCK(sc);
27042 ++	if (sc->sc_sessions == NULL) {
27043 ++		ses = sc->sc_sessions = (struct hifn_session *)kmalloc(sizeof(*ses),
27044 ++				SLAB_ATOMIC);
27045 ++		if (ses == NULL) {
27046 ++			HIFN_UNLOCK(sc);
27047 ++			return (ENOMEM);
27048 ++		}
27049 ++		sesn = 0;
27050 ++		sc->sc_nsessions = 1;
27051 ++	} else {
27052 ++		for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
27053 ++			if (!sc->sc_sessions[sesn].hs_used) {
27054 ++				ses = &sc->sc_sessions[sesn];
27055 ++				break;
27056 ++			}
27057 ++		}
27058 ++
27059 ++		if (ses == NULL) {
27060 ++			sesn = sc->sc_nsessions;
27061 ++			ses = (struct hifn_session *)kmalloc((sesn + 1) * sizeof(*ses),
27062 ++					SLAB_ATOMIC);
27063 ++			if (ses == NULL) {
27064 ++				HIFN_UNLOCK(sc);
27065 ++				return (ENOMEM);
27066 ++			}
27067 ++			bcopy(sc->sc_sessions, ses, sesn * sizeof(*ses));
27068 ++			bzero(sc->sc_sessions, sesn * sizeof(*ses));
27069 ++			kfree(sc->sc_sessions);
27070 ++			sc->sc_sessions = ses;
27071 ++			ses = &sc->sc_sessions[sesn];
27072 ++			sc->sc_nsessions++;
27073 ++		}
27074 ++	}
27075 ++	HIFN_UNLOCK(sc);
27076 ++
27077 ++	bzero(ses, sizeof(*ses));
27078 ++	ses->hs_used = 1;
27079 ++
27080 ++	for (c = cri; c != NULL; c = c->cri_next) {
27081 ++		switch (c->cri_alg) {
27082 ++		case CRYPTO_MD5:
27083 ++		case CRYPTO_SHA1:
27084 ++		case CRYPTO_MD5_HMAC:
27085 ++		case CRYPTO_SHA1_HMAC:
27086 ++			if (mac) {
27087 ++				DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27088 ++				return (EINVAL);
27089 ++			}
27090 ++			mac = 1;
27091 ++			ses->hs_mlen = c->cri_mlen;
27092 ++			if (ses->hs_mlen == 0) {
27093 ++				switch (c->cri_alg) {
27094 ++				case CRYPTO_MD5:
27095 ++				case CRYPTO_MD5_HMAC:
27096 ++					ses->hs_mlen = 16;
27097 ++					break;
27098 ++				case CRYPTO_SHA1:
27099 ++				case CRYPTO_SHA1_HMAC:
27100 ++					ses->hs_mlen = 20;
27101 ++					break;
27102 ++				}
27103 ++			}
27104 ++			break;
27105 ++		case CRYPTO_DES_CBC:
27106 ++		case CRYPTO_3DES_CBC:
27107 ++		case CRYPTO_AES_CBC:
27108 ++			/* XXX this may read fewer, does it matter? */
27109 ++			read_random(ses->hs_iv,
27110 ++				c->cri_alg == CRYPTO_AES_CBC ?
27111 ++					HIFN_AES_IV_LENGTH : HIFN_IV_LENGTH);
27112 ++			/*FALLTHROUGH*/
27113 ++		case CRYPTO_ARC4:
27114 ++			if (cry) {
27115 ++				DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27116 ++				return (EINVAL);
27117 ++			}
27118 ++			cry = 1;
27119 ++			break;
27120 ++		default:
27121 ++			DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27122 ++			return (EINVAL);
27123 ++		}
27124 ++	}
27125 ++	if (mac == 0 && cry == 0) {
27126 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27127 ++		return (EINVAL);
27128 ++	}
27129 ++
27130 ++	*sidp = HIFN_SID(device_get_unit(sc->sc_dev), sesn);
27131 ++
27132 ++	return (0);
27133 ++}
27134 ++
27135 ++/*
27136 ++ * Deallocate a session.
27137 ++ * XXX this routine should run a zero'd mac/encrypt key into context ram.
27138 ++ * XXX to blow away any keys already stored there.
27139 ++ */
27140 ++static int
27141 ++hifn_freesession(device_t dev, u_int64_t tid)
27142 ++{
27143 ++	struct hifn_softc *sc = device_get_softc(dev);
27144 ++	int session, error;
27145 ++	u_int32_t sid = CRYPTO_SESID2LID(tid);
27146 ++	unsigned long l_flags;
27147 ++
27148 ++	DPRINTF("%s()\n", __FUNCTION__);
27149 ++
27150 ++	KASSERT(sc != NULL, ("hifn_freesession: null softc"));
27151 ++	if (sc == NULL) {
27152 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27153 ++		return (EINVAL);
27154 ++	}
27155 ++
27156 ++	HIFN_LOCK(sc);
27157 ++	session = HIFN_SESSION(sid);
27158 ++	if (session < sc->sc_nsessions) {
27159 ++		bzero(&sc->sc_sessions[session], sizeof(struct hifn_session));
27160 ++		error = 0;
27161 ++	} else {
27162 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27163 ++		error = EINVAL;
27164 ++	}
27165 ++	HIFN_UNLOCK(sc);
27166 ++
27167 ++	return (error);
27168 ++}
27169 ++
27170 ++static int
27171 ++hifn_process(device_t dev, struct cryptop *crp, int hint)
27172 ++{
27173 ++	struct hifn_softc *sc = device_get_softc(dev);
27174 ++	struct hifn_command *cmd = NULL;
27175 ++	int session, err, ivlen;
27176 ++	struct cryptodesc *crd1, *crd2, *maccrd, *enccrd;
27177 ++
27178 ++	DPRINTF("%s()\n", __FUNCTION__);
27179 ++
27180 ++	if (crp == NULL || crp->crp_callback == NULL) {
27181 ++		hifnstats.hst_invalid++;
27182 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27183 ++		return (EINVAL);
27184 ++	}
27185 ++	session = HIFN_SESSION(crp->crp_sid);
27186 ++
27187 ++	if (sc == NULL || session >= sc->sc_nsessions) {
27188 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27189 ++		err = EINVAL;
27190 ++		goto errout;
27191 ++	}
27192 ++
27193 ++	cmd = kmalloc(sizeof(struct hifn_command), SLAB_ATOMIC);
27194 ++	if (cmd == NULL) {
27195 ++		hifnstats.hst_nomem++;
27196 ++		err = ENOMEM;
27197 ++		goto errout;
27198 ++	}
27199 ++	memset(cmd, 0, sizeof(*cmd));
27200 ++
27201 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
27202 ++		cmd->src_skb = (struct sk_buff *)crp->crp_buf;
27203 ++		cmd->dst_skb = (struct sk_buff *)crp->crp_buf;
27204 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
27205 ++		cmd->src_io = (struct uio *)crp->crp_buf;
27206 ++		cmd->dst_io = (struct uio *)crp->crp_buf;
27207 ++	} else {
27208 ++		cmd->src_buf = crp->crp_buf;
27209 ++		cmd->dst_buf = crp->crp_buf;
27210 ++	}
27211 ++
27212 ++	crd1 = crp->crp_desc;
27213 ++	if (crd1 == NULL) {
27214 ++		DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27215 ++		err = EINVAL;
27216 ++		goto errout;
27217 ++	}
27218 ++	crd2 = crd1->crd_next;
27219 ++
27220 ++	if (crd2 == NULL) {
27221 ++		if (crd1->crd_alg == CRYPTO_MD5_HMAC ||
27222 ++		    crd1->crd_alg == CRYPTO_SHA1_HMAC ||
27223 ++		    crd1->crd_alg == CRYPTO_SHA1 ||
27224 ++		    crd1->crd_alg == CRYPTO_MD5) {
27225 ++			maccrd = crd1;
27226 ++			enccrd = NULL;
27227 ++		} else if (crd1->crd_alg == CRYPTO_DES_CBC ||
27228 ++		    crd1->crd_alg == CRYPTO_3DES_CBC ||
27229 ++		    crd1->crd_alg == CRYPTO_AES_CBC ||
27230 ++		    crd1->crd_alg == CRYPTO_ARC4) {
27231 ++			if ((crd1->crd_flags & CRD_F_ENCRYPT) == 0)
27232 ++				cmd->base_masks |= HIFN_BASE_CMD_DECODE;
27233 ++			maccrd = NULL;
27234 ++			enccrd = crd1;
27235 ++		} else {
27236 ++			DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27237 ++			err = EINVAL;
27238 ++			goto errout;
27239 ++		}
27240 ++	} else {
27241 ++		if ((crd1->crd_alg == CRYPTO_MD5_HMAC ||
27242 ++                     crd1->crd_alg == CRYPTO_SHA1_HMAC ||
27243 ++                     crd1->crd_alg == CRYPTO_MD5 ||
27244 ++                     crd1->crd_alg == CRYPTO_SHA1) &&
27245 ++		    (crd2->crd_alg == CRYPTO_DES_CBC ||
27246 ++		     crd2->crd_alg == CRYPTO_3DES_CBC ||
27247 ++		     crd2->crd_alg == CRYPTO_AES_CBC ||
27248 ++		     crd2->crd_alg == CRYPTO_ARC4) &&
27249 ++		    ((crd2->crd_flags & CRD_F_ENCRYPT) == 0)) {
27250 ++			cmd->base_masks = HIFN_BASE_CMD_DECODE;
27251 ++			maccrd = crd1;
27252 ++			enccrd = crd2;
27253 ++		} else if ((crd1->crd_alg == CRYPTO_DES_CBC ||
27254 ++		     crd1->crd_alg == CRYPTO_ARC4 ||
27255 ++		     crd1->crd_alg == CRYPTO_3DES_CBC ||
27256 ++		     crd1->crd_alg == CRYPTO_AES_CBC) &&
27257 ++		    (crd2->crd_alg == CRYPTO_MD5_HMAC ||
27258 ++                     crd2->crd_alg == CRYPTO_SHA1_HMAC ||
27259 ++                     crd2->crd_alg == CRYPTO_MD5 ||
27260 ++                     crd2->crd_alg == CRYPTO_SHA1) &&
27261 ++		    (crd1->crd_flags & CRD_F_ENCRYPT)) {
27262 ++			enccrd = crd1;
27263 ++			maccrd = crd2;
27264 ++		} else {
27265 ++			/*
27266 ++			 * We cannot order the 7751 as requested
27267 ++			 */
27268 ++			DPRINTF("%s,%d: %s %d,%d,%d - EINVAL\n",__FILE__,__LINE__,__FUNCTION__, crd1->crd_alg, crd2->crd_alg, crd1->crd_flags & CRD_F_ENCRYPT);
27269 ++			err = EINVAL;
27270 ++			goto errout;
27271 ++		}
27272 ++	}
27273 ++
27274 ++	if (enccrd) {
27275 ++		cmd->enccrd = enccrd;
27276 ++		cmd->base_masks |= HIFN_BASE_CMD_CRYPT;
27277 ++		switch (enccrd->crd_alg) {
27278 ++		case CRYPTO_ARC4:
27279 ++			cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_RC4;
27280 ++			break;
27281 ++		case CRYPTO_DES_CBC:
27282 ++			cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_DES |
27283 ++			    HIFN_CRYPT_CMD_MODE_CBC |
27284 ++			    HIFN_CRYPT_CMD_NEW_IV;
27285 ++			break;
27286 ++		case CRYPTO_3DES_CBC:
27287 ++			cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_3DES |
27288 ++			    HIFN_CRYPT_CMD_MODE_CBC |
27289 ++			    HIFN_CRYPT_CMD_NEW_IV;
27290 ++			break;
27291 ++		case CRYPTO_AES_CBC:
27292 ++			cmd->cry_masks |= HIFN_CRYPT_CMD_ALG_AES |
27293 ++			    HIFN_CRYPT_CMD_MODE_CBC |
27294 ++			    HIFN_CRYPT_CMD_NEW_IV;
27295 ++			break;
27296 ++		default:
27297 ++			DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27298 ++			err = EINVAL;
27299 ++			goto errout;
27300 ++		}
27301 ++		if (enccrd->crd_alg != CRYPTO_ARC4) {
27302 ++			ivlen = ((enccrd->crd_alg == CRYPTO_AES_CBC) ?
27303 ++				HIFN_AES_IV_LENGTH : HIFN_IV_LENGTH);
27304 ++			if (enccrd->crd_flags & CRD_F_ENCRYPT) {
27305 ++				if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
27306 ++					bcopy(enccrd->crd_iv, cmd->iv, ivlen);
27307 ++				else
27308 ++					bcopy(sc->sc_sessions[session].hs_iv,
27309 ++					    cmd->iv, ivlen);
27310 ++
27311 ++				if ((enccrd->crd_flags & CRD_F_IV_PRESENT)
27312 ++				    == 0) {
27313 ++					crypto_copyback(crp->crp_flags,
27314 ++					    crp->crp_buf, enccrd->crd_inject,
27315 ++					    ivlen, cmd->iv);
27316 ++				}
27317 ++			} else {
27318 ++				if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
27319 ++					bcopy(enccrd->crd_iv, cmd->iv, ivlen);
27320 ++				else {
27321 ++					crypto_copydata(crp->crp_flags,
27322 ++					    crp->crp_buf, enccrd->crd_inject,
27323 ++					    ivlen, cmd->iv);
27324 ++				}
27325 ++			}
27326 ++		}
27327 ++
27328 ++		if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT)
27329 ++			cmd->cry_masks |= HIFN_CRYPT_CMD_NEW_KEY;
27330 ++		cmd->ck = enccrd->crd_key;
27331 ++		cmd->cklen = enccrd->crd_klen >> 3;
27332 ++		cmd->cry_masks |= HIFN_CRYPT_CMD_NEW_KEY;
27333 ++
27334 ++		/* 
27335 ++		 * Need to specify the size for the AES key in the masks.
27336 ++		 */
27337 ++		if ((cmd->cry_masks & HIFN_CRYPT_CMD_ALG_MASK) ==
27338 ++		    HIFN_CRYPT_CMD_ALG_AES) {
27339 ++			switch (cmd->cklen) {
27340 ++			case 16:
27341 ++				cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_128;
27342 ++				break;
27343 ++			case 24:
27344 ++				cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_192;
27345 ++				break;
27346 ++			case 32:
27347 ++				cmd->cry_masks |= HIFN_CRYPT_CMD_KSZ_256;
27348 ++				break;
27349 ++			default:
27350 ++				DPRINTF("%s,%d: %s - EINVAL\n",__FILE__,__LINE__,__FUNCTION__);
27351 ++				err = EINVAL;
27352 ++				goto errout;
27353 ++			}
27354 ++		}
27355 ++	}
27356 ++
27357 ++	if (maccrd) {
27358 ++		cmd->maccrd = maccrd;
27359 ++		cmd->base_masks |= HIFN_BASE_CMD_MAC;
27360 ++
27361 ++		switch (maccrd->crd_alg) {
27362 ++		case CRYPTO_MD5:
27363 ++			cmd->mac_masks |= HIFN_MAC_CMD_ALG_MD5 |
27364 ++			    HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HASH |
27365 ++			    HIFN_MAC_CMD_POS_IPSEC;
27366 ++                       break;
27367 ++		case CRYPTO_MD5_HMAC:
27368 ++			cmd->mac_masks |= HIFN_MAC_CMD_ALG_MD5 |
27369 ++			    HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HMAC |
27370 ++			    HIFN_MAC_CMD_POS_IPSEC | HIFN_MAC_CMD_TRUNC;
27371 ++			break;
27372 ++		case CRYPTO_SHA1:
27373 ++			cmd->mac_masks |= HIFN_MAC_CMD_ALG_SHA1 |
27374 ++			    HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HASH |
27375 ++			    HIFN_MAC_CMD_POS_IPSEC;
27376 ++			break;
27377 ++		case CRYPTO_SHA1_HMAC:
27378 ++			cmd->mac_masks |= HIFN_MAC_CMD_ALG_SHA1 |
27379 ++			    HIFN_MAC_CMD_RESULT | HIFN_MAC_CMD_MODE_HMAC |
27380 ++			    HIFN_MAC_CMD_POS_IPSEC | HIFN_MAC_CMD_TRUNC;
27381 ++			break;
27382 ++		}
27383 ++
27384 ++		if (maccrd->crd_alg == CRYPTO_SHA1_HMAC ||
27385 ++		     maccrd->crd_alg == CRYPTO_MD5_HMAC) {
27386 ++			cmd->mac_masks |= HIFN_MAC_CMD_NEW_KEY;
27387 ++			bcopy(maccrd->crd_key, cmd->mac, maccrd->crd_klen >> 3);
27388 ++			bzero(cmd->mac + (maccrd->crd_klen >> 3),
27389 ++			    HIFN_MAC_KEY_LENGTH - (maccrd->crd_klen >> 3));
27390 ++		}
27391 ++	}
27392 ++
27393 ++	cmd->crp = crp;
27394 ++	cmd->session_num = session;
27395 ++	cmd->softc = sc;
27396 ++
27397 ++	err = hifn_crypto(sc, cmd, crp, hint);
27398 ++	if (!err) {
27399 ++		return 0;
27400 ++	} else if (err == ERESTART) {
27401 ++		/*
27402 ++		 * There weren't enough resources to dispatch the request
27403 ++		 * to the part.  Notify the caller so they'll requeue this
27404 ++		 * request and resubmit it again soon.
27405 ++		 */
27406 ++#ifdef HIFN_DEBUG
27407 ++		if (hifn_debug)
27408 ++			device_printf(sc->sc_dev, "requeue request\n");
27409 ++#endif
27410 ++		kfree(cmd);
27411 ++		sc->sc_needwakeup |= CRYPTO_SYMQ;
27412 ++		return (err);
27413 ++	}
27414 ++
27415 ++errout:
27416 ++	if (cmd != NULL)
27417 ++		kfree(cmd);
27418 ++	if (err == EINVAL)
27419 ++		hifnstats.hst_invalid++;
27420 ++	else
27421 ++		hifnstats.hst_nomem++;
27422 ++	crp->crp_etype = err;
27423 ++	crypto_done(crp);
27424 ++	return (err);
27425 ++}
27426 ++
27427 ++static void
27428 ++hifn_abort(struct hifn_softc *sc)
27429 ++{
27430 ++	struct hifn_dma *dma = sc->sc_dma;
27431 ++	struct hifn_command *cmd;
27432 ++	struct cryptop *crp;
27433 ++	int i, u;
27434 ++
27435 ++	DPRINTF("%s()\n", __FUNCTION__);
27436 ++
27437 ++	i = dma->resk; u = dma->resu;
27438 ++	while (u != 0) {
27439 ++		cmd = dma->hifn_commands[i];
27440 ++		KASSERT(cmd != NULL, ("hifn_abort: null command slot %u", i));
27441 ++		dma->hifn_commands[i] = NULL;
27442 ++		crp = cmd->crp;
27443 ++
27444 ++		if ((dma->resr[i].l & htole32(HIFN_D_VALID)) == 0) {
27445 ++			/* Salvage what we can. */
27446 ++			u_int8_t *macbuf;
27447 ++
27448 ++			if (cmd->base_masks & HIFN_BASE_CMD_MAC) {
27449 ++				macbuf = dma->result_bufs[i];
27450 ++				macbuf += 12;
27451 ++			} else
27452 ++				macbuf = NULL;
27453 ++			hifnstats.hst_opackets++;
27454 ++			hifn_callback(sc, cmd, macbuf);
27455 ++		} else {
27456 ++#if 0
27457 ++			if (cmd->src_map == cmd->dst_map) {
27458 ++				bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
27459 ++				    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
27460 ++			} else {
27461 ++				bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
27462 ++				    BUS_DMASYNC_POSTWRITE);
27463 ++				bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
27464 ++				    BUS_DMASYNC_POSTREAD);
27465 ++			}
27466 ++#endif
27467 ++
27468 ++			if (cmd->src_skb != cmd->dst_skb) {
27469 ++#ifdef NOTYET
27470 ++				m_freem(cmd->src_m);
27471 ++				crp->crp_buf = (caddr_t)cmd->dst_m;
27472 ++#else
27473 ++				device_printf(sc->sc_dev,
27474 ++						"%s,%d: CRYPTO_F_SKBUF src != dst not implemented\n",
27475 ++						__FILE__, __LINE__);
27476 ++#endif
27477 ++			}
27478 ++
27479 ++			/* non-shared buffers cannot be restarted */
27480 ++			if (cmd->src_map != cmd->dst_map) {
27481 ++				/*
27482 ++				 * XXX should be EAGAIN, delayed until
27483 ++				 * after the reset.
27484 ++				 */
27485 ++				crp->crp_etype = ENOMEM;
27486 ++				pci_unmap_buf(sc, &cmd->dst);
27487 ++			} else
27488 ++				crp->crp_etype = ENOMEM;
27489 ++
27490 ++			pci_unmap_buf(sc, &cmd->src);
27491 ++
27492 ++			kfree(cmd);
27493 ++			if (crp->crp_etype != EAGAIN)
27494 ++				crypto_done(crp);
27495 ++		}
27496 ++
27497 ++		if (++i == HIFN_D_RES_RSIZE)
27498 ++			i = 0;
27499 ++		u--;
27500 ++	}
27501 ++	dma->resk = i; dma->resu = u;
27502 ++
27503 ++	hifn_reset_board(sc, 1);
27504 ++	hifn_init_dma(sc);
27505 ++	hifn_init_pci_registers(sc);
27506 ++}
27507 ++
27508 ++static void
27509 ++hifn_callback(struct hifn_softc *sc, struct hifn_command *cmd, u_int8_t *macbuf)
27510 ++{
27511 ++	struct hifn_dma *dma = sc->sc_dma;
27512 ++	struct cryptop *crp = cmd->crp;
27513 ++	struct cryptodesc *crd;
27514 ++	int i, u, ivlen;
27515 ++
27516 ++	DPRINTF("%s()\n", __FUNCTION__);
27517 ++
27518 ++#if 0
27519 ++	if (cmd->src_map == cmd->dst_map) {
27520 ++		bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
27521 ++		    BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
27522 ++	} else {
27523 ++		bus_dmamap_sync(sc->sc_dmat, cmd->src_map,
27524 ++		    BUS_DMASYNC_POSTWRITE);
27525 ++		bus_dmamap_sync(sc->sc_dmat, cmd->dst_map,
27526 ++		    BUS_DMASYNC_POSTREAD);
27527 ++	}
27528 ++#endif
27529 ++
27530 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
27531 ++		if (cmd->src_skb != cmd->dst_skb) {
27532 ++#ifdef NOTYET
27533 ++			crp->crp_buf = (caddr_t)cmd->dst_m;
27534 ++			totlen = cmd->src_mapsize;
27535 ++			for (m = cmd->dst_m; m != NULL; m = m->m_next) {
27536 ++				if (totlen < m->m_len) {
27537 ++					m->m_len = totlen;
27538 ++					totlen = 0;
27539 ++				} else
27540 ++					totlen -= m->m_len;
27541 ++			}
27542 ++			cmd->dst_m->m_pkthdr.len = cmd->src_m->m_pkthdr.len;
27543 ++			m_freem(cmd->src_m);
27544 ++#else
27545 ++			device_printf(sc->sc_dev,
27546 ++					"%s,%d: CRYPTO_F_SKBUF src != dst not implemented\n",
27547 ++					__FILE__, __LINE__);
27548 ++#endif
27549 ++		}
27550 ++	}
27551 ++
27552 ++	if (cmd->sloplen != 0) {
27553 ++		crypto_copyback(crp->crp_flags, crp->crp_buf,
27554 ++		    cmd->src_mapsize - cmd->sloplen, cmd->sloplen,
27555 ++		    (caddr_t)&dma->slop[cmd->slopidx]);
27556 ++	}
27557 ++
27558 ++	i = dma->dstk; u = dma->dstu;
27559 ++	while (u != 0) {
27560 ++		if (i == HIFN_D_DST_RSIZE)
27561 ++			i = 0;
27562 ++#if 0
27563 ++		bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
27564 ++		    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
27565 ++#endif
27566 ++		if (dma->dstr[i].l & htole32(HIFN_D_VALID)) {
27567 ++#if 0
27568 ++			bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
27569 ++			    BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
27570 ++#endif
27571 ++			break;
27572 ++		}
27573 ++		i++, u--;
27574 ++	}
27575 ++	dma->dstk = i; dma->dstu = u;
27576 ++
27577 ++	hifnstats.hst_obytes += cmd->dst_mapsize;
27578 ++
27579 ++	if ((cmd->base_masks & (HIFN_BASE_CMD_CRYPT | HIFN_BASE_CMD_DECODE)) ==
27580 ++	    HIFN_BASE_CMD_CRYPT) {
27581 ++		for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
27582 ++			if (crd->crd_alg != CRYPTO_DES_CBC &&
27583 ++			    crd->crd_alg != CRYPTO_3DES_CBC &&
27584 ++			    crd->crd_alg != CRYPTO_AES_CBC)
27585 ++				continue;
27586 ++			ivlen = ((crd->crd_alg == CRYPTO_AES_CBC) ?
27587 ++				HIFN_AES_IV_LENGTH : HIFN_IV_LENGTH);
27588 ++			crypto_copydata(crp->crp_flags, crp->crp_buf,
27589 ++			    crd->crd_skip + crd->crd_len - ivlen, ivlen,
27590 ++			    cmd->softc->sc_sessions[cmd->session_num].hs_iv);
27591 ++			break;
27592 ++		}
27593 ++	}
27594 ++
27595 ++	if (macbuf != NULL) {
27596 ++		for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
27597 ++                        int len;
27598 ++
27599 ++			if (crd->crd_alg != CRYPTO_MD5 &&
27600 ++			    crd->crd_alg != CRYPTO_SHA1 &&
27601 ++			    crd->crd_alg != CRYPTO_MD5_HMAC &&
27602 ++			    crd->crd_alg != CRYPTO_SHA1_HMAC) {
27603 ++				continue;
27604 ++			}
27605 ++			len = cmd->softc->sc_sessions[cmd->session_num].hs_mlen;
27606 ++			crypto_copyback(crp->crp_flags, crp->crp_buf,
27607 ++			    crd->crd_inject, len, macbuf);
27608 ++			break;
27609 ++		}
27610 ++	}
27611 ++
27612 ++	if (cmd->src_map != cmd->dst_map)
27613 ++		pci_unmap_buf(sc, &cmd->dst);
27614 ++	pci_unmap_buf(sc, &cmd->src);
27615 ++	kfree(cmd);
27616 ++	crypto_done(crp);
27617 ++}
27618 ++
27619 ++/*
27620 ++ * 7811 PB3 rev/2 parts lock-up on burst writes to Group 0
27621 ++ * and Group 1 registers; avoid conditions that could create
27622 ++ * burst writes by doing a read in between the writes.
27623 ++ *
27624 ++ * NB: The read we interpose is always to the same register;
27625 ++ *     we do this because reading from an arbitrary (e.g. last)
27626 ++ *     register may not always work.
27627 ++ */
27628 ++static void
27629 ++hifn_write_reg_0(struct hifn_softc *sc, bus_size_t reg, u_int32_t val)
27630 ++{
27631 ++	if (sc->sc_flags & HIFN_IS_7811) {
27632 ++		if (sc->sc_bar0_lastreg == reg - 4)
27633 ++			readl(sc->sc_bar0 + HIFN_0_PUCNFG);
27634 ++		sc->sc_bar0_lastreg = reg;
27635 ++	}
27636 ++	writel(val, sc->sc_bar0 + reg);
27637 ++}
27638 ++
27639 ++static void
27640 ++hifn_write_reg_1(struct hifn_softc *sc, bus_size_t reg, u_int32_t val)
27641 ++{
27642 ++	if (sc->sc_flags & HIFN_IS_7811) {
27643 ++		if (sc->sc_bar1_lastreg == reg - 4)
27644 ++			readl(sc->sc_bar1 + HIFN_1_REVID);
27645 ++		sc->sc_bar1_lastreg = reg;
27646 ++	}
27647 ++	writel(val, sc->sc_bar1 + reg);
27648 ++}
27649 ++
27650 ++
27651 ++static struct pci_device_id hifn_pci_tbl[] = {
27652 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7951,
27653 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27654 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7955,
27655 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27656 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7956,
27657 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27658 ++	{ PCI_VENDOR_NETSEC, PCI_PRODUCT_NETSEC_7751,
27659 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27660 ++	{ PCI_VENDOR_INVERTEX, PCI_PRODUCT_INVERTEX_AEON,
27661 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27662 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7811,
27663 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27664 ++	/*
27665 ++	 * Other vendors share this PCI ID as well, such as
27666 ++	 * http://www.powercrypt.com, and obviously they also
27667 ++	 * use the same key.
27668 ++	 */
27669 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7751,
27670 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
27671 ++};
27672 ++MODULE_DEVICE_TABLE(pci, hifn_pci_tbl);
27673 ++
27674 ++static struct pci_driver hifn_driver = {
27675 ++	.name         = "hifn",
27676 ++	.id_table     = hifn_pci_tbl,
27677 ++	.probe        =	hifn_probe,
27678 ++	.remove       = hifn_remove,
27679 ++	/* add PM stuff here one day */
27680 ++};
27681 ++
27682 ++static int __init hifn_init (void)
27683 ++{
27684 ++	struct hifn_softc *sc = NULL;
27685 ++	int rc;
27686 ++
27687 ++	DPRINTF("%s(%p)\n", __FUNCTION__, hifn_init);
27688 ++
27689 ++	rc = pci_register_driver(&hifn_driver);
27690 ++	pci_register_driver_compat(&hifn_driver, rc);
27691 ++
27692 ++	return rc;
27693 ++}
27694 ++
27695 ++static void __exit hifn_exit (void)
27696 ++{
27697 ++	pci_unregister_driver(&hifn_driver);
27698 ++}
27699 ++
27700 ++module_init(hifn_init);
27701 ++module_exit(hifn_exit);
27702 ++
27703 ++MODULE_LICENSE("BSD");
27704 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
27705 ++MODULE_DESCRIPTION("OCF driver for hifn PCI crypto devices");
27706 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751reg.h linux-2.6.23.16/crypto/ocf/hifn/hifn7751reg.h
27707 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751reg.h	1969-12-31 19:00:00.000000000 -0500
27708 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifn7751reg.h	2008-02-26 09:29:13.000000000 -0500
27709 +@@ -0,0 +1,540 @@
27710 ++/* $FreeBSD: src/sys/dev/hifn/hifn7751reg.h,v 1.7 2007/03/21 03:42:49 sam Exp $ */
27711 ++/*	$OpenBSD: hifn7751reg.h,v 1.35 2002/04/08 17:49:42 jason Exp $	*/
27712 ++
27713 ++/*-
27714 ++ * Invertex AEON / Hifn 7751 driver
27715 ++ * Copyright (c) 1999 Invertex Inc. All rights reserved.
27716 ++ * Copyright (c) 1999 Theo de Raadt
27717 ++ * Copyright (c) 2000-2001 Network Security Technologies, Inc.
27718 ++ *			http://www.netsec.net
27719 ++ *
27720 ++ * Please send any comments, feedback, bug-fixes, or feature requests to
27721 ++ * software@invertex.com.
27722 ++ *
27723 ++ * Redistribution and use in source and binary forms, with or without
27724 ++ * modification, are permitted provided that the following conditions
27725 ++ * are met:
27726 ++ *
27727 ++ * 1. Redistributions of source code must retain the above copyright
27728 ++ *    notice, this list of conditions and the following disclaimer.
27729 ++ * 2. Redistributions in binary form must reproduce the above copyright
27730 ++ *    notice, this list of conditions and the following disclaimer in the
27731 ++ *    documentation and/or other materials provided with the distribution.
27732 ++ * 3. The name of the author may not be used to endorse or promote products
27733 ++ *    derived from this software without specific prior written permission.
27734 ++ *
27735 ++ *
27736 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27737 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27738 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27739 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27740 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27741 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27742 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27743 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27744 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27745 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27746 ++ *
27747 ++ * Effort sponsored in part by the Defense Advanced Research Projects
27748 ++ * Agency (DARPA) and Air Force Research Laboratory, Air Force
27749 ++ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
27750 ++ *
27751 ++ */
27752 ++#ifndef __HIFN_H__
27753 ++#define	__HIFN_H__
27754 ++
27755 ++/*
27756 ++ * Some PCI configuration space offset defines.  The names were made
27757 ++ * identical to the names used by the Linux kernel.
27758 ++ */
27759 ++#define	HIFN_BAR0		PCIR_BAR(0)	/* PUC register map */
27760 ++#define	HIFN_BAR1		PCIR_BAR(1)	/* DMA register map */
27761 ++#define	HIFN_TRDY_TIMEOUT	0x40
27762 ++#define	HIFN_RETRY_TIMEOUT	0x41
27763 ++
27764 ++/*
27765 ++ * PCI vendor and device identifiers
27766 ++ * (the names are preserved from their OpenBSD source).
27767 ++ */
27768 ++#define	PCI_VENDOR_HIFN		0x13a3		/* Hifn */
27769 ++#define	PCI_PRODUCT_HIFN_7751	0x0005		/* 7751 */
27770 ++#define	PCI_PRODUCT_HIFN_6500	0x0006		/* 6500 */
27771 ++#define	PCI_PRODUCT_HIFN_7811	0x0007		/* 7811 */
27772 ++#define	PCI_PRODUCT_HIFN_7855	0x001f		/* 7855 */
27773 ++#define	PCI_PRODUCT_HIFN_7951	0x0012		/* 7951 */
27774 ++#define	PCI_PRODUCT_HIFN_7955	0x0020		/* 7954/7955 */
27775 ++#define	PCI_PRODUCT_HIFN_7956	0x001d		/* 7956 */
27776 ++
27777 ++#define	PCI_VENDOR_INVERTEX	0x14e1		/* Invertex */
27778 ++#define	PCI_PRODUCT_INVERTEX_AEON 0x0005	/* AEON */
27779 ++
27780 ++#define	PCI_VENDOR_NETSEC	0x1660		/* NetSec */
27781 ++#define	PCI_PRODUCT_NETSEC_7751	0x7751		/* 7751 */
27782 ++
27783 ++/*
27784 ++ * The values below should multiple of 4 -- and be large enough to handle
27785 ++ * any command the driver implements.
27786 ++ *
27787 ++ * MAX_COMMAND = base command + mac command + encrypt command +
27788 ++ *			mac-key + rc4-key
27789 ++ * MAX_RESULT  = base result + mac result + mac + encrypt result
27790 ++ *			
27791 ++ *
27792 ++ */
27793 ++#define	HIFN_MAX_COMMAND	(8 + 8 + 8 + 64 + 260)
27794 ++#define	HIFN_MAX_RESULT		(8 + 4 + 20 + 4)
27795 ++
27796 ++/*
27797 ++ * hifn_desc_t
27798 ++ *
27799 ++ * Holds an individual descriptor for any of the rings.
27800 ++ */
27801 ++typedef struct hifn_desc {
27802 ++	volatile u_int32_t l;		/* length and status bits */
27803 ++	volatile u_int32_t p;
27804 ++} hifn_desc_t;
27805 ++
27806 ++/*
27807 ++ * Masks for the "length" field of struct hifn_desc.
27808 ++ */
27809 ++#define	HIFN_D_LENGTH		0x0000ffff	/* length bit mask */
27810 ++#define	HIFN_D_MASKDONEIRQ	0x02000000	/* mask the done interrupt */
27811 ++#define	HIFN_D_DESTOVER		0x04000000	/* destination overflow */
27812 ++#define	HIFN_D_OVER		0x08000000	/* overflow */
27813 ++#define	HIFN_D_LAST		0x20000000	/* last descriptor in chain */
27814 ++#define	HIFN_D_JUMP		0x40000000	/* jump descriptor */
27815 ++#define	HIFN_D_VALID		0x80000000	/* valid bit */
27816 ++
27817 ++
27818 ++/*
27819 ++ * Processing Unit Registers (offset from BASEREG0)
27820 ++ */
27821 ++#define	HIFN_0_PUDATA		0x00	/* Processing Unit Data */
27822 ++#define	HIFN_0_PUCTRL		0x04	/* Processing Unit Control */
27823 ++#define	HIFN_0_PUISR		0x08	/* Processing Unit Interrupt Status */
27824 ++#define	HIFN_0_PUCNFG		0x0c	/* Processing Unit Configuration */
27825 ++#define	HIFN_0_PUIER		0x10	/* Processing Unit Interrupt Enable */
27826 ++#define	HIFN_0_PUSTAT		0x14	/* Processing Unit Status/Chip ID */
27827 ++#define	HIFN_0_FIFOSTAT		0x18	/* FIFO Status */
27828 ++#define	HIFN_0_FIFOCNFG		0x1c	/* FIFO Configuration */
27829 ++#define	HIFN_0_PUCTRL2		0x28	/* Processing Unit Control (2nd map) */
27830 ++#define	HIFN_0_MUTE1		0x80
27831 ++#define	HIFN_0_MUTE2		0x90
27832 ++#define	HIFN_0_SPACESIZE	0x100	/* Register space size */
27833 ++
27834 ++/* Processing Unit Control Register (HIFN_0_PUCTRL) */
27835 ++#define	HIFN_PUCTRL_CLRSRCFIFO	0x0010	/* clear source fifo */
27836 ++#define	HIFN_PUCTRL_STOP	0x0008	/* stop pu */
27837 ++#define	HIFN_PUCTRL_LOCKRAM	0x0004	/* lock ram */
27838 ++#define	HIFN_PUCTRL_DMAENA	0x0002	/* enable dma */
27839 ++#define	HIFN_PUCTRL_RESET	0x0001	/* Reset processing unit */
27840 ++
27841 ++/* Processing Unit Interrupt Status Register (HIFN_0_PUISR) */
27842 ++#define	HIFN_PUISR_CMDINVAL	0x8000	/* Invalid command interrupt */
27843 ++#define	HIFN_PUISR_DATAERR	0x4000	/* Data error interrupt */
27844 ++#define	HIFN_PUISR_SRCFIFO	0x2000	/* Source FIFO ready interrupt */
27845 ++#define	HIFN_PUISR_DSTFIFO	0x1000	/* Destination FIFO ready interrupt */
27846 ++#define	HIFN_PUISR_DSTOVER	0x0200	/* Destination overrun interrupt */
27847 ++#define	HIFN_PUISR_SRCCMD	0x0080	/* Source command interrupt */
27848 ++#define	HIFN_PUISR_SRCCTX	0x0040	/* Source context interrupt */
27849 ++#define	HIFN_PUISR_SRCDATA	0x0020	/* Source data interrupt */
27850 ++#define	HIFN_PUISR_DSTDATA	0x0010	/* Destination data interrupt */
27851 ++#define	HIFN_PUISR_DSTRESULT	0x0004	/* Destination result interrupt */
27852 ++
27853 ++/* Processing Unit Configuration Register (HIFN_0_PUCNFG) */
27854 ++#define	HIFN_PUCNFG_DRAMMASK	0xe000	/* DRAM size mask */
27855 ++#define	HIFN_PUCNFG_DSZ_256K	0x0000	/* 256k dram */
27856 ++#define	HIFN_PUCNFG_DSZ_512K	0x2000	/* 512k dram */
27857 ++#define	HIFN_PUCNFG_DSZ_1M	0x4000	/* 1m dram */
27858 ++#define	HIFN_PUCNFG_DSZ_2M	0x6000	/* 2m dram */
27859 ++#define	HIFN_PUCNFG_DSZ_4M	0x8000	/* 4m dram */
27860 ++#define	HIFN_PUCNFG_DSZ_8M	0xa000	/* 8m dram */
27861 ++#define	HIFN_PUNCFG_DSZ_16M	0xc000	/* 16m dram */
27862 ++#define	HIFN_PUCNFG_DSZ_32M	0xe000	/* 32m dram */
27863 ++#define	HIFN_PUCNFG_DRAMREFRESH	0x1800	/* DRAM refresh rate mask */
27864 ++#define	HIFN_PUCNFG_DRFR_512	0x0000	/* 512 divisor of ECLK */
27865 ++#define	HIFN_PUCNFG_DRFR_256	0x0800	/* 256 divisor of ECLK */
27866 ++#define	HIFN_PUCNFG_DRFR_128	0x1000	/* 128 divisor of ECLK */
27867 ++#define	HIFN_PUCNFG_TCALLPHASES	0x0200	/* your guess is as good as mine... */
27868 ++#define	HIFN_PUCNFG_TCDRVTOTEM	0x0100	/* your guess is as good as mine... */
27869 ++#define	HIFN_PUCNFG_BIGENDIAN	0x0080	/* DMA big endian mode */
27870 ++#define	HIFN_PUCNFG_BUS32	0x0040	/* Bus width 32bits */
27871 ++#define	HIFN_PUCNFG_BUS16	0x0000	/* Bus width 16 bits */
27872 ++#define	HIFN_PUCNFG_CHIPID	0x0020	/* Allow chipid from PUSTAT */
27873 ++#define	HIFN_PUCNFG_DRAM	0x0010	/* Context RAM is DRAM */
27874 ++#define	HIFN_PUCNFG_SRAM	0x0000	/* Context RAM is SRAM */
27875 ++#define	HIFN_PUCNFG_COMPSING	0x0004	/* Enable single compression context */
27876 ++#define	HIFN_PUCNFG_ENCCNFG	0x0002	/* Encryption configuration */
27877 ++
27878 ++/* Processing Unit Interrupt Enable Register (HIFN_0_PUIER) */
27879 ++#define	HIFN_PUIER_CMDINVAL	0x8000	/* Invalid command interrupt */
27880 ++#define	HIFN_PUIER_DATAERR	0x4000	/* Data error interrupt */
27881 ++#define	HIFN_PUIER_SRCFIFO	0x2000	/* Source FIFO ready interrupt */
27882 ++#define	HIFN_PUIER_DSTFIFO	0x1000	/* Destination FIFO ready interrupt */
27883 ++#define	HIFN_PUIER_DSTOVER	0x0200	/* Destination overrun interrupt */
27884 ++#define	HIFN_PUIER_SRCCMD	0x0080	/* Source command interrupt */
27885 ++#define	HIFN_PUIER_SRCCTX	0x0040	/* Source context interrupt */
27886 ++#define	HIFN_PUIER_SRCDATA	0x0020	/* Source data interrupt */
27887 ++#define	HIFN_PUIER_DSTDATA	0x0010	/* Destination data interrupt */
27888 ++#define	HIFN_PUIER_DSTRESULT	0x0004	/* Destination result interrupt */
27889 ++
27890 ++/* Processing Unit Status Register/Chip ID (HIFN_0_PUSTAT) */
27891 ++#define	HIFN_PUSTAT_CMDINVAL	0x8000	/* Invalid command interrupt */
27892 ++#define	HIFN_PUSTAT_DATAERR	0x4000	/* Data error interrupt */
27893 ++#define	HIFN_PUSTAT_SRCFIFO	0x2000	/* Source FIFO ready interrupt */
27894 ++#define	HIFN_PUSTAT_DSTFIFO	0x1000	/* Destination FIFO ready interrupt */
27895 ++#define	HIFN_PUSTAT_DSTOVER	0x0200	/* Destination overrun interrupt */
27896 ++#define	HIFN_PUSTAT_SRCCMD	0x0080	/* Source command interrupt */
27897 ++#define	HIFN_PUSTAT_SRCCTX	0x0040	/* Source context interrupt */
27898 ++#define	HIFN_PUSTAT_SRCDATA	0x0020	/* Source data interrupt */
27899 ++#define	HIFN_PUSTAT_DSTDATA	0x0010	/* Destination data interrupt */
27900 ++#define	HIFN_PUSTAT_DSTRESULT	0x0004	/* Destination result interrupt */
27901 ++#define	HIFN_PUSTAT_CHIPREV	0x00ff	/* Chip revision mask */
27902 ++#define	HIFN_PUSTAT_CHIPENA	0xff00	/* Chip enabled mask */
27903 ++#define	HIFN_PUSTAT_ENA_2	0x1100	/* Level 2 enabled */
27904 ++#define	HIFN_PUSTAT_ENA_1	0x1000	/* Level 1 enabled */
27905 ++#define	HIFN_PUSTAT_ENA_0	0x3000	/* Level 0 enabled */
27906 ++#define	HIFN_PUSTAT_REV_2	0x0020	/* 7751 PT6/2 */
27907 ++#define	HIFN_PUSTAT_REV_3	0x0030	/* 7751 PT6/3 */
27908 ++
27909 ++/* FIFO Status Register (HIFN_0_FIFOSTAT) */
27910 ++#define	HIFN_FIFOSTAT_SRC	0x7f00	/* Source FIFO available */
27911 ++#define	HIFN_FIFOSTAT_DST	0x007f	/* Destination FIFO available */
27912 ++
27913 ++/* FIFO Configuration Register (HIFN_0_FIFOCNFG) */
27914 ++#define	HIFN_FIFOCNFG_THRESHOLD	0x0400	/* must be written as this value */
27915 ++
27916 ++/*
27917 ++ * DMA Interface Registers (offset from BASEREG1)
27918 ++ */
27919 ++#define	HIFN_1_DMA_CRAR		0x0c	/* DMA Command Ring Address */
27920 ++#define	HIFN_1_DMA_SRAR		0x1c	/* DMA Source Ring Address */
27921 ++#define	HIFN_1_DMA_RRAR		0x2c	/* DMA Result Ring Address */
27922 ++#define	HIFN_1_DMA_DRAR		0x3c	/* DMA Destination Ring Address */
27923 ++#define	HIFN_1_DMA_CSR		0x40	/* DMA Status and Control */
27924 ++#define	HIFN_1_DMA_IER		0x44	/* DMA Interrupt Enable */
27925 ++#define	HIFN_1_DMA_CNFG		0x48	/* DMA Configuration */
27926 ++#define	HIFN_1_PLL		0x4c	/* 7955/7956: PLL config */
27927 ++#define	HIFN_1_7811_RNGENA	0x60	/* 7811: rng enable */
27928 ++#define	HIFN_1_7811_RNGCFG	0x64	/* 7811: rng config */
27929 ++#define	HIFN_1_7811_RNGDAT	0x68	/* 7811: rng data */
27930 ++#define	HIFN_1_7811_RNGSTS	0x6c	/* 7811: rng status */
27931 ++#define	HIFN_1_DMA_CNFG2	0x6c	/* 7955/7956: dma config #2 */
27932 ++#define	HIFN_1_7811_MIPSRST	0x94	/* 7811: MIPS reset */
27933 ++#define	HIFN_1_REVID		0x98	/* Revision ID */
27934 ++
27935 ++#define	HIFN_1_PUB_RESET	0x204	/* Public/RNG Reset */
27936 ++#define	HIFN_1_PUB_BASE		0x300	/* Public Base Address */
27937 ++#define	HIFN_1_PUB_OPLEN	0x304	/* 7951-compat Public Operand Length */
27938 ++#define	HIFN_1_PUB_OP		0x308	/* 7951-compat Public Operand */
27939 ++#define	HIFN_1_PUB_STATUS	0x30c	/* 7951-compat Public Status */
27940 ++#define	HIFN_1_PUB_IEN		0x310	/* Public Interrupt enable */
27941 ++#define	HIFN_1_RNG_CONFIG	0x314	/* RNG config */
27942 ++#define	HIFN_1_RNG_DATA		0x318	/* RNG data */
27943 ++#define	HIFN_1_PUB_MODE		0x320	/* PK mode */
27944 ++#define	HIFN_1_PUB_FIFO_OPLEN	0x380	/* first element of oplen fifo */
27945 ++#define	HIFN_1_PUB_FIFO_OP	0x384	/* first element of op fifo */
27946 ++#define	HIFN_1_PUB_MEM		0x400	/* start of Public key memory */
27947 ++#define	HIFN_1_PUB_MEMEND	0xbff	/* end of Public key memory */
27948 ++
27949 ++/* DMA Status and Control Register (HIFN_1_DMA_CSR) */
27950 ++#define	HIFN_DMACSR_D_CTRLMASK	0xc0000000	/* Destinition Ring Control */
27951 ++#define	HIFN_DMACSR_D_CTRL_NOP	0x00000000	/* Dest. Control: no-op */
27952 ++#define	HIFN_DMACSR_D_CTRL_DIS	0x40000000	/* Dest. Control: disable */
27953 ++#define	HIFN_DMACSR_D_CTRL_ENA	0x80000000	/* Dest. Control: enable */
27954 ++#define	HIFN_DMACSR_D_ABORT	0x20000000	/* Destinition Ring PCIAbort */
27955 ++#define	HIFN_DMACSR_D_DONE	0x10000000	/* Destinition Ring Done */
27956 ++#define	HIFN_DMACSR_D_LAST	0x08000000	/* Destinition Ring Last */
27957 ++#define	HIFN_DMACSR_D_WAIT	0x04000000	/* Destinition Ring Waiting */
27958 ++#define	HIFN_DMACSR_D_OVER	0x02000000	/* Destinition Ring Overflow */
27959 ++#define	HIFN_DMACSR_R_CTRL	0x00c00000	/* Result Ring Control */
27960 ++#define	HIFN_DMACSR_R_CTRL_NOP	0x00000000	/* Result Control: no-op */
27961 ++#define	HIFN_DMACSR_R_CTRL_DIS	0x00400000	/* Result Control: disable */
27962 ++#define	HIFN_DMACSR_R_CTRL_ENA	0x00800000	/* Result Control: enable */
27963 ++#define	HIFN_DMACSR_R_ABORT	0x00200000	/* Result Ring PCI Abort */
27964 ++#define	HIFN_DMACSR_R_DONE	0x00100000	/* Result Ring Done */
27965 ++#define	HIFN_DMACSR_R_LAST	0x00080000	/* Result Ring Last */
27966 ++#define	HIFN_DMACSR_R_WAIT	0x00040000	/* Result Ring Waiting */
27967 ++#define	HIFN_DMACSR_R_OVER	0x00020000	/* Result Ring Overflow */
27968 ++#define	HIFN_DMACSR_S_CTRL	0x0000c000	/* Source Ring Control */
27969 ++#define	HIFN_DMACSR_S_CTRL_NOP	0x00000000	/* Source Control: no-op */
27970 ++#define	HIFN_DMACSR_S_CTRL_DIS	0x00004000	/* Source Control: disable */
27971 ++#define	HIFN_DMACSR_S_CTRL_ENA	0x00008000	/* Source Control: enable */
27972 ++#define	HIFN_DMACSR_S_ABORT	0x00002000	/* Source Ring PCI Abort */
27973 ++#define	HIFN_DMACSR_S_DONE	0x00001000	/* Source Ring Done */
27974 ++#define	HIFN_DMACSR_S_LAST	0x00000800	/* Source Ring Last */
27975 ++#define	HIFN_DMACSR_S_WAIT	0x00000400	/* Source Ring Waiting */
27976 ++#define	HIFN_DMACSR_ILLW	0x00000200	/* Illegal write (7811 only) */
27977 ++#define	HIFN_DMACSR_ILLR	0x00000100	/* Illegal read (7811 only) */
27978 ++#define	HIFN_DMACSR_C_CTRL	0x000000c0	/* Command Ring Control */
27979 ++#define	HIFN_DMACSR_C_CTRL_NOP	0x00000000	/* Command Control: no-op */
27980 ++#define	HIFN_DMACSR_C_CTRL_DIS	0x00000040	/* Command Control: disable */
27981 ++#define	HIFN_DMACSR_C_CTRL_ENA	0x00000080	/* Command Control: enable */
27982 ++#define	HIFN_DMACSR_C_ABORT	0x00000020	/* Command Ring PCI Abort */
27983 ++#define	HIFN_DMACSR_C_DONE	0x00000010	/* Command Ring Done */
27984 ++#define	HIFN_DMACSR_C_LAST	0x00000008	/* Command Ring Last */
27985 ++#define	HIFN_DMACSR_C_WAIT	0x00000004	/* Command Ring Waiting */
27986 ++#define	HIFN_DMACSR_PUBDONE	0x00000002	/* Public op done (7951 only) */
27987 ++#define	HIFN_DMACSR_ENGINE	0x00000001	/* Command Ring Engine IRQ */
27988 ++
27989 ++/* DMA Interrupt Enable Register (HIFN_1_DMA_IER) */
27990 ++#define	HIFN_DMAIER_D_ABORT	0x20000000	/* Destination Ring PCIAbort */
27991 ++#define	HIFN_DMAIER_D_DONE	0x10000000	/* Destination Ring Done */
27992 ++#define	HIFN_DMAIER_D_LAST	0x08000000	/* Destination Ring Last */
27993 ++#define	HIFN_DMAIER_D_WAIT	0x04000000	/* Destination Ring Waiting */
27994 ++#define	HIFN_DMAIER_D_OVER	0x02000000	/* Destination Ring Overflow */
27995 ++#define	HIFN_DMAIER_R_ABORT	0x00200000	/* Result Ring PCI Abort */
27996 ++#define	HIFN_DMAIER_R_DONE	0x00100000	/* Result Ring Done */
27997 ++#define	HIFN_DMAIER_R_LAST	0x00080000	/* Result Ring Last */
27998 ++#define	HIFN_DMAIER_R_WAIT	0x00040000	/* Result Ring Waiting */
27999 ++#define	HIFN_DMAIER_R_OVER	0x00020000	/* Result Ring Overflow */
28000 ++#define	HIFN_DMAIER_S_ABORT	0x00002000	/* Source Ring PCI Abort */
28001 ++#define	HIFN_DMAIER_S_DONE	0x00001000	/* Source Ring Done */
28002 ++#define	HIFN_DMAIER_S_LAST	0x00000800	/* Source Ring Last */
28003 ++#define	HIFN_DMAIER_S_WAIT	0x00000400	/* Source Ring Waiting */
28004 ++#define	HIFN_DMAIER_ILLW	0x00000200	/* Illegal write (7811 only) */
28005 ++#define	HIFN_DMAIER_ILLR	0x00000100	/* Illegal read (7811 only) */
28006 ++#define	HIFN_DMAIER_C_ABORT	0x00000020	/* Command Ring PCI Abort */
28007 ++#define	HIFN_DMAIER_C_DONE	0x00000010	/* Command Ring Done */
28008 ++#define	HIFN_DMAIER_C_LAST	0x00000008	/* Command Ring Last */
28009 ++#define	HIFN_DMAIER_C_WAIT	0x00000004	/* Command Ring Waiting */
28010 ++#define	HIFN_DMAIER_PUBDONE	0x00000002	/* public op done (7951 only) */
28011 ++#define	HIFN_DMAIER_ENGINE	0x00000001	/* Engine IRQ */
28012 ++
28013 ++/* DMA Configuration Register (HIFN_1_DMA_CNFG) */
28014 ++#define	HIFN_DMACNFG_BIGENDIAN	0x10000000	/* big endian mode */
28015 ++#define	HIFN_DMACNFG_POLLFREQ	0x00ff0000	/* Poll frequency mask */
28016 ++#define	HIFN_DMACNFG_UNLOCK	0x00000800
28017 ++#define	HIFN_DMACNFG_POLLINVAL	0x00000700	/* Invalid Poll Scalar */
28018 ++#define	HIFN_DMACNFG_LAST	0x00000010	/* Host control LAST bit */
28019 ++#define	HIFN_DMACNFG_MODE	0x00000004	/* DMA mode */
28020 ++#define	HIFN_DMACNFG_DMARESET	0x00000002	/* DMA Reset # */
28021 ++#define	HIFN_DMACNFG_MSTRESET	0x00000001	/* Master Reset # */
28022 ++
28023 ++/* DMA Configuration Register (HIFN_1_DMA_CNFG2) */
28024 ++#define	HIFN_DMACNFG2_PKSWAP32	(1 << 19)	/* swap the OPLEN/OP reg */
28025 ++#define	HIFN_DMACNFG2_PKSWAP8	(1 << 18)	/* swap the bits of OPLEN/OP */
28026 ++#define	HIFN_DMACNFG2_BAR0_SWAP32 (1<<17)	/* swap the bytes of BAR0 */
28027 ++#define	HIFN_DMACNFG2_BAR1_SWAP8 (1<<16)	/* swap the bits  of BAR0 */
28028 ++#define	HIFN_DMACNFG2_INIT_WRITE_BURST_SHIFT 12
28029 ++#define	HIFN_DMACNFG2_INIT_READ_BURST_SHIFT 8
28030 ++#define	HIFN_DMACNFG2_TGT_WRITE_BURST_SHIFT 4
28031 ++#define	HIFN_DMACNFG2_TGT_READ_BURST_SHIFT  0
28032 ++
28033 ++/* 7811 RNG Enable Register (HIFN_1_7811_RNGENA) */
28034 ++#define	HIFN_7811_RNGENA_ENA	0x00000001	/* enable RNG */
28035 ++
28036 ++/* 7811 RNG Config Register (HIFN_1_7811_RNGCFG) */
28037 ++#define	HIFN_7811_RNGCFG_PRE1	0x00000f00	/* first prescalar */
28038 ++#define	HIFN_7811_RNGCFG_OPRE	0x00000080	/* output prescalar */
28039 ++#define	HIFN_7811_RNGCFG_DEFL	0x00000f80	/* 2 words/ 1/100 sec */
28040 ++
28041 ++/* 7811 RNG Status Register (HIFN_1_7811_RNGSTS) */
28042 ++#define	HIFN_7811_RNGSTS_RDY	0x00004000	/* two numbers in FIFO */
28043 ++#define	HIFN_7811_RNGSTS_UFL	0x00001000	/* rng underflow */
28044 ++
28045 ++/* 7811 MIPS Reset Register (HIFN_1_7811_MIPSRST) */
28046 ++#define	HIFN_MIPSRST_BAR2SIZE	0xffff0000	/* sdram size */
28047 ++#define	HIFN_MIPSRST_GPRAMINIT	0x00008000	/* gpram can be accessed */
28048 ++#define	HIFN_MIPSRST_CRAMINIT	0x00004000	/* ctxram can be accessed */
28049 ++#define	HIFN_MIPSRST_LED2	0x00000400	/* external LED2 */
28050 ++#define	HIFN_MIPSRST_LED1	0x00000200	/* external LED1 */
28051 ++#define	HIFN_MIPSRST_LED0	0x00000100	/* external LED0 */
28052 ++#define	HIFN_MIPSRST_MIPSDIS	0x00000004	/* disable MIPS */
28053 ++#define	HIFN_MIPSRST_MIPSRST	0x00000002	/* warm reset MIPS */
28054 ++#define	HIFN_MIPSRST_MIPSCOLD	0x00000001	/* cold reset MIPS */
28055 ++
28056 ++/* Public key reset register (HIFN_1_PUB_RESET) */
28057 ++#define	HIFN_PUBRST_RESET	0x00000001	/* reset public/rng unit */
28058 ++
28059 ++/* Public operation register (HIFN_1_PUB_OP) */
28060 ++#define	HIFN_PUBOP_AOFFSET	0x0000003e	/* A offset */
28061 ++#define	HIFN_PUBOP_BOFFSET	0x00000fc0	/* B offset */
28062 ++#define	HIFN_PUBOP_MOFFSET	0x0003f000	/* M offset */
28063 ++#define	HIFN_PUBOP_OP_MASK	0x003c0000	/* Opcode: */
28064 ++#define	HIFN_PUBOP_OP_NOP	0x00000000	/*  NOP */
28065 ++#define	HIFN_PUBOP_OP_ADD	0x00040000	/*  ADD */
28066 ++#define	HIFN_PUBOP_OP_ADDC	0x00080000	/*  ADD w/carry */
28067 ++#define	HIFN_PUBOP_OP_SUB	0x000c0000	/*  SUB */
28068 ++#define	HIFN_PUBOP_OP_SUBC	0x00100000	/*  SUB w/carry */
28069 ++#define	HIFN_PUBOP_OP_MODADD	0x00140000	/*  Modular ADD */
28070 ++#define	HIFN_PUBOP_OP_MODSUB	0x00180000	/*  Modular SUB */
28071 ++#define	HIFN_PUBOP_OP_INCA	0x001c0000	/*  INC A */
28072 ++#define	HIFN_PUBOP_OP_DECA	0x00200000	/*  DEC A */
28073 ++#define	HIFN_PUBOP_OP_MULT	0x00240000	/*  MULT */
28074 ++#define	HIFN_PUBOP_OP_MODMULT	0x00280000	/*  Modular MULT */
28075 ++#define	HIFN_PUBOP_OP_MODRED	0x002c0000	/*  Modular Red */
28076 ++#define	HIFN_PUBOP_OP_MODEXP	0x00300000	/*  Modular Exp */
28077 ++
28078 ++/* Public operand length register (HIFN_1_PUB_OPLEN) */
28079 ++#define	HIFN_PUBOPLEN_MODLEN	0x0000007f
28080 ++#define	HIFN_PUBOPLEN_EXPLEN	0x0003ff80
28081 ++#define	HIFN_PUBOPLEN_REDLEN	0x003c0000
28082 ++
28083 ++/* Public status register (HIFN_1_PUB_STATUS) */
28084 ++#define	HIFN_PUBSTS_DONE	0x00000001	/* operation done */
28085 ++#define	HIFN_PUBSTS_CARRY	0x00000002	/* carry */
28086 ++#define	HIFN_PUBSTS_FIFO_EMPTY	0x00000100	/* fifo empty */
28087 ++#define	HIFN_PUBSTS_FIFO_FULL	0x00000200	/* fifo full */
28088 ++#define	HIFN_PUBSTS_FIFO_OVFL	0x00000400	/* fifo overflow */
28089 ++#define	HIFN_PUBSTS_FIFO_WRITE	0x000f0000	/* fifo write */
28090 ++#define	HIFN_PUBSTS_FIFO_READ	0x0f000000	/* fifo read */
28091 ++
28092 ++/* Public interrupt enable register (HIFN_1_PUB_IEN) */
28093 ++#define	HIFN_PUBIEN_DONE	0x00000001	/* operation done interrupt */
28094 ++
28095 ++/* Random number generator config register (HIFN_1_RNG_CONFIG) */
28096 ++#define	HIFN_RNGCFG_ENA		0x00000001	/* enable rng */
28097 ++
28098 ++/*
28099 ++ * Register offsets in register set 1
28100 ++ */
28101 ++
28102 ++#define	HIFN_UNLOCK_SECRET1	0xf4
28103 ++#define	HIFN_UNLOCK_SECRET2	0xfc
28104 ++
28105 ++/*
28106 ++ * PLL config register
28107 ++ *
28108 ++ * This register is present only on 7954/7955/7956 parts. It must be
28109 ++ * programmed according to the bus interface method used by the h/w.
28110 ++ * Note that the parts require a stable clock.  Since the PCI clock
28111 ++ * may vary the reference clock must usually be used.  To avoid
28112 ++ * overclocking the core logic, setup must be done carefully, refer
28113 ++ * to the driver for details.  The exact multiplier required varies
28114 ++ * by part and system configuration; refer to the Hifn documentation.
28115 ++ */
28116 ++#define	HIFN_PLL_REF_SEL	0x00000001	/* REF/HBI clk selection */
28117 ++#define	HIFN_PLL_BP		0x00000002	/* bypass (used during setup) */
28118 ++/* bit 2 reserved */
28119 ++#define	HIFN_PLL_PK_CLK_SEL	0x00000008	/* public key clk select */
28120 ++#define	HIFN_PLL_PE_CLK_SEL	0x00000010	/* packet engine clk select */
28121 ++/* bits 5-9 reserved */
28122 ++#define	HIFN_PLL_MBSET		0x00000400	/* must be set to 1 */
28123 ++#define	HIFN_PLL_ND		0x00003800	/* Fpll_ref multiplier select */
28124 ++#define	HIFN_PLL_ND_SHIFT	11
28125 ++#define	HIFN_PLL_ND_2		0x00000000	/* 2x */
28126 ++#define	HIFN_PLL_ND_4		0x00000800	/* 4x */
28127 ++#define	HIFN_PLL_ND_6		0x00001000	/* 6x */
28128 ++#define	HIFN_PLL_ND_8		0x00001800	/* 8x */
28129 ++#define	HIFN_PLL_ND_10		0x00002000	/* 10x */
28130 ++#define	HIFN_PLL_ND_12		0x00002800	/* 12x */
28131 ++/* bits 14-15 reserved */
28132 ++#define	HIFN_PLL_IS		0x00010000	/* charge pump current select */
28133 ++/* bits 17-31 reserved */
28134 ++
28135 ++/*
28136 ++ * Board configuration specifies only these bits.
28137 ++ */
28138 ++#define	HIFN_PLL_CONFIG		(HIFN_PLL_IS|HIFN_PLL_ND|HIFN_PLL_REF_SEL)
28139 ++
28140 ++/*
28141 ++ * Public Key Engine Mode Register
28142 ++ */
28143 ++#define	HIFN_PKMODE_HOSTINVERT	(1 << 0)	/* HOST INVERT */
28144 ++#define	HIFN_PKMODE_ENHANCED	(1 << 1)	/* Enable enhanced mode */
28145 ++
28146 ++
28147 ++/*********************************************************************
28148 ++ * Structs for board commands 
28149 ++ *
28150 ++ *********************************************************************/
28151 ++
28152 ++/*
28153 ++ * Structure to help build up the command data structure.
28154 ++ */
28155 ++typedef struct hifn_base_command {
28156 ++	volatile u_int16_t masks;
28157 ++	volatile u_int16_t session_num;
28158 ++	volatile u_int16_t total_source_count;
28159 ++	volatile u_int16_t total_dest_count;
28160 ++} hifn_base_command_t;
28161 ++
28162 ++#define	HIFN_BASE_CMD_MAC		0x0400
28163 ++#define	HIFN_BASE_CMD_CRYPT		0x0800
28164 ++#define	HIFN_BASE_CMD_DECODE		0x2000
28165 ++#define	HIFN_BASE_CMD_SRCLEN_M		0xc000
28166 ++#define	HIFN_BASE_CMD_SRCLEN_S		14
28167 ++#define	HIFN_BASE_CMD_DSTLEN_M		0x3000
28168 ++#define	HIFN_BASE_CMD_DSTLEN_S		12
28169 ++#define	HIFN_BASE_CMD_LENMASK_HI	0x30000
28170 ++#define	HIFN_BASE_CMD_LENMASK_LO	0x0ffff
28171 ++
28172 ++/*
28173 ++ * Structure to help build up the command data structure.
28174 ++ */
28175 ++typedef struct hifn_crypt_command {
28176 ++	volatile u_int16_t masks;
28177 ++	volatile u_int16_t header_skip;
28178 ++	volatile u_int16_t source_count;
28179 ++	volatile u_int16_t reserved;
28180 ++} hifn_crypt_command_t;
28181 ++
28182 ++#define	HIFN_CRYPT_CMD_ALG_MASK		0x0003		/* algorithm: */
28183 ++#define	HIFN_CRYPT_CMD_ALG_DES		0x0000		/*   DES */
28184 ++#define	HIFN_CRYPT_CMD_ALG_3DES		0x0001		/*   3DES */
28185 ++#define	HIFN_CRYPT_CMD_ALG_RC4		0x0002		/*   RC4 */
28186 ++#define	HIFN_CRYPT_CMD_ALG_AES		0x0003		/*   AES */
28187 ++#define	HIFN_CRYPT_CMD_MODE_MASK	0x0018		/* Encrypt mode: */
28188 ++#define	HIFN_CRYPT_CMD_MODE_ECB		0x0000		/*   ECB */
28189 ++#define	HIFN_CRYPT_CMD_MODE_CBC		0x0008		/*   CBC */
28190 ++#define	HIFN_CRYPT_CMD_MODE_CFB		0x0010		/*   CFB */
28191 ++#define	HIFN_CRYPT_CMD_MODE_OFB		0x0018		/*   OFB */
28192 ++#define	HIFN_CRYPT_CMD_CLR_CTX		0x0040		/* clear context */
28193 ++#define	HIFN_CRYPT_CMD_NEW_KEY		0x0800		/* expect new key */
28194 ++#define	HIFN_CRYPT_CMD_NEW_IV		0x1000		/* expect new iv */
28195 ++
28196 ++#define	HIFN_CRYPT_CMD_SRCLEN_M		0xc000
28197 ++#define	HIFN_CRYPT_CMD_SRCLEN_S		14
28198 ++
28199 ++#define	HIFN_CRYPT_CMD_KSZ_MASK		0x0600		/* AES key size: */
28200 ++#define	HIFN_CRYPT_CMD_KSZ_128		0x0000		/*   128 bit */
28201 ++#define	HIFN_CRYPT_CMD_KSZ_192		0x0200		/*   192 bit */
28202 ++#define	HIFN_CRYPT_CMD_KSZ_256		0x0400		/*   256 bit */
28203 ++
28204 ++/*
28205 ++ * Structure to help build up the command data structure.
28206 ++ */
28207 ++typedef struct hifn_mac_command {
28208 ++	volatile u_int16_t masks;
28209 ++	volatile u_int16_t header_skip;
28210 ++	volatile u_int16_t source_count;
28211 ++	volatile u_int16_t reserved;
28212 ++} hifn_mac_command_t;
28213 ++
28214 ++#define	HIFN_MAC_CMD_ALG_MASK		0x0001
28215 ++#define	HIFN_MAC_CMD_ALG_SHA1		0x0000
28216 ++#define	HIFN_MAC_CMD_ALG_MD5		0x0001
28217 ++#define	HIFN_MAC_CMD_MODE_MASK		0x000c
28218 ++#define	HIFN_MAC_CMD_MODE_HMAC		0x0000
28219 ++#define	HIFN_MAC_CMD_MODE_SSL_MAC	0x0004
28220 ++#define	HIFN_MAC_CMD_MODE_HASH		0x0008
28221 ++#define	HIFN_MAC_CMD_MODE_FULL		0x0004
28222 ++#define	HIFN_MAC_CMD_TRUNC		0x0010
28223 ++#define	HIFN_MAC_CMD_RESULT		0x0020
28224 ++#define	HIFN_MAC_CMD_APPEND		0x0040
28225 ++#define	HIFN_MAC_CMD_SRCLEN_M		0xc000
28226 ++#define	HIFN_MAC_CMD_SRCLEN_S		14
28227 ++
28228 ++/*
28229 ++ * MAC POS IPsec initiates authentication after encryption on encodes
28230 ++ * and before decryption on decodes.
28231 ++ */
28232 ++#define	HIFN_MAC_CMD_POS_IPSEC		0x0200
28233 ++#define	HIFN_MAC_CMD_NEW_KEY		0x0800
28234 ++
28235 ++/*
28236 ++ * The poll frequency and poll scalar defines are unshifted values used
28237 ++ * to set fields in the DMA Configuration Register.
28238 ++ */
28239 ++#ifndef HIFN_POLL_FREQUENCY
28240 ++#define	HIFN_POLL_FREQUENCY	0x1
28241 ++#endif
28242 ++
28243 ++#ifndef HIFN_POLL_SCALAR
28244 ++#define	HIFN_POLL_SCALAR	0x0
28245 ++#endif
28246 ++
28247 ++#define	HIFN_MAX_SEGLEN 	0xffff		/* maximum dma segment len */
28248 ++#define	HIFN_MAX_DMALEN		0x3ffff		/* maximum dma length */
28249 ++#endif /* __HIFN_H__ */
28250 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751var.h linux-2.6.23.16/crypto/ocf/hifn/hifn7751var.h
28251 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifn7751var.h	1969-12-31 19:00:00.000000000 -0500
28252 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifn7751var.h	2008-02-26 09:29:13.000000000 -0500
28253 +@@ -0,0 +1,369 @@
28254 ++/* $FreeBSD: src/sys/dev/hifn/hifn7751var.h,v 1.9 2007/03/21 03:42:49 sam Exp $ */
28255 ++/*	$OpenBSD: hifn7751var.h,v 1.42 2002/04/08 17:49:42 jason Exp $	*/
28256 ++
28257 ++/*-
28258 ++ * Invertex AEON / Hifn 7751 driver
28259 ++ * Copyright (c) 1999 Invertex Inc. All rights reserved.
28260 ++ * Copyright (c) 1999 Theo de Raadt
28261 ++ * Copyright (c) 2000-2001 Network Security Technologies, Inc.
28262 ++ *			http://www.netsec.net
28263 ++ *
28264 ++ * Please send any comments, feedback, bug-fixes, or feature requests to
28265 ++ * software@invertex.com.
28266 ++ *
28267 ++ * Redistribution and use in source and binary forms, with or without
28268 ++ * modification, are permitted provided that the following conditions
28269 ++ * are met:
28270 ++ *
28271 ++ * 1. Redistributions of source code must retain the above copyright
28272 ++ *    notice, this list of conditions and the following disclaimer.
28273 ++ * 2. Redistributions in binary form must reproduce the above copyright
28274 ++ *    notice, this list of conditions and the following disclaimer in the
28275 ++ *    documentation and/or other materials provided with the distribution.
28276 ++ * 3. The name of the author may not be used to endorse or promote products
28277 ++ *    derived from this software without specific prior written permission.
28278 ++ *
28279 ++ *
28280 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28281 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28282 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28283 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28284 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28285 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28286 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28287 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28288 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28289 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28290 ++ *
28291 ++ * Effort sponsored in part by the Defense Advanced Research Projects
28292 ++ * Agency (DARPA) and Air Force Research Laboratory, Air Force
28293 ++ * Materiel Command, USAF, under agreement number F30602-01-2-0537.
28294 ++ *
28295 ++ */
28296 ++
28297 ++#ifndef __HIFN7751VAR_H__
28298 ++#define __HIFN7751VAR_H__
28299 ++
28300 ++#ifdef __KERNEL__
28301 ++
28302 ++/*
28303 ++ * Some configurable values for the driver.  By default command+result
28304 ++ * descriptor rings are the same size.  The src+dst descriptor rings
28305 ++ * are sized at 3.5x the number of potential commands.  Slower parts
28306 ++ * (e.g. 7951) tend to run out of src descriptors; faster parts (7811)
28307 ++ * src+cmd/result descriptors.  It's not clear that increasing the size
28308 ++ * of the descriptor rings helps performance significantly as other
28309 ++ * factors tend to come into play (e.g. copying misaligned packets).
28310 ++ */
28311 ++#define	HIFN_D_CMD_RSIZE	24	/* command descriptors */
28312 ++#define	HIFN_D_SRC_RSIZE	((HIFN_D_CMD_RSIZE * 7) / 2)	/* source descriptors */
28313 ++#define	HIFN_D_RES_RSIZE	HIFN_D_CMD_RSIZE	/* result descriptors */
28314 ++#define	HIFN_D_DST_RSIZE	HIFN_D_SRC_RSIZE	/* destination descriptors */
28315 ++
28316 ++/*
28317 ++ *  Length values for cryptography
28318 ++ */
28319 ++#define HIFN_DES_KEY_LENGTH		8
28320 ++#define HIFN_3DES_KEY_LENGTH		24
28321 ++#define HIFN_MAX_CRYPT_KEY_LENGTH	HIFN_3DES_KEY_LENGTH
28322 ++#define HIFN_IV_LENGTH			8
28323 ++#define	HIFN_AES_IV_LENGTH		16
28324 ++#define HIFN_MAX_IV_LENGTH		HIFN_AES_IV_LENGTH
28325 ++
28326 ++/*
28327 ++ *  Length values for authentication
28328 ++ */
28329 ++#define HIFN_MAC_KEY_LENGTH		64
28330 ++#define HIFN_MD5_LENGTH			16
28331 ++#define HIFN_SHA1_LENGTH		20
28332 ++#define HIFN_MAC_TRUNC_LENGTH		12
28333 ++
28334 ++#define MAX_SCATTER 64
28335 ++
28336 ++/*
28337 ++ * Data structure to hold all 4 rings and any other ring related data.
28338 ++ */
28339 ++struct hifn_dma {
28340 ++	/*
28341 ++	 *  Descriptor rings.  We add +1 to the size to accomidate the
28342 ++	 *  jump descriptor.
28343 ++	 */
28344 ++	struct hifn_desc	cmdr[HIFN_D_CMD_RSIZE+1];
28345 ++	struct hifn_desc	srcr[HIFN_D_SRC_RSIZE+1];
28346 ++	struct hifn_desc	dstr[HIFN_D_DST_RSIZE+1];
28347 ++	struct hifn_desc	resr[HIFN_D_RES_RSIZE+1];
28348 ++
28349 ++	struct hifn_command	*hifn_commands[HIFN_D_RES_RSIZE];
28350 ++
28351 ++	u_char			command_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_COMMAND];
28352 ++	u_char			result_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_RESULT];
28353 ++	u_int32_t		slop[HIFN_D_CMD_RSIZE];
28354 ++
28355 ++	u_int64_t		test_src, test_dst;
28356 ++
28357 ++	/*
28358 ++	 *  Our current positions for insertion and removal from the desriptor
28359 ++	 *  rings. 
28360 ++	 */
28361 ++	int			cmdi, srci, dsti, resi;
28362 ++	volatile int		cmdu, srcu, dstu, resu;
28363 ++	int			cmdk, srck, dstk, resk;
28364 ++};
28365 ++
28366 ++struct hifn_session {
28367 ++	int hs_used;
28368 ++	int hs_mlen;
28369 ++	u_int8_t hs_iv[HIFN_MAX_IV_LENGTH];
28370 ++};
28371 ++
28372 ++#define	HIFN_RING_SYNC(sc, r, i, f)					\
28373 ++	/* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
28374 ++
28375 ++#define	HIFN_CMDR_SYNC(sc, i, f)	HIFN_RING_SYNC((sc), cmdr, (i), (f))
28376 ++#define	HIFN_RESR_SYNC(sc, i, f)	HIFN_RING_SYNC((sc), resr, (i), (f))
28377 ++#define	HIFN_SRCR_SYNC(sc, i, f)	HIFN_RING_SYNC((sc), srcr, (i), (f))
28378 ++#define	HIFN_DSTR_SYNC(sc, i, f)	HIFN_RING_SYNC((sc), dstr, (i), (f))
28379 ++
28380 ++#define	HIFN_CMD_SYNC(sc, i, f)						\
28381 ++	/* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
28382 ++
28383 ++#define	HIFN_RES_SYNC(sc, i, f)						\
28384 ++	/* DAVIDM bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap, (f)) */
28385 ++
28386 ++typedef int bus_size_t;
28387 ++
28388 ++/*
28389 ++ * Holds data specific to a single HIFN board.
28390 ++ */
28391 ++struct hifn_softc {
28392 ++	softc_device_decl		 sc_dev;
28393 ++
28394 ++	struct pci_dev		*sc_pcidev;	/* PCI device pointer */
28395 ++	spinlock_t		sc_mtx;		/* per-instance lock */
28396 ++
28397 ++	int			sc_num;		/* for multiple devs */
28398 ++
28399 ++	ocf_iomem_t		sc_bar0;
28400 ++	bus_size_t		sc_bar0_lastreg;/* bar0 last reg written */
28401 ++	ocf_iomem_t		sc_bar1;
28402 ++	bus_size_t		sc_bar1_lastreg;/* bar1 last reg written */
28403 ++
28404 ++	int			sc_irq;
28405 ++
28406 ++	u_int32_t		sc_dmaier;
28407 ++	u_int32_t		sc_drammodel;	/* 1=dram, 0=sram */
28408 ++	u_int32_t		sc_pllconfig;	/* 7954/7955/7956 PLL config */
28409 ++
28410 ++	struct hifn_dma		*sc_dma;
28411 ++	dma_addr_t		sc_dma_physaddr;/* physical address of sc_dma */
28412 ++
28413 ++	int			sc_dmansegs;
28414 ++	int32_t			sc_cid;
28415 ++	int			sc_maxses;
28416 ++	int			sc_nsessions;
28417 ++	struct hifn_session	*sc_sessions;
28418 ++	int			sc_ramsize;
28419 ++	int			sc_flags;
28420 ++#define	HIFN_HAS_RNG		0x1	/* includes random number generator */
28421 ++#define	HIFN_HAS_PUBLIC		0x2	/* includes public key support */
28422 ++#define	HIFN_HAS_AES		0x4	/* includes AES support */
28423 ++#define	HIFN_IS_7811		0x8	/* Hifn 7811 part */
28424 ++#define	HIFN_IS_7956		0x10	/* Hifn 7956/7955 don't have SDRAM */
28425 ++
28426 ++	struct timer_list	sc_tickto;	/* for managing DMA */
28427 ++
28428 ++	int			sc_rngfirst;
28429 ++	int			sc_rnghz;	/* RNG polling frequency */
28430 ++
28431 ++	int			sc_c_busy;	/* command ring busy */
28432 ++	int			sc_s_busy;	/* source data ring busy */
28433 ++	int			sc_d_busy;	/* destination data ring busy */
28434 ++	int			sc_r_busy;	/* result ring busy */
28435 ++	int			sc_active;	/* for initial countdown */
28436 ++	int			sc_needwakeup;	/* ops q'd wating on resources */
28437 ++	int			sc_curbatch;	/* # ops submitted w/o int */
28438 ++	int			sc_suspended;
28439 ++#ifdef HIFN_VULCANDEV
28440 ++	struct cdev            *sc_pkdev;
28441 ++#endif
28442 ++};
28443 ++
28444 ++#define	HIFN_LOCK(_sc)		spin_lock_irqsave(&(_sc)->sc_mtx, l_flags)
28445 ++#define	HIFN_UNLOCK(_sc)	spin_unlock_irqrestore(&(_sc)->sc_mtx, l_flags)
28446 ++
28447 ++/*
28448 ++ *  hifn_command_t
28449 ++ *
28450 ++ *  This is the control structure used to pass commands to hifn_encrypt().
28451 ++ *
28452 ++ *  flags
28453 ++ *  -----
28454 ++ *  Flags is the bitwise "or" values for command configuration.  A single
28455 ++ *  encrypt direction needs to be set:
28456 ++ *
28457 ++ *	HIFN_ENCODE or HIFN_DECODE
28458 ++ *
28459 ++ *  To use cryptography, a single crypto algorithm must be included:
28460 ++ *
28461 ++ *	HIFN_CRYPT_3DES or HIFN_CRYPT_DES
28462 ++ *
28463 ++ *  To use authentication is used, a single MAC algorithm must be included:
28464 ++ *
28465 ++ *	HIFN_MAC_MD5 or HIFN_MAC_SHA1
28466 ++ *
28467 ++ *  By default MD5 uses a 16 byte hash and SHA-1 uses a 20 byte hash.
28468 ++ *  If the value below is set, hash values are truncated or assumed
28469 ++ *  truncated to 12 bytes:
28470 ++ *
28471 ++ *	HIFN_MAC_TRUNC
28472 ++ *
28473 ++ *  Keys for encryption and authentication can be sent as part of a command,
28474 ++ *  or the last key value used with a particular session can be retrieved
28475 ++ *  and used again if either of these flags are not specified.
28476 ++ *
28477 ++ *	HIFN_CRYPT_NEW_KEY, HIFN_MAC_NEW_KEY
28478 ++ *
28479 ++ *  session_num
28480 ++ *  -----------
28481 ++ *  A number between 0 and 2048 (for DRAM models) or a number between 
28482 ++ *  0 and 768 (for SRAM models).  Those who don't want to use session
28483 ++ *  numbers should leave value at zero and send a new crypt key and/or
28484 ++ *  new MAC key on every command.  If you use session numbers and
28485 ++ *  don't send a key with a command, the last key sent for that same
28486 ++ *  session number will be used.
28487 ++ *
28488 ++ *  Warning:  Using session numbers and multiboard at the same time
28489 ++ *            is currently broken.
28490 ++ *
28491 ++ *  mbuf
28492 ++ *  ----
28493 ++ *  Either fill in the mbuf pointer and npa=0 or
28494 ++ *	 fill packp[] and packl[] and set npa to > 0
28495 ++ * 
28496 ++ *  mac_header_skip
28497 ++ *  ---------------
28498 ++ *  The number of bytes of the source_buf that are skipped over before
28499 ++ *  authentication begins.  This must be a number between 0 and 2^16-1
28500 ++ *  and can be used by IPsec implementers to skip over IP headers.
28501 ++ *  *** Value ignored if authentication not used ***
28502 ++ *
28503 ++ *  crypt_header_skip
28504 ++ *  -----------------
28505 ++ *  The number of bytes of the source_buf that are skipped over before
28506 ++ *  the cryptographic operation begins.  This must be a number between 0
28507 ++ *  and 2^16-1.  For IPsec, this number will always be 8 bytes larger
28508 ++ *  than the auth_header_skip (to skip over the ESP header).
28509 ++ *  *** Value ignored if cryptography not used ***
28510 ++ *
28511 ++ */
28512 ++struct hifn_operand {
28513 ++	union {
28514 ++		struct sk_buff *skb;
28515 ++		struct uio *io;
28516 ++		unsigned char *buf;
28517 ++	} u;
28518 ++	void		*map;
28519 ++	bus_size_t	mapsize;
28520 ++	int		nsegs;
28521 ++	struct {
28522 ++	    dma_addr_t  ds_addr;
28523 ++	    int         ds_len;
28524 ++	} segs[MAX_SCATTER];
28525 ++};
28526 ++
28527 ++struct hifn_command {
28528 ++	u_int16_t session_num;
28529 ++	u_int16_t base_masks, cry_masks, mac_masks;
28530 ++	u_int8_t iv[HIFN_MAX_IV_LENGTH], *ck, mac[HIFN_MAC_KEY_LENGTH];
28531 ++	int cklen;
28532 ++	int sloplen, slopidx;
28533 ++
28534 ++	struct hifn_operand src;
28535 ++	struct hifn_operand dst;
28536 ++
28537 ++	struct hifn_softc *softc;
28538 ++	struct cryptop *crp;
28539 ++	struct cryptodesc *enccrd, *maccrd;
28540 ++};
28541 ++
28542 ++#define	src_skb		src.u.skb
28543 ++#define	src_io		src.u.io
28544 ++#define	src_map		src.map
28545 ++#define	src_mapsize	src.mapsize
28546 ++#define	src_segs	src.segs
28547 ++#define	src_nsegs	src.nsegs
28548 ++#define	src_buf		src.u.buf
28549 ++
28550 ++#define	dst_skb		dst.u.skb
28551 ++#define	dst_io		dst.u.io
28552 ++#define	dst_map		dst.map
28553 ++#define	dst_mapsize	dst.mapsize
28554 ++#define	dst_segs	dst.segs
28555 ++#define	dst_nsegs	dst.nsegs
28556 ++#define	dst_buf		dst.u.buf
28557 ++
28558 ++/*
28559 ++ *  Return values for hifn_crypto()
28560 ++ */
28561 ++#define HIFN_CRYPTO_SUCCESS	0
28562 ++#define HIFN_CRYPTO_BAD_INPUT	(-1)
28563 ++#define HIFN_CRYPTO_RINGS_FULL	(-2)
28564 ++
28565 ++/**************************************************************************
28566 ++ *
28567 ++ *  Function:  hifn_crypto
28568 ++ *
28569 ++ *  Purpose:   Called by external drivers to begin an encryption on the
28570 ++ *             HIFN board.
28571 ++ *
28572 ++ *  Blocking/Non-blocking Issues
28573 ++ *  ============================
28574 ++ *  The driver cannot block in hifn_crypto (no calls to tsleep) currently.
28575 ++ *  hifn_crypto() returns HIFN_CRYPTO_RINGS_FULL if there is not enough
28576 ++ *  room in any of the rings for the request to proceed.
28577 ++ *
28578 ++ *  Return Values
28579 ++ *  =============
28580 ++ *  0 for success, negative values on error
28581 ++ *
28582 ++ *  Defines for negative error codes are:
28583 ++ *  
28584 ++ *    HIFN_CRYPTO_BAD_INPUT  :  The passed in command had invalid settings.
28585 ++ *    HIFN_CRYPTO_RINGS_FULL :  All DMA rings were full and non-blocking
28586 ++ *                              behaviour was requested.
28587 ++ *
28588 ++ *************************************************************************/
28589 ++
28590 ++/*
28591 ++ * Convert back and forth from 'sid' to 'card' and 'session'
28592 ++ */
28593 ++#define HIFN_CARD(sid)		(((sid) & 0xf0000000) >> 28)
28594 ++#define HIFN_SESSION(sid)	((sid) & 0x000007ff)
28595 ++#define HIFN_SID(crd,ses)	(((crd) << 28) | ((ses) & 0x7ff))
28596 ++
28597 ++#endif /* _KERNEL */
28598 ++
28599 ++struct hifn_stats {
28600 ++	u_int64_t hst_ibytes;
28601 ++	u_int64_t hst_obytes;
28602 ++	u_int32_t hst_ipackets;
28603 ++	u_int32_t hst_opackets;
28604 ++	u_int32_t hst_invalid;
28605 ++	u_int32_t hst_nomem;		/* malloc or one of hst_nomem_* */
28606 ++	u_int32_t hst_abort;
28607 ++	u_int32_t hst_noirq;		/* IRQ for no reason */
28608 ++	u_int32_t hst_totbatch;		/* ops submitted w/o interrupt */
28609 ++	u_int32_t hst_maxbatch;		/* max ops submitted together */
28610 ++	u_int32_t hst_unaligned;	/* unaligned src caused copy */
28611 ++	/*
28612 ++	 * The following divides hst_nomem into more specific buckets.
28613 ++	 */
28614 ++	u_int32_t hst_nomem_map;	/* bus_dmamap_create failed */
28615 ++	u_int32_t hst_nomem_load;	/* bus_dmamap_load_* failed */
28616 ++	u_int32_t hst_nomem_mbuf;	/* MGET* failed */
28617 ++	u_int32_t hst_nomem_mcl;	/* MCLGET* failed */
28618 ++	u_int32_t hst_nomem_cr;		/* out of command/result descriptor */
28619 ++	u_int32_t hst_nomem_sd;		/* out of src/dst descriptors */
28620 ++};
28621 ++
28622 ++#endif /* __HIFN7751VAR_H__ */
28623 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPP.c linux-2.6.23.16/crypto/ocf/hifn/hifnHIPP.c
28624 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPP.c	1969-12-31 19:00:00.000000000 -0500
28625 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifnHIPP.c	2008-02-26 09:29:13.000000000 -0500
28626 +@@ -0,0 +1,420 @@
28627 ++/*-
28628 ++ * Driver for Hifn HIPP-I/II chipset
28629 ++ * Copyright (c) 2006 Michael Richardson <mcr@xelerance.com>
28630 ++ *
28631 ++ * Redistribution and use in source and binary forms, with or without
28632 ++ * modification, are permitted provided that the following conditions
28633 ++ * are met:
28634 ++ *
28635 ++ * 1. Redistributions of source code must retain the above copyright
28636 ++ *   notice, this list of conditions and the following disclaimer.
28637 ++ * 2. Redistributions in binary form must reproduce the above copyright
28638 ++ *   notice, this list of conditions and the following disclaimer in the
28639 ++ *   documentation and/or other materials provided with the distribution.
28640 ++ * 3. The name of the author may not be used to endorse or promote products
28641 ++ *   derived from this software without specific prior written permission.
28642 ++ *
28643 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28644 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28645 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28646 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28647 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28648 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28649 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28650 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28651 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28652 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28653 ++ *
28654 ++ * Effort sponsored by Hifn Inc.
28655 ++ *
28656 ++ */
28657 ++
28658 ++/*
28659 ++ * Driver for various Hifn encryption processors.
28660 ++ */
28661 ++#ifndef AUTOCONF_INCLUDED
28662 ++#include <linux/config.h>
28663 ++#endif
28664 ++#include <linux/module.h>
28665 ++#include <linux/init.h>
28666 ++#include <linux/list.h>
28667 ++#include <linux/slab.h>
28668 ++#include <linux/wait.h>
28669 ++#include <linux/sched.h>
28670 ++#include <linux/pci.h>
28671 ++#include <linux/delay.h>
28672 ++#include <linux/interrupt.h>
28673 ++#include <linux/spinlock.h>
28674 ++#include <linux/random.h>
28675 ++#include <linux/version.h>
28676 ++#include <linux/skbuff.h>
28677 ++#include <linux/uio.h>
28678 ++#include <linux/sysfs.h>
28679 ++#include <linux/miscdevice.h>
28680 ++#include <asm/io.h>
28681 ++
28682 ++#include <cryptodev.h>
28683 ++
28684 ++#include "hifnHIPPreg.h"
28685 ++#include "hifnHIPPvar.h"
28686 ++
28687 ++#if 1
28688 ++#define	DPRINTF(a...)	if (hipp_debug) { \
28689 ++							printk("%s: ", sc ? \
28690 ++								device_get_nameunit(sc->sc_dev) : "hifn"); \
28691 ++							printk(a); \
28692 ++						} else
28693 ++#else
28694 ++#define	DPRINTF(a...)
28695 ++#endif
28696 ++
28697 ++typedef int bus_size_t;
28698 ++
28699 ++static inline int
28700 ++pci_get_revid(struct pci_dev *dev)
28701 ++{
28702 ++	u8 rid = 0;
28703 ++	pci_read_config_byte(dev, PCI_REVISION_ID, &rid);
28704 ++	return rid;
28705 ++}
28706 ++
28707 ++#define debug hipp_debug
28708 ++int hipp_debug = 0;
28709 ++module_param(hipp_debug, int, 0644);
28710 ++MODULE_PARM_DESC(hipp_debug, "Enable debug");
28711 ++
28712 ++int hipp_maxbatch = 1;
28713 ++module_param(hipp_maxbatch, int, 0644);
28714 ++MODULE_PARM_DESC(hipp_maxbatch, "max ops to batch w/o interrupt");
28715 ++
28716 ++static	int  hipp_probe(struct pci_dev *dev, const struct pci_device_id *ent);
28717 ++static	void hipp_remove(struct pci_dev *dev);
28718 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
28719 ++static irqreturn_t hipp_intr(int irq, void *arg);
28720 ++#else
28721 ++static irqreturn_t hipp_intr(int irq, void *arg, struct pt_regs *regs);
28722 ++#endif
28723 ++
28724 ++static int hipp_num_chips = 0;
28725 ++static struct hipp_softc *hipp_chip_idx[HIPP_MAX_CHIPS];
28726 ++
28727 ++static	int hipp_newsession(device_t, u_int32_t *, struct cryptoini *);
28728 ++static	int hipp_freesession(device_t, u_int64_t);
28729 ++static	int hipp_process(device_t, struct cryptop *, int);
28730 ++
28731 ++static device_method_t hipp_methods = {
28732 ++	/* crypto device methods */
28733 ++	DEVMETHOD(cryptodev_newsession,	hipp_newsession),
28734 ++	DEVMETHOD(cryptodev_freesession,hipp_freesession),
28735 ++	DEVMETHOD(cryptodev_process,	hipp_process),
28736 ++};
28737 ++
28738 ++static __inline u_int32_t
28739 ++READ_REG(struct hipp_softc *sc, unsigned int barno, bus_size_t reg)
28740 ++{
28741 ++	u_int32_t v = readl(sc->sc_bar[barno] + reg);
28742 ++	//sc->sc_bar0_lastreg = (bus_size_t) -1;
28743 ++	return (v);
28744 ++}
28745 ++static __inline void
28746 ++WRITE_REG(struct hipp_softc *sc, unsigned int barno, bus_size_t reg, u_int32_t val)
28747 ++{
28748 ++	writel(val, sc->sc_bar[barno] + reg);
28749 ++}
28750 ++
28751 ++#define READ_REG_0(sc, reg)         READ_REG(sc, 0, reg)
28752 ++#define WRITE_REG_0(sc, reg, val)   WRITE_REG(sc,0, reg, val)
28753 ++#define READ_REG_1(sc, reg)         READ_REG(sc, 1, reg)
28754 ++#define WRITE_REG_1(sc, reg, val)   WRITE_REG(sc,1, reg, val)
28755 ++
28756 ++static int
28757 ++hipp_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
28758 ++{
28759 ++	return EINVAL;
28760 ++}
28761 ++
28762 ++static int
28763 ++hipp_freesession(device_t dev, u_int64_t tid)
28764 ++{
28765 ++	return EINVAL;
28766 ++}
28767 ++
28768 ++static int
28769 ++hipp_process(device_t dev, struct cryptop *crp, int hint)
28770 ++{
28771 ++	return EINVAL;
28772 ++}
28773 ++
28774 ++static const char*
28775 ++hipp_partname(struct hipp_softc *sc, char buf[128], size_t blen)
28776 ++{
28777 ++	char *n = NULL;
28778 ++
28779 ++	switch (pci_get_vendor(sc->sc_pcidev)) {
28780 ++	case PCI_VENDOR_HIFN:
28781 ++		switch (pci_get_device(sc->sc_pcidev)) {
28782 ++		case PCI_PRODUCT_HIFN_7855:	n = "Hifn 7855";
28783 ++		case PCI_PRODUCT_HIFN_8155:	n = "Hifn 8155";
28784 ++		case PCI_PRODUCT_HIFN_6500:	n = "Hifn 6500";
28785 ++		}
28786 ++	}
28787 ++
28788 ++	if(n==NULL) {
28789 ++		snprintf(buf, blen, "VID=%02x,PID=%02x",
28790 ++			 pci_get_vendor(sc->sc_pcidev),
28791 ++			 pci_get_device(sc->sc_pcidev));
28792 ++	} else {
28793 ++		buf[0]='\0';
28794 ++		strncat(buf, n, blen);
28795 ++	}
28796 ++	return buf;
28797 ++}
28798 ++
28799 ++struct hipp_fs_entry {
28800 ++	struct attribute attr;
28801 ++	/* other stuff */
28802 ++};
28803 ++
28804 ++
28805 ++static ssize_t
28806 ++cryptoid_show(struct device *dev,
28807 ++	      struct device_attribute *attr,
28808 ++	      char *buf)						
28809 ++{								
28810 ++	struct hipp_softc *sc;					
28811 ++
28812 ++	sc = pci_get_drvdata(to_pci_dev (dev));
28813 ++	return sprintf (buf, "%d\n", sc->sc_cid);
28814 ++}
28815 ++
28816 ++struct device_attribute hipp_dev_cryptoid = __ATTR_RO(cryptoid);
28817 ++
28818 ++/*
28819 ++ * Attach an interface that successfully probed.
28820 ++ */
28821 ++static int
28822 ++hipp_probe(struct pci_dev *dev, const struct pci_device_id *ent)
28823 ++{
28824 ++	struct hipp_softc *sc = NULL;
28825 ++	int i;
28826 ++	//char rbase;
28827 ++	//u_int16_t ena;
28828 ++	int rev;
28829 ++	//int rseg;
28830 ++	int rc;
28831 ++
28832 ++	DPRINTF("%s()\n", __FUNCTION__);
28833 ++
28834 ++	if (pci_enable_device(dev) < 0)
28835 ++		return(-ENODEV);
28836 ++
28837 ++	if (pci_set_mwi(dev))
28838 ++		return(-ENODEV);
28839 ++
28840 ++	if (!dev->irq) {
28841 ++		printk("hifn: found device with no IRQ assigned. check BIOS settings!");
28842 ++		pci_disable_device(dev);
28843 ++		return(-ENODEV);
28844 ++	}
28845 ++
28846 ++	sc = (struct hipp_softc *) kmalloc(sizeof(*sc), GFP_KERNEL);
28847 ++	if (!sc)
28848 ++		return(-ENOMEM);
28849 ++	memset(sc, 0, sizeof(*sc));
28850 ++
28851 ++	softc_device_init(sc, "hifn-hipp", hipp_num_chips, hipp_methods);
28852 ++
28853 ++	sc->sc_pcidev = dev;
28854 ++	sc->sc_irq = -1;
28855 ++	sc->sc_cid = -1;
28856 ++	sc->sc_num = hipp_num_chips++;
28857 ++
28858 ++	if (sc->sc_num < HIPP_MAX_CHIPS)
28859 ++		hipp_chip_idx[sc->sc_num] = sc;
28860 ++
28861 ++	pci_set_drvdata(sc->sc_pcidev, sc);
28862 ++
28863 ++	spin_lock_init(&sc->sc_mtx);
28864 ++
28865 ++	/*
28866 ++	 * Setup PCI resources.
28867 ++	 * The READ_REG_0, WRITE_REG_0, READ_REG_1,
28868 ++	 * and WRITE_REG_1 macros throughout the driver are used
28869 ++	 * to permit better debugging.
28870 ++	 */
28871 ++	for(i=0; i<4; i++) {
28872 ++		unsigned long mem_start, mem_len;
28873 ++		mem_start = pci_resource_start(sc->sc_pcidev, i);
28874 ++		mem_len   = pci_resource_len(sc->sc_pcidev, i);
28875 ++		sc->sc_barphy[i] = (caddr_t)mem_start;
28876 ++		sc->sc_bar[i] = (ocf_iomem_t) ioremap(mem_start, mem_len);
28877 ++		if (!sc->sc_bar[i]) {
28878 ++			device_printf(sc->sc_dev, "cannot map bar%d register space\n", i);
28879 ++			goto fail;
28880 ++		}
28881 ++	}
28882 ++
28883 ++	//hipp_reset_board(sc, 0);
28884 ++	pci_set_master(sc->sc_pcidev);
28885 ++
28886 ++	/*
28887 ++	 * Arrange the interrupt line.
28888 ++	 */
28889 ++	rc = request_irq(dev->irq, hipp_intr, IRQF_SHARED, "hifn", sc);
28890 ++	if (rc) {
28891 ++		device_printf(sc->sc_dev, "could not map interrupt: %d\n", rc);
28892 ++		goto fail;
28893 ++	}
28894 ++	sc->sc_irq = dev->irq;
28895 ++
28896 ++	rev = READ_REG_1(sc, HIPP_1_REVID) & 0xffff;
28897 ++
28898 ++	{
28899 ++		char b[32];
28900 ++		device_printf(sc->sc_dev, "%s, rev %u",
28901 ++			      hipp_partname(sc, b, sizeof(b)), rev);
28902 ++	}
28903 ++
28904 ++#if 0
28905 ++	if (sc->sc_flags & HIFN_IS_7956)
28906 ++		printf(", pll=0x%x<%s clk, %ux mult>",
28907 ++			sc->sc_pllconfig,
28908 ++			sc->sc_pllconfig & HIFN_PLL_REF_SEL ? "ext" : "pci",
28909 ++			2 + 2*((sc->sc_pllconfig & HIFN_PLL_ND) >> 11));
28910 ++#endif
28911 ++	printf("\n");
28912 ++
28913 ++	sc->sc_cid = crypto_get_driverid(softc_get_device(sc),CRYPTOCAP_F_HARDWARE);
28914 ++	if (sc->sc_cid < 0) {
28915 ++		device_printf(sc->sc_dev, "could not get crypto driver id\n");
28916 ++		goto fail;
28917 ++	}
28918 ++
28919 ++#if 0 /* cannot work with a non-GPL module */
28920 ++	/* make a sysfs entry to let the world know what entry we got */
28921 ++	sysfs_create_file(&sc->sc_pcidev->dev.kobj, &hipp_dev_cryptoid.attr);
28922 ++#endif
28923 ++
28924 ++#if 0
28925 ++	init_timer(&sc->sc_tickto);
28926 ++	sc->sc_tickto.function = hifn_tick;
28927 ++	sc->sc_tickto.data = (unsigned long) sc->sc_num;
28928 ++	mod_timer(&sc->sc_tickto, jiffies + HZ);
28929 ++#endif
28930 ++
28931 ++#if 0 /* no code here yet ?? */
28932 ++	crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
28933 ++#endif
28934 ++
28935 ++	return (0);
28936 ++
28937 ++fail:
28938 ++	if (sc->sc_cid >= 0)
28939 ++		crypto_unregister_all(sc->sc_cid);
28940 ++	if (sc->sc_irq != -1)
28941 ++		free_irq(sc->sc_irq, sc);
28942 ++	
28943 ++#if 0
28944 ++	if (sc->sc_dma) {
28945 ++		/* Turn off DMA polling */
28946 ++		WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
28947 ++			    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
28948 ++		
28949 ++		pci_free_consistent(sc->sc_pcidev,
28950 ++				    sizeof(*sc->sc_dma),
28951 ++				    sc->sc_dma, sc->sc_dma_physaddr);
28952 ++	}
28953 ++#endif
28954 ++	kfree(sc);
28955 ++	return (-ENXIO);
28956 ++}
28957 ++
28958 ++/*
28959 ++ * Detach an interface that successfully probed.
28960 ++ */
28961 ++static void
28962 ++hipp_remove(struct pci_dev *dev)
28963 ++{
28964 ++	struct hipp_softc *sc = pci_get_drvdata(dev);
28965 ++	unsigned long l_flags;
28966 ++
28967 ++	DPRINTF("%s()\n", __FUNCTION__);
28968 ++
28969 ++	/* disable interrupts */
28970 ++	HIPP_LOCK(sc);
28971 ++
28972 ++#if 0
28973 ++	WRITE_REG_1(sc, HIFN_1_DMA_IER, 0);
28974 ++	HIFN_UNLOCK(sc);
28975 ++
28976 ++	/*XXX other resources */
28977 ++	del_timer_sync(&sc->sc_tickto);
28978 ++
28979 ++	/* Turn off DMA polling */
28980 ++	WRITE_REG_1(sc, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
28981 ++	    HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
28982 ++#endif
28983 ++
28984 ++	crypto_unregister_all(sc->sc_cid);
28985 ++
28986 ++	free_irq(sc->sc_irq, sc);
28987 ++
28988 ++#if 0
28989 ++	pci_free_consistent(sc->sc_pcidev, sizeof(*sc->sc_dma),
28990 ++                sc->sc_dma, sc->sc_dma_physaddr);
28991 ++#endif
28992 ++}
28993 ++
28994 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
28995 ++static irqreturn_t hipp_intr(int irq, void *arg)
28996 ++#else
28997 ++static irqreturn_t hipp_intr(int irq, void *arg, struct pt_regs *regs)
28998 ++#endif
28999 ++{
29000 ++	struct hipp_softc *sc = arg;
29001 ++
29002 ++	sc = sc; /* shut up compiler */
29003 ++
29004 ++	return IRQ_HANDLED;
29005 ++}
29006 ++
29007 ++static struct pci_device_id hipp_pci_tbl[] = {
29008 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_7855,
29009 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
29010 ++	{ PCI_VENDOR_HIFN, PCI_PRODUCT_HIFN_8155,
29011 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
29012 ++};
29013 ++MODULE_DEVICE_TABLE(pci, hipp_pci_tbl);
29014 ++
29015 ++static struct pci_driver hipp_driver = {
29016 ++	.name         = "hipp",
29017 ++	.id_table     = hipp_pci_tbl,
29018 ++	.probe        =	hipp_probe,
29019 ++	.remove       = hipp_remove,
29020 ++	/* add PM stuff here one day */
29021 ++};
29022 ++
29023 ++static int __init hipp_init (void)
29024 ++{
29025 ++	struct hipp_softc *sc = NULL;
29026 ++	int rc;
29027 ++
29028 ++	DPRINTF("%s(%p)\n", __FUNCTION__, hipp_init);
29029 ++
29030 ++	rc = pci_register_driver(&hipp_driver);
29031 ++	pci_register_driver_compat(&hipp_driver, rc);
29032 ++
29033 ++	return rc;
29034 ++}
29035 ++
29036 ++static void __exit hipp_exit (void)
29037 ++{
29038 ++	pci_unregister_driver(&hipp_driver);
29039 ++}
29040 ++
29041 ++module_init(hipp_init);
29042 ++module_exit(hipp_exit);
29043 ++
29044 ++MODULE_LICENSE("BSD");
29045 ++MODULE_AUTHOR("Michael Richardson <mcr@xelerance.com>");
29046 ++MODULE_DESCRIPTION("OCF driver for hifn HIPP-I/II PCI crypto devices");
29047 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPPreg.h linux-2.6.23.16/crypto/ocf/hifn/hifnHIPPreg.h
29048 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPPreg.h	1969-12-31 19:00:00.000000000 -0500
29049 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifnHIPPreg.h	2008-02-26 09:29:13.000000000 -0500
29050 +@@ -0,0 +1,46 @@
29051 ++/*-
29052 ++ * Hifn HIPP-I/HIPP-II (7855/8155) driver.
29053 ++ * Copyright (c) 2006 Michael Richardson <mcr@xelerance.com>
29054 ++ *
29055 ++ * Redistribution and use in source and binary forms, with or without
29056 ++ * modification, are permitted provided that the following conditions
29057 ++ * are met:
29058 ++ *
29059 ++ * 1. Redistributions of source code must retain the above copyright
29060 ++ *    notice, this list of conditions and the following disclaimer.
29061 ++ * 2. Redistributions in binary form must reproduce the above copyright
29062 ++ *    notice, this list of conditions and the following disclaimer in the
29063 ++ *    documentation and/or other materials provided with the distribution.
29064 ++ * 3. The name of the author may not be used to endorse or promote products
29065 ++ *    derived from this software without specific prior written permission.
29066 ++ *
29067 ++ *
29068 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29069 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29070 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29071 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29072 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29073 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29074 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29075 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29076 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29077 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29078 ++ *
29079 ++ * Effort sponsored by Hifn inc.
29080 ++ *
29081 ++ */
29082 ++
29083 ++#ifndef __HIFNHIPP_H__
29084 ++#define	__HIFNHIPP_H__
29085 ++
29086 ++/*
29087 ++ * PCI vendor and device identifiers
29088 ++ */
29089 ++#define	PCI_VENDOR_HIFN		0x13a3		/* Hifn */
29090 ++#define	PCI_PRODUCT_HIFN_6500	0x0006		/* 6500 */
29091 ++#define	PCI_PRODUCT_HIFN_7855	0x001f		/* 7855 */
29092 ++#define	PCI_PRODUCT_HIFN_8155	0x999		/* XXX 8155 */
29093 ++
29094 ++#define HIPP_1_REVID            0x01 /* BOGUS */
29095 ++
29096 ++#endif /* __HIPP_H__ */
29097 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPPvar.h linux-2.6.23.16/crypto/ocf/hifn/hifnHIPPvar.h
29098 +--- linux-2.6.23.16.old/crypto/ocf/hifn/hifnHIPPvar.h	1969-12-31 19:00:00.000000000 -0500
29099 ++++ linux-2.6.23.16/crypto/ocf/hifn/hifnHIPPvar.h	2008-02-26 09:29:13.000000000 -0500
29100 +@@ -0,0 +1,93 @@
29101 ++/*
29102 ++ * Hifn HIPP-I/HIPP-II (7855/8155) driver.
29103 ++ * Copyright (c) 2006 Michael Richardson <mcr@xelerance.com> * 
29104 ++ *
29105 ++ * Redistribution and use in source and binary forms, with or without
29106 ++ * modification, are permitted provided that the following conditions
29107 ++ * are met:
29108 ++ *
29109 ++ * 1. Redistributions of source code must retain the above copyright
29110 ++ *    notice, this list of conditions and the following disclaimer.
29111 ++ * 2. Redistributions in binary form must reproduce the above copyright
29112 ++ *    notice, this list of conditions and the following disclaimer in the
29113 ++ *    documentation and/or other materials provided with the distribution.
29114 ++ * 3. The name of the author may not be used to endorse or promote products
29115 ++ *    derived from this software without specific prior written permission.
29116 ++ *
29117 ++ *
29118 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29119 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29120 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29121 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29122 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29123 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29124 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29125 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29126 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29127 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29128 ++ *
29129 ++ * Effort sponsored by Hifn inc.
29130 ++ *
29131 ++ */
29132 ++
29133 ++#ifndef __HIFNHIPPVAR_H__
29134 ++#define __HIFNHIPPVAR_H__
29135 ++
29136 ++#define HIPP_MAX_CHIPS 8
29137 ++
29138 ++/*
29139 ++ * Holds data specific to a single Hifn HIPP-I board.
29140 ++ */
29141 ++struct hipp_softc {
29142 ++	softc_device_decl		 sc_dev;
29143 ++
29144 ++	struct pci_dev		*sc_pcidev;	/* device backpointer */
29145 ++	ocf_iomem_t             sc_bar[5];
29146 ++	caddr_t		        sc_barphy[5];   /* physical address */
29147 ++	int			sc_num;		/* for multiple devs */
29148 ++	spinlock_t		sc_mtx;		/* per-instance lock */
29149 ++	int32_t			sc_cid;
29150 ++	int			sc_irq;
29151 ++
29152 ++#if 0
29153 ++
29154 ++	u_int32_t		sc_dmaier;
29155 ++	u_int32_t		sc_drammodel;	/* 1=dram, 0=sram */
29156 ++	u_int32_t		sc_pllconfig;	/* 7954/7955/7956 PLL config */
29157 ++
29158 ++	struct hifn_dma		*sc_dma;
29159 ++	dma_addr_t		sc_dma_physaddr;/* physical address of sc_dma */
29160 ++
29161 ++	int			sc_dmansegs;
29162 ++	int			sc_maxses;
29163 ++	int			sc_nsessions;
29164 ++	struct hifn_session	*sc_sessions;
29165 ++	int			sc_ramsize;
29166 ++	int			sc_flags;
29167 ++#define	HIFN_HAS_RNG		0x1	/* includes random number generator */
29168 ++#define	HIFN_HAS_PUBLIC		0x2	/* includes public key support */
29169 ++#define	HIFN_HAS_AES		0x4	/* includes AES support */
29170 ++#define	HIFN_IS_7811		0x8	/* Hifn 7811 part */
29171 ++#define	HIFN_IS_7956		0x10	/* Hifn 7956/7955 don't have SDRAM */
29172 ++
29173 ++	struct timer_list	sc_tickto;	/* for managing DMA */
29174 ++
29175 ++	int			sc_rngfirst;
29176 ++	int			sc_rnghz;	/* RNG polling frequency */
29177 ++
29178 ++	int			sc_c_busy;	/* command ring busy */
29179 ++	int			sc_s_busy;	/* source data ring busy */
29180 ++	int			sc_d_busy;	/* destination data ring busy */
29181 ++	int			sc_r_busy;	/* result ring busy */
29182 ++	int			sc_active;	/* for initial countdown */
29183 ++	int			sc_needwakeup;	/* ops q'd wating on resources */
29184 ++	int			sc_curbatch;	/* # ops submitted w/o int */
29185 ++	int			sc_suspended;
29186 ++	struct miscdevice       sc_miscdev;
29187 ++#endif
29188 ++};
29189 ++
29190 ++#define	HIPP_LOCK(_sc)		spin_lock_irqsave(&(_sc)->sc_mtx, l_flags)
29191 ++#define	HIPP_UNLOCK(_sc)	spin_unlock_irqrestore(&(_sc)->sc_mtx, l_flags)
29192 ++
29193 ++#endif /* __HIFNHIPPVAR_H__ */
29194 +diff -urN linux-2.6.23.16.old/crypto/ocf/hifn/Makefile linux-2.6.23.16/crypto/ocf/hifn/Makefile
29195 +--- linux-2.6.23.16.old/crypto/ocf/hifn/Makefile	1969-12-31 19:00:00.000000000 -0500
29196 ++++ linux-2.6.23.16/crypto/ocf/hifn/Makefile	2008-02-26 09:29:13.000000000 -0500
29197 +@@ -0,0 +1,13 @@
29198 ++# for SGlinux builds
29199 ++-include $(ROOTDIR)/modules/.config
29200 ++
29201 ++obj-$(CONFIG_OCF_HIFN)     += hifn7751.o
29202 ++obj-$(CONFIG_OCF_HIFNHIPP) += hifnHIPP.o
29203 ++
29204 ++obj ?= .
29205 ++EXTRA_CFLAGS += -I$(obj)/.. -I$(obj)/
29206 ++
29207 ++ifdef TOPDIR
29208 ++-include $(TOPDIR)/Rules.make
29209 ++endif
29210 ++
29211 +diff -urN linux-2.6.23.16.old/crypto/ocf/ixp4xx/ixp4xx.c linux-2.6.23.16/crypto/ocf/ixp4xx/ixp4xx.c
29212 +--- linux-2.6.23.16.old/crypto/ocf/ixp4xx/ixp4xx.c	1969-12-31 19:00:00.000000000 -0500
29213 ++++ linux-2.6.23.16/crypto/ocf/ixp4xx/ixp4xx.c	2008-02-26 09:29:13.000000000 -0500
29214 +@@ -0,0 +1,1324 @@
29215 ++/*
29216 ++ * An OCF module that uses Intels IXP CryptACC API to do the crypto.
29217 ++ * This driver requires the IXP400 Access Library that is available
29218 ++ * from Intel in order to operate (or compile).
29219 ++ *
29220 ++ * Written by David McCullough <david_mccullough@securecomputing.com>
29221 ++ * Copyright (C) 2006-2007 David McCullough
29222 ++ * Copyright (C) 2004-2005 Intel Corporation.
29223 ++ *
29224 ++ * LICENSE TERMS
29225 ++ *
29226 ++ * The free distribution and use of this software in both source and binary
29227 ++ * form is allowed (with or without changes) provided that:
29228 ++ *
29229 ++ *   1. distributions of this source code include the above copyright
29230 ++ *      notice, this list of conditions and the following disclaimer;
29231 ++ *
29232 ++ *   2. distributions in binary form include the above copyright
29233 ++ *      notice, this list of conditions and the following disclaimer
29234 ++ *      in the documentation and/or other associated materials;
29235 ++ *
29236 ++ *   3. the copyright holder's name is not used to endorse products
29237 ++ *      built using this software without specific written permission.
29238 ++ *
29239 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
29240 ++ * may be distributed under the terms of the GNU General Public License (GPL),
29241 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
29242 ++ *
29243 ++ * DISCLAIMER
29244 ++ *
29245 ++ * This software is provided 'as is' with no explicit or implied warranties
29246 ++ * in respect of its properties, including, but not limited to, correctness
29247 ++ * and/or fitness for purpose.
29248 ++ */
29249 ++
29250 ++#ifndef AUTOCONF_INCLUDED
29251 ++#include <linux/config.h>
29252 ++#endif
29253 ++#include <linux/module.h>
29254 ++#include <linux/init.h>
29255 ++#include <linux/list.h>
29256 ++#include <linux/slab.h>
29257 ++#include <linux/sched.h>
29258 ++#include <linux/wait.h>
29259 ++#include <linux/crypto.h>
29260 ++#include <linux/interrupt.h>
29261 ++#include <asm/scatterlist.h>
29262 ++
29263 ++#include <IxTypes.h>
29264 ++#include <IxOsBuffMgt.h>
29265 ++#include <IxNpeDl.h>
29266 ++#include <IxCryptoAcc.h>
29267 ++#include <IxQMgr.h>
29268 ++#include <IxOsServices.h>
29269 ++#include <IxOsCacheMMU.h>
29270 ++
29271 ++#include <cryptodev.h>
29272 ++#include <uio.h>
29273 ++
29274 ++#ifndef IX_MBUF_PRIV
29275 ++#define IX_MBUF_PRIV(x) ((x)->priv)
29276 ++#endif
29277 ++
29278 ++struct ixp_data;
29279 ++
29280 ++struct ixp_q {
29281 ++	struct list_head	 ixp_q_list;
29282 ++	struct ixp_data		*ixp_q_data;
29283 ++	struct cryptop		*ixp_q_crp;
29284 ++	struct cryptodesc	*ixp_q_ccrd;
29285 ++	struct cryptodesc	*ixp_q_acrd;
29286 ++	IX_MBUF				 ixp_q_mbuf;
29287 ++	UINT8				*ixp_hash_dest; /* Location for hash in client buffer */
29288 ++	UINT8				*ixp_hash_src; /* Location of hash in internal buffer */
29289 ++	unsigned char		 ixp_q_iv_data[IX_CRYPTO_ACC_MAX_CIPHER_IV_LENGTH];
29290 ++	unsigned char		*ixp_q_iv;
29291 ++};
29292 ++
29293 ++struct ixp_data {
29294 ++	int					 ixp_registered;	/* is the context registered */
29295 ++	int					 ixp_crd_flags;		/* detect direction changes */
29296 ++
29297 ++	int					 ixp_cipher_alg;
29298 ++	int					 ixp_auth_alg;
29299 ++
29300 ++	UINT32				 ixp_ctx_id;
29301 ++	UINT32				 ixp_hash_key_id;	/* used when hashing */
29302 ++	IxCryptoAccCtx		 ixp_ctx;
29303 ++	IX_MBUF				 ixp_pri_mbuf;
29304 ++	IX_MBUF				 ixp_sec_mbuf;
29305 ++
29306 ++	struct work_struct   ixp_pending_work;
29307 ++	struct work_struct   ixp_registration_work;
29308 ++	struct list_head	 ixp_q;				/* unprocessed requests */
29309 ++};
29310 ++
29311 ++#ifdef __ixp46X
29312 ++
29313 ++#define	MAX_IOP_SIZE	64	/* words */
29314 ++#define	MAX_OOP_SIZE	128
29315 ++
29316 ++#define	MAX_PARAMS		3
29317 ++
29318 ++struct ixp_pkq {
29319 ++	struct list_head			 pkq_list;
29320 ++	struct cryptkop				*pkq_krp;
29321 ++
29322 ++	IxCryptoAccPkeEauInOperands	 pkq_op;
29323 ++	IxCryptoAccPkeEauOpResult	 pkq_result;
29324 ++
29325 ++	UINT32						 pkq_ibuf0[MAX_IOP_SIZE];
29326 ++	UINT32						 pkq_ibuf1[MAX_IOP_SIZE];
29327 ++	UINT32						 pkq_ibuf2[MAX_IOP_SIZE];
29328 ++	UINT32						 pkq_obuf[MAX_OOP_SIZE];
29329 ++};
29330 ++
29331 ++static LIST_HEAD(ixp_pkq); /* current PK wait list */
29332 ++static struct ixp_pkq *ixp_pk_cur;
29333 ++static spinlock_t ixp_pkq_lock;
29334 ++
29335 ++#endif /* __ixp46X */
29336 ++
29337 ++static int ixp_blocked = 0;
29338 ++
29339 ++static int32_t			 ixp_id = -1;
29340 ++static struct ixp_data **ixp_sessions = NULL;
29341 ++static u_int32_t		 ixp_sesnum = 0;
29342 ++
29343 ++static int ixp_process(device_t, struct cryptop *, int);
29344 ++static int ixp_newsession(device_t, u_int32_t *, struct cryptoini *);
29345 ++static int ixp_freesession(device_t, u_int64_t);
29346 ++#ifdef __ixp46X
29347 ++static int ixp_kprocess(device_t, struct cryptkop *krp, int hint);
29348 ++#endif
29349 ++
29350 ++static struct kmem_cache *qcache;
29351 ++
29352 ++#define debug ixp_debug
29353 ++static int ixp_debug = 0;
29354 ++module_param(ixp_debug, int, 0644);
29355 ++MODULE_PARM_DESC(ixp_debug, "Enable debug");
29356 ++
29357 ++static int ixp_init_crypto = 1;
29358 ++module_param(ixp_init_crypto, int, 0444); /* RO after load/boot */
29359 ++MODULE_PARM_DESC(ixp_init_crypto, "Call ixCryptoAccInit (default is 1)");
29360 ++
29361 ++static void ixp_process_pending(void *arg);
29362 ++static void ixp_registration(void *arg);
29363 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
29364 ++static void ixp_process_pending_wq(struct work_struct *work);
29365 ++static void ixp_registration_wq(struct work_struct *work);
29366 ++#endif
29367 ++
29368 ++/*
29369 ++ * dummy device structure
29370 ++ */
29371 ++
29372 ++static struct {
29373 ++	softc_device_decl	sc_dev;
29374 ++} ixpdev;
29375 ++
29376 ++static device_method_t ixp_methods = {
29377 ++	/* crypto device methods */
29378 ++	DEVMETHOD(cryptodev_newsession,	ixp_newsession),
29379 ++	DEVMETHOD(cryptodev_freesession,ixp_freesession),
29380 ++	DEVMETHOD(cryptodev_process,	ixp_process),
29381 ++#ifdef __ixp46X
29382 ++	DEVMETHOD(cryptodev_kprocess,	ixp_kprocess),
29383 ++#endif
29384 ++};
29385 ++
29386 ++/*
29387 ++ * Generate a new software session.
29388 ++ */
29389 ++static int
29390 ++ixp_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri)
29391 ++{
29392 ++	struct ixp_data *ixp;
29393 ++	u_int32_t i;
29394 ++#define AUTH_LEN(cri, def) \
29395 ++	(cri->cri_mlen ? cri->cri_mlen : (def))
29396 ++
29397 ++	dprintk("%s():alg %d\n", __FUNCTION__,cri->cri_alg);
29398 ++	if (sid == NULL || cri == NULL) {
29399 ++		dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
29400 ++		return EINVAL;
29401 ++	}
29402 ++
29403 ++	if (ixp_sessions) {
29404 ++		for (i = 1; i < ixp_sesnum; i++)
29405 ++			if (ixp_sessions[i] == NULL)
29406 ++				break;
29407 ++	} else
29408 ++		i = 1;		/* NB: to silence compiler warning */
29409 ++
29410 ++	if (ixp_sessions == NULL || i == ixp_sesnum) {
29411 ++		struct ixp_data **ixpd;
29412 ++
29413 ++		if (ixp_sessions == NULL) {
29414 ++			i = 1; /* We leave ixp_sessions[0] empty */
29415 ++			ixp_sesnum = CRYPTO_SW_SESSIONS;
29416 ++		} else
29417 ++			ixp_sesnum *= 2;
29418 ++
29419 ++		ixpd = kmalloc(ixp_sesnum * sizeof(struct ixp_data *), SLAB_ATOMIC);
29420 ++		if (ixpd == NULL) {
29421 ++			/* Reset session number */
29422 ++			if (ixp_sesnum == CRYPTO_SW_SESSIONS)
29423 ++				ixp_sesnum = 0;
29424 ++			else
29425 ++				ixp_sesnum /= 2;
29426 ++			dprintk("%s,%d: ENOBUFS\n", __FILE__, __LINE__);
29427 ++			return ENOBUFS;
29428 ++		}
29429 ++		memset(ixpd, 0, ixp_sesnum * sizeof(struct ixp_data *));
29430 ++
29431 ++		/* Copy existing sessions */
29432 ++		if (ixp_sessions) {
29433 ++			memcpy(ixpd, ixp_sessions,
29434 ++			    (ixp_sesnum / 2) * sizeof(struct ixp_data *));
29435 ++			kfree(ixp_sessions);
29436 ++		}
29437 ++
29438 ++		ixp_sessions = ixpd;
29439 ++	}
29440 ++
29441 ++	ixp_sessions[i] = (struct ixp_data *) kmalloc(sizeof(struct ixp_data),
29442 ++			SLAB_ATOMIC);
29443 ++	if (ixp_sessions[i] == NULL) {
29444 ++		ixp_freesession(NULL, i);
29445 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
29446 ++		return ENOBUFS;
29447 ++	}
29448 ++
29449 ++	*sid = i;
29450 ++
29451 ++	ixp = ixp_sessions[i];
29452 ++	memset(ixp, 0, sizeof(*ixp));
29453 ++
29454 ++	ixp->ixp_cipher_alg = -1;
29455 ++	ixp->ixp_auth_alg = -1;
29456 ++	ixp->ixp_ctx_id = -1;
29457 ++	INIT_LIST_HEAD(&ixp->ixp_q);
29458 ++
29459 ++	ixp->ixp_ctx.useDifferentSrcAndDestMbufs = 0;
29460 ++
29461 ++	while (cri) {
29462 ++		switch (cri->cri_alg) {
29463 ++		case CRYPTO_DES_CBC:
29464 ++			ixp->ixp_cipher_alg = cri->cri_alg;
29465 ++			ixp->ixp_ctx.cipherCtx.cipherAlgo = IX_CRYPTO_ACC_CIPHER_DES;
29466 ++			ixp->ixp_ctx.cipherCtx.cipherMode = IX_CRYPTO_ACC_MODE_CBC;
29467 ++			ixp->ixp_ctx.cipherCtx.cipherKeyLen = (cri->cri_klen + 7) / 8;
29468 ++			ixp->ixp_ctx.cipherCtx.cipherBlockLen = IX_CRYPTO_ACC_DES_BLOCK_64;
29469 ++			ixp->ixp_ctx.cipherCtx.cipherInitialVectorLen =
29470 ++						IX_CRYPTO_ACC_DES_IV_64;
29471 ++			memcpy(ixp->ixp_ctx.cipherCtx.key.cipherKey,
29472 ++					cri->cri_key, (cri->cri_klen + 7) / 8);
29473 ++			break;
29474 ++
29475 ++		case CRYPTO_3DES_CBC:
29476 ++			ixp->ixp_cipher_alg = cri->cri_alg;
29477 ++			ixp->ixp_ctx.cipherCtx.cipherAlgo = IX_CRYPTO_ACC_CIPHER_3DES;
29478 ++			ixp->ixp_ctx.cipherCtx.cipherMode = IX_CRYPTO_ACC_MODE_CBC;
29479 ++			ixp->ixp_ctx.cipherCtx.cipherKeyLen = (cri->cri_klen + 7) / 8;
29480 ++			ixp->ixp_ctx.cipherCtx.cipherBlockLen = IX_CRYPTO_ACC_DES_BLOCK_64;
29481 ++			ixp->ixp_ctx.cipherCtx.cipherInitialVectorLen =
29482 ++						IX_CRYPTO_ACC_DES_IV_64;
29483 ++			memcpy(ixp->ixp_ctx.cipherCtx.key.cipherKey,
29484 ++					cri->cri_key, (cri->cri_klen + 7) / 8);
29485 ++			break;
29486 ++
29487 ++		case CRYPTO_RIJNDAEL128_CBC:
29488 ++			ixp->ixp_cipher_alg = cri->cri_alg;
29489 ++			ixp->ixp_ctx.cipherCtx.cipherAlgo = IX_CRYPTO_ACC_CIPHER_AES;
29490 ++			ixp->ixp_ctx.cipherCtx.cipherMode = IX_CRYPTO_ACC_MODE_CBC;
29491 ++			ixp->ixp_ctx.cipherCtx.cipherKeyLen = (cri->cri_klen + 7) / 8;
29492 ++			ixp->ixp_ctx.cipherCtx.cipherBlockLen = 16;
29493 ++			ixp->ixp_ctx.cipherCtx.cipherInitialVectorLen = 16;
29494 ++			memcpy(ixp->ixp_ctx.cipherCtx.key.cipherKey,
29495 ++					cri->cri_key, (cri->cri_klen + 7) / 8);
29496 ++			break;
29497 ++
29498 ++		case CRYPTO_MD5:
29499 ++		case CRYPTO_MD5_HMAC:
29500 ++			ixp->ixp_auth_alg = cri->cri_alg;
29501 ++			ixp->ixp_ctx.authCtx.authAlgo = IX_CRYPTO_ACC_AUTH_MD5;
29502 ++			ixp->ixp_ctx.authCtx.authDigestLen = AUTH_LEN(cri, MD5_HASH_LEN);
29503 ++			ixp->ixp_ctx.authCtx.aadLen = 0;
29504 ++			/* Only MD5_HMAC needs a key */
29505 ++			if (cri->cri_alg == CRYPTO_MD5_HMAC) {
29506 ++				ixp->ixp_ctx.authCtx.authKeyLen = (cri->cri_klen + 7) / 8;
29507 ++				if (ixp->ixp_ctx.authCtx.authKeyLen >
29508 ++						sizeof(ixp->ixp_ctx.authCtx.key.authKey)) {
29509 ++					printk(
29510 ++						"ixp4xx: Invalid key length for MD5_HMAC - %d bits\n",
29511 ++							cri->cri_klen);
29512 ++					ixp_freesession(NULL, i);
29513 ++					return EINVAL;
29514 ++				}
29515 ++				memcpy(ixp->ixp_ctx.authCtx.key.authKey,
29516 ++						cri->cri_key, (cri->cri_klen + 7) / 8);
29517 ++			}
29518 ++			break;
29519 ++
29520 ++		case CRYPTO_SHA1:
29521 ++		case CRYPTO_SHA1_HMAC:
29522 ++			ixp->ixp_auth_alg = cri->cri_alg;
29523 ++			ixp->ixp_ctx.authCtx.authAlgo = IX_CRYPTO_ACC_AUTH_SHA1;
29524 ++			ixp->ixp_ctx.authCtx.authDigestLen = AUTH_LEN(cri, SHA1_HASH_LEN);
29525 ++			ixp->ixp_ctx.authCtx.aadLen = 0;
29526 ++			/* Only SHA1_HMAC needs a key */
29527 ++			if (cri->cri_alg == CRYPTO_SHA1_HMAC) {
29528 ++				ixp->ixp_ctx.authCtx.authKeyLen = (cri->cri_klen + 7) / 8;
29529 ++				if (ixp->ixp_ctx.authCtx.authKeyLen >
29530 ++						sizeof(ixp->ixp_ctx.authCtx.key.authKey)) {
29531 ++					printk(
29532 ++						"ixp4xx: Invalid key length for SHA1_HMAC - %d bits\n",
29533 ++							cri->cri_klen);
29534 ++					ixp_freesession(NULL, i);
29535 ++					return EINVAL;
29536 ++				}
29537 ++				memcpy(ixp->ixp_ctx.authCtx.key.authKey,
29538 ++						cri->cri_key, (cri->cri_klen + 7) / 8);
29539 ++			}
29540 ++			break;
29541 ++
29542 ++		default:
29543 ++			printk("ixp: unknown algo 0x%x\n", cri->cri_alg);
29544 ++			ixp_freesession(NULL, i);
29545 ++			return EINVAL;
29546 ++		}
29547 ++		cri = cri->cri_next;
29548 ++	}
29549 ++
29550 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
29551 ++	INIT_WORK(&ixp->ixp_pending_work, ixp_process_pending_wq);
29552 ++	INIT_WORK(&ixp->ixp_registration_work, ixp_registration_wq);
29553 ++#else
29554 ++	INIT_WORK(&ixp->ixp_pending_work, ixp_process_pending, ixp);
29555 ++	INIT_WORK(&ixp->ixp_registration_work, ixp_registration, ixp);
29556 ++#endif
29557 ++
29558 ++	return 0;
29559 ++}
29560 ++
29561 ++
29562 ++/*
29563 ++ * Free a session.
29564 ++ */
29565 ++static int
29566 ++ixp_freesession(device_t dev, u_int64_t tid)
29567 ++{
29568 ++	u_int32_t sid = CRYPTO_SESID2LID(tid);
29569 ++
29570 ++	dprintk("%s()\n", __FUNCTION__);
29571 ++	if (sid > ixp_sesnum || ixp_sessions == NULL ||
29572 ++			ixp_sessions[sid] == NULL) {
29573 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
29574 ++		return EINVAL;
29575 ++	}
29576 ++
29577 ++	/* Silently accept and return */
29578 ++	if (sid == 0)
29579 ++		return 0;
29580 ++
29581 ++	if (ixp_sessions[sid]) {
29582 ++		if (ixp_sessions[sid]->ixp_ctx_id != -1) {
29583 ++			ixCryptoAccCtxUnregister(ixp_sessions[sid]->ixp_ctx_id);
29584 ++			ixp_sessions[sid]->ixp_ctx_id = -1;
29585 ++		}
29586 ++
29587 ++		flush_scheduled_work();
29588 ++
29589 ++		kfree(ixp_sessions[sid]);
29590 ++	}
29591 ++	ixp_sessions[sid] = NULL;
29592 ++	if (ixp_blocked) {
29593 ++		ixp_blocked = 0;
29594 ++		crypto_unblock(ixp_id, CRYPTO_SYMQ);
29595 ++	}
29596 ++	return 0;
29597 ++}
29598 ++
29599 ++
29600 ++/*
29601 ++ * callback for when hash processing is complete
29602 ++ */
29603 ++
29604 ++static void
29605 ++ixp_hash_perform_cb(
29606 ++	UINT32 hash_key_id,
29607 ++	IX_MBUF *bufp,
29608 ++	IxCryptoAccStatus status)
29609 ++{
29610 ++	struct ixp_q *q;
29611 ++
29612 ++	dprintk("%s(%u, %p, 0x%x)\n", __FUNCTION__, hash_key_id, bufp, status);
29613 ++
29614 ++	if (bufp == NULL) {
29615 ++		printk("ixp: NULL buf in %s\n", __FUNCTION__);
29616 ++		return;
29617 ++	}
29618 ++
29619 ++	q = IX_MBUF_PRIV(bufp);
29620 ++	if (q == NULL) {
29621 ++		printk("ixp: NULL priv in %s\n", __FUNCTION__);
29622 ++		return;
29623 ++	}
29624 ++
29625 ++	if (status == IX_CRYPTO_ACC_STATUS_SUCCESS) {
29626 ++		/* On success, need to copy hash back into original client buffer */
29627 ++		memcpy(q->ixp_hash_dest, q->ixp_hash_src,
29628 ++				(q->ixp_q_data->ixp_auth_alg == CRYPTO_SHA1) ?
29629 ++					SHA1_HASH_LEN : MD5_HASH_LEN);
29630 ++	}
29631 ++	else {
29632 ++		printk("ixp: hash perform failed status=%d\n", status);
29633 ++		q->ixp_q_crp->crp_etype = EINVAL;
29634 ++	}
29635 ++
29636 ++	/* Free internal buffer used for hashing */
29637 ++	kfree(IX_MBUF_MDATA(&q->ixp_q_mbuf));
29638 ++
29639 ++	crypto_done(q->ixp_q_crp);
29640 ++	kmem_cache_free(qcache, q);
29641 ++}
29642 ++
29643 ++/*
29644 ++ * setup a request and perform it
29645 ++ */
29646 ++static void
29647 ++ixp_q_process(struct ixp_q *q)
29648 ++{
29649 ++	IxCryptoAccStatus status;
29650 ++	struct ixp_data *ixp = q->ixp_q_data;
29651 ++	int auth_off = 0;
29652 ++	int auth_len = 0;
29653 ++	int crypt_off = 0;
29654 ++	int crypt_len = 0;
29655 ++	int icv_off = 0;
29656 ++	char *crypt_func;
29657 ++
29658 ++	dprintk("%s(%p)\n", __FUNCTION__, q);
29659 ++
29660 ++	if (q->ixp_q_ccrd) {
29661 ++		if (q->ixp_q_ccrd->crd_flags & CRD_F_IV_EXPLICIT) {
29662 ++			q->ixp_q_iv = q->ixp_q_ccrd->crd_iv;
29663 ++		} else {
29664 ++			q->ixp_q_iv = q->ixp_q_iv_data;
29665 ++			crypto_copydata(q->ixp_q_crp->crp_flags, q->ixp_q_crp->crp_buf,
29666 ++					q->ixp_q_ccrd->crd_inject,
29667 ++					ixp->ixp_ctx.cipherCtx.cipherInitialVectorLen,
29668 ++					(caddr_t) q->ixp_q_iv);
29669 ++		}
29670 ++
29671 ++		if (q->ixp_q_acrd) {
29672 ++			auth_off = q->ixp_q_acrd->crd_skip;
29673 ++			auth_len = q->ixp_q_acrd->crd_len;
29674 ++			icv_off  = q->ixp_q_acrd->crd_inject;
29675 ++		}
29676 ++
29677 ++		crypt_off = q->ixp_q_ccrd->crd_skip;
29678 ++		crypt_len = q->ixp_q_ccrd->crd_len;
29679 ++	} else { /* if (q->ixp_q_acrd) */
29680 ++		auth_off = q->ixp_q_acrd->crd_skip;
29681 ++		auth_len = q->ixp_q_acrd->crd_len;
29682 ++		icv_off  = q->ixp_q_acrd->crd_inject;
29683 ++	}
29684 ++
29685 ++	if (q->ixp_q_crp->crp_flags & CRYPTO_F_SKBUF) {
29686 ++		struct sk_buff *skb = (struct sk_buff *) q->ixp_q_crp->crp_buf;
29687 ++		if (skb_shinfo(skb)->nr_frags) {
29688 ++			/*
29689 ++			 * DAVIDM fix this limitation one day by using
29690 ++			 * a buffer pool and chaining,  it is not currently
29691 ++			 * needed for current user/kernel space acceleration
29692 ++			 */
29693 ++			printk("ixp: Cannot handle fragmented skb's yet !\n");
29694 ++			q->ixp_q_crp->crp_etype = ENOENT;
29695 ++			goto done;
29696 ++		}
29697 ++		IX_MBUF_MLEN(&q->ixp_q_mbuf) =
29698 ++				IX_MBUF_PKT_LEN(&q->ixp_q_mbuf) =  skb->len;
29699 ++		IX_MBUF_MDATA(&q->ixp_q_mbuf) = skb->data;
29700 ++	} else if (q->ixp_q_crp->crp_flags & CRYPTO_F_IOV) {
29701 ++		struct uio *uiop = (struct uio *) q->ixp_q_crp->crp_buf;
29702 ++		if (uiop->uio_iovcnt != 1) {
29703 ++			/*
29704 ++			 * DAVIDM fix this limitation one day by using
29705 ++			 * a buffer pool and chaining,  it is not currently
29706 ++			 * needed for current user/kernel space acceleration
29707 ++			 */
29708 ++			printk("ixp: Cannot handle more than 1 iovec yet !\n");
29709 ++			q->ixp_q_crp->crp_etype = ENOENT;
29710 ++			goto done;
29711 ++		}
29712 ++		IX_MBUF_MLEN(&q->ixp_q_mbuf) =
29713 ++				IX_MBUF_PKT_LEN(&q->ixp_q_mbuf) = uiop->uio_iov[0].iov_len;
29714 ++		IX_MBUF_MDATA(&q->ixp_q_mbuf) = uiop->uio_iov[0].iov_base;
29715 ++	} else /* contig buffer */ {
29716 ++		IX_MBUF_MLEN(&q->ixp_q_mbuf)  =
29717 ++				IX_MBUF_PKT_LEN(&q->ixp_q_mbuf) = q->ixp_q_crp->crp_ilen;
29718 ++		IX_MBUF_MDATA(&q->ixp_q_mbuf) = q->ixp_q_crp->crp_buf;
29719 ++	}
29720 ++
29721 ++	IX_MBUF_PRIV(&q->ixp_q_mbuf) = q;
29722 ++
29723 ++	if (ixp->ixp_auth_alg == CRYPTO_SHA1 || ixp->ixp_auth_alg == CRYPTO_MD5) {
29724 ++		/*
29725 ++		 * For SHA1 and MD5 hash, need to create an internal buffer that is big
29726 ++		 * enough to hold the original data + the appropriate padding for the
29727 ++		 * hash algorithm.
29728 ++		 */
29729 ++		UINT8 *tbuf = NULL;
29730 ++
29731 ++		IX_MBUF_MLEN(&q->ixp_q_mbuf) = IX_MBUF_PKT_LEN(&q->ixp_q_mbuf) =
29732 ++			((IX_MBUF_MLEN(&q->ixp_q_mbuf) * 8) + 72 + 511) / 8;
29733 ++		tbuf = kmalloc(IX_MBUF_MLEN(&q->ixp_q_mbuf), SLAB_ATOMIC);
29734 ++		
29735 ++		if (IX_MBUF_MDATA(&q->ixp_q_mbuf) == NULL) {
29736 ++			printk("ixp: kmalloc(%u, SLAB_ATOMIC) failed\n",
29737 ++					IX_MBUF_MLEN(&q->ixp_q_mbuf));
29738 ++			q->ixp_q_crp->crp_etype = ENOMEM;
29739 ++			goto done;
29740 ++		}
29741 ++		memcpy(tbuf, &(IX_MBUF_MDATA(&q->ixp_q_mbuf))[auth_off], auth_len);
29742 ++
29743 ++		/* Set location in client buffer to copy hash into */
29744 ++		q->ixp_hash_dest =
29745 ++			&(IX_MBUF_MDATA(&q->ixp_q_mbuf))[auth_off + auth_len];
29746 ++
29747 ++		IX_MBUF_MDATA(&q->ixp_q_mbuf) = tbuf;
29748 ++
29749 ++		/* Set location in internal buffer for where hash starts */
29750 ++		q->ixp_hash_src = &(IX_MBUF_MDATA(&q->ixp_q_mbuf))[auth_len];
29751 ++
29752 ++		crypt_func = "ixCryptoAccHashPerform";
29753 ++		status = ixCryptoAccHashPerform(ixp->ixp_ctx.authCtx.authAlgo,
29754 ++				&q->ixp_q_mbuf, ixp_hash_perform_cb, 0, auth_len, auth_len,
29755 ++				&ixp->ixp_hash_key_id);
29756 ++	}
29757 ++	else {
29758 ++		crypt_func = "ixCryptoAccAuthCryptPerform";
29759 ++		status = ixCryptoAccAuthCryptPerform(ixp->ixp_ctx_id, &q->ixp_q_mbuf,
29760 ++			NULL, auth_off, auth_len, crypt_off, crypt_len, icv_off,
29761 ++			q->ixp_q_iv);
29762 ++	}
29763 ++
29764 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS == status)
29765 ++		return;
29766 ++
29767 ++	if (IX_CRYPTO_ACC_STATUS_QUEUE_FULL == status) {
29768 ++		q->ixp_q_crp->crp_etype = ENOMEM;
29769 ++		goto done;
29770 ++	}
29771 ++
29772 ++	printk("ixp: %s failed %u\n", crypt_func, status);
29773 ++	q->ixp_q_crp->crp_etype = EINVAL;
29774 ++
29775 ++done:
29776 ++	crypto_done(q->ixp_q_crp);
29777 ++	kmem_cache_free(qcache, q);
29778 ++}
29779 ++
29780 ++
29781 ++/*
29782 ++ * because we cannot process the Q from the Register callback
29783 ++ * we do it here on a task Q.
29784 ++ */
29785 ++
29786 ++static void
29787 ++ixp_process_pending(void *arg)
29788 ++{
29789 ++	struct ixp_data *ixp = arg;
29790 ++	struct ixp_q *q = NULL;
29791 ++
29792 ++	dprintk("%s(%p)\n", __FUNCTION__, arg);
29793 ++
29794 ++	if (!ixp)
29795 ++		return;
29796 ++
29797 ++	while (!list_empty(&ixp->ixp_q)) {
29798 ++		q = list_entry(ixp->ixp_q.next, struct ixp_q, ixp_q_list);
29799 ++		list_del(&q->ixp_q_list);
29800 ++		ixp_q_process(q);
29801 ++	}
29802 ++}
29803 ++
29804 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
29805 ++static void
29806 ++ixp_process_pending_wq(struct work_struct *work)
29807 ++{
29808 ++	struct ixp_data *ixp = container_of(work, struct ixp_data,
29809 ++								ixp_pending_work);
29810 ++	ixp_process_pending(ixp);
29811 ++}
29812 ++#endif
29813 ++
29814 ++/*
29815 ++ * callback for when context registration is complete
29816 ++ */
29817 ++
29818 ++static void
29819 ++ixp_register_cb(UINT32 ctx_id, IX_MBUF *bufp, IxCryptoAccStatus status)
29820 ++{
29821 ++	int i;
29822 ++	struct ixp_data *ixp;
29823 ++	struct ixp_q *q;
29824 ++
29825 ++	dprintk("%s(%d, %p, %d)\n", __FUNCTION__, ctx_id, bufp, status);
29826 ++
29827 ++	/*
29828 ++	 * free any buffer passed in to this routine
29829 ++	 */
29830 ++	if (bufp) {
29831 ++		IX_MBUF_MLEN(bufp) = IX_MBUF_PKT_LEN(bufp) = 0;
29832 ++		kfree(IX_MBUF_MDATA(bufp));
29833 ++		IX_MBUF_MDATA(bufp) = NULL;
29834 ++	}
29835 ++
29836 ++	for (i = 0; i < ixp_sesnum; i++) {
29837 ++		ixp = ixp_sessions[i];
29838 ++		if (ixp && ixp->ixp_ctx_id == ctx_id)
29839 ++			break;
29840 ++	}
29841 ++	if (i >= ixp_sesnum) {
29842 ++		printk("ixp: invalid context id %d\n", ctx_id);
29843 ++		return;
29844 ++	}
29845 ++
29846 ++	if (IX_CRYPTO_ACC_STATUS_WAIT == status) {
29847 ++		/* this is normal to free the first of two buffers */
29848 ++		dprintk("ixp: register not finished yet.\n");
29849 ++		return;
29850 ++	}
29851 ++
29852 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS != status) {
29853 ++		printk("ixp: register failed 0x%x\n", status);
29854 ++		while (!list_empty(&ixp->ixp_q)) {
29855 ++			q = list_entry(ixp->ixp_q.next, struct ixp_q, ixp_q_list);
29856 ++			list_del(&q->ixp_q_list);
29857 ++			q->ixp_q_crp->crp_etype = EINVAL;
29858 ++			crypto_done(q->ixp_q_crp);
29859 ++			kmem_cache_free(qcache, q);
29860 ++		}
29861 ++		return;
29862 ++	}
29863 ++
29864 ++	/*
29865 ++	 * we are now registered,  we cannot start processing the Q here
29866 ++	 * or we get strange errors with AES (DES/3DES seem to be ok).
29867 ++	 */
29868 ++	ixp->ixp_registered = 1;
29869 ++	schedule_work(&ixp->ixp_pending_work);
29870 ++}
29871 ++
29872 ++
29873 ++/*
29874 ++ * callback for when data processing is complete
29875 ++ */
29876 ++
29877 ++static void
29878 ++ixp_perform_cb(
29879 ++	UINT32 ctx_id,
29880 ++	IX_MBUF *sbufp,
29881 ++	IX_MBUF *dbufp,
29882 ++	IxCryptoAccStatus status)
29883 ++{
29884 ++	struct ixp_q *q;
29885 ++
29886 ++	dprintk("%s(%d, %p, %p, 0x%x)\n", __FUNCTION__, ctx_id, sbufp,
29887 ++			dbufp, status);
29888 ++
29889 ++	if (sbufp == NULL) {
29890 ++		printk("ixp: NULL sbuf in ixp_perform_cb\n");
29891 ++		return;
29892 ++	}
29893 ++
29894 ++	q = IX_MBUF_PRIV(sbufp);
29895 ++	if (q == NULL) {
29896 ++		printk("ixp: NULL priv in ixp_perform_cb\n");
29897 ++		return;
29898 ++	}
29899 ++
29900 ++	if (status != IX_CRYPTO_ACC_STATUS_SUCCESS) {
29901 ++		printk("ixp: perform failed status=%d\n", status);
29902 ++		q->ixp_q_crp->crp_etype = EINVAL;
29903 ++	}
29904 ++
29905 ++	crypto_done(q->ixp_q_crp);
29906 ++	kmem_cache_free(qcache, q);
29907 ++}
29908 ++
29909 ++
29910 ++/*
29911 ++ * registration is not callable at IRQ time,  so we defer
29912 ++ * to a task queue,  this routines completes the registration for us
29913 ++ * when the task queue runs
29914 ++ *
29915 ++ * Unfortunately this means we cannot tell OCF that the driver is blocked,
29916 ++ * we do that on the next request.
29917 ++ */
29918 ++
29919 ++static void
29920 ++ixp_registration(void *arg)
29921 ++{
29922 ++	struct ixp_data *ixp = arg;
29923 ++	struct ixp_q *q = NULL;
29924 ++	IX_MBUF *pri = NULL, *sec = NULL;
29925 ++	int status = IX_CRYPTO_ACC_STATUS_SUCCESS;
29926 ++
29927 ++	if (!ixp) {
29928 ++		printk("ixp: ixp_registration with no arg\n");
29929 ++		return;
29930 ++	}
29931 ++
29932 ++	if (ixp->ixp_ctx_id != -1) {
29933 ++		ixCryptoAccCtxUnregister(ixp->ixp_ctx_id);
29934 ++		ixp->ixp_ctx_id = -1;
29935 ++	}
29936 ++
29937 ++	if (list_empty(&ixp->ixp_q)) {
29938 ++		printk("ixp: ixp_registration with no Q\n");
29939 ++		return;
29940 ++	}
29941 ++
29942 ++	/*
29943 ++	 * setup the primary and secondary buffers
29944 ++	 */
29945 ++	q = list_entry(ixp->ixp_q.next, struct ixp_q, ixp_q_list);
29946 ++	if (q->ixp_q_acrd) {
29947 ++		pri = &ixp->ixp_pri_mbuf;
29948 ++		sec = &ixp->ixp_sec_mbuf;
29949 ++		IX_MBUF_MLEN(pri)  = IX_MBUF_PKT_LEN(pri) = 128;
29950 ++		IX_MBUF_MDATA(pri) = (unsigned char *) kmalloc(128, SLAB_ATOMIC);
29951 ++		IX_MBUF_MLEN(sec)  = IX_MBUF_PKT_LEN(sec) = 128;
29952 ++		IX_MBUF_MDATA(sec) = (unsigned char *) kmalloc(128, SLAB_ATOMIC);
29953 ++	}
29954 ++
29955 ++	/* Only need to register if a crypt op or HMAC op */
29956 ++	if (!(ixp->ixp_auth_alg == CRYPTO_SHA1 ||
29957 ++				ixp->ixp_auth_alg == CRYPTO_MD5)) {
29958 ++		status = ixCryptoAccCtxRegister(
29959 ++					&ixp->ixp_ctx,
29960 ++					pri, sec,
29961 ++					ixp_register_cb,
29962 ++					ixp_perform_cb,
29963 ++					&ixp->ixp_ctx_id);
29964 ++	}
29965 ++	else {
29966 ++		/* Otherwise we start processing pending q */
29967 ++		schedule_work(&ixp->ixp_pending_work);
29968 ++	}
29969 ++
29970 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS == status)
29971 ++		return;
29972 ++
29973 ++	if (IX_CRYPTO_ACC_STATUS_EXCEED_MAX_TUNNELS == status) {
29974 ++		printk("ixp: ixCryptoAccCtxRegister failed (out of tunnels)\n");
29975 ++		ixp_blocked = 1;
29976 ++		/* perhaps we should return EGAIN on queued ops ? */
29977 ++		return;
29978 ++	}
29979 ++
29980 ++	printk("ixp: ixCryptoAccCtxRegister failed %d\n", status);
29981 ++	ixp->ixp_ctx_id = -1;
29982 ++
29983 ++	/*
29984 ++	 * everything waiting is toasted
29985 ++	 */
29986 ++	while (!list_empty(&ixp->ixp_q)) {
29987 ++		q = list_entry(ixp->ixp_q.next, struct ixp_q, ixp_q_list);
29988 ++		list_del(&q->ixp_q_list);
29989 ++		q->ixp_q_crp->crp_etype = ENOENT;
29990 ++		crypto_done(q->ixp_q_crp);
29991 ++		kmem_cache_free(qcache, q);
29992 ++	}
29993 ++}
29994 ++
29995 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
29996 ++static void
29997 ++ixp_registration_wq(struct work_struct *work)
29998 ++{
29999 ++	struct ixp_data *ixp = container_of(work, struct ixp_data,
30000 ++								ixp_registration_work);
30001 ++	ixp_registration(ixp);
30002 ++}
30003 ++#endif
30004 ++
30005 ++/*
30006 ++ * Process a request.
30007 ++ */
30008 ++static int
30009 ++ixp_process(device_t dev, struct cryptop *crp, int hint)
30010 ++{
30011 ++	struct ixp_data *ixp;
30012 ++	unsigned int lid;
30013 ++	struct ixp_q *q = NULL;
30014 ++	int status;
30015 ++
30016 ++	dprintk("%s()\n", __FUNCTION__);
30017 ++
30018 ++	/* Sanity check */
30019 ++	if (crp == NULL) {
30020 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
30021 ++		return EINVAL;
30022 ++	}
30023 ++
30024 ++	crp->crp_etype = 0;
30025 ++
30026 ++	if (ixp_blocked)
30027 ++		return ERESTART;
30028 ++
30029 ++	if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
30030 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
30031 ++		crp->crp_etype = EINVAL;
30032 ++		goto done;
30033 ++	}
30034 ++
30035 ++	/*
30036 ++	 * find the session we are using
30037 ++	 */
30038 ++
30039 ++	lid = crp->crp_sid & 0xffffffff;
30040 ++	if (lid >= ixp_sesnum || lid == 0 || ixp_sessions == NULL ||
30041 ++			ixp_sessions[lid] == NULL) {
30042 ++		crp->crp_etype = ENOENT;
30043 ++		dprintk("%s,%d: ENOENT\n", __FILE__, __LINE__);
30044 ++		goto done;
30045 ++	}
30046 ++	ixp = ixp_sessions[lid];
30047 ++
30048 ++	/*
30049 ++	 * setup a new request ready for queuing
30050 ++	 */
30051 ++	q = kmem_cache_alloc(qcache, SLAB_ATOMIC);
30052 ++	if (q == NULL) {
30053 ++		dprintk("%s,%d: ENOMEM\n", __FILE__, __LINE__);
30054 ++		crp->crp_etype = ENOMEM;
30055 ++		goto done;
30056 ++	}
30057 ++	/*
30058 ++	 * save some cycles by only zeroing the important bits
30059 ++	 */
30060 ++	memset(&q->ixp_q_mbuf, 0, sizeof(q->ixp_q_mbuf));
30061 ++	q->ixp_q_ccrd = NULL;
30062 ++	q->ixp_q_acrd = NULL;
30063 ++	q->ixp_q_crp = crp;
30064 ++	q->ixp_q_data = ixp;
30065 ++
30066 ++	/*
30067 ++	 * point the cipher and auth descriptors appropriately
30068 ++	 * check that we have something to do
30069 ++	 */
30070 ++	if (crp->crp_desc->crd_alg == ixp->ixp_cipher_alg)
30071 ++		q->ixp_q_ccrd = crp->crp_desc;
30072 ++	else if (crp->crp_desc->crd_alg == ixp->ixp_auth_alg)
30073 ++		q->ixp_q_acrd = crp->crp_desc;
30074 ++	else {
30075 ++		crp->crp_etype = ENOENT;
30076 ++		dprintk("%s,%d: bad desc match: ENOENT\n", __FILE__, __LINE__);
30077 ++		goto done;
30078 ++	}
30079 ++	if (crp->crp_desc->crd_next) {
30080 ++		if (crp->crp_desc->crd_next->crd_alg == ixp->ixp_cipher_alg)
30081 ++			q->ixp_q_ccrd = crp->crp_desc->crd_next;
30082 ++		else if (crp->crp_desc->crd_next->crd_alg == ixp->ixp_auth_alg)
30083 ++			q->ixp_q_acrd = crp->crp_desc->crd_next;
30084 ++		else {
30085 ++			crp->crp_etype = ENOENT;
30086 ++			dprintk("%s,%d: bad desc match: ENOENT\n", __FILE__, __LINE__);
30087 ++			goto done;
30088 ++		}
30089 ++	}
30090 ++
30091 ++	/*
30092 ++	 * If there is a direction change for this context then we mark it as
30093 ++	 * unregistered and re-register is for the new direction.  This is not
30094 ++	 * a very expensive operation and currently only tends to happen when
30095 ++	 * user-space application are doing benchmarks
30096 ++	 *
30097 ++	 * DM - we should be checking for pending requests before unregistering.
30098 ++	 */
30099 ++	if (q->ixp_q_ccrd && ixp->ixp_registered &&
30100 ++			ixp->ixp_crd_flags != (q->ixp_q_ccrd->crd_flags & CRD_F_ENCRYPT)) {
30101 ++		dprintk("%s - detected direction change on session\n", __FUNCTION__);
30102 ++		ixp->ixp_registered = 0;
30103 ++	}
30104 ++
30105 ++	/*
30106 ++	 * if we are registered,  call straight into the perform code
30107 ++	 */
30108 ++	if (ixp->ixp_registered) {
30109 ++		ixp_q_process(q);
30110 ++		return 0;
30111 ++	}
30112 ++
30113 ++	/*
30114 ++	 * the only part of the context not set in newsession is the direction
30115 ++	 * dependent parts
30116 ++	 */
30117 ++	if (q->ixp_q_ccrd) {
30118 ++		ixp->ixp_crd_flags = (q->ixp_q_ccrd->crd_flags & CRD_F_ENCRYPT);
30119 ++		if (q->ixp_q_ccrd->crd_flags & CRD_F_ENCRYPT) {
30120 ++			ixp->ixp_ctx.operation = q->ixp_q_acrd ?
30121 ++					IX_CRYPTO_ACC_OP_ENCRYPT_AUTH : IX_CRYPTO_ACC_OP_ENCRYPT;
30122 ++		} else {
30123 ++			ixp->ixp_ctx.operation = q->ixp_q_acrd ?
30124 ++					IX_CRYPTO_ACC_OP_AUTH_DECRYPT : IX_CRYPTO_ACC_OP_DECRYPT;
30125 ++		}
30126 ++	} else {
30127 ++		/* q->ixp_q_acrd must be set if we are here */
30128 ++		ixp->ixp_ctx.operation = IX_CRYPTO_ACC_OP_AUTH_CALC;
30129 ++	}
30130 ++
30131 ++	status = list_empty(&ixp->ixp_q);
30132 ++	list_add_tail(&q->ixp_q_list, &ixp->ixp_q);
30133 ++	if (status)
30134 ++		schedule_work(&ixp->ixp_registration_work);
30135 ++	return 0;
30136 ++
30137 ++done:
30138 ++	if (q)
30139 ++		kmem_cache_free(qcache, q);
30140 ++	crypto_done(crp);
30141 ++	return 0;
30142 ++}
30143 ++
30144 ++
30145 ++#ifdef __ixp46X
30146 ++/*
30147 ++ * key processing support for the ixp465
30148 ++ */
30149 ++
30150 ++
30151 ++/*
30152 ++ * copy a BN (LE) into a buffer (BE) an fill out the op appropriately
30153 ++ * assume zeroed and only copy bits that are significant
30154 ++ */
30155 ++
30156 ++static int
30157 ++ixp_copy_ibuf(struct crparam *p, IxCryptoAccPkeEauOperand *op, UINT32 *buf)
30158 ++{
30159 ++	unsigned char *src = (unsigned char *) p->crp_p;
30160 ++	unsigned char *dst;
30161 ++	int len, bits = p->crp_nbits;
30162 ++
30163 ++	dprintk("%s()\n", __FUNCTION__);
30164 ++
30165 ++	if (bits > MAX_IOP_SIZE * sizeof(UINT32) * 8) {
30166 ++		dprintk("%s - ibuf too big (%d > %d)\n", __FUNCTION__,
30167 ++				bits, MAX_IOP_SIZE * sizeof(UINT32) * 8);
30168 ++		return -1;
30169 ++	}
30170 ++
30171 ++	len = (bits + 31) / 32; /* the number UINT32's needed */
30172 ++
30173 ++	dst = (unsigned char *) &buf[len];
30174 ++	dst--;
30175 ++
30176 ++	while (bits > 0) {
30177 ++		*dst-- = *src++;
30178 ++		bits -= 8;
30179 ++	}
30180 ++
30181 ++#if 0 /* no need to zero remaining bits as it is done during request alloc */
30182 ++	while (dst > (unsigned char *) buf)
30183 ++		*dst-- = '\0';
30184 ++#endif
30185 ++
30186 ++	op->pData = buf;
30187 ++	op->dataLen = len;
30188 ++	return 0;
30189 ++}
30190 ++
30191 ++/*
30192 ++ * copy out the result,  be as forgiving as we can about small output buffers
30193 ++ */
30194 ++
30195 ++static int
30196 ++ixp_copy_obuf(struct crparam *p, IxCryptoAccPkeEauOpResult *op, UINT32 *buf)
30197 ++{
30198 ++	unsigned char *dst = (unsigned char *) p->crp_p;
30199 ++	unsigned char *src = (unsigned char *) buf;
30200 ++	int len, z, bits = p->crp_nbits;
30201 ++
30202 ++	dprintk("%s()\n", __FUNCTION__);
30203 ++
30204 ++	len = op->dataLen * sizeof(UINT32);
30205 ++
30206 ++	/* skip leading zeroes to be small buffer friendly */
30207 ++	z = 0;
30208 ++	while (z < len && src[z] == '\0')
30209 ++		z++;
30210 ++
30211 ++	src += len;
30212 ++	src--;
30213 ++	len -= z;
30214 ++
30215 ++	while (len > 0 && bits > 0) {
30216 ++		*dst++ = *src--;
30217 ++		len--;
30218 ++		bits -= 8;
30219 ++	}
30220 ++
30221 ++	while (bits > 0) {
30222 ++		*dst++ = '\0';
30223 ++		bits -= 8;
30224 ++	}
30225 ++
30226 ++	if (len > 0) {
30227 ++		dprintk("%s - obuf is %d (z=%d, ob=%d) bytes too small\n",
30228 ++				__FUNCTION__, len, z, p->crp_nbits / 8);
30229 ++		return -1;
30230 ++	}
30231 ++
30232 ++	return 0;
30233 ++}
30234 ++
30235 ++
30236 ++/*
30237 ++ * the parameter offsets for exp_mod
30238 ++ */
30239 ++
30240 ++#define IXP_PARAM_BASE 0
30241 ++#define IXP_PARAM_EXP  1
30242 ++#define IXP_PARAM_MOD  2
30243 ++#define IXP_PARAM_RES  3
30244 ++
30245 ++/*
30246 ++ * key processing complete callback,  is also used to start processing
30247 ++ * by passing a NULL for pResult
30248 ++ */
30249 ++
30250 ++static void
30251 ++ixp_kperform_cb(
30252 ++	IxCryptoAccPkeEauOperation operation,
30253 ++	IxCryptoAccPkeEauOpResult *pResult,
30254 ++	BOOL carryOrBorrow,
30255 ++	IxCryptoAccStatus status)
30256 ++{
30257 ++	struct ixp_pkq *q, *tmp;
30258 ++	unsigned long flags;
30259 ++
30260 ++	dprintk("%s(0x%x, %p, %d, 0x%x)\n", __FUNCTION__, operation, pResult,
30261 ++			carryOrBorrow, status);
30262 ++
30263 ++	/* handle a completed request */
30264 ++	if (pResult) {
30265 ++		if (ixp_pk_cur && &ixp_pk_cur->pkq_result == pResult) {
30266 ++			q = ixp_pk_cur;
30267 ++			if (status != IX_CRYPTO_ACC_STATUS_SUCCESS) {
30268 ++				dprintk("%s() - op failed 0x%x\n", __FUNCTION__, status);
30269 ++				q->pkq_krp->krp_status = ERANGE; /* could do better */
30270 ++			} else {
30271 ++				/* copy out the result */
30272 ++				if (ixp_copy_obuf(&q->pkq_krp->krp_param[IXP_PARAM_RES],
30273 ++						&q->pkq_result, q->pkq_obuf))
30274 ++					q->pkq_krp->krp_status = ERANGE;
30275 ++			}
30276 ++			crypto_kdone(q->pkq_krp);
30277 ++			kfree(q);
30278 ++			ixp_pk_cur = NULL;
30279 ++		} else
30280 ++			printk("%s - callback with invalid result pointer\n", __FUNCTION__);
30281 ++	}
30282 ++
30283 ++	spin_lock_irqsave(&ixp_pkq_lock, flags);
30284 ++	if (ixp_pk_cur || list_empty(&ixp_pkq)) {
30285 ++		spin_unlock_irqrestore(&ixp_pkq_lock, flags);
30286 ++		return;
30287 ++	}
30288 ++
30289 ++	list_for_each_entry_safe(q, tmp, &ixp_pkq, pkq_list) {
30290 ++
30291 ++		list_del(&q->pkq_list);
30292 ++		ixp_pk_cur = q;
30293 ++
30294 ++		spin_unlock_irqrestore(&ixp_pkq_lock, flags);
30295 ++
30296 ++		status = ixCryptoAccPkeEauPerform(
30297 ++				IX_CRYPTO_ACC_OP_EAU_MOD_EXP,
30298 ++				&q->pkq_op,
30299 ++				ixp_kperform_cb,
30300 ++				&q->pkq_result);
30301 ++	
30302 ++		if (status == IX_CRYPTO_ACC_STATUS_SUCCESS) {
30303 ++			dprintk("%s() - ixCryptoAccPkeEauPerform SUCCESS\n", __FUNCTION__);
30304 ++			return; /* callback will return here for callback */
30305 ++		} else if (status == IX_CRYPTO_ACC_STATUS_RETRY) {
30306 ++			printk("%s() - ixCryptoAccPkeEauPerform RETRY\n", __FUNCTION__);
30307 ++		} else {
30308 ++			printk("%s() - ixCryptoAccPkeEauPerform failed %d\n",
30309 ++					__FUNCTION__, status);
30310 ++		}
30311 ++		q->pkq_krp->krp_status = ERANGE; /* could do better */
30312 ++		crypto_kdone(q->pkq_krp);
30313 ++		kfree(q);
30314 ++		spin_lock_irqsave(&ixp_pkq_lock, flags);
30315 ++	}
30316 ++	spin_unlock_irqrestore(&ixp_pkq_lock, flags);
30317 ++}
30318 ++
30319 ++
30320 ++static int
30321 ++ixp_kprocess(device_t dev, struct cryptkop *krp, int hint)
30322 ++{
30323 ++	struct ixp_pkq *q;
30324 ++	int rc = 0;
30325 ++	unsigned long flags;
30326 ++
30327 ++	dprintk("%s l1=%d l2=%d l3=%d l4=%d\n", __FUNCTION__,
30328 ++			krp->krp_param[IXP_PARAM_BASE].crp_nbits,
30329 ++			krp->krp_param[IXP_PARAM_EXP].crp_nbits,
30330 ++			krp->krp_param[IXP_PARAM_MOD].crp_nbits,
30331 ++			krp->krp_param[IXP_PARAM_RES].crp_nbits);
30332 ++
30333 ++
30334 ++	if (krp->krp_op != CRK_MOD_EXP) {
30335 ++		krp->krp_status = EOPNOTSUPP;
30336 ++		goto err;
30337 ++	}
30338 ++
30339 ++	q = (struct ixp_pkq *) kmalloc(sizeof(*q), GFP_KERNEL);
30340 ++	if (q == NULL) {
30341 ++		krp->krp_status = ENOMEM;
30342 ++		goto err;
30343 ++	}
30344 ++
30345 ++	/*
30346 ++	 * The PKE engine does not appear to zero the output buffer
30347 ++	 * appropriately, so we need to do it all here.
30348 ++	 */
30349 ++	memset(q, 0, sizeof(*q));
30350 ++
30351 ++	q->pkq_krp = krp;
30352 ++	INIT_LIST_HEAD(&q->pkq_list);
30353 ++
30354 ++	if (ixp_copy_ibuf(&krp->krp_param[IXP_PARAM_BASE], &q->pkq_op.modExpOpr.M,
30355 ++			q->pkq_ibuf0))
30356 ++		rc = 1;
30357 ++	if (!rc && ixp_copy_ibuf(&krp->krp_param[IXP_PARAM_EXP],
30358 ++				&q->pkq_op.modExpOpr.e, q->pkq_ibuf1))
30359 ++		rc = 2;
30360 ++	if (!rc && ixp_copy_ibuf(&krp->krp_param[IXP_PARAM_MOD],
30361 ++				&q->pkq_op.modExpOpr.N, q->pkq_ibuf2))
30362 ++		rc = 3;
30363 ++
30364 ++	if (rc) {
30365 ++		kfree(q);
30366 ++		krp->krp_status = ERANGE;
30367 ++		goto err;
30368 ++	}
30369 ++
30370 ++	q->pkq_result.pData           = q->pkq_obuf;
30371 ++	q->pkq_result.dataLen         =
30372 ++			(krp->krp_param[IXP_PARAM_RES].crp_nbits + 31) / 32;
30373 ++
30374 ++	spin_lock_irqsave(&ixp_pkq_lock, flags);
30375 ++	list_add_tail(&q->pkq_list, &ixp_pkq);
30376 ++	spin_unlock_irqrestore(&ixp_pkq_lock, flags);
30377 ++
30378 ++	if (!ixp_pk_cur)
30379 ++		ixp_kperform_cb(0, NULL, 0, 0);
30380 ++	return (0);
30381 ++
30382 ++err:
30383 ++	crypto_kdone(krp);
30384 ++	return (0);
30385 ++}
30386 ++
30387 ++
30388 ++
30389 ++#ifdef CONFIG_OCF_RANDOMHARVEST
30390 ++/*
30391 ++ * We run the random number generator output through SHA so that it
30392 ++ * is FIPS compliant.
30393 ++ */
30394 ++
30395 ++static volatile int sha_done = 0;
30396 ++static unsigned char sha_digest[20];
30397 ++
30398 ++static void
30399 ++ixp_hash_cb(UINT8 *digest, IxCryptoAccStatus status)
30400 ++{
30401 ++	dprintk("%s(%p, %d)\n", __FUNCTION__, digest, status);
30402 ++	if (sha_digest != digest)
30403 ++		printk("digest error\n");
30404 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS == status)
30405 ++		sha_done = 1;
30406 ++	else
30407 ++		sha_done = -status;
30408 ++}
30409 ++
30410 ++static int
30411 ++ixp_read_random(void *arg, u_int32_t *buf, int maxwords)
30412 ++{
30413 ++	IxCryptoAccStatus status;
30414 ++	int i, n, rc;
30415 ++
30416 ++	dprintk("%s(%p, %d)\n", __FUNCTION__, buf, maxwords);
30417 ++	memset(buf, 0, maxwords * sizeof(*buf));
30418 ++	status = ixCryptoAccPkePseudoRandomNumberGet(maxwords, buf);
30419 ++	if (status != IX_CRYPTO_ACC_STATUS_SUCCESS) {
30420 ++		dprintk("%s: ixCryptoAccPkePseudoRandomNumberGet failed %d\n",
30421 ++				__FUNCTION__, status);
30422 ++		return 0;
30423 ++	}
30424 ++
30425 ++	/*
30426 ++	 * run the random data through SHA to make it look more random
30427 ++	 */
30428 ++
30429 ++	n = sizeof(sha_digest); /* process digest bytes at a time */
30430 ++
30431 ++	rc = 0;
30432 ++	for (i = 0; i < maxwords; i += n / sizeof(*buf)) {
30433 ++		if ((maxwords - i) * sizeof(*buf) < n)
30434 ++			n = (maxwords - i) * sizeof(*buf);
30435 ++		sha_done = 0;
30436 ++		status = ixCryptoAccPkeHashPerform(IX_CRYPTO_ACC_AUTH_SHA1,
30437 ++				(UINT8 *) &buf[i], n, ixp_hash_cb, sha_digest);
30438 ++		if (status != IX_CRYPTO_ACC_STATUS_SUCCESS) {
30439 ++			dprintk("ixCryptoAccPkeHashPerform failed %d\n", status);
30440 ++			return -EIO;
30441 ++		}
30442 ++		while (!sha_done)
30443 ++			schedule();
30444 ++		if (sha_done < 0) {
30445 ++			dprintk("ixCryptoAccPkeHashPerform failed CB %d\n", -sha_done);
30446 ++			return 0;
30447 ++		}
30448 ++		memcpy(&buf[i], sha_digest, n);
30449 ++		rc += n / sizeof(*buf);;
30450 ++	}
30451 ++
30452 ++	return rc;
30453 ++}
30454 ++#endif /* CONFIG_OCF_RANDOMHARVEST */
30455 ++
30456 ++#endif /* __ixp46X */
30457 ++
30458 ++
30459 ++
30460 ++/*
30461 ++ * our driver startup and shutdown routines
30462 ++ */
30463 ++
30464 ++static int
30465 ++ixp_init(void)
30466 ++{
30467 ++	dprintk("%s(%p)\n", __FUNCTION__, ixp_init);
30468 ++
30469 ++	if (ixp_init_crypto && ixCryptoAccInit() != IX_CRYPTO_ACC_STATUS_SUCCESS)
30470 ++		printk("ixCryptoAccInit failed, assuming already initialised!\n");
30471 ++
30472 ++	qcache = kmem_cache_create("ixp4xx_q", sizeof(struct ixp_q), 0,
30473 ++				SLAB_HWCACHE_ALIGN, NULL
30474 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
30475 ++				, NULL
30476 ++#endif
30477 ++				  );
30478 ++	if (!qcache) {
30479 ++		printk("failed to create Qcache\n");
30480 ++		return -ENOENT;
30481 ++	}
30482 ++
30483 ++	memset(&ixpdev, 0, sizeof(ixpdev));
30484 ++	softc_device_init(&ixpdev, "ixp4xx", 0, ixp_methods);
30485 ++
30486 ++	ixp_id = crypto_get_driverid(softc_get_device(&ixpdev),
30487 ++				CRYPTOCAP_F_HARDWARE);
30488 ++	if (ixp_id < 0)
30489 ++		panic("IXP/OCF crypto device cannot initialize!");
30490 ++
30491 ++#define	REGISTER(alg) \
30492 ++	crypto_register(ixp_id,alg,0,0)
30493 ++
30494 ++	REGISTER(CRYPTO_DES_CBC);
30495 ++	REGISTER(CRYPTO_3DES_CBC);
30496 ++	REGISTER(CRYPTO_RIJNDAEL128_CBC);
30497 ++#ifdef CONFIG_OCF_IXP4XX_SHA1_MD5
30498 ++	REGISTER(CRYPTO_MD5);
30499 ++	REGISTER(CRYPTO_SHA1);
30500 ++#endif
30501 ++	REGISTER(CRYPTO_MD5_HMAC);
30502 ++	REGISTER(CRYPTO_SHA1_HMAC);
30503 ++#undef REGISTER
30504 ++
30505 ++#ifdef __ixp46X
30506 ++	spin_lock_init(&ixp_pkq_lock);
30507 ++	/*
30508 ++	 * we do not enable the go fast options here as they can potentially
30509 ++	 * allow timing based attacks
30510 ++	 *
30511 ++	 * http://www.openssl.org/news/secadv_20030219.txt
30512 ++	 */
30513 ++	ixCryptoAccPkeEauExpConfig(0, 0);
30514 ++	crypto_kregister(ixp_id, CRK_MOD_EXP, 0);
30515 ++#ifdef CONFIG_OCF_RANDOMHARVEST
30516 ++	crypto_rregister(ixp_id, ixp_read_random, NULL);
30517 ++#endif
30518 ++#endif
30519 ++
30520 ++	return 0;
30521 ++}
30522 ++
30523 ++static void
30524 ++ixp_exit(void)
30525 ++{
30526 ++	dprintk("%s()\n", __FUNCTION__);
30527 ++	crypto_unregister_all(ixp_id);
30528 ++	ixp_id = -1;
30529 ++	kmem_cache_destroy(qcache);
30530 ++	qcache = NULL;
30531 ++}
30532 ++
30533 ++module_init(ixp_init);
30534 ++module_exit(ixp_exit);
30535 ++
30536 ++MODULE_LICENSE("Dual BSD/GPL");
30537 ++MODULE_AUTHOR("David McCullough <dmccullough@cyberguard.com>");
30538 ++MODULE_DESCRIPTION("ixp (OCF module for IXP4xx crypto)");
30539 +diff -urN linux-2.6.23.16.old/crypto/ocf/ixp4xx/Makefile linux-2.6.23.16/crypto/ocf/ixp4xx/Makefile
30540 +--- linux-2.6.23.16.old/crypto/ocf/ixp4xx/Makefile	1969-12-31 19:00:00.000000000 -0500
30541 ++++ linux-2.6.23.16/crypto/ocf/ixp4xx/Makefile	2008-02-26 09:29:13.000000000 -0500
30542 +@@ -0,0 +1,104 @@
30543 ++# for SGlinux builds
30544 ++-include $(ROOTDIR)/modules/.config
30545 ++
30546 ++#
30547 ++# You will need to point this at your Intel ixp425 includes,  this portion
30548 ++# of the Makefile only really works under SGLinux with the appropriate libs
30549 ++# installed.  They can be downloaded from http://www.snapgear.org/
30550 ++#
30551 ++ifeq ($(CONFIG_CPU_IXP46X),y)
30552 ++IXPLATFORM = ixp46X
30553 ++else
30554 ++ifeq ($(CONFIG_CPU_IXP43X),y)
30555 ++IXPLATFORM = ixp43X
30556 ++else
30557 ++IXPLATFORM = ixp42X
30558 ++endif
30559 ++endif
30560 ++
30561 ++ifdef CONFIG_IXP400_LIB_2_4
30562 ++IX_XSCALE_SW = $(ROOTDIR)/modules/ixp425/ixp400-2.4/ixp400_xscale_sw
30563 ++OSAL_DIR     = $(ROOTDIR)/modules/ixp425/ixp400-2.4/ixp_osal
30564 ++endif
30565 ++ifdef CONFIG_IXP400_LIB_2_1
30566 ++IX_XSCALE_SW = $(ROOTDIR)/modules/ixp425/ixp400-2.1/ixp400_xscale_sw
30567 ++OSAL_DIR     = $(ROOTDIR)/modules/ixp425/ixp400-2.1/ixp_osal
30568 ++endif
30569 ++ifdef CONFIG_IXP400_LIB_2_0
30570 ++IX_XSCALE_SW = $(ROOTDIR)/modules/ixp425/ixp400-2.0/ixp400_xscale_sw
30571 ++OSAL_DIR     = $(ROOTDIR)/modules/ixp425/ixp400-2.0/ixp_osal
30572 ++endif
30573 ++ifdef IX_XSCALE_SW
30574 ++ifdef CONFIG_IXP400_LIB_2_4
30575 ++IXP_CFLAGS = \
30576 ++	-I$(ROOTDIR)/. \
30577 ++	-I$(IX_XSCALE_SW)/src/include \
30578 ++	-I$(OSAL_DIR)/common/include/ \
30579 ++	-I$(OSAL_DIR)/common/include/modules/ \
30580 ++	-I$(OSAL_DIR)/common/include/modules/ddk/ \
30581 ++	-I$(OSAL_DIR)/common/include/modules/bufferMgt/ \
30582 ++	-I$(OSAL_DIR)/common/include/modules/ioMem/ \
30583 ++	-I$(OSAL_DIR)/common/os/linux/include/ \
30584 ++	-I$(OSAL_DIR)/common/os/linux/include/core/  \
30585 ++	-I$(OSAL_DIR)/common/os/linux/include/modules/ \
30586 ++	-I$(OSAL_DIR)/common/os/linux/include/modules/ddk/ \
30587 ++	-I$(OSAL_DIR)/common/os/linux/include/modules/bufferMgt/ \
30588 ++	-I$(OSAL_DIR)/common/os/linux/include/modules/ioMem/ \
30589 ++	-I$(OSAL_DIR)/platforms/$(IXPLATFORM)/include/ \
30590 ++	-I$(OSAL_DIR)/platforms/$(IXPLATFORM)/os/linux/include/ \
30591 ++	-DENABLE_IOMEM -DENABLE_BUFFERMGT -DENABLE_DDK \
30592 ++	-DUSE_IXP4XX_CRYPTO
30593 ++else
30594 ++IXP_CFLAGS = \
30595 ++	-I$(ROOTDIR)/. \
30596 ++	-I$(IX_XSCALE_SW)/src/include \
30597 ++	-I$(OSAL_DIR)/ \
30598 ++	-I$(OSAL_DIR)/os/linux/include/ \
30599 ++	-I$(OSAL_DIR)/os/linux/include/modules/ \
30600 ++	-I$(OSAL_DIR)/os/linux/include/modules/ioMem/ \
30601 ++	-I$(OSAL_DIR)/os/linux/include/modules/bufferMgt/ \
30602 ++	-I$(OSAL_DIR)/os/linux/include/core/  \
30603 ++	-I$(OSAL_DIR)/os/linux/include/platforms/ \
30604 ++	-I$(OSAL_DIR)/os/linux/include/platforms/ixp400/ \
30605 ++	-I$(OSAL_DIR)/os/linux/include/platforms/ixp400/ixp425 \
30606 ++	-I$(OSAL_DIR)/os/linux/include/platforms/ixp400/ixp465 \
30607 ++	-I$(OSAL_DIR)/os/linux/include/core/ \
30608 ++	-I$(OSAL_DIR)/include/ \
30609 ++	-I$(OSAL_DIR)/include/modules/ \
30610 ++	-I$(OSAL_DIR)/include/modules/bufferMgt/ \
30611 ++	-I$(OSAL_DIR)/include/modules/ioMem/ \
30612 ++	-I$(OSAL_DIR)/include/platforms/ \
30613 ++	-I$(OSAL_DIR)/include/platforms/ixp400/ \
30614 ++	-DUSE_IXP4XX_CRYPTO
30615 ++endif
30616 ++endif
30617 ++ifdef CONFIG_IXP400_LIB_1_4
30618 ++IXP_CFLAGS   = \
30619 ++	-I$(ROOTDIR)/. \
30620 ++	-I$(ROOTDIR)/modules/ixp425/ixp400-1.4/ixp400_xscale_sw/src/include \
30621 ++	-I$(ROOTDIR)/modules/ixp425/ixp400-1.4/ixp400_xscale_sw/src/linux \
30622 ++	-DUSE_IXP4XX_CRYPTO
30623 ++endif
30624 ++ifndef IXPDIR
30625 ++IXPDIR = ixp-version-is-not-supported
30626 ++endif
30627 ++
30628 ++ifeq ($(CONFIG_CPU_IXP46X),y)
30629 ++IXP_CFLAGS += -D__ixp46X
30630 ++else
30631 ++ifeq ($(CONFIG_CPU_IXP43X),y)
30632 ++IXP_CFLAGS += -D__ixp43X
30633 ++else
30634 ++IXP_CFLAGS += -D__ixp42X
30635 ++endif
30636 ++endif
30637 ++
30638 ++obj-$(CONFIG_OCF_IXP4XX) += ixp4xx.o
30639 ++
30640 ++obj ?= .
30641 ++EXTRA_CFLAGS += $(IXP_CFLAGS) -I$(obj)/.. -I$(obj)/.
30642 ++
30643 ++ifdef TOPDIR
30644 ++-include $(TOPDIR)/Rules.make
30645 ++endif
30646 ++
30647 +diff -urN linux-2.6.23.16.old/crypto/ocf/Kconfig linux-2.6.23.16/crypto/ocf/Kconfig
30648 +--- linux-2.6.23.16.old/crypto/ocf/Kconfig	1969-12-31 19:00:00.000000000 -0500
30649 ++++ linux-2.6.23.16/crypto/ocf/Kconfig	2008-02-26 09:29:13.000000000 -0500
30650 +@@ -0,0 +1,95 @@
30651 ++menu "OCF Configuration"
30652 ++
30653 ++config OCF_OCF
30654 ++	tristate "OCF (Open Cryptograhic Framework)"
30655 ++	help
30656 ++	  A linux port of the OpenBSD/FreeBSD crypto framework.
30657 ++
30658 ++config OCF_RANDOMHARVEST
30659 ++	tristate "crypto random --- harvest entropy for /dev/random"
30660 ++	depends on OCF_OCF
30661 ++	help
30662 ++	  Includes code to harvest random numbers from devices that support it.
30663 ++
30664 ++config OCF_FIPS
30665 ++	tristate "enable fips RNG checks"
30666 ++	depends on OCF_OCF && OCF_RANDOMHARVEST
30667 ++	help
30668 ++	  Run all RNG provided data through a fips check before
30669 ++	  adding it /dev/random's entropy pool.
30670 ++
30671 ++config OCF_CRYPTODEV
30672 ++	tristate "cryptodev (user space support)"
30673 ++	depends on OCF_OCF
30674 ++	help
30675 ++	  The user space API to access crypto hardware.
30676 ++
30677 ++config OCF_CRYPTOSOFT
30678 ++	tristate "cryptosoft (software crypto engine)"
30679 ++	depends on OCF_OCF
30680 ++	help
30681 ++	  A software driver for the OCF framework that uses
30682 ++	  the kernel CryptoAPI.
30683 ++
30684 ++config OCF_SAFE
30685 ++	tristate "safenet (HW crypto engine)"
30686 ++	depends on OCF_OCF
30687 ++	help
30688 ++	  A driver for a number of the safenet Excel crypto accelerators.
30689 ++	  Currently tested and working on the 1141 and 1741.
30690 ++
30691 ++config OCF_IXP4XX
30692 ++	tristate "IXP4xx (HW crypto engine)"
30693 ++	depends on OCF_OCF
30694 ++	help
30695 ++	  XScale IXP4xx crypto accelerator driver.  Requires the
30696 ++	  Intel Access library.
30697 ++
30698 ++config OCF_IXP4XX_SHA1_MD5
30699 ++	bool "IXP4xx SHA1 and MD5 Hashing"
30700 ++	depends on OCF_IXP4XX
30701 ++	help
30702 ++	  Allows the IXP4xx crypto accelerator to perform SHA1 and MD5 hashing.
30703 ++	  Note: this is MUCH slower than using cryptosoft (software crypto engine).
30704 ++
30705 ++config OCF_HIFN
30706 ++	tristate "hifn (HW crypto engine)"
30707 ++	depends on OCF_OCF
30708 ++	help
30709 ++	  OCF driver for various HIFN based crypto accelerators.
30710 ++	  (7951, 7955, 7956, 7751, 7811)
30711 ++
30712 ++config OCF_HIFNHIPP
30713 ++	tristate "Hifn HIPP (HW packet crypto engine)"
30714 ++	depends on OCF_OCF
30715 ++	help
30716 ++	  OCF driver for various HIFN (HIPP) based crypto accelerators
30717 ++	  (7855)
30718 ++
30719 ++config OCF_TALITOS
30720 ++	tristate "talitos (HW crypto engine)"
30721 ++	depends on OCF_OCF
30722 ++	help
30723 ++	  OCF driver for Freescale's security engine (SEC/talitos).
30724 ++
30725 ++config OCF_PASEMI
30726 ++        tristate "pasemi (HW crypto engine)"
30727 ++        depends on OCF_OCF && PPC_PASEMI
30728 ++        help
30729 ++          OCF driver for for PA Semi PWRficient DMA Engine
30730 ++
30731 ++config OCF_OCFNULL
30732 ++	tristate "ocfnull (fake crypto engine)"
30733 ++	depends on OCF_OCF
30734 ++	help
30735 ++	  OCF driver for measuring ipsec overheads (does no crypto)
30736 ++
30737 ++config OCF_BENCH
30738 ++	tristate "ocf-bench (HW crypto in-kernel benchmark)"
30739 ++	depends on OCF_OCF
30740 ++	help
30741 ++	  A very simple encryption test for the in-kernel interface
30742 ++	  of OCF.  Also includes code to benchmark the IXP Access library
30743 ++	  for comparison.
30744 ++
30745 ++endmenu
30746 +diff -urN linux-2.6.23.16.old/crypto/ocf/Makefile linux-2.6.23.16/crypto/ocf/Makefile
30747 +--- linux-2.6.23.16.old/crypto/ocf/Makefile	1969-12-31 19:00:00.000000000 -0500
30748 ++++ linux-2.6.23.16/crypto/ocf/Makefile	2008-02-26 09:29:13.000000000 -0500
30749 +@@ -0,0 +1,120 @@
30750 ++# for SGlinux builds
30751 ++-include $(ROOTDIR)/modules/.config
30752 ++
30753 ++OCF_OBJS = crypto.o criov.o
30754 ++
30755 ++ifdef CONFIG_OCF_RANDOMHARVEST
30756 ++	OCF_OBJS += random.o
30757 ++endif
30758 ++
30759 ++ifdef CONFIG_OCF_FIPS
30760 ++	OCF_OBJS += rndtest.o
30761 ++endif
30762 ++
30763 ++# Add in autoconf.h to get #defines for CONFIG_xxx
30764 ++AUTOCONF_H=$(ROOTDIR)/modules/autoconf.h
30765 ++ifeq ($(AUTOCONF_H), $(wildcard $(AUTOCONF_H)))
30766 ++	EXTRA_CFLAGS += -include $(AUTOCONF_H)
30767 ++	export EXTRA_CFLAGS
30768 ++endif
30769 ++
30770 ++ifndef obj
30771 ++	obj ?= .
30772 ++	_obj = subdir
30773 ++	mod-subdirs := safe hifn ixp4xx talitos ocfnull
30774 ++	export-objs += crypto.o criov.o random.o
30775 ++	list-multi += ocf.o
30776 ++	_slash :=
30777 ++else
30778 ++	_obj = obj
30779 ++	_slash := /
30780 ++endif
30781 ++
30782 ++EXTRA_CFLAGS += -I$(obj)/.
30783 ++
30784 ++obj-$(CONFIG_OCF_OCF)         += ocf.o
30785 ++obj-$(CONFIG_OCF_CRYPTODEV)   += cryptodev.o
30786 ++obj-$(CONFIG_OCF_CRYPTOSOFT)  += cryptosoft.o
30787 ++obj-$(CONFIG_OCF_BENCH)       += ocf-bench.o
30788 ++
30789 ++$(_obj)-$(CONFIG_OCF_SAFE)    += safe$(_slash)
30790 ++$(_obj)-$(CONFIG_OCF_HIFN)    += hifn$(_slash)
30791 ++$(_obj)-$(CONFIG_OCF_IXP4XX)  += ixp4xx$(_slash)
30792 ++$(_obj)-$(CONFIG_OCF_TALITOS) += talitos$(_slash)
30793 ++$(_obj)-$(CONFIG_OCF_PASEMI)  += pasemi$(_slash)
30794 ++$(_obj)-$(CONFIG_OCF_OCFNULL) += ocfnull$(_slash)
30795 ++
30796 ++ocf-objs := $(OCF_OBJS)
30797 ++
30798 ++$(list-multi) dummy1: $(ocf-objs)
30799 ++	$(LD) -r -o $@ $(ocf-objs)
30800 ++
30801 ++.PHONY:
30802 ++clean:
30803 ++	rm -f *.o *.ko .*.o.flags .*.ko.cmd .*.o.cmd .*.mod.o.cmd *.mod.c
30804 ++	rm -f */*.o */*.ko */.*.o.cmd */.*.ko.cmd */.*.mod.o.cmd */*.mod.c */.*.o.flags
30805 ++
30806 ++ifdef TOPDIR
30807 ++-include $(TOPDIR)/Rules.make
30808 ++endif
30809 ++
30810 ++#
30811 ++# release gen targets
30812 ++#
30813 ++
30814 ++.PHONY: patch
30815 ++patch:
30816 ++	REL=`date +%Y%m%d`; \
30817 ++		patch=ocf-linux-$$REL.patch; \
30818 ++		patch24=ocf-linux-24-$$REL.patch; \
30819 ++		patch26=ocf-linux-26-$$REL.patch; \
30820 ++		( \
30821 ++			find . -name Makefile; \
30822 ++			find . -name Config.in; \
30823 ++			find . -name Kconfig; \
30824 ++			find . -name README; \
30825 ++			find . -name '*.[ch]' | grep -v '.mod.c'; \
30826 ++		) | while read t; do \
30827 ++			diff -Nau /dev/null $$t | sed 's?^+++ \./?+++ linux/crypto/ocf/?'; \
30828 ++		done > $$patch; \
30829 ++		cat patches/linux-2.4.35-ocf.patch $$patch > $$patch24; \
30830 ++		cat patches/linux-2.6.23-ocf.patch $$patch > $$patch26
30831 ++
30832 ++.PHONY: tarball
30833 ++tarball:
30834 ++	REL=`date +%Y%m%d`; RELDIR=/tmp/ocf-linux-$$REL; \
30835 ++		CURDIR=`pwd`; \
30836 ++		rm -rf /tmp/ocf-linux-$$REL*; \
30837 ++		mkdir -p $$RELDIR/tools; \
30838 ++		cp README* $$RELDIR; \
30839 ++		cp patches/openss*.patch $$RELDIR; \
30840 ++		cp patches/crypto-tools.patch $$RELDIR; \
30841 ++		cp tools/[!C]* $$RELDIR/tools; \
30842 ++		cd ..; \
30843 ++		tar cvf $$RELDIR/ocf-linux.tar \
30844 ++					--exclude=CVS \
30845 ++					--exclude=.* \
30846 ++					--exclude=*.o \
30847 ++					--exclude=*.ko \
30848 ++					--exclude=*.mod.* \
30849 ++					--exclude=README* \
30850 ++					--exclude=ocf-*.patch \
30851 ++					--exclude=ocf/patches/openss*.patch \
30852 ++					--exclude=ocf/patches/crypto-tools.patch \
30853 ++					--exclude=ocf/tools \
30854 ++					ocf; \
30855 ++		gzip -9 $$RELDIR/ocf-linux.tar; \
30856 ++		cd /tmp; \
30857 ++		tar cvf ocf-linux-$$REL.tar ocf-linux-$$REL; \
30858 ++		gzip -9 ocf-linux-$$REL.tar; \
30859 ++		cd $$CURDIR/../../user; \
30860 ++		rm -rf /tmp/crypto-tools-$$REL*; \
30861 ++		tar cvf /tmp/crypto-tools-$$REL.tar \
30862 ++					--exclude=CVS \
30863 ++					--exclude=.* \
30864 ++					--exclude=*.o \
30865 ++					--exclude=cryptotest \
30866 ++					--exclude=cryptokeytest \
30867 ++					crypto-tools; \
30868 ++		gzip -9 /tmp/crypto-tools-$$REL.tar
30869 ++
30870 +diff -urN linux-2.6.23.16.old/crypto/ocf/ocf-bench.c linux-2.6.23.16/crypto/ocf/ocf-bench.c
30871 +--- linux-2.6.23.16.old/crypto/ocf/ocf-bench.c	1969-12-31 19:00:00.000000000 -0500
30872 ++++ linux-2.6.23.16/crypto/ocf/ocf-bench.c	2008-02-26 09:29:13.000000000 -0500
30873 +@@ -0,0 +1,436 @@
30874 ++/*
30875 ++ * A loadable module that benchmarks the OCF crypto speed from kernel space.
30876 ++ *
30877 ++ * Copyright (C) 2004-2007 David McCullough <david_mccullough@securecomputing.com>
30878 ++ *
30879 ++ * LICENSE TERMS
30880 ++ *
30881 ++ * The free distribution and use of this software in both source and binary
30882 ++ * form is allowed (with or without changes) provided that:
30883 ++ *
30884 ++ *   1. distributions of this source code include the above copyright
30885 ++ *      notice, this list of conditions and the following disclaimer;
30886 ++ *
30887 ++ *   2. distributions in binary form include the above copyright
30888 ++ *      notice, this list of conditions and the following disclaimer
30889 ++ *      in the documentation and/or other associated materials;
30890 ++ *
30891 ++ *   3. the copyright holder's name is not used to endorse products
30892 ++ *      built using this software without specific written permission.
30893 ++ *
30894 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
30895 ++ * may be distributed under the terms of the GNU General Public License (GPL),
30896 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
30897 ++ *
30898 ++ * DISCLAIMER
30899 ++ *
30900 ++ * This software is provided 'as is' with no explicit or implied warranties
30901 ++ * in respect of its properties, including, but not limited to, correctness
30902 ++ * and/or fitness for purpose.
30903 ++ */
30904 ++
30905 ++
30906 ++#ifndef AUTOCONF_INCLUDED
30907 ++#include <linux/config.h>
30908 ++#endif
30909 ++#include <linux/module.h>
30910 ++#include <linux/init.h>
30911 ++#include <linux/list.h>
30912 ++#include <linux/slab.h>
30913 ++#include <linux/wait.h>
30914 ++#include <linux/sched.h>
30915 ++#include <linux/spinlock.h>
30916 ++#include <linux/version.h>
30917 ++#include <linux/interrupt.h>
30918 ++#include <cryptodev.h>
30919 ++
30920 ++#ifdef I_HAVE_AN_XSCALE_WITH_INTEL_SDK
30921 ++#define BENCH_IXP_ACCESS_LIB 1
30922 ++#endif
30923 ++#ifdef BENCH_IXP_ACCESS_LIB
30924 ++#include <IxTypes.h>
30925 ++#include <IxOsBuffMgt.h>
30926 ++#include <IxNpeDl.h>
30927 ++#include <IxCryptoAcc.h>
30928 ++#include <IxQMgr.h>
30929 ++#include <IxOsServices.h>
30930 ++#include <IxOsCacheMMU.h>
30931 ++#endif
30932 ++
30933 ++/*
30934 ++ * support for access lib version 1.4
30935 ++ */
30936 ++#ifndef IX_MBUF_PRIV
30937 ++#define IX_MBUF_PRIV(x) ((x)->priv)
30938 ++#endif
30939 ++
30940 ++/*
30941 ++ * the number of simultaneously active requests
30942 ++ */
30943 ++static int request_q_len = 20;
30944 ++module_param(request_q_len, int, 0);
30945 ++MODULE_PARM_DESC(request_q_len, "Number of outstanding requests");
30946 ++/*
30947 ++ * how many requests we want to have processed
30948 ++ */
30949 ++static int request_num = 1024;
30950 ++module_param(request_num, int, 0);
30951 ++MODULE_PARM_DESC(request_num, "run for at least this many requests");
30952 ++/*
30953 ++ * the size of each request
30954 ++ */
30955 ++static int request_size = 1500;
30956 ++module_param(request_size, int, 0);
30957 ++MODULE_PARM_DESC(request_size, "size of each request");
30958 ++
30959 ++/*
30960 ++ * a structure for each request
30961 ++ */
30962 ++typedef struct  {
30963 ++	struct work_struct work;
30964 ++#ifdef BENCH_IXP_ACCESS_LIB
30965 ++	IX_MBUF mbuf;
30966 ++#endif
30967 ++	unsigned char *buffer;
30968 ++} request_t;
30969 ++
30970 ++static request_t *requests;
30971 ++
30972 ++static int outstanding;
30973 ++static int total;
30974 ++
30975 ++/*************************************************************************/
30976 ++/*
30977 ++ * OCF benchmark routines
30978 ++ */
30979 ++
30980 ++static uint64_t ocf_cryptoid;
30981 ++static int ocf_init(void);
30982 ++static int ocf_cb(struct cryptop *crp);
30983 ++static void ocf_request(void *arg);
30984 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
30985 ++static void ocf_request_wq(struct work_struct *work);
30986 ++#endif
30987 ++
30988 ++static int
30989 ++ocf_init(void)
30990 ++{
30991 ++	int error;
30992 ++	struct cryptoini crie, cria;
30993 ++	struct cryptodesc crda, crde;
30994 ++
30995 ++	memset(&crie, 0, sizeof(crie));
30996 ++	memset(&cria, 0, sizeof(cria));
30997 ++	memset(&crde, 0, sizeof(crde));
30998 ++	memset(&crda, 0, sizeof(crda));
30999 ++
31000 ++	cria.cri_alg  = CRYPTO_SHA1_HMAC;
31001 ++	cria.cri_klen = 20 * 8;
31002 ++	cria.cri_key  = "0123456789abcdefghij";
31003 ++
31004 ++	crie.cri_alg  = CRYPTO_3DES_CBC;
31005 ++	crie.cri_klen = 24 * 8;
31006 ++	crie.cri_key  = "0123456789abcdefghijklmn";
31007 ++
31008 ++	crie.cri_next = &cria;
31009 ++
31010 ++	error = crypto_newsession(&ocf_cryptoid, &crie, 0);
31011 ++	if (error) {
31012 ++		printk("crypto_newsession failed %d\n", error);
31013 ++		return -1;
31014 ++	}
31015 ++	return 0;
31016 ++}
31017 ++
31018 ++static int
31019 ++ocf_cb(struct cryptop *crp)
31020 ++{
31021 ++	request_t *r = (request_t *) crp->crp_opaque;
31022 ++
31023 ++	if (crp->crp_etype)
31024 ++		printk("Error in OCF processing: %d\n", crp->crp_etype);
31025 ++	total++;
31026 ++	crypto_freereq(crp);
31027 ++	crp = NULL;
31028 ++
31029 ++	if (total > request_num) {
31030 ++		outstanding--;
31031 ++		return 0;
31032 ++	}
31033 ++
31034 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
31035 ++	INIT_WORK(&r->work, ocf_request_wq);
31036 ++#else
31037 ++	INIT_WORK(&r->work, ocf_request, r);
31038 ++#endif
31039 ++	schedule_work(&r->work);
31040 ++	return 0;
31041 ++}
31042 ++
31043 ++
31044 ++static void
31045 ++ocf_request(void *arg)
31046 ++{
31047 ++	request_t *r = arg;
31048 ++	struct cryptop *crp = crypto_getreq(2);
31049 ++	struct cryptodesc *crde, *crda;
31050 ++
31051 ++	if (!crp) {
31052 ++		outstanding--;
31053 ++		return;
31054 ++	}
31055 ++
31056 ++	crde = crp->crp_desc;
31057 ++	crda = crde->crd_next;
31058 ++
31059 ++	crda->crd_skip = 0;
31060 ++	crda->crd_flags = 0;
31061 ++	crda->crd_len = request_size;
31062 ++	crda->crd_inject = request_size;
31063 ++	crda->crd_alg = CRYPTO_SHA1_HMAC;
31064 ++	crda->crd_key = "0123456789abcdefghij";
31065 ++	crda->crd_klen = 20 * 8;
31066 ++
31067 ++	crde->crd_skip = 0;
31068 ++	crde->crd_flags = CRD_F_IV_EXPLICIT | CRD_F_ENCRYPT;
31069 ++	crde->crd_len = request_size;
31070 ++	crde->crd_inject = request_size;
31071 ++	crde->crd_alg = CRYPTO_3DES_CBC;
31072 ++	crde->crd_key = "0123456789abcdefghijklmn";
31073 ++	crde->crd_klen = 24 * 8;
31074 ++
31075 ++	crp->crp_ilen = request_size + 64;
31076 ++	crp->crp_flags = CRYPTO_F_CBIMM;
31077 ++	crp->crp_buf = (caddr_t) r->buffer;
31078 ++	crp->crp_callback = ocf_cb;
31079 ++	crp->crp_sid = ocf_cryptoid;
31080 ++	crp->crp_opaque = (caddr_t) r;
31081 ++	crypto_dispatch(crp);
31082 ++}
31083 ++
31084 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
31085 ++static void
31086 ++ocf_request_wq(struct work_struct *work)
31087 ++{
31088 ++	request_t *r = container_of(work, request_t, work);
31089 ++	ocf_request(r);
31090 ++}
31091 ++#endif
31092 ++
31093 ++/*************************************************************************/
31094 ++#ifdef BENCH_IXP_ACCESS_LIB
31095 ++/*************************************************************************/
31096 ++/*
31097 ++ * CryptoAcc benchmark routines
31098 ++ */
31099 ++
31100 ++static IxCryptoAccCtx ixp_ctx;
31101 ++static UINT32 ixp_ctx_id;
31102 ++static IX_MBUF ixp_pri;
31103 ++static IX_MBUF ixp_sec;
31104 ++static int ixp_registered = 0;
31105 ++
31106 ++static void ixp_register_cb(UINT32 ctx_id, IX_MBUF *bufp,
31107 ++					IxCryptoAccStatus status);
31108 ++static void ixp_perform_cb(UINT32 ctx_id, IX_MBUF *sbufp, IX_MBUF *dbufp,
31109 ++					IxCryptoAccStatus status);
31110 ++static void ixp_request(void *arg);
31111 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
31112 ++static void ixp_request_wq(struct work_struct *work);
31113 ++#endif
31114 ++
31115 ++static int
31116 ++ixp_init(void)
31117 ++{
31118 ++	IxCryptoAccStatus status;
31119 ++
31120 ++	ixp_ctx.cipherCtx.cipherAlgo = IX_CRYPTO_ACC_CIPHER_3DES;
31121 ++	ixp_ctx.cipherCtx.cipherMode = IX_CRYPTO_ACC_MODE_CBC;
31122 ++	ixp_ctx.cipherCtx.cipherKeyLen = 24;
31123 ++	ixp_ctx.cipherCtx.cipherBlockLen = IX_CRYPTO_ACC_DES_BLOCK_64;
31124 ++	ixp_ctx.cipherCtx.cipherInitialVectorLen = IX_CRYPTO_ACC_DES_IV_64;
31125 ++	memcpy(ixp_ctx.cipherCtx.key.cipherKey, "0123456789abcdefghijklmn", 24);
31126 ++
31127 ++	ixp_ctx.authCtx.authAlgo = IX_CRYPTO_ACC_AUTH_SHA1;
31128 ++	ixp_ctx.authCtx.authDigestLen = 12;
31129 ++	ixp_ctx.authCtx.aadLen = 0;
31130 ++	ixp_ctx.authCtx.authKeyLen = 20;
31131 ++	memcpy(ixp_ctx.authCtx.key.authKey, "0123456789abcdefghij", 20);
31132 ++
31133 ++	ixp_ctx.useDifferentSrcAndDestMbufs = 0;
31134 ++	ixp_ctx.operation = IX_CRYPTO_ACC_OP_ENCRYPT_AUTH ;
31135 ++
31136 ++	IX_MBUF_MLEN(&ixp_pri)  = IX_MBUF_PKT_LEN(&ixp_pri) = 128;
31137 ++	IX_MBUF_MDATA(&ixp_pri) = (unsigned char *) kmalloc(128, SLAB_ATOMIC);
31138 ++	IX_MBUF_MLEN(&ixp_sec)  = IX_MBUF_PKT_LEN(&ixp_sec) = 128;
31139 ++	IX_MBUF_MDATA(&ixp_sec) = (unsigned char *) kmalloc(128, SLAB_ATOMIC);
31140 ++
31141 ++	status = ixCryptoAccCtxRegister(&ixp_ctx, &ixp_pri, &ixp_sec,
31142 ++			ixp_register_cb, ixp_perform_cb, &ixp_ctx_id);
31143 ++
31144 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS == status) {
31145 ++		while (!ixp_registered)
31146 ++			schedule();
31147 ++		return ixp_registered < 0 ? -1 : 0;
31148 ++	}
31149 ++
31150 ++	printk("ixp: ixCryptoAccCtxRegister failed %d\n", status);
31151 ++	return -1;
31152 ++}
31153 ++
31154 ++static void
31155 ++ixp_register_cb(UINT32 ctx_id, IX_MBUF *bufp, IxCryptoAccStatus status)
31156 ++{
31157 ++	if (bufp) {
31158 ++		IX_MBUF_MLEN(bufp) = IX_MBUF_PKT_LEN(bufp) = 0;
31159 ++		kfree(IX_MBUF_MDATA(bufp));
31160 ++		IX_MBUF_MDATA(bufp) = NULL;
31161 ++	}
31162 ++
31163 ++	if (IX_CRYPTO_ACC_STATUS_WAIT == status)
31164 ++		return;
31165 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS == status)
31166 ++		ixp_registered = 1;
31167 ++	else
31168 ++		ixp_registered = -1;
31169 ++}
31170 ++
31171 ++static void
31172 ++ixp_perform_cb(
31173 ++	UINT32 ctx_id,
31174 ++	IX_MBUF *sbufp,
31175 ++	IX_MBUF *dbufp,
31176 ++	IxCryptoAccStatus status)
31177 ++{
31178 ++	request_t *r = NULL;
31179 ++
31180 ++	total++;
31181 ++	if (total > request_num) {
31182 ++		outstanding--;
31183 ++		return;
31184 ++	}
31185 ++
31186 ++	if (!sbufp || !(r = IX_MBUF_PRIV(sbufp))) {
31187 ++		printk("crappo %p %p\n", sbufp, r);
31188 ++		outstanding--;
31189 ++		return;
31190 ++	}
31191 ++
31192 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
31193 ++	INIT_WORK(&r->work, ixp_request_wq);
31194 ++#else
31195 ++	INIT_WORK(&r->work, ixp_request, r);
31196 ++#endif
31197 ++	schedule_work(&r->work);
31198 ++}
31199 ++
31200 ++static void
31201 ++ixp_request(void *arg)
31202 ++{
31203 ++	request_t *r = arg;
31204 ++	IxCryptoAccStatus status;
31205 ++
31206 ++	memset(&r->mbuf, 0, sizeof(r->mbuf));
31207 ++	IX_MBUF_MLEN(&r->mbuf) = IX_MBUF_PKT_LEN(&r->mbuf) = request_size + 64;
31208 ++	IX_MBUF_MDATA(&r->mbuf) = r->buffer;
31209 ++	IX_MBUF_PRIV(&r->mbuf) = r;
31210 ++	status = ixCryptoAccAuthCryptPerform(ixp_ctx_id, &r->mbuf, NULL,
31211 ++			0, request_size, 0, request_size, request_size, r->buffer);
31212 ++	if (IX_CRYPTO_ACC_STATUS_SUCCESS != status) {
31213 ++		printk("status1 = %d\n", status);
31214 ++		outstanding--;
31215 ++		return;
31216 ++	}
31217 ++	return;
31218 ++}
31219 ++
31220 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
31221 ++static void
31222 ++ixp_request_wq(struct work_struct *work)
31223 ++{
31224 ++	request_t *r = container_of(work, request_t, work);
31225 ++	ixp_request(r);
31226 ++}
31227 ++#endif
31228 ++
31229 ++/*************************************************************************/
31230 ++#endif /* BENCH_IXP_ACCESS_LIB */
31231 ++/*************************************************************************/
31232 ++
31233 ++int
31234 ++ocfbench_init(void)
31235 ++{
31236 ++	int i, jstart, jstop;
31237 ++
31238 ++	printk("Crypto Speed tests\n");
31239 ++
31240 ++	requests = kmalloc(sizeof(request_t) * request_q_len, GFP_KERNEL);
31241 ++	if (!requests) {
31242 ++		printk("malloc failed\n");
31243 ++		return -EINVAL;
31244 ++	}
31245 ++
31246 ++	for (i = 0; i < request_q_len; i++) {
31247 ++		/* +64 for return data */
31248 ++		requests[i].buffer = kmalloc(request_size + 128, GFP_DMA);
31249 ++		if (!requests[i].buffer) {
31250 ++			printk("malloc failed\n");
31251 ++			return -EINVAL;
31252 ++		}
31253 ++		memset(requests[i].buffer, '0' + i, request_size + 128);
31254 ++	}
31255 ++
31256 ++	/*
31257 ++	 * OCF benchmark
31258 ++	 */
31259 ++	printk("OCF: testing ...\n");
31260 ++	ocf_init();
31261 ++	total = outstanding = 0;
31262 ++	jstart = jiffies;
31263 ++	for (i = 0; i < request_q_len; i++) {
31264 ++		outstanding++;
31265 ++		ocf_request(&requests[i]);
31266 ++	}
31267 ++	while (outstanding > 0)
31268 ++		schedule();
31269 ++	jstop = jiffies;
31270 ++
31271 ++	printk("OCF: %d requests of %d bytes in %d jiffies\n", total, request_size,
31272 ++			jstop - jstart);
31273 ++
31274 ++#ifdef BENCH_IXP_ACCESS_LIB
31275 ++	/*
31276 ++	 * IXP benchmark
31277 ++	 */
31278 ++	printk("IXP: testing ...\n");
31279 ++	ixp_init();
31280 ++	total = outstanding = 0;
31281 ++	jstart = jiffies;
31282 ++	for (i = 0; i < request_q_len; i++) {
31283 ++		outstanding++;
31284 ++		ixp_request(&requests[i]);
31285 ++	}
31286 ++	while (outstanding > 0)
31287 ++		schedule();
31288 ++	jstop = jiffies;
31289 ++
31290 ++	printk("IXP: %d requests of %d bytes in %d jiffies\n", total, request_size,
31291 ++			jstop - jstart);
31292 ++#endif /* BENCH_IXP_ACCESS_LIB */
31293 ++
31294 ++	for (i = 0; i < request_q_len; i++)
31295 ++		kfree(requests[i].buffer);
31296 ++	kfree(requests);
31297 ++	return -EINVAL; /* always fail to load so it can be re-run quickly ;-) */
31298 ++}
31299 ++
31300 ++static void __exit ocfbench_exit(void)
31301 ++{
31302 ++}
31303 ++
31304 ++module_init(ocfbench_init);
31305 ++module_exit(ocfbench_exit);
31306 ++
31307 ++MODULE_LICENSE("BSD");
31308 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
31309 ++MODULE_DESCRIPTION("Benchmark various in-kernel crypto speeds");
31310 +diff -urN linux-2.6.23.16.old/crypto/ocf/ocf-compat.h linux-2.6.23.16/crypto/ocf/ocf-compat.h
31311 +--- linux-2.6.23.16.old/crypto/ocf/ocf-compat.h	1969-12-31 19:00:00.000000000 -0500
31312 ++++ linux-2.6.23.16/crypto/ocf/ocf-compat.h	2008-02-26 09:29:13.000000000 -0500
31313 +@@ -0,0 +1,249 @@
31314 ++#ifndef _BSD_COMPAT_H_
31315 ++#define _BSD_COMPAT_H_ 1
31316 ++/****************************************************************************/
31317 ++/*
31318 ++ * Provide compat routines for older linux kernels and BSD kernels
31319 ++ *
31320 ++ * Written by David McCullough <david_mccullough@securecomputing.com>
31321 ++ * Copyright (C) 2007 David McCullough <david_mccullough@securecomputing.com>
31322 ++ *
31323 ++ * LICENSE TERMS
31324 ++ *
31325 ++ * The free distribution and use of this software in both source and binary
31326 ++ * form is allowed (with or without changes) provided that:
31327 ++ *
31328 ++ *   1. distributions of this source code include the above copyright
31329 ++ *      notice, this list of conditions and the following disclaimer;
31330 ++ *
31331 ++ *   2. distributions in binary form include the above copyright
31332 ++ *      notice, this list of conditions and the following disclaimer
31333 ++ *      in the documentation and/or other associated materials;
31334 ++ *
31335 ++ *   3. the copyright holder's name is not used to endorse products
31336 ++ *      built using this software without specific written permission.
31337 ++ *
31338 ++ * ALTERNATIVELY, provided that this notice is retained in full, this file
31339 ++ * may be distributed under the terms of the GNU General Public License (GPL),
31340 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
31341 ++ *
31342 ++ * DISCLAIMER
31343 ++ *
31344 ++ * This software is provided 'as is' with no explicit or implied warranties
31345 ++ * in respect of its properties, including, but not limited to, correctness
31346 ++ * and/or fitness for purpose.
31347 ++ */
31348 ++/****************************************************************************/
31349 ++#ifdef __KERNEL__
31350 ++/*
31351 ++ * fake some BSD driver interface stuff specifically for OCF use
31352 ++ */
31353 ++
31354 ++typedef struct ocf_device *device_t;
31355 ++
31356 ++typedef struct {
31357 ++	int (*cryptodev_newsession)(device_t dev, u_int32_t *sidp, struct cryptoini *cri);
31358 ++	int (*cryptodev_freesession)(device_t dev, u_int64_t tid);
31359 ++	int (*cryptodev_process)(device_t dev, struct cryptop *crp, int hint);
31360 ++	int (*cryptodev_kprocess)(device_t dev, struct cryptkop *krp, int hint);
31361 ++} device_method_t;
31362 ++#define DEVMETHOD(id, func)	id: func
31363 ++
31364 ++struct ocf_device {
31365 ++	char name[32];		/* the driver name */
31366 ++	char nameunit[32];	/* the driver name + HW instance */
31367 ++	int  unit;
31368 ++	device_method_t	methods;
31369 ++	void *softc;
31370 ++};
31371 ++
31372 ++#define CRYPTODEV_NEWSESSION(dev, sid, cri) \
31373 ++	((*(dev)->methods.cryptodev_newsession)(dev,sid,cri))
31374 ++#define CRYPTODEV_FREESESSION(dev, sid) \
31375 ++	((*(dev)->methods.cryptodev_freesession)(dev, sid))
31376 ++#define CRYPTODEV_PROCESS(dev, crp, hint) \
31377 ++	((*(dev)->methods.cryptodev_process)(dev, crp, hint))
31378 ++#define CRYPTODEV_KPROCESS(dev, krp, hint) \
31379 ++	((*(dev)->methods.cryptodev_kprocess)(dev, krp, hint))
31380 ++
31381 ++#define device_get_name(dev)	((dev)->name)
31382 ++#define device_get_nameunit(dev)	((dev)->nameunit)
31383 ++#define device_get_unit(dev)	((dev)->unit)
31384 ++#define device_get_softc(dev)	((dev)->softc)
31385 ++
31386 ++#define	softc_device_decl \
31387 ++		struct ocf_device _device; \
31388 ++		device_t
31389 ++
31390 ++#define	softc_device_init(_sc, _name, _unit, _methods) \
31391 ++	if (1) {\
31392 ++	strncpy((_sc)->_device.name, _name, sizeof((_sc)->_device.name) - 1); \
31393 ++	snprintf((_sc)->_device.nameunit, sizeof((_sc)->_device.name), "%s%d", _name, _unit); \
31394 ++	(_sc)->_device.unit = _unit; \
31395 ++	(_sc)->_device.methods = _methods; \
31396 ++	(_sc)->_device.softc = (void *) _sc; \
31397 ++	*(device_t *)((softc_get_device(_sc))+1) = &(_sc)->_device; \
31398 ++	} else
31399 ++
31400 ++#define	softc_get_device(_sc)	(&(_sc)->_device)
31401 ++
31402 ++/*
31403 ++ * iomem support for 2.4 and 2.6 kernels
31404 ++ */
31405 ++#include <linux/version.h>
31406 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
31407 ++#define ocf_iomem_t	unsigned long
31408 ++
31409 ++/*
31410 ++ * implement simple workqueue like support for older kernels
31411 ++ */
31412 ++
31413 ++#include <linux/tqueue.h>
31414 ++
31415 ++#define work_struct tq_struct
31416 ++
31417 ++#define INIT_WORK(wp, fp, ap) \
31418 ++	do { \
31419 ++		(wp)->sync = 0; \
31420 ++		(wp)->routine = (fp); \
31421 ++		(wp)->data = (ap); \
31422 ++	} while (0)
31423 ++
31424 ++#define schedule_work(wp) \
31425 ++	do { \
31426 ++		queue_task((wp), &tq_immediate); \
31427 ++		mark_bh(IMMEDIATE_BH); \
31428 ++	} while (0)
31429 ++
31430 ++#define flush_scheduled_work()	run_task_queue(&tq_immediate)
31431 ++
31432 ++#else
31433 ++#define ocf_iomem_t	void __iomem *
31434 ++
31435 ++#include <linux/workqueue.h>
31436 ++
31437 ++#endif
31438 ++
31439 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
31440 ++#define files_fdtable(files)	(files)
31441 ++#endif
31442 ++
31443 ++#ifdef MODULE_PARM
31444 ++#undef module_param	/* just in case */
31445 ++#define	module_param(a,b,c)		MODULE_PARM(a,"i")
31446 ++#endif
31447 ++
31448 ++#define bzero(s,l)		memset(s,0,l)
31449 ++#define bcopy(s,d,l)	memcpy(d,s,l)
31450 ++#define bcmp(x, y, l)	memcmp(x,y,l)
31451 ++
31452 ++#define MIN(x,y)	((x) < (y) ? (x) : (y))
31453 ++
31454 ++#define device_printf(dev, a...) ({ \
31455 ++				printk("%s: ", device_get_nameunit(dev)); printk(a); \
31456 ++			})
31457 ++
31458 ++#undef printf
31459 ++#define printf(fmt...)	printk(fmt)
31460 ++
31461 ++#define KASSERT(c,p)	if (!(c)) { printk p ; } else
31462 ++
31463 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
31464 ++#define ocf_daemonize(str) \
31465 ++	daemonize(); \
31466 ++	spin_lock_irq(&current->sigmask_lock); \
31467 ++	sigemptyset(&current->blocked); \
31468 ++	recalc_sigpending(current); \
31469 ++	spin_unlock_irq(&current->sigmask_lock); \
31470 ++	sprintf(current->comm, str);
31471 ++#else
31472 ++#define ocf_daemonize(str) daemonize(str);
31473 ++#endif
31474 ++
31475 ++#define	TAILQ_INSERT_TAIL(q,d,m) list_add_tail(&(d)->m, (q))
31476 ++#define	TAILQ_EMPTY(q)	list_empty(q)
31477 ++#define	TAILQ_FOREACH(v, q, m) list_for_each_entry(v, q, m)
31478 ++
31479 ++#define read_random(p,l) get_random_bytes(p,l)
31480 ++
31481 ++#define DELAY(x)	((x) > 2000 ? mdelay((x)/1000) : udelay(x))
31482 ++#define strtoul simple_strtoul
31483 ++
31484 ++#define pci_get_vendor(dev)	((dev)->vendor)
31485 ++#define pci_get_device(dev)	((dev)->device)
31486 ++
31487 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
31488 ++#define pci_set_consistent_dma_mask(dev, mask) (0)
31489 ++#endif
31490 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
31491 ++#define pci_dma_sync_single_for_cpu pci_dma_sync_single
31492 ++#endif
31493 ++
31494 ++#ifndef DMA_32BIT_MASK
31495 ++#define DMA_32BIT_MASK  0x00000000ffffffffULL
31496 ++#endif
31497 ++
31498 ++#define htole32(x)	cpu_to_le32(x)
31499 ++#define htobe32(x)	cpu_to_be32(x)
31500 ++#define htole16(x)	cpu_to_le16(x)
31501 ++#define htobe16(x)	cpu_to_be16(x)
31502 ++
31503 ++/* older kernels don't have these */
31504 ++
31505 ++#ifndef IRQ_NONE
31506 ++#define IRQ_NONE
31507 ++#define IRQ_HANDLED
31508 ++#define irqreturn_t void
31509 ++#endif
31510 ++#ifndef IRQF_SHARED
31511 ++#define IRQF_SHARED	SA_SHIRQ
31512 ++#endif
31513 ++
31514 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
31515 ++# define strlcpy(dest,src,len) \
31516 ++		({strncpy(dest,src,(len)-1); ((char *)dest)[(len)-1] = '\0'; })
31517 ++#endif
31518 ++
31519 ++#ifndef MAX_ERRNO
31520 ++#define MAX_ERRNO	4095
31521 ++#endif
31522 ++#ifndef IS_ERR_VALUE
31523 ++#define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-MAX_ERRNO)
31524 ++#endif
31525 ++
31526 ++/*
31527 ++ * common debug for all
31528 ++ */
31529 ++#if 1
31530 ++#define dprintk(a...)	do { if (debug) printk(a); } while(0)
31531 ++#else
31532 ++#define dprintk(a...)
31533 ++#endif
31534 ++
31535 ++#ifndef SLAB_ATOMIC
31536 ++/* Changed in 2.6.20, must use GFP_ATOMIC now */
31537 ++#define	SLAB_ATOMIC	GFP_ATOMIC
31538 ++#endif
31539 ++
31540 ++/*
31541 ++ * need some additional support for older kernels */
31542 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,2)
31543 ++#define pci_register_driver_compat(driver, rc) \
31544 ++	do { \
31545 ++		if ((rc) > 0) { \
31546 ++			(rc) = 0; \
31547 ++		} else if (rc == 0) { \
31548 ++			(rc) = -ENODEV; \
31549 ++		} else { \
31550 ++			pci_unregister_driver(driver); \
31551 ++		} \
31552 ++	} while (0)
31553 ++#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
31554 ++#define pci_register_driver_compat(driver,rc) ((rc) = (rc) < 0 ? (rc) : 0)
31555 ++#else
31556 ++#define pci_register_driver_compat(driver,rc)
31557 ++#endif
31558 ++
31559 ++#endif /* __KERNEL__ */
31560 ++
31561 ++/****************************************************************************/
31562 ++#endif /* _BSD_COMPAT_H_ */
31563 +diff -urN linux-2.6.23.16.old/crypto/ocf/ocfnull/Makefile linux-2.6.23.16/crypto/ocf/ocfnull/Makefile
31564 +--- linux-2.6.23.16.old/crypto/ocf/ocfnull/Makefile	1969-12-31 19:00:00.000000000 -0500
31565 ++++ linux-2.6.23.16/crypto/ocf/ocfnull/Makefile	2008-02-26 09:29:13.000000000 -0500
31566 +@@ -0,0 +1,12 @@
31567 ++# for SGlinux builds
31568 ++-include $(ROOTDIR)/modules/.config
31569 ++
31570 ++obj-$(CONFIG_OCF_OCFNULL) += ocfnull.o
31571 ++
31572 ++obj ?= .
31573 ++EXTRA_CFLAGS += -I$(obj)/..
31574 ++
31575 ++ifdef TOPDIR
31576 ++-include $(TOPDIR)/Rules.make
31577 ++endif
31578 ++
31579 +diff -urN linux-2.6.23.16.old/crypto/ocf/ocfnull/ocfnull.c linux-2.6.23.16/crypto/ocf/ocfnull/ocfnull.c
31580 +--- linux-2.6.23.16.old/crypto/ocf/ocfnull/ocfnull.c	1969-12-31 19:00:00.000000000 -0500
31581 ++++ linux-2.6.23.16/crypto/ocf/ocfnull/ocfnull.c	2008-02-26 09:29:13.000000000 -0500
31582 +@@ -0,0 +1,203 @@
31583 ++/*
31584 ++ * An OCF module for determining the cost of crypto versus the cost of
31585 ++ * IPSec processing outside of OCF.  This modules gives us the effect of
31586 ++ * zero cost encryption,  of course you will need to run it at both ends
31587 ++ * since it does no crypto at all.
31588 ++ *
31589 ++ * Written by David McCullough <david_mccullough@securecomputing.com>
31590 ++ * Copyright (C) 2006-2007 David McCullough 
31591 ++ *
31592 ++ * LICENSE TERMS
31593 ++ *
31594 ++ * The free distribution and use of this software in both source and binary
31595 ++ * form is allowed (with or without changes) provided that:
31596 ++ *
31597 ++ *   1. distributions of this source code include the above copyright
31598 ++ *      notice, this list of conditions and the following disclaimer;
31599 ++ *
31600 ++ *   2. distributions in binary form include the above copyright
31601 ++ *      notice, this list of conditions and the following disclaimer
31602 ++ *      in the documentation and/or other associated materials;
31603 ++ *
31604 ++ *   3. the copyright holder's name is not used to endorse products
31605 ++ *      built using this software without specific written permission.
31606 ++ *
31607 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
31608 ++ * may be distributed under the terms of the GNU General Public License (GPL),
31609 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
31610 ++ *
31611 ++ * DISCLAIMER
31612 ++ *
31613 ++ * This software is provided 'as is' with no explicit or implied warranties
31614 ++ * in respect of its properties, including, but not limited to, correctness
31615 ++ * and/or fitness for purpose.
31616 ++ */
31617 ++
31618 ++#ifndef AUTOCONF_INCLUDED
31619 ++#include <linux/config.h>
31620 ++#endif
31621 ++#include <linux/module.h>
31622 ++#include <linux/init.h>
31623 ++#include <linux/list.h>
31624 ++#include <linux/slab.h>
31625 ++#include <linux/sched.h>
31626 ++#include <linux/wait.h>
31627 ++#include <linux/crypto.h>
31628 ++#include <linux/interrupt.h>
31629 ++
31630 ++#include <cryptodev.h>
31631 ++#include <uio.h>
31632 ++
31633 ++static int32_t			 null_id = -1;
31634 ++static u_int32_t		 null_sesnum = 0;
31635 ++
31636 ++static int null_process(device_t, struct cryptop *, int);
31637 ++static int null_newsession(device_t, u_int32_t *, struct cryptoini *);
31638 ++static int null_freesession(device_t, u_int64_t);
31639 ++
31640 ++#define debug ocfnull_debug
31641 ++int ocfnull_debug = 0;
31642 ++module_param(ocfnull_debug, int, 0644);
31643 ++MODULE_PARM_DESC(ocfnull_debug, "Enable debug");
31644 ++
31645 ++/*
31646 ++ * dummy device structure
31647 ++ */
31648 ++
31649 ++static struct {
31650 ++	softc_device_decl	sc_dev;
31651 ++} nulldev;
31652 ++
31653 ++static device_method_t null_methods = {
31654 ++	/* crypto device methods */
31655 ++	DEVMETHOD(cryptodev_newsession,	null_newsession),
31656 ++	DEVMETHOD(cryptodev_freesession,null_freesession),
31657 ++	DEVMETHOD(cryptodev_process,	null_process),
31658 ++};
31659 ++
31660 ++/*
31661 ++ * Generate a new software session.
31662 ++ */
31663 ++static int
31664 ++null_newsession(device_t arg, u_int32_t *sid, struct cryptoini *cri)
31665 ++{
31666 ++	dprintk("%s()\n", __FUNCTION__);
31667 ++	if (sid == NULL || cri == NULL) {
31668 ++		dprintk("%s,%d - EINVAL\n", __FILE__, __LINE__);
31669 ++		return EINVAL;
31670 ++	}
31671 ++
31672 ++	if (null_sesnum == 0)
31673 ++		null_sesnum++;
31674 ++	*sid = null_sesnum++;
31675 ++	return 0;
31676 ++}
31677 ++
31678 ++
31679 ++/*
31680 ++ * Free a session.
31681 ++ */
31682 ++static int
31683 ++null_freesession(device_t arg, u_int64_t tid)
31684 ++{
31685 ++	u_int32_t sid = CRYPTO_SESID2LID(tid);
31686 ++
31687 ++	dprintk("%s()\n", __FUNCTION__);
31688 ++	if (sid > null_sesnum) {
31689 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
31690 ++		return EINVAL;
31691 ++	}
31692 ++
31693 ++	/* Silently accept and return */
31694 ++	if (sid == 0)
31695 ++		return 0;
31696 ++	return 0;
31697 ++}
31698 ++
31699 ++
31700 ++/*
31701 ++ * Process a request.
31702 ++ */
31703 ++static int
31704 ++null_process(device_t arg, struct cryptop *crp, int hint)
31705 ++{
31706 ++	unsigned int lid;
31707 ++
31708 ++	dprintk("%s()\n", __FUNCTION__);
31709 ++
31710 ++	/* Sanity check */
31711 ++	if (crp == NULL) {
31712 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
31713 ++		return EINVAL;
31714 ++	}
31715 ++
31716 ++	crp->crp_etype = 0;
31717 ++
31718 ++	if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
31719 ++		dprintk("%s,%d: EINVAL\n", __FILE__, __LINE__);
31720 ++		crp->crp_etype = EINVAL;
31721 ++		goto done;
31722 ++	}
31723 ++
31724 ++	/*
31725 ++	 * find the session we are using
31726 ++	 */
31727 ++
31728 ++	lid = crp->crp_sid & 0xffffffff;
31729 ++	if (lid >= null_sesnum || lid == 0) {
31730 ++		crp->crp_etype = ENOENT;
31731 ++		dprintk("%s,%d: ENOENT\n", __FILE__, __LINE__);
31732 ++		goto done;
31733 ++	}
31734 ++
31735 ++done:
31736 ++	crypto_done(crp);
31737 ++	return 0;
31738 ++}
31739 ++
31740 ++
31741 ++/*
31742 ++ * our driver startup and shutdown routines
31743 ++ */
31744 ++
31745 ++static int
31746 ++null_init(void)
31747 ++{
31748 ++	dprintk("%s(%p)\n", __FUNCTION__, null_init);
31749 ++
31750 ++	memset(&nulldev, 0, sizeof(nulldev));
31751 ++	softc_device_init(&nulldev, "ocfnull", 0, null_methods);
31752 ++
31753 ++	null_id = crypto_get_driverid(softc_get_device(&nulldev),
31754 ++				CRYPTOCAP_F_HARDWARE);
31755 ++	if (null_id < 0)
31756 ++		panic("ocfnull: crypto device cannot initialize!");
31757 ++
31758 ++#define	REGISTER(alg) \
31759 ++	crypto_register(null_id,alg,0,0)
31760 ++	REGISTER(CRYPTO_DES_CBC);
31761 ++	REGISTER(CRYPTO_3DES_CBC);
31762 ++	REGISTER(CRYPTO_RIJNDAEL128_CBC);
31763 ++	REGISTER(CRYPTO_MD5);
31764 ++	REGISTER(CRYPTO_SHA1);
31765 ++	REGISTER(CRYPTO_MD5_HMAC);
31766 ++	REGISTER(CRYPTO_SHA1_HMAC);
31767 ++#undef REGISTER
31768 ++
31769 ++	return 0;
31770 ++}
31771 ++
31772 ++static void
31773 ++null_exit(void)
31774 ++{
31775 ++	dprintk("%s()\n", __FUNCTION__);
31776 ++	crypto_unregister_all(null_id);
31777 ++	null_id = -1;
31778 ++}
31779 ++
31780 ++module_init(null_init);
31781 ++module_exit(null_exit);
31782 ++
31783 ++MODULE_LICENSE("Dual BSD/GPL");
31784 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
31785 ++MODULE_DESCRIPTION("ocfnull - claims a lot but does nothing");
31786 +diff -urN linux-2.6.23.16.old/crypto/ocf/pasemi/Makefile linux-2.6.23.16/crypto/ocf/pasemi/Makefile
31787 +--- linux-2.6.23.16.old/crypto/ocf/pasemi/Makefile	1969-12-31 19:00:00.000000000 -0500
31788 ++++ linux-2.6.23.16/crypto/ocf/pasemi/Makefile	2008-02-26 09:29:13.000000000 -0500
31789 +@@ -0,0 +1,12 @@
31790 ++# for SGlinux builds
31791 ++-include $(ROOTDIR)/modules/.config
31792 ++
31793 ++obj-$(CONFIG_OCF_PASEMI) += pasemi.o
31794 ++
31795 ++obj ?= .
31796 ++EXTRA_CFLAGS += -I$(obj)/.. -I$(obj)/
31797 ++
31798 ++ifdef TOPDIR
31799 ++-include $(TOPDIR)/Rules.make
31800 ++endif
31801 ++
31802 +diff -urN linux-2.6.23.16.old/crypto/ocf/pasemi/pasemi.c linux-2.6.23.16/crypto/ocf/pasemi/pasemi.c
31803 +--- linux-2.6.23.16.old/crypto/ocf/pasemi/pasemi.c	1969-12-31 19:00:00.000000000 -0500
31804 ++++ linux-2.6.23.16/crypto/ocf/pasemi/pasemi.c	2008-02-26 09:29:13.000000000 -0500
31805 +@@ -0,0 +1,1009 @@
31806 ++/*
31807 ++ * Copyright (C) 2007 PA Semi, Inc
31808 ++ *
31809 ++ * Driver for the PA Semi PWRficient DMA Crypto Engine
31810 ++ *
31811 ++ * This program is free software; you can redistribute it and/or modify
31812 ++ * it under the terms of the GNU General Public License version 2 as
31813 ++ * published by the Free Software Foundation.
31814 ++ *
31815 ++ * This program is distributed in the hope that it will be useful,
31816 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
31817 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31818 ++ * GNU General Public License for more details.
31819 ++ *
31820 ++ * You should have received a copy of the GNU General Public License
31821 ++ * along with this program; if not, write to the Free Software
31822 ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
31823 ++ */
31824 ++
31825 ++#ifndef AUTOCONF_INCLUDED
31826 ++#include <linux/config.h>
31827 ++#endif
31828 ++#include <linux/module.h>
31829 ++#include <linux/init.h>
31830 ++#include <linux/interrupt.h>
31831 ++#include <linux/timer.h>
31832 ++#include <linux/random.h>
31833 ++#include <linux/skbuff.h>
31834 ++#include <asm/scatterlist.h>
31835 ++#include <linux/moduleparam.h>
31836 ++#include <linux/pci.h>
31837 ++#include <cryptodev.h>
31838 ++#include <uio.h>
31839 ++#include "pasemi_fnu.h"
31840 ++
31841 ++#define DRV_NAME "pasemi"
31842 ++
31843 ++#define TIMER_INTERVAL 1000
31844 ++
31845 ++static void __devexit pasemi_dma_remove(struct pci_dev *pdev);
31846 ++static struct pasdma_status volatile * dma_status;
31847 ++
31848 ++static int debug;
31849 ++module_param(debug, int, 0644);
31850 ++MODULE_PARM_DESC(debug, "Enable debug");
31851 ++
31852 ++static void pasemi_desc_start(struct pasemi_desc *desc, u64 hdr)
31853 ++{
31854 ++	desc->postop = 0;
31855 ++	desc->quad[0] = hdr;
31856 ++	desc->quad_cnt = 1;
31857 ++	desc->size = 1;
31858 ++}
31859 ++
31860 ++static void pasemi_desc_build(struct pasemi_desc *desc, u64 val)
31861 ++{
31862 ++	desc->quad[desc->quad_cnt++] = val;
31863 ++	desc->size = (desc->quad_cnt + 1) / 2;
31864 ++}
31865 ++
31866 ++static void pasemi_desc_hdr(struct pasemi_desc *desc, u64 hdr)
31867 ++{
31868 ++	desc->quad[0] |= hdr;
31869 ++}
31870 ++
31871 ++static int pasemi_desc_size(struct pasemi_desc *desc)
31872 ++{
31873 ++	return desc->size;
31874 ++}
31875 ++
31876 ++static void pasemi_ring_add_desc(
31877 ++				 struct pasemi_fnu_txring *ring,
31878 ++				 struct pasemi_desc *desc,
31879 ++				 struct cryptop *crp) {
31880 ++	int i;
31881 ++	int ring_index = 2 * (ring->next_to_fill & (TX_RING_SIZE-1));
31882 ++
31883 ++	TX_DESC_INFO(ring, ring->next_to_fill).desc_size = desc->size;
31884 ++	TX_DESC_INFO(ring, ring->next_to_fill).desc_postop = desc->postop;
31885 ++	TX_DESC_INFO(ring, ring->next_to_fill).cf_crp = crp;
31886 ++
31887 ++	for (i = 0; i < desc->quad_cnt; i += 2) {
31888 ++		ring_index = 2 * (ring->next_to_fill & (TX_RING_SIZE-1));
31889 ++		ring->desc[ring_index] = desc->quad[i];
31890 ++		ring->desc[ring_index + 1] = desc->quad[i + 1];
31891 ++		ring->next_to_fill++;
31892 ++	}
31893 ++
31894 ++	if (desc->quad_cnt & 1)
31895 ++		ring->desc[ring_index + 1] = 0;
31896 ++}
31897 ++
31898 ++static void pasemi_ring_incr(struct pasemi_softc *sc, int chan_index, int incr)
31899 ++{
31900 ++	out_le32(sc->dma_regs + PAS_DMA_TXCHAN_INCR(sc->base_chan + chan_index),
31901 ++		 incr);
31902 ++}
31903 ++
31904 ++/*
31905 ++ * Generate a new software session.
31906 ++ */
31907 ++static int
31908 ++pasemi_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
31909 ++{
31910 ++	struct cryptoini *c, *encini = NULL, *macini = NULL;
31911 ++	struct pasemi_softc *sc = device_get_softc(dev);
31912 ++	struct pasemi_session *ses = NULL, **sespp;
31913 ++	int sesn, blksz = 0;
31914 ++	u64 ccmd = 0;
31915 ++	unsigned long flags;
31916 ++	struct pasemi_desc init_desc;
31917 ++	struct pasemi_fnu_txring *txring;
31918 ++
31919 ++	DPRINTF("%s()\n", __FUNCTION__);
31920 ++	if (sidp == NULL || cri == NULL || sc == NULL) {
31921 ++		DPRINTF("%s,%d - EINVAL\n", __FILE__, __LINE__);
31922 ++		return -EINVAL;
31923 ++	}
31924 ++	for (c = cri; c != NULL; c = c->cri_next) {
31925 ++		if (ALG_IS_SIG(c->cri_alg)) {
31926 ++			if (macini)
31927 ++				return -EINVAL;
31928 ++			macini = c;
31929 ++		} else if (ALG_IS_CIPHER(c->cri_alg)) {
31930 ++			if (encini)
31931 ++				return -EINVAL;
31932 ++			encini = c;
31933 ++		} else {
31934 ++			DPRINTF("UNKNOWN c->cri_alg %d\n", c->cri_alg);
31935 ++			return -EINVAL;
31936 ++		}
31937 ++	}
31938 ++	if (encini == NULL && macini == NULL)
31939 ++		return -EINVAL;
31940 ++	if (encini) {
31941 ++		/* validate key length */
31942 ++		switch (encini->cri_alg) {
31943 ++		case CRYPTO_DES_CBC:
31944 ++			if (encini->cri_klen != 64)
31945 ++				return -EINVAL;
31946 ++			ccmd = DMA_CALGO_DES;
31947 ++			break;
31948 ++		case CRYPTO_3DES_CBC:
31949 ++			if (encini->cri_klen != 192)
31950 ++				return -EINVAL;
31951 ++			ccmd = DMA_CALGO_3DES;
31952 ++			break;
31953 ++		case CRYPTO_AES_CBC:
31954 ++			if (encini->cri_klen != 128 &&
31955 ++			    encini->cri_klen != 192 &&
31956 ++			    encini->cri_klen != 256)
31957 ++				return -EINVAL;
31958 ++			ccmd = DMA_CALGO_AES;
31959 ++			break;
31960 ++		case CRYPTO_ARC4:
31961 ++			if (encini->cri_klen != 128)
31962 ++				return -EINVAL;
31963 ++			ccmd = DMA_CALGO_ARC;
31964 ++			break;
31965 ++		default:
31966 ++			DPRINTF("UNKNOWN encini->cri_alg %d\n",
31967 ++				encini->cri_alg);
31968 ++			return -EINVAL;
31969 ++		}
31970 ++	}
31971 ++
31972 ++	if (macini) {
31973 ++		switch (macini->cri_alg) {
31974 ++		case CRYPTO_MD5:
31975 ++		case CRYPTO_MD5_HMAC:
31976 ++			blksz = 16;
31977 ++			break;
31978 ++		case CRYPTO_SHA1:
31979 ++		case CRYPTO_SHA1_HMAC:
31980 ++			blksz = 20;
31981 ++			break;
31982 ++		default:
31983 ++			DPRINTF("UNKNOWN macini->cri_alg %d\n",
31984 ++				macini->cri_alg);
31985 ++			return -EINVAL;
31986 ++		}
31987 ++		if (((macini->cri_klen + 7) / 8) > blksz) {
31988 ++			DPRINTF("key length %d bigger than blksize %d not supported\n",
31989 ++				((macini->cri_klen + 7) / 8), blksz);
31990 ++			return -EINVAL;
31991 ++		}
31992 ++	}
31993 ++
31994 ++	for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
31995 ++		if (sc->sc_sessions[sesn] == NULL) {
31996 ++			sc->sc_sessions[sesn] = (struct pasemi_session *)
31997 ++				kzalloc(sizeof(struct pasemi_session), GFP_ATOMIC);
31998 ++			ses = sc->sc_sessions[sesn];
31999 ++			break;
32000 ++		} else if (sc->sc_sessions[sesn]->used == 0) {
32001 ++			ses = sc->sc_sessions[sesn];
32002 ++			break;
32003 ++		}
32004 ++	}
32005 ++
32006 ++	if (ses == NULL) {
32007 ++		sespp = (struct pasemi_session **)
32008 ++			kzalloc(sc->sc_nsessions * 2 *
32009 ++				sizeof(struct pasemi_session *), GFP_ATOMIC);
32010 ++		if (sespp == NULL)
32011 ++			return -ENOMEM;
32012 ++		memcpy(sespp, sc->sc_sessions,
32013 ++		       sc->sc_nsessions * sizeof(struct pasemi_session *));
32014 ++		kfree(sc->sc_sessions);
32015 ++		sc->sc_sessions = sespp;
32016 ++		sesn = sc->sc_nsessions;
32017 ++		ses = sc->sc_sessions[sesn] = (struct pasemi_session *)
32018 ++			kzalloc(sizeof(struct pasemi_session), GFP_ATOMIC);
32019 ++		if (ses == NULL)
32020 ++			return -ENOMEM;
32021 ++		sc->sc_nsessions *= 2;
32022 ++	}
32023 ++
32024 ++	ses->used = 1;
32025 ++
32026 ++	ses->dma_addr = pci_map_single(sc->dma_pdev, (void *) ses->civ,
32027 ++				       sizeof(struct pasemi_session), DMA_TO_DEVICE);
32028 ++
32029 ++	/* enter the channel scheduler */
32030 ++	spin_lock_irqsave(&sc->sc_chnlock, flags);
32031 ++
32032 ++	/* ARC4 has to be processed by the even channel */
32033 ++	if (encini && (encini->cri_alg == CRYPTO_ARC4))
32034 ++		ses->chan = sc->sc_lastchn & ~1;
32035 ++	else
32036 ++		ses->chan = sc->sc_lastchn;
32037 ++	sc->sc_lastchn = (sc->sc_lastchn + 1) % sc->sc_num_channels;
32038 ++
32039 ++	spin_unlock_irqrestore(&sc->sc_chnlock, flags);
32040 ++
32041 ++	txring = &sc->tx[ses->chan];
32042 ++
32043 ++	if (encini) {
32044 ++		ses->ccmd = ccmd;
32045 ++
32046 ++		/* get an IV */
32047 ++		/* XXX may read fewer than requested */
32048 ++		get_random_bytes(ses->civ, sizeof(ses->civ));
32049 ++
32050 ++		ses->keysz = (encini->cri_klen - 63) / 64;
32051 ++		memcpy(ses->key, encini->cri_key, (ses->keysz + 1) * 8);
32052 ++
32053 ++		pasemi_desc_start(&init_desc,
32054 ++				  XCT_CTRL_HDR(ses->chan, (encini && macini) ? 0x68 : 0x40, DMA_FN_CIV0));
32055 ++		pasemi_desc_build(&init_desc,
32056 ++				  XCT_FUN_SRC_PTR((encini && macini) ? 0x68 : 0x40, ses->dma_addr));
32057 ++	}
32058 ++	if (macini) {
32059 ++		if (macini->cri_alg == CRYPTO_MD5_HMAC ||
32060 ++		    macini->cri_alg == CRYPTO_SHA1_HMAC)
32061 ++			memcpy(ses->hkey, macini->cri_key, blksz);
32062 ++		else {
32063 ++			/* Load initialization constants(RFC 1321, 3174) */
32064 ++			ses->hiv[0] = 0x67452301efcdab89ULL;
32065 ++			ses->hiv[1] = 0x98badcfe10325476ULL;
32066 ++			ses->hiv[2] = 0xc3d2e1f000000000ULL;
32067 ++		}
32068 ++		ses->hseq = 0ULL;
32069 ++	}
32070 ++
32071 ++	spin_lock_irqsave(&txring->fill_lock, flags);
32072 ++
32073 ++	if (((txring->next_to_fill + pasemi_desc_size(&init_desc)) -
32074 ++	     txring->next_to_clean) > TX_RING_SIZE) {
32075 ++		spin_unlock_irqrestore(&txring->fill_lock, flags);
32076 ++		return ERESTART;
32077 ++	}
32078 ++
32079 ++	if (encini) {
32080 ++		pasemi_ring_add_desc(txring, &init_desc, NULL);
32081 ++		pasemi_ring_incr(sc, ses->chan,
32082 ++				 pasemi_desc_size(&init_desc));
32083 ++	}
32084 ++
32085 ++	txring->sesn = sesn;
32086 ++	spin_unlock_irqrestore(&txring->fill_lock, flags);
32087 ++
32088 ++	*sidp = PASEMI_SID(sesn);
32089 ++	return 0;
32090 ++}
32091 ++
32092 ++/*
32093 ++ * Deallocate a session.
32094 ++ */
32095 ++static int
32096 ++pasemi_freesession(device_t dev, u_int64_t tid)
32097 ++{
32098 ++	struct pasemi_softc *sc = device_get_softc(dev);
32099 ++	int session;
32100 ++	u_int32_t sid = ((u_int32_t) tid) & 0xffffffff;
32101 ++
32102 ++	DPRINTF("%s()\n", __FUNCTION__);
32103 ++
32104 ++	if (sc == NULL)
32105 ++		return -EINVAL;
32106 ++	session = PASEMI_SESSION(sid);
32107 ++	if (session >= sc->sc_nsessions || !sc->sc_sessions[session])
32108 ++		return -EINVAL;
32109 ++
32110 ++	pci_unmap_single(sc->dma_pdev,
32111 ++			 sc->sc_sessions[session]->dma_addr,
32112 ++			 sizeof(struct pasemi_session), DMA_TO_DEVICE);
32113 ++	memset(sc->sc_sessions[session], 0,
32114 ++	       sizeof(struct pasemi_session));
32115 ++
32116 ++	return 0;
32117 ++}
32118 ++
32119 ++static int
32120 ++pasemi_process(device_t dev, struct cryptop *crp, int hint)
32121 ++{
32122 ++
32123 ++	int err = 0, ivsize, srclen = 0, reinit = 0, reinit_size = 0, chsel;
32124 ++	struct pasemi_softc *sc = device_get_softc(dev);
32125 ++	struct cryptodesc *crd1, *crd2, *maccrd, *enccrd;
32126 ++	caddr_t ivp;
32127 ++	struct pasemi_desc init_desc, work_desc;
32128 ++	struct pasemi_session *ses;
32129 ++	struct sk_buff *skb;
32130 ++	struct uio *uiop;
32131 ++	unsigned long flags;
32132 ++	struct pasemi_fnu_txring *txring;
32133 ++
32134 ++	DPRINTF("%s()\n", __FUNCTION__);
32135 ++
32136 ++	if (crp == NULL || crp->crp_callback == NULL || sc == NULL)
32137 ++		return -EINVAL;
32138 ++
32139 ++	crp->crp_etype = 0;
32140 ++	if (PASEMI_SESSION(crp->crp_sid) >= sc->sc_nsessions)
32141 ++		return -EINVAL;
32142 ++
32143 ++	ses = sc->sc_sessions[PASEMI_SESSION(crp->crp_sid)];
32144 ++
32145 ++	crd1 = crp->crp_desc;
32146 ++	if (crd1 == NULL) {
32147 ++		err = -EINVAL;
32148 ++		goto errout;
32149 ++	}
32150 ++	crd2 = crd1->crd_next;
32151 ++
32152 ++	if (ALG_IS_SIG(crd1->crd_alg)) {
32153 ++		maccrd = crd1;
32154 ++		if (crd2 == NULL)
32155 ++			enccrd = NULL;
32156 ++		else if (ALG_IS_CIPHER(crd2->crd_alg) &&
32157 ++			 (crd2->crd_flags & CRD_F_ENCRYPT) == 0)
32158 ++			enccrd = crd2;
32159 ++		else
32160 ++			goto erralg;
32161 ++	} else if (ALG_IS_CIPHER(crd1->crd_alg)) {
32162 ++		enccrd = crd1;
32163 ++		if (crd2 == NULL)
32164 ++			maccrd = NULL;
32165 ++		else if (ALG_IS_SIG(crd2->crd_alg) &&
32166 ++			 (crd1->crd_flags & CRD_F_ENCRYPT))
32167 ++			maccrd = crd2;
32168 ++		else
32169 ++			goto erralg;
32170 ++	} else
32171 ++		goto erralg;
32172 ++
32173 ++	chsel = ses->chan;
32174 ++
32175 ++	txring = &sc->tx[chsel];
32176 ++
32177 ++	if (enccrd && !maccrd) {
32178 ++		if (enccrd->crd_alg == CRYPTO_ARC4)
32179 ++			reinit = 1;
32180 ++		reinit_size = 0x40;
32181 ++		srclen = crp->crp_ilen;
32182 ++
32183 ++		pasemi_desc_start(&work_desc, XCT_FUN_O | XCT_FUN_I
32184 ++				  | XCT_FUN_FUN(chsel));
32185 ++		if (enccrd->crd_flags & CRD_F_ENCRYPT)
32186 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_CRM_ENC);
32187 ++		else
32188 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_CRM_DEC);
32189 ++	} else if (enccrd && maccrd) {
32190 ++		if (enccrd->crd_alg == CRYPTO_ARC4)
32191 ++			reinit = 1;
32192 ++		reinit_size = 0x68;
32193 ++
32194 ++		if (enccrd->crd_flags & CRD_F_ENCRYPT) {
32195 ++			/* Encrypt -> Authenticate */
32196 ++			pasemi_desc_start(&work_desc, XCT_FUN_O | XCT_FUN_I | XCT_FUN_CRM_ENC_SIG
32197 ++					  | XCT_FUN_A | XCT_FUN_FUN(chsel));
32198 ++			srclen = maccrd->crd_skip + maccrd->crd_len;
32199 ++		} else {
32200 ++			/* Authenticate -> Decrypt */
32201 ++			pasemi_desc_start(&work_desc, XCT_FUN_O | XCT_FUN_I | XCT_FUN_CRM_SIG_DEC
32202 ++					  | XCT_FUN_24BRES | XCT_FUN_FUN(chsel));
32203 ++			pasemi_desc_build(&work_desc, 0);
32204 ++			pasemi_desc_build(&work_desc, 0);
32205 ++			pasemi_desc_build(&work_desc, 0);
32206 ++			work_desc.postop = PASEMI_CHECK_SIG;
32207 ++			srclen = crp->crp_ilen;
32208 ++		}
32209 ++
32210 ++		pasemi_desc_hdr(&work_desc, XCT_FUN_SHL(maccrd->crd_skip / 4));
32211 ++		pasemi_desc_hdr(&work_desc, XCT_FUN_CHL(enccrd->crd_skip - maccrd->crd_skip));
32212 ++	} else if (!enccrd && maccrd) {
32213 ++		srclen = maccrd->crd_len;
32214 ++
32215 ++		pasemi_desc_start(&init_desc,
32216 ++				  XCT_CTRL_HDR(chsel, 0x58, DMA_FN_HKEY0));
32217 ++		pasemi_desc_build(&init_desc,
32218 ++				  XCT_FUN_SRC_PTR(0x58, ((struct pasemi_session *)ses->dma_addr)->hkey));
32219 ++
32220 ++		pasemi_desc_start(&work_desc, XCT_FUN_O | XCT_FUN_I | XCT_FUN_CRM_SIG
32221 ++				  | XCT_FUN_A | XCT_FUN_FUN(chsel));
32222 ++	}
32223 ++
32224 ++	if (enccrd) {
32225 ++		switch (enccrd->crd_alg) {
32226 ++		case CRYPTO_3DES_CBC:
32227 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_ALG_3DES |
32228 ++					XCT_FUN_BCM_CBC);
32229 ++			ivsize = sizeof(u64);
32230 ++			break;
32231 ++		case CRYPTO_DES_CBC:
32232 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_ALG_DES |
32233 ++					XCT_FUN_BCM_CBC);
32234 ++			ivsize = sizeof(u64);
32235 ++			break;
32236 ++		case CRYPTO_AES_CBC:
32237 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_ALG_AES |
32238 ++					XCT_FUN_BCM_CBC);
32239 ++			ivsize = 2 * sizeof(u64);
32240 ++			break;
32241 ++		case CRYPTO_ARC4:
32242 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_ALG_ARC);
32243 ++			ivsize = 0;
32244 ++			break;
32245 ++		default:
32246 ++			printk(DRV_NAME ": unimplemented enccrd->crd_alg %d\n",
32247 ++			       enccrd->crd_alg);
32248 ++			err = -EINVAL;
32249 ++			goto errout;
32250 ++		}
32251 ++
32252 ++		ivp = (ivsize == sizeof(u64)) ? (caddr_t) &ses->civ[1] : (caddr_t) &ses->civ[0];
32253 ++		if (enccrd->crd_flags & CRD_F_ENCRYPT) {
32254 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
32255 ++				memcpy(ivp, enccrd->crd_iv, ivsize);
32256 ++			/* If IV is not present in the buffer already, it has to be copied there */
32257 ++			if ((enccrd->crd_flags & CRD_F_IV_PRESENT) == 0)
32258 ++				crypto_copyback(crp->crp_flags, crp->crp_buf,
32259 ++						enccrd->crd_inject, ivsize, ivp);
32260 ++		} else {
32261 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
32262 ++				/* IV is provided expicitly in descriptor */
32263 ++				memcpy(ivp, enccrd->crd_iv, ivsize);
32264 ++			else
32265 ++				/* IV is provided in the packet */
32266 ++				crypto_copydata(crp->crp_flags, crp->crp_buf,
32267 ++						enccrd->crd_inject, ivsize,
32268 ++						ivp);
32269 ++		}
32270 ++	}
32271 ++
32272 ++	if (maccrd) {
32273 ++		switch (maccrd->crd_alg) {
32274 ++		case CRYPTO_MD5:
32275 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_SIG_MD5 |
32276 ++					XCT_FUN_HSZ((crp->crp_ilen - maccrd->crd_inject) / 4));
32277 ++			break;
32278 ++		case CRYPTO_SHA1:
32279 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_SIG_SHA1 |
32280 ++					XCT_FUN_HSZ((crp->crp_ilen - maccrd->crd_inject) / 4));
32281 ++			break;
32282 ++		case CRYPTO_MD5_HMAC:
32283 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_SIG_HMAC_MD5 |
32284 ++					XCT_FUN_HSZ((crp->crp_ilen - maccrd->crd_inject) / 4));
32285 ++			break;
32286 ++		case CRYPTO_SHA1_HMAC:
32287 ++			pasemi_desc_hdr(&work_desc, XCT_FUN_SIG_HMAC_SHA1 |
32288 ++					XCT_FUN_HSZ((crp->crp_ilen - maccrd->crd_inject) / 4));
32289 ++			break;
32290 ++		default:
32291 ++			printk(DRV_NAME ": unimplemented maccrd->crd_alg %d\n",
32292 ++			       maccrd->crd_alg);
32293 ++			err = -EINVAL;
32294 ++			goto errout;
32295 ++		}
32296 ++	}
32297 ++
32298 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
32299 ++		/* using SKB buffers */
32300 ++		skb = (struct sk_buff *)crp->crp_buf;
32301 ++		if (skb_shinfo(skb)->nr_frags) {
32302 ++			printk(DRV_NAME ": skb frags unimplemented\n");
32303 ++			err = -EINVAL;
32304 ++			goto errout;
32305 ++		}
32306 ++		pasemi_desc_build(
32307 ++			&work_desc,
32308 ++			XCT_FUN_DST_PTR(skb->len, pci_map_single(
32309 ++						sc->dma_pdev, skb->data,
32310 ++						skb->len, DMA_TO_DEVICE)));
32311 ++		pasemi_desc_build(
32312 ++			&work_desc,
32313 ++			XCT_FUN_SRC_PTR(
32314 ++				srclen, pci_map_single(
32315 ++					sc->dma_pdev, skb->data,
32316 ++					srclen, DMA_TO_DEVICE)));
32317 ++		pasemi_desc_hdr(&work_desc, XCT_FUN_LLEN(srclen));
32318 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
32319 ++		/* using IOV buffers */
32320 ++		uiop = (struct uio *)crp->crp_buf;
32321 ++		if (uiop->uio_iovcnt > 1) {
32322 ++			printk(DRV_NAME ": iov frags unimplemented\n");
32323 ++			err = -EINVAL;
32324 ++			goto errout;
32325 ++		}
32326 ++
32327 ++		/* crp_olen is never set; always use crp_ilen */
32328 ++		pasemi_desc_build(
32329 ++			&work_desc,
32330 ++			XCT_FUN_DST_PTR(crp->crp_ilen, pci_map_single(
32331 ++						sc->dma_pdev,
32332 ++						uiop->uio_iov->iov_base,
32333 ++						crp->crp_ilen, DMA_TO_DEVICE)));
32334 ++		pasemi_desc_hdr(&work_desc, XCT_FUN_LLEN(srclen));
32335 ++
32336 ++		pasemi_desc_build(
32337 ++			&work_desc,
32338 ++			XCT_FUN_SRC_PTR(srclen, pci_map_single(
32339 ++						sc->dma_pdev,
32340 ++						uiop->uio_iov->iov_base,
32341 ++						srclen, DMA_TO_DEVICE)));
32342 ++	} else {
32343 ++		/* using contig buffers */
32344 ++		pasemi_desc_build(
32345 ++			&work_desc,
32346 ++			XCT_FUN_DST_PTR(crp->crp_ilen, pci_map_single(
32347 ++						sc->dma_pdev,
32348 ++						crp->crp_buf,
32349 ++						crp->crp_ilen, DMA_TO_DEVICE)));
32350 ++		pasemi_desc_build(
32351 ++			&work_desc,
32352 ++			XCT_FUN_SRC_PTR(srclen, pci_map_single(
32353 ++						sc->dma_pdev,
32354 ++						crp->crp_buf, srclen,
32355 ++						DMA_TO_DEVICE)));
32356 ++		pasemi_desc_hdr(&work_desc, XCT_FUN_LLEN(srclen));
32357 ++	}
32358 ++
32359 ++	spin_lock_irqsave(&txring->fill_lock, flags);
32360 ++
32361 ++	if (txring->sesn != PASEMI_SESSION(crp->crp_sid)) {
32362 ++		txring->sesn = PASEMI_SESSION(crp->crp_sid);
32363 ++		reinit = 1;
32364 ++	}
32365 ++
32366 ++	if (enccrd) {
32367 ++		pasemi_desc_start(&init_desc,
32368 ++				  XCT_CTRL_HDR(chsel, reinit ? reinit_size : 0x10, DMA_FN_CIV0));
32369 ++		pasemi_desc_build(&init_desc,
32370 ++				  XCT_FUN_SRC_PTR(reinit ? reinit_size : 0x10, ses->dma_addr));
32371 ++	}
32372 ++
32373 ++	if (((txring->next_to_fill + pasemi_desc_size(&init_desc) +
32374 ++	      pasemi_desc_size(&work_desc)) -
32375 ++	     txring->next_to_clean) > TX_RING_SIZE) {
32376 ++		spin_unlock_irqrestore(&txring->fill_lock, flags);
32377 ++		err = ERESTART;
32378 ++		goto errout;
32379 ++	}
32380 ++
32381 ++	pasemi_ring_add_desc(txring, &init_desc, NULL);
32382 ++	pasemi_ring_add_desc(txring, &work_desc, crp);
32383 ++
32384 ++	pasemi_ring_incr(sc, chsel,
32385 ++			 pasemi_desc_size(&init_desc) +
32386 ++			 pasemi_desc_size(&work_desc));
32387 ++
32388 ++	spin_unlock_irqrestore(&txring->fill_lock, flags);
32389 ++
32390 ++	mod_timer(&txring->crypto_timer, jiffies + TIMER_INTERVAL);
32391 ++
32392 ++	return 0;
32393 ++
32394 ++erralg:
32395 ++	printk(DRV_NAME ": unsupported algorithm or algorithm order alg1 %d alg2 %d\n",
32396 ++	       crd1->crd_alg, crd2->crd_alg);
32397 ++	err = -EINVAL;
32398 ++
32399 ++errout:
32400 ++	if (err != ERESTART) {
32401 ++		crp->crp_etype = err;
32402 ++		crypto_done(crp);
32403 ++	}
32404 ++	return err;
32405 ++}
32406 ++
32407 ++static int pasemi_clean_tx(struct pasemi_softc *sc, int chan)
32408 ++{
32409 ++	int i, j, ring_idx;
32410 ++	struct pasemi_fnu_txring *ring = &sc->tx[chan];
32411 ++	u16 delta_cnt;
32412 ++	int flags, loops = 10;
32413 ++	int desc_size;
32414 ++	struct cryptop *crp;
32415 ++
32416 ++	spin_lock_irqsave(&ring->clean_lock, flags);
32417 ++
32418 ++	while ((delta_cnt = (dma_status->tx_sta[sc->base_chan + chan]
32419 ++			     & PAS_STATUS_PCNT_M) - ring->total_pktcnt)
32420 ++	       && loops--) {
32421 ++
32422 ++		for (i = 0; i < delta_cnt; i++) {
32423 ++			desc_size = TX_DESC_INFO(ring, ring->next_to_clean).desc_size;
32424 ++			crp = TX_DESC_INFO(ring, ring->next_to_clean).cf_crp;
32425 ++			if (crp) {
32426 ++				ring_idx = 2 * (ring->next_to_clean & (TX_RING_SIZE-1));
32427 ++				if (TX_DESC_INFO(ring, ring->next_to_clean).desc_postop & PASEMI_CHECK_SIG) {
32428 ++					/* Need to make sure signature matched,
32429 ++					 * if not - return error */
32430 ++					if (!(ring->desc[ring_idx + 1] & (1ULL << 63)))
32431 ++						crp->crp_etype = -EINVAL;
32432 ++				}
32433 ++				crypto_done(TX_DESC_INFO(ring,
32434 ++							 ring->next_to_clean).cf_crp);
32435 ++				TX_DESC_INFO(ring, ring->next_to_clean).cf_crp = NULL;
32436 ++				pci_unmap_single(
32437 ++					sc->dma_pdev,
32438 ++					XCT_PTR_ADDR_LEN(ring->desc[ring_idx + 1]),
32439 ++					PCI_DMA_TODEVICE);
32440 ++
32441 ++				ring->desc[ring_idx] = ring->desc[ring_idx + 1] = 0;
32442 ++
32443 ++				ring->next_to_clean++;
32444 ++				for (j = 1; j < desc_size; j++) {
32445 ++					ring_idx = 2 *
32446 ++						(ring->next_to_clean &
32447 ++						 (TX_RING_SIZE-1));
32448 ++					pci_unmap_single(
32449 ++						sc->dma_pdev,
32450 ++						XCT_PTR_ADDR_LEN(ring->desc[ring_idx]),
32451 ++						PCI_DMA_TODEVICE);
32452 ++					if (ring->desc[ring_idx + 1])
32453 ++						pci_unmap_single(
32454 ++							sc->dma_pdev,
32455 ++							XCT_PTR_ADDR_LEN(
32456 ++								ring->desc[
32457 ++									ring_idx + 1]),
32458 ++							PCI_DMA_TODEVICE);
32459 ++					ring->desc[ring_idx] =
32460 ++						ring->desc[ring_idx + 1] = 0;
32461 ++					ring->next_to_clean++;
32462 ++				}
32463 ++			} else {
32464 ++				for (j = 0; j < desc_size; j++) {
32465 ++					ring_idx = 2 * (ring->next_to_clean & (TX_RING_SIZE-1));
32466 ++					ring->desc[ring_idx] =
32467 ++						ring->desc[ring_idx + 1] = 0;
32468 ++					ring->next_to_clean++;
32469 ++				}
32470 ++			}
32471 ++		}
32472 ++
32473 ++		ring->total_pktcnt += delta_cnt;
32474 ++	}
32475 ++	spin_unlock_irqrestore(&ring->clean_lock, flags);
32476 ++
32477 ++	return 0;
32478 ++}
32479 ++
32480 ++static void sweepup_tx(struct pasemi_softc *sc)
32481 ++{
32482 ++	int i;
32483 ++
32484 ++	for (i = 0; i < sc->sc_num_channels; i++)
32485 ++		pasemi_clean_tx(sc, i);
32486 ++}
32487 ++
32488 ++static irqreturn_t pasemi_intr(int irq, void *arg, struct pt_regs *regs)
32489 ++{
32490 ++	struct pasemi_softc *sc = arg;
32491 ++	unsigned int reg;
32492 ++	int chan = irq - sc->base_irq;
32493 ++	int chan_index = sc->base_chan + chan;
32494 ++	u64 stat = dma_status->tx_sta[chan_index];
32495 ++
32496 ++	DPRINTF("%s()\n", __FUNCTION__);
32497 ++
32498 ++	if (!(stat & PAS_STATUS_CAUSE_M))
32499 ++		return IRQ_NONE;
32500 ++
32501 ++	pasemi_clean_tx(sc, chan);
32502 ++
32503 ++	stat = dma_status->tx_sta[chan_index];
32504 ++
32505 ++	reg = PAS_IOB_DMA_TXCH_RESET_PINTC |
32506 ++		PAS_IOB_DMA_TXCH_RESET_PCNT(sc->tx[chan].total_pktcnt);
32507 ++
32508 ++	if (stat & PAS_STATUS_SOFT)
32509 ++		reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
32510 ++
32511 ++	out_le32(sc->iob_regs + PAS_IOB_DMA_TXCH_RESET(chan_index), reg);
32512 ++
32513 ++
32514 ++	return IRQ_HANDLED;
32515 ++}
32516 ++
32517 ++static int pasemi_dma_setup_tx_resources(struct pasemi_softc *sc, int chan)
32518 ++{
32519 ++	u32 val;
32520 ++	int chan_index = chan + sc->base_chan;
32521 ++	int ret;
32522 ++	struct pasemi_fnu_txring *ring;
32523 ++
32524 ++	ring = &sc->tx[chan];
32525 ++
32526 ++	spin_lock_init(&ring->fill_lock);
32527 ++	spin_lock_init(&ring->clean_lock);
32528 ++
32529 ++	ring->desc_info = kzalloc(sizeof(struct pasemi_desc_info) *
32530 ++				  TX_RING_SIZE, GFP_KERNEL);
32531 ++	if (!ring->desc_info)
32532 ++		return -ENOMEM;
32533 ++
32534 ++	/* Allocate descriptors */
32535 ++	ring->desc = dma_alloc_coherent(&sc->dma_pdev->dev,
32536 ++					TX_RING_SIZE *
32537 ++					2 * sizeof(u64),
32538 ++					&ring->dma, GFP_KERNEL);
32539 ++	if (!ring->desc)
32540 ++		return -ENOMEM;
32541 ++
32542 ++	memset((void *) ring->desc, 0, TX_RING_SIZE * 2 * sizeof(u64));
32543 ++
32544 ++	out_le32(sc->iob_regs + PAS_IOB_DMA_TXCH_RESET(chan_index), 0x30);
32545 ++
32546 ++	ring->total_pktcnt = 0;
32547 ++
32548 ++	out_le32(sc->dma_regs + PAS_DMA_TXCHAN_BASEL(chan_index),
32549 ++		 PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma));
32550 ++
32551 ++	val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32);
32552 ++	val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 2);
32553 ++
32554 ++	out_le32(sc->dma_regs + PAS_DMA_TXCHAN_BASEU(chan_index), val);
32555 ++
32556 ++	out_le32(sc->dma_regs + PAS_DMA_TXCHAN_CFG(chan_index),
32557 ++		 PAS_DMA_TXCHAN_CFG_TY_FUNC |
32558 ++		 PAS_DMA_TXCHAN_CFG_TATTR(chan) |
32559 ++		 PAS_DMA_TXCHAN_CFG_WT(2));
32560 ++
32561 ++	/* enable tx channel */
32562 ++	out_le32(sc->dma_regs +
32563 ++		 PAS_DMA_TXCHAN_TCMDSTA(chan_index),
32564 ++		 PAS_DMA_TXCHAN_TCMDSTA_EN);
32565 ++
32566 ++	out_le32(sc->iob_regs + PAS_IOB_DMA_TXCH_CFG(chan_index),
32567 ++		 PAS_IOB_DMA_TXCH_CFG_CNTTH(1000));
32568 ++
32569 ++	ring->next_to_fill = 0;
32570 ++	ring->next_to_clean = 0;
32571 ++
32572 ++	snprintf(ring->irq_name, sizeof(ring->irq_name),
32573 ++		 "%s%d", "crypto", chan);
32574 ++
32575 ++	ring->irq = irq_create_mapping(NULL, sc->base_irq + chan);
32576 ++	ret = request_irq(ring->irq, (irq_handler_t)
32577 ++			  pasemi_intr, IRQF_DISABLED, ring->irq_name, sc);
32578 ++	if (ret) {
32579 ++		printk(KERN_ERR DRV_NAME ": failed to hook irq %d ret %d\n",
32580 ++		       ring->irq, ret);
32581 ++		ring->irq = -1;
32582 ++		return ret;
32583 ++	}
32584 ++
32585 ++	setup_timer(&ring->crypto_timer, (void *) sweepup_tx, (unsigned long) sc);
32586 ++
32587 ++	return 0;
32588 ++}
32589 ++
32590 ++static device_method_t pasemi_methods = {
32591 ++	/* crypto device methods */
32592 ++	DEVMETHOD(cryptodev_newsession,		pasemi_newsession),
32593 ++	DEVMETHOD(cryptodev_freesession,	pasemi_freesession),
32594 ++	DEVMETHOD(cryptodev_process,		pasemi_process),
32595 ++};
32596 ++
32597 ++/* Set up the crypto device structure, private data,
32598 ++ * and anything else we need before we start */
32599 ++
32600 ++static int __devinit
32601 ++pasemi_dma_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
32602 ++{
32603 ++	struct pasemi_softc *sc;
32604 ++	int ret, i;
32605 ++
32606 ++	DPRINTF(KERN_ERR "%s()\n", __FUNCTION__);
32607 ++
32608 ++	sc = kzalloc(sizeof(*sc), GFP_KERNEL);
32609 ++	if (!sc)
32610 ++		return -ENOMEM;
32611 ++
32612 ++	softc_device_init(sc, DRV_NAME, 1, pasemi_methods);
32613 ++
32614 ++	pci_set_drvdata(pdev, sc);
32615 ++
32616 ++	spin_lock_init(&sc->sc_chnlock);
32617 ++
32618 ++	sc->sc_sessions = (struct pasemi_session **)
32619 ++		kzalloc(PASEMI_INITIAL_SESSIONS *
32620 ++			sizeof(struct pasemi_session *), GFP_ATOMIC);
32621 ++	if (sc->sc_sessions == NULL) {
32622 ++		ret = -ENOMEM;
32623 ++		goto out;
32624 ++	}
32625 ++
32626 ++	sc->sc_nsessions = PASEMI_INITIAL_SESSIONS;
32627 ++	sc->sc_lastchn = 0;
32628 ++	sc->base_irq = pdev->irq + 6;
32629 ++	sc->base_chan = 6;
32630 ++	sc->sc_cid = -1;
32631 ++	sc->dma_pdev = pdev;
32632 ++
32633 ++	sc->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
32634 ++	if (!sc->iob_pdev) {
32635 ++		dev_err(&pdev->dev, "Can't find I/O Bridge\n");
32636 ++		ret = -ENODEV;
32637 ++		goto out;
32638 ++	}
32639 ++
32640 ++	/* This is hardcoded and ugly, but we have some firmware versions
32641 ++	 * who don't provide the register space in the device tree. Luckily
32642 ++	 * they are at well-known locations so we can just do the math here.
32643 ++	 */
32644 ++	sc->dma_regs =
32645 ++		ioremap(0xe0000000 + (sc->dma_pdev->devfn << 12), 0x2000);
32646 ++	sc->iob_regs =
32647 ++		ioremap(0xe0000000 + (sc->iob_pdev->devfn << 12), 0x2000);
32648 ++	if (!sc->dma_regs || !sc->iob_regs) {
32649 ++		dev_err(&pdev->dev, "Can't map registers\n");
32650 ++		ret = -ENODEV;
32651 ++		goto out;
32652 ++	}
32653 ++
32654 ++	dma_status = __ioremap(0xfd800000, 0x1000, 0);
32655 ++	if (!dma_status) {
32656 ++		ret = -ENODEV;
32657 ++		dev_err(&pdev->dev, "Can't map dmastatus space\n");
32658 ++		goto out;
32659 ++	}
32660 ++
32661 ++	sc->tx = (struct pasemi_fnu_txring *)
32662 ++		kzalloc(sizeof(struct pasemi_fnu_txring)
32663 ++			* 8, GFP_KERNEL);
32664 ++	if (!sc->tx) {
32665 ++		ret = -ENOMEM;
32666 ++		goto out;
32667 ++	}
32668 ++
32669 ++	/* Initialize the h/w */
32670 ++	out_le32(sc->dma_regs + PAS_DMA_COM_CFG,
32671 ++		 (in_le32(sc->dma_regs + PAS_DMA_COM_CFG) |
32672 ++		  PAS_DMA_COM_CFG_FWF));
32673 ++	out_le32(sc->dma_regs + PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN);
32674 ++
32675 ++	for (i = 0; i < PASEMI_FNU_CHANNELS; i++) {
32676 ++		sc->sc_num_channels++;
32677 ++		ret = pasemi_dma_setup_tx_resources(sc, i);
32678 ++		if (ret)
32679 ++			goto out;
32680 ++	}
32681 ++
32682 ++	sc->sc_cid = crypto_get_driverid(softc_get_device(sc),
32683 ++					 CRYPTOCAP_F_HARDWARE);
32684 ++	if (sc->sc_cid < 0) {
32685 ++		printk(KERN_ERR DRV_NAME ": could not get crypto driver id\n");
32686 ++		ret = -ENXIO;
32687 ++		goto out;
32688 ++	}
32689 ++
32690 ++	/* register algorithms with the framework */
32691 ++	printk(DRV_NAME ":");
32692 ++
32693 ++	crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0);
32694 ++	crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
32695 ++	crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0);
32696 ++	crypto_register(sc->sc_cid, CRYPTO_ARC4, 0, 0);
32697 ++	crypto_register(sc->sc_cid, CRYPTO_SHA1, 0, 0);
32698 ++	crypto_register(sc->sc_cid, CRYPTO_MD5, 0, 0);
32699 ++	crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0);
32700 ++	crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0);
32701 ++
32702 ++	return 0;
32703 ++
32704 ++out:
32705 ++	pasemi_dma_remove(pdev);
32706 ++	return ret;
32707 ++}
32708 ++
32709 ++#define MAX_RETRIES 5000
32710 ++
32711 ++static void pasemi_free_tx_resources(struct pasemi_softc *sc, int chan)
32712 ++{
32713 ++	struct pasemi_fnu_txring *ring = &sc->tx[chan];
32714 ++	int chan_index = chan + sc->base_chan;
32715 ++	int retries;
32716 ++	u32 stat;
32717 ++
32718 ++	/* Stop the channel */
32719 ++	out_le32(sc->dma_regs +
32720 ++		 PAS_DMA_TXCHAN_TCMDSTA(chan_index),
32721 ++		 PAS_DMA_TXCHAN_TCMDSTA_ST);
32722 ++
32723 ++	for (retries = 0; retries < MAX_RETRIES; retries++) {
32724 ++		stat = in_le32(sc->dma_regs +
32725 ++			       PAS_DMA_TXCHAN_TCMDSTA(chan_index));
32726 ++		if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT))
32727 ++			break;
32728 ++		cond_resched();
32729 ++	}
32730 ++
32731 ++	if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)
32732 ++		dev_err(&sc->dma_pdev->dev, "Failed to stop tx channel %d\n",
32733 ++			chan_index);
32734 ++
32735 ++	/* Disable the channel */
32736 ++	out_le32(sc->dma_regs +
32737 ++		 PAS_DMA_TXCHAN_TCMDSTA(chan_index),
32738 ++		 0);
32739 ++
32740 ++	if (ring->desc_info)
32741 ++		kfree((void *) ring->desc_info);
32742 ++	if (ring->desc)
32743 ++		dma_free_coherent(&sc->dma_pdev->dev,
32744 ++				  TX_RING_SIZE *
32745 ++				  2 * sizeof(u64),
32746 ++				  (void *) ring->desc, ring->dma);
32747 ++	if (ring->irq != -1)
32748 ++		free_irq(ring->irq, sc);
32749 ++
32750 ++	del_timer(&ring->crypto_timer);
32751 ++}
32752 ++
32753 ++static void __devexit pasemi_dma_remove(struct pci_dev *pdev)
32754 ++{
32755 ++	struct pasemi_softc *sc = pci_get_drvdata(pdev);
32756 ++	int i;
32757 ++
32758 ++	DPRINTF("%s()\n", __FUNCTION__);
32759 ++
32760 ++	if (sc->sc_cid >= 0) {
32761 ++		crypto_unregister_all(sc->sc_cid);
32762 ++	}
32763 ++
32764 ++	if (sc->tx) {
32765 ++		for (i = 0; i < sc->sc_num_channels; i++)
32766 ++			pasemi_free_tx_resources(sc, i);
32767 ++
32768 ++		kfree(sc->tx);
32769 ++	}
32770 ++	if (sc->sc_sessions) {
32771 ++		for (i = 0; i < sc->sc_nsessions; i++)
32772 ++			kfree(sc->sc_sessions[i]);
32773 ++		kfree(sc->sc_sessions);
32774 ++	}
32775 ++	if (sc->iob_pdev)
32776 ++		pci_dev_put(sc->iob_pdev);
32777 ++	if (sc->dma_regs)
32778 ++		iounmap(sc->dma_regs);
32779 ++	if (sc->iob_regs)
32780 ++		iounmap(sc->iob_regs);
32781 ++	kfree(sc);
32782 ++}
32783 ++
32784 ++static struct pci_device_id pasemi_dma_pci_tbl[] = {
32785 ++	{ PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa007) },
32786 ++};
32787 ++
32788 ++MODULE_DEVICE_TABLE(pci, pasemi_dma_pci_tbl);
32789 ++
32790 ++static struct pci_driver pasemi_dma_driver = {
32791 ++	.name		= "pasemi_dma",
32792 ++	.id_table	= pasemi_dma_pci_tbl,
32793 ++	.probe		= pasemi_dma_probe,
32794 ++	.remove		= __devexit_p(pasemi_dma_remove),
32795 ++};
32796 ++
32797 ++static void __exit pasemi_dma_cleanup_module(void)
32798 ++{
32799 ++	pci_unregister_driver(&pasemi_dma_driver);
32800 ++	__iounmap(dma_status);
32801 ++	dma_status = NULL;
32802 ++}
32803 ++
32804 ++int pasemi_dma_init_module(void)
32805 ++{
32806 ++	return pci_register_driver(&pasemi_dma_driver);
32807 ++}
32808 ++
32809 ++module_init(pasemi_dma_init_module);
32810 ++module_exit(pasemi_dma_cleanup_module);
32811 ++
32812 ++MODULE_LICENSE("Dual BSD/GPL");
32813 ++MODULE_AUTHOR("Egor Martovetsky egor@pasemi.com");
32814 ++MODULE_DESCRIPTION("OCF driver for PA Semi PWRficient DMA Crypto Engine");
32815 +diff -urN linux-2.6.23.16.old/crypto/ocf/pasemi/pasemi_fnu.h linux-2.6.23.16/crypto/ocf/pasemi/pasemi_fnu.h
32816 +--- linux-2.6.23.16.old/crypto/ocf/pasemi/pasemi_fnu.h	1969-12-31 19:00:00.000000000 -0500
32817 ++++ linux-2.6.23.16/crypto/ocf/pasemi/pasemi_fnu.h	2008-02-26 09:29:13.000000000 -0500
32818 +@@ -0,0 +1,410 @@
32819 ++/*
32820 ++ * Copyright (C) 2007 PA Semi, Inc
32821 ++ *
32822 ++ * Driver for the PA Semi PWRficient DMA Crypto Engine, soft state and
32823 ++ * hardware register layouts.
32824 ++ *
32825 ++ * This program is free software; you can redistribute it and/or modify
32826 ++ * it under the terms of the GNU General Public License version 2 as
32827 ++ * published by the Free Software Foundation.
32828 ++ *
32829 ++ * This program is distributed in the hope that it will be useful,
32830 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32831 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32832 ++ * GNU General Public License for more details.
32833 ++ *
32834 ++ * You should have received a copy of the GNU General Public License
32835 ++ * along with this program; if not, write to the Free Software
32836 ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
32837 ++ */
32838 ++
32839 ++#ifndef PASEMI_FNU_H
32840 ++#define PASEMI_FNU_H
32841 ++
32842 ++#include <linux/spinlock.h>
32843 ++
32844 ++#define	PASEMI_SESSION(sid)	((sid) & 0xffffffff)
32845 ++#define	PASEMI_SID(sesn)	((sesn) & 0xffffffff)
32846 ++#define	DPRINTF(a...)	if (debug) { printk(DRV_NAME ": " a); }
32847 ++
32848 ++/* Must be a power of two */
32849 ++#define RX_RING_SIZE 512
32850 ++#define TX_RING_SIZE 512
32851 ++#define TX_DESC(ring, num)	((ring)->desc[2 * (num & (TX_RING_SIZE-1))])
32852 ++#define TX_DESC_INFO(ring, num)	((ring)->desc_info[(num) & (TX_RING_SIZE-1)])
32853 ++#define MAX_DESC_SIZE 8
32854 ++#define PASEMI_INITIAL_SESSIONS 10
32855 ++#define PASEMI_FNU_CHANNELS 8
32856 ++
32857 ++/* DMA descriptor */
32858 ++struct pasemi_desc {
32859 ++	u64 quad[2*MAX_DESC_SIZE];
32860 ++	int quad_cnt;
32861 ++	int size;
32862 ++	int postop;
32863 ++};
32864 ++
32865 ++/*
32866 ++ * Holds per descriptor data
32867 ++ */
32868 ++struct pasemi_desc_info {
32869 ++	int			desc_size;
32870 ++	int			desc_postop;
32871 ++#define PASEMI_CHECK_SIG 0x1
32872 ++
32873 ++	struct cryptop          *cf_crp;
32874 ++};
32875 ++
32876 ++/*
32877 ++ * Holds per channel data
32878 ++ */
32879 ++struct pasemi_fnu_txring {
32880 ++	volatile u64		*desc;
32881 ++	volatile struct
32882 ++	pasemi_desc_info	*desc_info;
32883 ++	dma_addr_t		dma;
32884 ++	struct timer_list       crypto_timer;
32885 ++	spinlock_t		fill_lock;
32886 ++	spinlock_t		clean_lock;
32887 ++	unsigned int		next_to_fill;
32888 ++	unsigned int		next_to_clean;
32889 ++	u16			total_pktcnt;
32890 ++	int			irq;
32891 ++	int			sesn;
32892 ++	char			irq_name[10];
32893 ++};
32894 ++
32895 ++/*
32896 ++ * Holds data specific to a single pasemi device.
32897 ++ */
32898 ++struct pasemi_softc {
32899 ++	softc_device_decl	sc_cdev;
32900 ++	struct pci_dev		*dma_pdev;	/* device backpointer */
32901 ++	struct pci_dev		*iob_pdev;	/* device backpointer */
32902 ++	void __iomem		*dma_regs;
32903 ++	void __iomem		*iob_regs;
32904 ++	int			base_irq;
32905 ++	int			base_chan;
32906 ++	int32_t			sc_cid;		/* crypto tag */
32907 ++	int			sc_nsessions;
32908 ++	struct pasemi_session	**sc_sessions;
32909 ++	int			sc_num_channels;/* number of crypto channels */
32910 ++
32911 ++	/* pointer to the array of txring datastructures, one txring per channel */
32912 ++	struct pasemi_fnu_txring *tx;
32913 ++
32914 ++	/*
32915 ++	 * mutual exclusion for the channel scheduler
32916 ++	 */
32917 ++	spinlock_t		sc_chnlock;
32918 ++	/* last channel used, for now use round-robin to allocate channels */
32919 ++	int			sc_lastchn;
32920 ++};
32921 ++
32922 ++struct pasemi_session {
32923 ++	u64 civ[2];
32924 ++	u64 keysz;
32925 ++	u64 key[4];
32926 ++	u64 ccmd;
32927 ++	u64 hkey[4];
32928 ++	u64 hseq;
32929 ++	u64 giv[2];
32930 ++	u64 hiv[4];
32931 ++
32932 ++	int used;
32933 ++	dma_addr_t	dma_addr;
32934 ++	int chan;
32935 ++};
32936 ++
32937 ++/* status register layout in IOB region, at 0xfd800000 */
32938 ++struct pasdma_status {
32939 ++	u64 rx_sta[64];
32940 ++	u64 tx_sta[20];
32941 ++};
32942 ++
32943 ++#define ALG_IS_CIPHER(alg) ((alg == CRYPTO_DES_CBC)		|| \
32944 ++				(alg == CRYPTO_3DES_CBC)	|| \
32945 ++				(alg == CRYPTO_AES_CBC)		|| \
32946 ++				(alg == CRYPTO_ARC4)		|| \
32947 ++				(alg == CRYPTO_NULL_CBC))
32948 ++
32949 ++#define ALG_IS_SIG(alg) ((alg == CRYPTO_MD5)			|| \
32950 ++				(alg == CRYPTO_MD5_HMAC)	|| \
32951 ++				(alg == CRYPTO_SHA1)		|| \
32952 ++				(alg == CRYPTO_SHA1_HMAC)	|| \
32953 ++				(alg == CRYPTO_NULL_HMAC))
32954 ++
32955 ++enum {
32956 ++	PAS_DMA_COM_TXCMD = 0x100,	/* Transmit Command Register  */
32957 ++	PAS_DMA_COM_TXSTA = 0x104,	/* Transmit Status Register   */
32958 ++	PAS_DMA_COM_RXCMD = 0x108,	/* Receive Command Register   */
32959 ++	PAS_DMA_COM_RXSTA = 0x10c,	/* Receive Status Register    */
32960 ++	PAS_DMA_COM_CFG   = 0x114,	/* DMA Configuration Register */
32961 ++};
32962 ++
32963 ++/* All these registers live in the PCI configuration space for the DMA PCI
32964 ++ * device. Use the normal PCI config access functions for them.
32965 ++ */
32966 ++
32967 ++#define PAS_DMA_COM_CFG_FWF	0x18000000
32968 ++
32969 ++#define PAS_DMA_COM_TXCMD_EN	0x00000001 /* enable */
32970 ++#define PAS_DMA_COM_TXSTA_ACT	0x00000001 /* active */
32971 ++#define PAS_DMA_COM_RXCMD_EN	0x00000001 /* enable */
32972 ++#define PAS_DMA_COM_RXSTA_ACT	0x00000001 /* active */
32973 ++
32974 ++#define _PAS_DMA_TXCHAN_STRIDE	0x20    /* Size per channel		*/
32975 ++#define _PAS_DMA_TXCHAN_TCMDSTA	0x300	/* Command / Status		*/
32976 ++#define _PAS_DMA_TXCHAN_CFG	0x304	/* Configuration		*/
32977 ++#define _PAS_DMA_TXCHAN_DSCRBU	0x308	/* Descriptor BU Allocation	*/
32978 ++#define _PAS_DMA_TXCHAN_INCR	0x310	/* Descriptor increment		*/
32979 ++#define _PAS_DMA_TXCHAN_CNT	0x314	/* Descriptor count/offset	*/
32980 ++#define _PAS_DMA_TXCHAN_BASEL	0x318	/* Descriptor ring base (low)	*/
32981 ++#define _PAS_DMA_TXCHAN_BASEU	0x31c	/*			(high)	*/
32982 ++#define PAS_DMA_TXCHAN_TCMDSTA(c) (0x300+(c)*_PAS_DMA_TXCHAN_STRIDE)
32983 ++#define    PAS_DMA_TXCHAN_TCMDSTA_EN	0x00000001	/* Enabled */
32984 ++#define    PAS_DMA_TXCHAN_TCMDSTA_ST	0x00000002	/* Stop interface */
32985 ++#define    PAS_DMA_TXCHAN_TCMDSTA_ACT	0x00010000	/* Active */
32986 ++#define PAS_DMA_TXCHAN_CFG(c)     (0x304+(c)*_PAS_DMA_TXCHAN_STRIDE)
32987 ++#define    PAS_DMA_TXCHAN_CFG_TY_FUNC	0x00000002	/* Type = interface */
32988 ++#define    PAS_DMA_TXCHAN_CFG_TY_IFACE	0x00000000	/* Type = interface */
32989 ++#define    PAS_DMA_TXCHAN_CFG_TATTR_M	0x0000003c
32990 ++#define    PAS_DMA_TXCHAN_CFG_TATTR_S	2
32991 ++#define    PAS_DMA_TXCHAN_CFG_TATTR(x)	(((x) << PAS_DMA_TXCHAN_CFG_TATTR_S) & \
32992 ++					 PAS_DMA_TXCHAN_CFG_TATTR_M)
32993 ++#define    PAS_DMA_TXCHAN_CFG_WT_M	0x000001c0
32994 ++#define    PAS_DMA_TXCHAN_CFG_WT_S	6
32995 ++#define    PAS_DMA_TXCHAN_CFG_WT(x)	(((x) << PAS_DMA_TXCHAN_CFG_WT_S) & \
32996 ++					 PAS_DMA_TXCHAN_CFG_WT_M)
32997 ++#define    PAS_DMA_TXCHAN_CFG_LPSQ_FAST	0x00000400
32998 ++#define    PAS_DMA_TXCHAN_CFG_LPDQ_FAST	0x00000800
32999 ++#define    PAS_DMA_TXCHAN_CFG_CF	0x00001000	/* Clean first line */
33000 ++#define    PAS_DMA_TXCHAN_CFG_CL	0x00002000	/* Clean last line */
33001 ++#define    PAS_DMA_TXCHAN_CFG_UP	0x00004000	/* update tx descr when sent */
33002 ++#define PAS_DMA_TXCHAN_INCR(c)    (0x310+(c)*_PAS_DMA_TXCHAN_STRIDE)
33003 ++#define PAS_DMA_TXCHAN_BASEL(c)   (0x318+(c)*_PAS_DMA_TXCHAN_STRIDE)
33004 ++#define    PAS_DMA_TXCHAN_BASEL_BRBL_M	0xffffffc0
33005 ++#define    PAS_DMA_TXCHAN_BASEL_BRBL_S	0
33006 ++#define    PAS_DMA_TXCHAN_BASEL_BRBL(x)	(((x) << PAS_DMA_TXCHAN_BASEL_BRBL_S) & \
33007 ++					 PAS_DMA_TXCHAN_BASEL_BRBL_M)
33008 ++#define PAS_DMA_TXCHAN_BASEU(c)   (0x31c+(c)*_PAS_DMA_TXCHAN_STRIDE)
33009 ++#define    PAS_DMA_TXCHAN_BASEU_BRBH_M	0x00000fff
33010 ++#define    PAS_DMA_TXCHAN_BASEU_BRBH_S	0
33011 ++#define    PAS_DMA_TXCHAN_BASEU_BRBH(x)	(((x) << PAS_DMA_TXCHAN_BASEU_BRBH_S) & \
33012 ++					 PAS_DMA_TXCHAN_BASEU_BRBH_M)
33013 ++/* # of cache lines worth of buffer ring */
33014 ++#define    PAS_DMA_TXCHAN_BASEU_SIZ_M	0x3fff0000
33015 ++#define    PAS_DMA_TXCHAN_BASEU_SIZ_S	16		/* 0 = 16K */
33016 ++#define    PAS_DMA_TXCHAN_BASEU_SIZ(x)	(((x) << PAS_DMA_TXCHAN_BASEU_SIZ_S) & \
33017 ++					 PAS_DMA_TXCHAN_BASEU_SIZ_M)
33018 ++
33019 ++#define    PAS_STATUS_PCNT_M		0x000000000000ffffull
33020 ++#define    PAS_STATUS_PCNT_S		0
33021 ++#define    PAS_STATUS_DCNT_M		0x00000000ffff0000ull
33022 ++#define    PAS_STATUS_DCNT_S		16
33023 ++#define    PAS_STATUS_BPCNT_M		0x0000ffff00000000ull
33024 ++#define    PAS_STATUS_BPCNT_S		32
33025 ++#define    PAS_STATUS_CAUSE_M		0xf000000000000000ull
33026 ++#define    PAS_STATUS_TIMER		0x1000000000000000ull
33027 ++#define    PAS_STATUS_ERROR		0x2000000000000000ull
33028 ++#define    PAS_STATUS_SOFT		0x4000000000000000ull
33029 ++#define    PAS_STATUS_INT		0x8000000000000000ull
33030 ++
33031 ++#define PAS_IOB_DMA_RXCH_CFG(i)		(0x1100 + (i)*4)
33032 ++#define    PAS_IOB_DMA_RXCH_CFG_CNTTH_M		0x00000fff
33033 ++#define    PAS_IOB_DMA_RXCH_CFG_CNTTH_S		0
33034 ++#define    PAS_IOB_DMA_RXCH_CFG_CNTTH(x)	(((x) << PAS_IOB_DMA_RXCH_CFG_CNTTH_S) & \
33035 ++						 PAS_IOB_DMA_RXCH_CFG_CNTTH_M)
33036 ++#define PAS_IOB_DMA_TXCH_CFG(i)		(0x1200 + (i)*4)
33037 ++#define    PAS_IOB_DMA_TXCH_CFG_CNTTH_M		0x00000fff
33038 ++#define    PAS_IOB_DMA_TXCH_CFG_CNTTH_S		0
33039 ++#define    PAS_IOB_DMA_TXCH_CFG_CNTTH(x)	(((x) << PAS_IOB_DMA_TXCH_CFG_CNTTH_S) & \
33040 ++						 PAS_IOB_DMA_TXCH_CFG_CNTTH_M)
33041 ++#define PAS_IOB_DMA_RXCH_STAT(i)	(0x1300 + (i)*4)
33042 ++#define    PAS_IOB_DMA_RXCH_STAT_INTGEN	0x00001000
33043 ++#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL_M	0x00000fff
33044 ++#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL_S	0
33045 ++#define    PAS_IOB_DMA_RXCH_STAT_CNTDEL(x)	(((x) << PAS_IOB_DMA_RXCH_STAT_CNTDEL_S) &\
33046 ++						 PAS_IOB_DMA_RXCH_STAT_CNTDEL_M)
33047 ++#define PAS_IOB_DMA_TXCH_STAT(i)	(0x1400 + (i)*4)
33048 ++#define    PAS_IOB_DMA_TXCH_STAT_INTGEN	0x00001000
33049 ++#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL_M	0x00000fff
33050 ++#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL_S	0
33051 ++#define    PAS_IOB_DMA_TXCH_STAT_CNTDEL(x)	(((x) << PAS_IOB_DMA_TXCH_STAT_CNTDEL_S) &\
33052 ++						 PAS_IOB_DMA_TXCH_STAT_CNTDEL_M)
33053 ++#define PAS_IOB_DMA_RXCH_RESET(i)	(0x1500 + (i)*4)
33054 ++#define    PAS_IOB_DMA_RXCH_RESET_PCNT_M	0xffff0000
33055 ++#define    PAS_IOB_DMA_RXCH_RESET_PCNT_S	16
33056 ++#define    PAS_IOB_DMA_RXCH_RESET_PCNT(x)	(((x) << PAS_IOB_DMA_RXCH_RESET_PCNT_S) & \
33057 ++						 PAS_IOB_DMA_RXCH_RESET_PCNT_M)
33058 ++#define    PAS_IOB_DMA_RXCH_RESET_PCNTRST	0x00000020
33059 ++#define    PAS_IOB_DMA_RXCH_RESET_DCNTRST	0x00000010
33060 ++#define    PAS_IOB_DMA_RXCH_RESET_TINTC		0x00000008
33061 ++#define    PAS_IOB_DMA_RXCH_RESET_DINTC		0x00000004
33062 ++#define    PAS_IOB_DMA_RXCH_RESET_SINTC		0x00000002
33063 ++#define    PAS_IOB_DMA_RXCH_RESET_PINTC		0x00000001
33064 ++#define PAS_IOB_DMA_TXCH_RESET(i)	(0x1600 + (i)*4)
33065 ++#define    PAS_IOB_DMA_TXCH_RESET_PCNT_M	0xffff0000
33066 ++#define    PAS_IOB_DMA_TXCH_RESET_PCNT_S	16
33067 ++#define    PAS_IOB_DMA_TXCH_RESET_PCNT(x)	(((x) << PAS_IOB_DMA_TXCH_RESET_PCNT_S) & \
33068 ++						 PAS_IOB_DMA_TXCH_RESET_PCNT_M)
33069 ++#define    PAS_IOB_DMA_TXCH_RESET_PCNTRST	0x00000020
33070 ++#define    PAS_IOB_DMA_TXCH_RESET_DCNTRST	0x00000010
33071 ++#define    PAS_IOB_DMA_TXCH_RESET_TINTC		0x00000008
33072 ++#define    PAS_IOB_DMA_TXCH_RESET_DINTC		0x00000004
33073 ++#define    PAS_IOB_DMA_TXCH_RESET_SINTC		0x00000002
33074 ++#define    PAS_IOB_DMA_TXCH_RESET_PINTC		0x00000001
33075 ++
33076 ++#define PAS_IOB_DMA_COM_TIMEOUTCFG		0x1700
33077 ++#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_M	0x00ffffff
33078 ++#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_S	0
33079 ++#define    PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(x)	(((x) << PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_S) & \
33080 ++						 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT_M)
33081 ++
33082 ++/* Transmit descriptor fields */
33083 ++#define	XCT_MACTX_T		0x8000000000000000ull
33084 ++#define	XCT_MACTX_ST		0x4000000000000000ull
33085 ++#define XCT_MACTX_NORES		0x0000000000000000ull
33086 ++#define XCT_MACTX_8BRES		0x1000000000000000ull
33087 ++#define XCT_MACTX_24BRES	0x2000000000000000ull
33088 ++#define XCT_MACTX_40BRES	0x3000000000000000ull
33089 ++#define XCT_MACTX_I		0x0800000000000000ull
33090 ++#define XCT_MACTX_O		0x0400000000000000ull
33091 ++#define XCT_MACTX_E		0x0200000000000000ull
33092 ++#define XCT_MACTX_VLAN_M	0x0180000000000000ull
33093 ++#define XCT_MACTX_VLAN_NOP	0x0000000000000000ull
33094 ++#define XCT_MACTX_VLAN_REMOVE	0x0080000000000000ull
33095 ++#define XCT_MACTX_VLAN_INSERT   0x0100000000000000ull
33096 ++#define XCT_MACTX_VLAN_REPLACE  0x0180000000000000ull
33097 ++#define XCT_MACTX_CRC_M		0x0060000000000000ull
33098 ++#define XCT_MACTX_CRC_NOP	0x0000000000000000ull
33099 ++#define XCT_MACTX_CRC_INSERT	0x0020000000000000ull
33100 ++#define XCT_MACTX_CRC_PAD	0x0040000000000000ull
33101 ++#define XCT_MACTX_CRC_REPLACE	0x0060000000000000ull
33102 ++#define XCT_MACTX_SS		0x0010000000000000ull
33103 ++#define XCT_MACTX_LLEN_M	0x00007fff00000000ull
33104 ++#define XCT_MACTX_LLEN_S	32ull
33105 ++#define XCT_MACTX_LLEN(x)	((((long)(x)) << XCT_MACTX_LLEN_S) & \
33106 ++				 XCT_MACTX_LLEN_M)
33107 ++#define XCT_MACTX_IPH_M		0x00000000f8000000ull
33108 ++#define XCT_MACTX_IPH_S		27ull
33109 ++#define XCT_MACTX_IPH(x)	((((long)(x)) << XCT_MACTX_IPH_S) & \
33110 ++				 XCT_MACTX_IPH_M)
33111 ++#define XCT_MACTX_IPO_M		0x0000000007c00000ull
33112 ++#define XCT_MACTX_IPO_S		22ull
33113 ++#define XCT_MACTX_IPO(x)	((((long)(x)) << XCT_MACTX_IPO_S) & \
33114 ++				 XCT_MACTX_IPO_M)
33115 ++#define XCT_MACTX_CSUM_M	0x0000000000000060ull
33116 ++#define XCT_MACTX_CSUM_NOP	0x0000000000000000ull
33117 ++#define XCT_MACTX_CSUM_TCP	0x0000000000000040ull
33118 ++#define XCT_MACTX_CSUM_UDP	0x0000000000000060ull
33119 ++#define XCT_MACTX_V6		0x0000000000000010ull
33120 ++#define XCT_MACTX_C		0x0000000000000004ull
33121 ++#define XCT_MACTX_AL2		0x0000000000000002ull
33122 ++
33123 ++#define XCT_PTR_T		0x8000000000000000ull
33124 ++#define XCT_PTR_LEN_M		0x7ffff00000000000ull
33125 ++#define XCT_PTR_LEN_S		44
33126 ++#define XCT_PTR_LEN(x)		((((long)(x)) << XCT_PTR_LEN_S) & \
33127 ++				 XCT_PTR_LEN_M)
33128 ++#define XCT_PTR_ADDR_M		0x00000fffffffffffull
33129 ++#define XCT_PTR_ADDR_S		0
33130 ++#define XCT_PTR_ADDR(x)		((((long)(x)) << XCT_PTR_ADDR_S) & \
33131 ++				 XCT_PTR_ADDR_M)
33132 ++
33133 ++/* Function descriptor fields */
33134 ++#define	XCT_FUN_T		0x8000000000000000ull
33135 ++#define	XCT_FUN_ST		0x4000000000000000ull
33136 ++#define XCT_FUN_NORES		0x0000000000000000ull
33137 ++#define XCT_FUN_8BRES		0x1000000000000000ull
33138 ++#define XCT_FUN_24BRES		0x2000000000000000ull
33139 ++#define XCT_FUN_40BRES		0x3000000000000000ull
33140 ++#define XCT_FUN_I		0x0800000000000000ull
33141 ++#define XCT_FUN_O		0x0400000000000000ull
33142 ++#define XCT_FUN_E		0x0200000000000000ull
33143 ++#define XCT_FUN_FUN_S		54
33144 ++#define XCT_FUN_FUN_M		0x01c0000000000000ull
33145 ++#define XCT_FUN_FUN(num)	((((long)(num)) << XCT_FUN_FUN_S) & \
33146 ++				XCT_FUN_FUN_M)
33147 ++#define XCT_FUN_CRM_NOP		0x0000000000000000ull
33148 ++#define XCT_FUN_CRM_SIG		0x0008000000000000ull
33149 ++#define XCT_FUN_CRM_ENC		0x0010000000000000ull
33150 ++#define XCT_FUN_CRM_DEC		0x0018000000000000ull
33151 ++#define XCT_FUN_CRM_SIG_ENC	0x0020000000000000ull
33152 ++#define XCT_FUN_CRM_ENC_SIG	0x0028000000000000ull
33153 ++#define XCT_FUN_CRM_SIG_DEC	0x0030000000000000ull
33154 ++#define XCT_FUN_CRM_DEC_SIG	0x0038000000000000ull
33155 ++#define XCT_FUN_LLEN_M		0x0007ffff00000000ull
33156 ++#define XCT_FUN_LLEN_S		32ULL
33157 ++#define XCT_FUN_LLEN(x)		((((long)(x)) << XCT_FUN_LLEN_S) & \
33158 ++				 XCT_FUN_LLEN_M)
33159 ++#define XCT_FUN_SHL_M		0x00000000f8000000ull
33160 ++#define XCT_FUN_SHL_S		27ull
33161 ++#define XCT_FUN_SHL(x)		((((long)(x)) << XCT_FUN_SHL_S) & \
33162 ++				 XCT_FUN_SHL_M)
33163 ++#define XCT_FUN_CHL_M		0x0000000007c00000ull
33164 ++#define XCT_FUN_CHL_S		22ull
33165 ++#define XCT_FUN_CHL(x)		((((long)(x)) << XCT_FUN_CHL_S) & \
33166 ++				 XCT_FUN_CHL_M)
33167 ++#define XCT_FUN_HSZ_M		0x00000000003c0000ull
33168 ++#define XCT_FUN_HSZ_S		18ull
33169 ++#define XCT_FUN_HSZ(x)		((((long)(x)) << XCT_FUN_HSZ_S) & \
33170 ++				 XCT_FUN_HSZ_M)
33171 ++#define XCT_FUN_ALG_DES		0x0000000000000000ull
33172 ++#define XCT_FUN_ALG_3DES	0x0000000000008000ull
33173 ++#define XCT_FUN_ALG_AES		0x0000000000010000ull
33174 ++#define XCT_FUN_ALG_ARC		0x0000000000018000ull
33175 ++#define XCT_FUN_ALG_KASUMI	0x0000000000020000ull
33176 ++#define XCT_FUN_BCM_ECB		0x0000000000000000ull
33177 ++#define XCT_FUN_BCM_CBC		0x0000000000001000ull
33178 ++#define XCT_FUN_BCM_CFB		0x0000000000002000ull
33179 ++#define XCT_FUN_BCM_OFB		0x0000000000003000ull
33180 ++#define XCT_FUN_BCM_CNT		0x0000000000003800ull
33181 ++#define XCT_FUN_BCM_KAS_F8	0x0000000000002800ull
33182 ++#define XCT_FUN_BCM_KAS_F9	0x0000000000001800ull
33183 ++#define XCT_FUN_BCP_NO_PAD	0x0000000000000000ull
33184 ++#define XCT_FUN_BCP_ZRO		0x0000000000000200ull
33185 ++#define XCT_FUN_BCP_PL		0x0000000000000400ull
33186 ++#define XCT_FUN_BCP_INCR	0x0000000000000600ull
33187 ++#define XCT_FUN_SIG_MD5		(0ull << 4)
33188 ++#define XCT_FUN_SIG_SHA1	(2ull << 4)
33189 ++#define XCT_FUN_SIG_HMAC_MD5	(8ull << 4)
33190 ++#define XCT_FUN_SIG_HMAC_SHA1	(10ull << 4)
33191 ++#define XCT_FUN_A		0x0000000000000008ull
33192 ++#define XCT_FUN_C		0x0000000000000004ull
33193 ++#define XCT_FUN_AL2		0x0000000000000002ull
33194 ++#define XCT_FUN_SE		0x0000000000000001ull
33195 ++
33196 ++#define XCT_FUN_SRC_PTR(len, addr)	(XCT_PTR_LEN(len) | XCT_PTR_ADDR(addr))
33197 ++#define XCT_FUN_DST_PTR(len, addr)	(XCT_FUN_SRC_PTR(len, addr) | \
33198 ++					0x8000000000000000ull)
33199 ++
33200 ++#define XCT_CTRL_HDR_FUN_NUM_M		0x01c0000000000000ull
33201 ++#define XCT_CTRL_HDR_FUN_NUM_S		54
33202 ++#define XCT_CTRL_HDR_LEN_M		0x0007ffff00000000ull
33203 ++#define XCT_CTRL_HDR_LEN_S		32
33204 ++#define XCT_CTRL_HDR_REG_M		0x00000000000000ffull
33205 ++#define XCT_CTRL_HDR_REG_S		0
33206 ++
33207 ++#define XCT_CTRL_HDR(funcN,len,reg)	(0x9400000000000000ull | \
33208 ++			((((long)(funcN)) << XCT_CTRL_HDR_FUN_NUM_S) \
33209 ++			& XCT_CTRL_HDR_FUN_NUM_M) | \
33210 ++			((((long)(len)) << \
33211 ++			XCT_CTRL_HDR_LEN_S) & XCT_CTRL_HDR_LEN_M) | \
33212 ++			((((long)(reg)) << \
33213 ++			XCT_CTRL_HDR_REG_S) & XCT_CTRL_HDR_REG_M))
33214 ++
33215 ++/* Function config command options */
33216 ++#define	DMA_CALGO_DES			0x00
33217 ++#define	DMA_CALGO_3DES			0x01
33218 ++#define	DMA_CALGO_AES			0x02
33219 ++#define	DMA_CALGO_ARC			0x03
33220 ++
33221 ++#define DMA_FN_CIV0			0x02
33222 ++#define DMA_FN_CIV1			0x03
33223 ++#define DMA_FN_HKEY0			0x0a
33224 ++
33225 ++#define XCT_PTR_ADDR_LEN(ptr)		((ptr) & XCT_PTR_ADDR_M), \
33226 ++			(((ptr) & XCT_PTR_LEN_M) >> XCT_PTR_LEN_S)
33227 ++
33228 ++#endif /* PASEMI_FNU_H */
33229 +diff -urN linux-2.6.23.16.old/crypto/ocf/random.c linux-2.6.23.16/crypto/ocf/random.c
33230 +--- linux-2.6.23.16.old/crypto/ocf/random.c	1969-12-31 19:00:00.000000000 -0500
33231 ++++ linux-2.6.23.16/crypto/ocf/random.c	2008-02-26 09:29:13.000000000 -0500
33232 +@@ -0,0 +1,317 @@
33233 ++/*
33234 ++ * A system independant way of adding entropy to the kernels pool
33235 ++ * this way the drivers can focus on the real work and we can take
33236 ++ * care of pushing it to the appropriate place in the kernel.
33237 ++ *
33238 ++ * This should be fast and callable from timers/interrupts
33239 ++ *
33240 ++ * Written by David McCullough <david_mccullough@securecomputing.com>
33241 ++ * Copyright (C) 2006-2007 David McCullough
33242 ++ * Copyright (C) 2004-2005 Intel Corporation.
33243 ++ *
33244 ++ * LICENSE TERMS
33245 ++ *
33246 ++ * The free distribution and use of this software in both source and binary
33247 ++ * form is allowed (with or without changes) provided that:
33248 ++ *
33249 ++ *   1. distributions of this source code include the above copyright
33250 ++ *      notice, this list of conditions and the following disclaimer;
33251 ++ *
33252 ++ *   2. distributions in binary form include the above copyright
33253 ++ *      notice, this list of conditions and the following disclaimer
33254 ++ *      in the documentation and/or other associated materials;
33255 ++ *
33256 ++ *   3. the copyright holder's name is not used to endorse products
33257 ++ *      built using this software without specific written permission.
33258 ++ *
33259 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
33260 ++ * may be distributed under the terms of the GNU General Public License (GPL),
33261 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
33262 ++ *
33263 ++ * DISCLAIMER
33264 ++ *
33265 ++ * This software is provided 'as is' with no explicit or implied warranties
33266 ++ * in respect of its properties, including, but not limited to, correctness
33267 ++ * and/or fitness for purpose.
33268 ++ */
33269 ++
33270 ++#ifndef AUTOCONF_INCLUDED
33271 ++#include <linux/config.h>
33272 ++#endif
33273 ++#include <linux/module.h>
33274 ++#include <linux/init.h>
33275 ++#include <linux/list.h>
33276 ++#include <linux/slab.h>
33277 ++#include <linux/wait.h>
33278 ++#include <linux/sched.h>
33279 ++#include <linux/spinlock.h>
33280 ++#include <linux/version.h>
33281 ++#include <linux/unistd.h>
33282 ++#include <linux/poll.h>
33283 ++#include <linux/random.h>
33284 ++#include <cryptodev.h>
33285 ++
33286 ++#ifdef CONFIG_OCF_FIPS
33287 ++#include "rndtest.h"
33288 ++#endif
33289 ++
33290 ++#ifndef HAS_RANDOM_INPUT_WAIT
33291 ++#error "Please do not enable OCF_RANDOMHARVEST unless you have applied patches"
33292 ++#endif
33293 ++
33294 ++/*
33295 ++ * a hack to access the debug levels from the crypto driver
33296 ++ */
33297 ++extern int crypto_debug;
33298 ++#define debug crypto_debug
33299 ++
33300 ++/*
33301 ++ * a list of all registered random providers
33302 ++ */
33303 ++static LIST_HEAD(random_ops);
33304 ++static int started = 0;
33305 ++static int initted = 0;
33306 ++
33307 ++struct random_op {
33308 ++	struct list_head random_list;
33309 ++	u_int32_t driverid;
33310 ++	int (*read_random)(void *arg, u_int32_t *buf, int len);
33311 ++	void *arg;
33312 ++};
33313 ++
33314 ++static int random_proc(void *arg);
33315 ++
33316 ++static pid_t		randomproc = (pid_t) -1;
33317 ++static spinlock_t	random_lock;
33318 ++
33319 ++/*
33320 ++ * just init the spin locks
33321 ++ */
33322 ++static int
33323 ++crypto_random_init(void)
33324 ++{
33325 ++	spin_lock_init(&random_lock);
33326 ++	initted = 1;
33327 ++	return(0);
33328 ++}
33329 ++
33330 ++/*
33331 ++ * Add the given random reader to our list (if not present)
33332 ++ * and start the thread (if not already started)
33333 ++ *
33334 ++ * we have to assume that driver id is ok for now
33335 ++ */
33336 ++int
33337 ++crypto_rregister(
33338 ++	u_int32_t driverid,
33339 ++	int (*read_random)(void *arg, u_int32_t *buf, int len),
33340 ++	void *arg)
33341 ++{
33342 ++	unsigned long flags;
33343 ++	int ret = 0;
33344 ++	struct random_op	*rops, *tmp;
33345 ++
33346 ++	dprintk("%s,%d: %s(0x%x, %p, %p)\n", __FILE__, __LINE__,
33347 ++			__FUNCTION__, driverid, read_random, arg);
33348 ++
33349 ++	if (!initted)
33350 ++		crypto_random_init();
33351 ++
33352 ++#if 0
33353 ++	struct cryptocap	*cap;
33354 ++
33355 ++	cap = crypto_checkdriver(driverid);
33356 ++	if (!cap)
33357 ++		return EINVAL;
33358 ++#endif
33359 ++
33360 ++	list_for_each_entry_safe(rops, tmp, &random_ops, random_list) {
33361 ++		if (rops->driverid == driverid && rops->read_random == read_random)
33362 ++			return EEXIST;
33363 ++	}
33364 ++
33365 ++	rops = (struct random_op *) kmalloc(sizeof(*rops), GFP_KERNEL);
33366 ++	if (!rops)
33367 ++		return ENOMEM;
33368 ++
33369 ++	rops->driverid    = driverid;
33370 ++	rops->read_random = read_random;
33371 ++	rops->arg = arg;
33372 ++
33373 ++	spin_lock_irqsave(&random_lock, flags);
33374 ++	list_add_tail(&rops->random_list, &random_ops);
33375 ++	if (!started) {
33376 ++		randomproc = kernel_thread(random_proc, NULL, CLONE_FS|CLONE_FILES);
33377 ++		if (randomproc < 0) {
33378 ++			ret = randomproc;
33379 ++			printk("crypto: crypto_rregister cannot start random thread; "
33380 ++					"error %d", ret);
33381 ++		} else
33382 ++			started = 1;
33383 ++	}
33384 ++	spin_unlock_irqrestore(&random_lock, flags);
33385 ++
33386 ++	return ret;
33387 ++}
33388 ++EXPORT_SYMBOL(crypto_rregister);
33389 ++
33390 ++int
33391 ++crypto_runregister_all(u_int32_t driverid)
33392 ++{
33393 ++	struct random_op *rops, *tmp;
33394 ++	unsigned long flags;
33395 ++
33396 ++	dprintk("%s,%d: %s(0x%x)\n", __FILE__, __LINE__, __FUNCTION__, driverid);
33397 ++
33398 ++	list_for_each_entry_safe(rops, tmp, &random_ops, random_list) {
33399 ++		if (rops->driverid == driverid) {
33400 ++			list_del(&rops->random_list);
33401 ++			kfree(rops);
33402 ++		}
33403 ++	}
33404 ++
33405 ++	spin_lock_irqsave(&random_lock, flags);
33406 ++	if (list_empty(&random_ops) && started)
33407 ++		kill_proc(randomproc, SIGKILL, 1);
33408 ++	spin_unlock_irqrestore(&random_lock, flags);
33409 ++	return(0);
33410 ++}
33411 ++EXPORT_SYMBOL(crypto_runregister_all);
33412 ++
33413 ++/*
33414 ++ * while we can add entropy to random.c continue to read random data from
33415 ++ * the drivers and push it to random.
33416 ++ */
33417 ++static int
33418 ++random_proc(void *arg)
33419 ++{
33420 ++	int n;
33421 ++	int wantcnt;
33422 ++	int bufcnt = 0;
33423 ++	int retval = 0;
33424 ++	int *buf = NULL;
33425 ++
33426 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
33427 ++	daemonize();
33428 ++	spin_lock_irq(&current->sigmask_lock);
33429 ++	sigemptyset(&current->blocked);
33430 ++	recalc_sigpending(current);
33431 ++	spin_unlock_irq(&current->sigmask_lock);
33432 ++	sprintf(current->comm, "ocf-random");
33433 ++#else
33434 ++	daemonize("ocf-random");
33435 ++	allow_signal(SIGKILL);
33436 ++#endif
33437 ++
33438 ++	(void) get_fs();
33439 ++	set_fs(get_ds());
33440 ++
33441 ++#ifdef CONFIG_OCF_FIPS
33442 ++#define NUM_INT (RNDTEST_NBYTES/sizeof(int))
33443 ++#else
33444 ++#define NUM_INT 32
33445 ++#endif
33446 ++
33447 ++	/*
33448 ++	 * some devices can transferr their RNG data direct into memory,
33449 ++	 * so make sure it is device friendly
33450 ++	 */
33451 ++	buf = kmalloc(NUM_INT * sizeof(int), GFP_DMA);
33452 ++	if (NULL == buf) {
33453 ++		printk("crypto: RNG could not allocate memory\n");
33454 ++		retval = -ENOMEM;
33455 ++		goto bad_alloc;
33456 ++	}
33457 ++
33458 ++	wantcnt = NUM_INT;   /* start by adding some entropy */
33459 ++
33460 ++	/*
33461 ++	 * its possible due to errors or driver removal that we no longer
33462 ++	 * have anything to do,  if so exit or we will consume all the CPU
33463 ++	 * doing nothing
33464 ++	 */
33465 ++	while (!list_empty(&random_ops)) {
33466 ++		struct random_op	*rops, *tmp;
33467 ++
33468 ++#ifdef CONFIG_OCF_FIPS
33469 ++		if (wantcnt)
33470 ++			wantcnt = NUM_INT; /* FIPs mode can do 20000 bits or none */
33471 ++#endif
33472 ++
33473 ++		/* see if we can get enough entropy to make the world
33474 ++		 * a better place.
33475 ++		 */
33476 ++		while (bufcnt < wantcnt && bufcnt < NUM_INT) {
33477 ++			list_for_each_entry_safe(rops, tmp, &random_ops, random_list) {
33478 ++
33479 ++				n = (*rops->read_random)(rops->arg, &buf[bufcnt],
33480 ++							 NUM_INT - bufcnt);
33481 ++
33482 ++				/* on failure remove the random number generator */
33483 ++				if (n == -1) {
33484 ++					list_del(&rops->random_list);
33485 ++					printk("crypto: RNG (driverid=0x%x) failed, disabling\n",
33486 ++							rops->driverid);
33487 ++					kfree(rops);
33488 ++				} else if (n > 0)
33489 ++					bufcnt += n;
33490 ++			}
33491 ++			/* give up CPU for a bit, just in case as this is a loop */
33492 ++			schedule();
33493 ++		}
33494 ++
33495 ++
33496 ++#ifdef CONFIG_OCF_FIPS
33497 ++		if (bufcnt > 0 && rndtest_buf((unsigned char *) &buf[0])) {
33498 ++			dprintk("crypto: buffer had fips errors, discarding\n");
33499 ++			bufcnt = 0;
33500 ++		}
33501 ++#endif
33502 ++
33503 ++		/*
33504 ++		 * if we have a certified buffer,  we can send some data
33505 ++		 * to /dev/random and move along
33506 ++		 */
33507 ++		if (bufcnt > 0) {
33508 ++			/* add what we have */
33509 ++			random_input_words(buf, bufcnt, bufcnt*sizeof(int)*8);
33510 ++			bufcnt = 0;
33511 ++		}
33512 ++
33513 ++		/* give up CPU for a bit so we don't hog while filling */
33514 ++		schedule();
33515 ++
33516 ++		/* wait for needing more */
33517 ++		wantcnt = random_input_wait();
33518 ++
33519 ++		if (wantcnt <= 0)
33520 ++			wantcnt = 0; /* try to get some info again */
33521 ++		else
33522 ++		 	/* round up to one word or we can loop forever */
33523 ++			wantcnt = (wantcnt + (sizeof(int)*8)) / (sizeof(int)*8);
33524 ++		if (wantcnt > NUM_INT) {
33525 ++			wantcnt = NUM_INT;
33526 ++		}
33527 ++
33528 ++		if (signal_pending(current)) {
33529 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
33530 ++			spin_lock_irq(&current->sigmask_lock);
33531 ++#endif
33532 ++			flush_signals(current);
33533 ++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
33534 ++			spin_unlock_irq(&current->sigmask_lock);
33535 ++#endif
33536 ++		}
33537 ++	}
33538 ++	
33539 ++	kfree(buf);
33540 ++
33541 ++bad_alloc:
33542 ++	spin_lock_irq(&random_lock);
33543 ++	randomproc = (pid_t) -1;
33544 ++	started = 0;
33545 ++	spin_unlock_irq(&random_lock);
33546 ++
33547 ++	return retval;
33548 ++}
33549 ++
33550 +diff -urN linux-2.6.23.16.old/crypto/ocf/README linux-2.6.23.16/crypto/ocf/README
33551 +--- linux-2.6.23.16.old/crypto/ocf/README	1969-12-31 19:00:00.000000000 -0500
33552 ++++ linux-2.6.23.16/crypto/ocf/README	2008-02-26 09:29:13.000000000 -0500
33553 +@@ -0,0 +1,166 @@
33554 ++README - ocf-linux-20071215
33555 ++---------------------------
33556 ++
33557 ++This README provides instructions for getting ocf-linux compiled and
33558 ++operating in a generic linux environment.  For other information you
33559 ++might like to visit the home page for this project:
33560 ++
33561 ++    http://ocf-linux.sourceforge.net/
33562 ++
33563 ++Adding OCF to linux
33564 ++-------------------
33565 ++
33566 ++    Not much in this file for now,  just some notes.  I usually build
33567 ++    the ocf support as modules but it can be built into the kernel as
33568 ++    well.  To use it:
33569 ++
33570 ++    * mknod /dev/crypto c 10 70
33571 ++
33572 ++    * to add OCF to your kernel source,  you have two options.  Apply
33573 ++      the kernel specific patch:
33574 ++
33575 ++          cd linux-2.4*; gunzip < ocf-linux-24-XXXXXXXX.patch.gz | patch -p1
33576 ++          cd linux-2.6*; gunzip < ocf-linux-26-XXXXXXXX.patch.gz | patch -p1
33577 ++    
33578 ++      if you do one of the above,  then you can proceed to the next step,
33579 ++      or you can do the above process by hand with using the patches against
33580 ++      linux-2.4.35 and 2.6.23 to include the ocf code under crypto/ocf.
33581 ++      Here's how to add it:
33582 ++
33583 ++      for 2.4.35 (and later)
33584 ++
33585 ++          cd linux-2.4.35/crypto
33586 ++          tar xvzf ocf-linux.tar.gz
33587 ++          cd ..
33588 ++          patch -p1 < crypto/ocf/patches/linux-2.4.35-ocf.patch
33589 ++
33590 ++      for 2.6.23 (and later)
33591 ++
33592 ++          cd linux-2.6.23/crypto
33593 ++          tar xvzf ocf-linux.tar.gz
33594 ++          cd ..
33595 ++          patch -p1 < crypto/ocf/patches/linux-2.6.23-ocf.patch
33596 ++
33597 ++      It should be easy to take this patch and apply it to other more
33598 ++      recent versions of the kernels.  The same patches should also work
33599 ++      relatively easily on kernels as old as 2.6.11 and 2.4.18.
33600 ++      
33601 ++    * under 2.4 if you are on a non-x86 platform,  you may need to:
33602 ++
33603 ++        cp linux-2.X.x/include/asm-i386/kmap_types.h linux-2.X.x/include/asm-YYY
33604 ++
33605 ++      so that you can build the kernel crypto support needed for the cryptosoft
33606 ++      driver.
33607 ++
33608 ++    * For simplicity you should enable all the crypto support in your kernel
33609 ++      except for the test driver.  Likewise for the OCF options.  Do not
33610 ++      enable OCF crypto drivers for HW that you do not have (for example
33611 ++      ixp4xx will not compile on non-Xscale systems).
33612 ++
33613 ++    * make sure that cryptodev.h (from ocf-linux.tar.gz) is installed as
33614 ++      crypto/cryptodev.h in an include directory that is used for building
33615 ++      applications for your platform.  For example on a host system that
33616 ++      might be:
33617 ++
33618 ++              /usr/include/crypto/cryptodev.h
33619 ++
33620 ++    * patch your openssl-0.9.8g code with the openssl-0.9.8g.patch.
33621 ++      (NOTE: there is no longer a need to patch ssh). The patch is against:
33622 ++      openssl-0_9_8e
33623 ++
33624 ++      If you need a patch for an older version of openssl,  you should look
33625 ++      to older OCF releases.  This patch is unlikely to work on older
33626 ++      openssl versions.
33627 ++
33628 ++      openssl-0.9.8g.patch
33629 ++                - enables --with-cryptodev for non BSD systems
33630 ++                - adds -cpu option to openssl speed for calculating CPU load
33631 ++                  under linux
33632 ++                - fixes null pointer in openssl speed multi thread output.
33633 ++                - fixes test keys to work with linux crypto's more stringent
33634 ++                  key checking.
33635 ++                - adds MD5/SHA acceleration (Ronen Shitrit), only enabled
33636 ++                  with the --with-cryptodev-digests option
33637 ++                - fixes bug in engine code caching.
33638 ++
33639 ++    * build crypto-tools-XXXXXXXX.tar.gz if you want to try some of the BSD
33640 ++      tools for testing OCF (ie., cryptotest).
33641 ++
33642 ++How to load the OCF drivers
33643 ++---------------------------
33644 ++
33645 ++    First insert the base modules:
33646 ++
33647 ++        insmod ocf
33648 ++        insmod cryptodev
33649 ++
33650 ++    You can then install the software OCF driver with:
33651 ++
33652 ++        insmod cryptosoft
33653 ++
33654 ++    and one or more of the OCF HW drivers with:
33655 ++
33656 ++        insmod safe
33657 ++        insmod hifn7751
33658 ++        insmod ixp4xx
33659 ++        ...
33660 ++
33661 ++    all the drivers take a debug option to enable verbose debug so that
33662 ++    you can see what is going on.  For debug you load them as:
33663 ++
33664 ++        insmod ocf crypto_debug=1
33665 ++        insmod cryptodev cryptodev_debug=1
33666 ++        insmod cryptosoft swcr_debug=1
33667 ++
33668 ++    You may load more than one OCF crypto driver but then there is no guarantee
33669 ++    as to which will be used.
33670 ++
33671 ++    You can also enable debug at run time on 2.6 systems with the following:
33672 ++
33673 ++        echo 1 > /sys/module/ocf/parameters/crypto_debug
33674 ++        echo 1 > /sys/module/cryptodev/parameters/cryptodev_debug
33675 ++        echo 1 > /sys/module/cryptosoft/parameters/swcr_debug
33676 ++        echo 1 > /sys/module/hifn7751/parameters/hifn_debug
33677 ++        echo 1 > /sys/module/safe/parameters/safe_debug
33678 ++        echo 1 > /sys/module/ixp4xx/parameters/ixp_debug
33679 ++        ...
33680 ++
33681 ++Testing the OCF support
33682 ++-----------------------
33683 ++
33684 ++    run "cryptotest",  it should do a short test for a couple of
33685 ++    des packets.  If it does everything is working.
33686 ++
33687 ++    If this works,  then ssh will use the driver when invoked as:
33688 ++
33689 ++        ssh -c 3des username@host
33690 ++
33691 ++    to see for sure that it is operating, enable debug as defined above.
33692 ++
33693 ++    To get a better idea of performance run:
33694 ++
33695 ++        cryptotest 100 4096
33696 ++
33697 ++    There are more options to cryptotest,  see the help.
33698 ++
33699 ++    It is also possible to use openssl to test the speed of the crypto
33700 ++    drivers.
33701 ++
33702 ++        openssl speed -evp des -engine cryptodev -elapsed
33703 ++        openssl speed -evp des3 -engine cryptodev -elapsed
33704 ++        openssl speed -evp aes128 -engine cryptodev -elapsed
33705 ++
33706 ++    and multiple threads (10) with:
33707 ++
33708 ++        openssl speed -evp des -engine cryptodev -elapsed -multi 10
33709 ++        openssl speed -evp des3 -engine cryptodev -elapsed -multi 10
33710 ++        openssl speed -evp aes128 -engine cryptodev -elapsed -multi 10
33711 ++
33712 ++    for public key testing you can try:
33713 ++
33714 ++        cryptokeytest
33715 ++        openssl speed -engine cryptodev rsa -elapsed
33716 ++        openssl speed -engine cryptodev dsa -elapsed
33717 ++
33718 ++David McCullough
33719 ++david_mccullough@securecomputing.com
33720 +diff -urN linux-2.6.23.16.old/crypto/ocf/rndtest.c linux-2.6.23.16/crypto/ocf/rndtest.c
33721 +--- linux-2.6.23.16.old/crypto/ocf/rndtest.c	1969-12-31 19:00:00.000000000 -0500
33722 ++++ linux-2.6.23.16/crypto/ocf/rndtest.c	2008-02-26 09:29:13.000000000 -0500
33723 +@@ -0,0 +1,300 @@
33724 ++/*	$OpenBSD$	*/
33725 ++
33726 ++/*
33727 ++ * OCF/Linux port done by David McCullough <david_mccullough@securecomputing.com>
33728 ++ * Copyright (C) 2006-2007 David McCullough
33729 ++ * Copyright (C) 2004-2005 Intel Corporation.
33730 ++ * The license and original author are listed below.
33731 ++ *
33732 ++ * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
33733 ++ * All rights reserved.
33734 ++ *
33735 ++ * Redistribution and use in source and binary forms, with or without
33736 ++ * modification, are permitted provided that the following conditions
33737 ++ * are met:
33738 ++ * 1. Redistributions of source code must retain the above copyright
33739 ++ *    notice, this list of conditions and the following disclaimer.
33740 ++ * 2. Redistributions in binary form must reproduce the above copyright
33741 ++ *    notice, this list of conditions and the following disclaimer in the
33742 ++ *    documentation and/or other materials provided with the distribution.
33743 ++ * 3. All advertising materials mentioning features or use of this software
33744 ++ *    must display the following acknowledgement:
33745 ++ *	This product includes software developed by Jason L. Wright
33746 ++ * 4. The name of the author may not be used to endorse or promote products
33747 ++ *    derived from this software without specific prior written permission.
33748 ++ *
33749 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33750 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33751 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33752 ++ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
33753 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33754 ++ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33755 ++ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33756 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33757 ++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33758 ++ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33759 ++ * POSSIBILITY OF SUCH DAMAGE.
33760 ++ */
33761 ++
33762 ++#ifndef AUTOCONF_INCLUDED
33763 ++#include <linux/config.h>
33764 ++#endif
33765 ++#include <linux/module.h>
33766 ++#include <linux/list.h>
33767 ++#include <linux/wait.h>
33768 ++#include <linux/time.h>
33769 ++#include <linux/version.h>
33770 ++#include <linux/unistd.h>
33771 ++#include <linux/kernel.h>
33772 ++#include <linux/string.h>
33773 ++#include <linux/time.h>
33774 ++#include <cryptodev.h>
33775 ++#include "rndtest.h"
33776 ++
33777 ++static struct rndtest_stats rndstats;
33778 ++
33779 ++static	void rndtest_test(struct rndtest_state *);
33780 ++
33781 ++/* The tests themselves */
33782 ++static	int rndtest_monobit(struct rndtest_state *);
33783 ++static	int rndtest_runs(struct rndtest_state *);
33784 ++static	int rndtest_longruns(struct rndtest_state *);
33785 ++static	int rndtest_chi_4(struct rndtest_state *);
33786 ++
33787 ++static	int rndtest_runs_check(struct rndtest_state *, int, int *);
33788 ++static	void rndtest_runs_record(struct rndtest_state *, int, int *);
33789 ++
33790 ++static const struct rndtest_testfunc {
33791 ++	int (*test)(struct rndtest_state *);
33792 ++} rndtest_funcs[] = {
33793 ++	{ rndtest_monobit },
33794 ++	{ rndtest_runs },
33795 ++	{ rndtest_chi_4 },
33796 ++	{ rndtest_longruns },
33797 ++};
33798 ++
33799 ++#define	RNDTEST_NTESTS	(sizeof(rndtest_funcs)/sizeof(rndtest_funcs[0]))
33800 ++
33801 ++static void
33802 ++rndtest_test(struct rndtest_state *rsp)
33803 ++{
33804 ++	int i, rv = 0;
33805 ++
33806 ++	rndstats.rst_tests++;
33807 ++	for (i = 0; i < RNDTEST_NTESTS; i++)
33808 ++		rv |= (*rndtest_funcs[i].test)(rsp);
33809 ++	rsp->rs_discard = (rv != 0);
33810 ++}
33811 ++
33812 ++
33813 ++extern int crypto_debug;
33814 ++#define rndtest_verbose 2
33815 ++#define rndtest_report(rsp, failure, fmt, a...) \
33816 ++	{ if (failure || crypto_debug) { printk("rng_test: " fmt "\n", a); } else; }
33817 ++
33818 ++#define	RNDTEST_MONOBIT_MINONES	9725
33819 ++#define	RNDTEST_MONOBIT_MAXONES	10275
33820 ++
33821 ++static int
33822 ++rndtest_monobit(struct rndtest_state *rsp)
33823 ++{
33824 ++	int i, ones = 0, j;
33825 ++	u_int8_t r;
33826 ++
33827 ++	for (i = 0; i < RNDTEST_NBYTES; i++) {
33828 ++		r = rsp->rs_buf[i];
33829 ++		for (j = 0; j < 8; j++, r <<= 1)
33830 ++			if (r & 0x80)
33831 ++				ones++;
33832 ++	}
33833 ++	if (ones > RNDTEST_MONOBIT_MINONES &&
33834 ++	    ones < RNDTEST_MONOBIT_MAXONES) {
33835 ++		if (rndtest_verbose > 1)
33836 ++			rndtest_report(rsp, 0, "monobit pass (%d < %d < %d)",
33837 ++			    RNDTEST_MONOBIT_MINONES, ones,
33838 ++			    RNDTEST_MONOBIT_MAXONES);
33839 ++		return (0);
33840 ++	} else {
33841 ++		if (rndtest_verbose)
33842 ++			rndtest_report(rsp, 1,
33843 ++			    "monobit failed (%d ones)", ones);
33844 ++		rndstats.rst_monobit++;
33845 ++		return (-1);
33846 ++	}
33847 ++}
33848 ++
33849 ++#define	RNDTEST_RUNS_NINTERVAL	6
33850 ++
33851 ++static const struct rndtest_runs_tabs {
33852 ++	u_int16_t min, max;
33853 ++} rndtest_runs_tab[] = {
33854 ++	{ 2343, 2657 },
33855 ++	{ 1135, 1365 },
33856 ++	{ 542, 708 },
33857 ++	{ 251, 373 },
33858 ++	{ 111, 201 },
33859 ++	{ 111, 201 },
33860 ++};
33861 ++
33862 ++static int
33863 ++rndtest_runs(struct rndtest_state *rsp)
33864 ++{
33865 ++	int i, j, ones, zeros, rv = 0;
33866 ++	int onei[RNDTEST_RUNS_NINTERVAL], zeroi[RNDTEST_RUNS_NINTERVAL];
33867 ++	u_int8_t c;
33868 ++
33869 ++	bzero(onei, sizeof(onei));
33870 ++	bzero(zeroi, sizeof(zeroi));
33871 ++	ones = zeros = 0;
33872 ++	for (i = 0; i < RNDTEST_NBYTES; i++) {
33873 ++		c = rsp->rs_buf[i];
33874 ++		for (j = 0; j < 8; j++, c <<= 1) {
33875 ++			if (c & 0x80) {
33876 ++				ones++;
33877 ++				rndtest_runs_record(rsp, zeros, zeroi);
33878 ++				zeros = 0;
33879 ++			} else {
33880 ++				zeros++;
33881 ++				rndtest_runs_record(rsp, ones, onei);
33882 ++				ones = 0;
33883 ++			}
33884 ++		}
33885 ++	}
33886 ++	rndtest_runs_record(rsp, ones, onei);
33887 ++	rndtest_runs_record(rsp, zeros, zeroi);
33888 ++
33889 ++	rv |= rndtest_runs_check(rsp, 0, zeroi);
33890 ++	rv |= rndtest_runs_check(rsp, 1, onei);
33891 ++
33892 ++	if (rv)
33893 ++		rndstats.rst_runs++;
33894 ++
33895 ++	return (rv);
33896 ++}
33897 ++
33898 ++static void
33899 ++rndtest_runs_record(struct rndtest_state *rsp, int len, int *intrv)
33900 ++{
33901 ++	if (len == 0)
33902 ++		return;
33903 ++	if (len > RNDTEST_RUNS_NINTERVAL)
33904 ++		len = RNDTEST_RUNS_NINTERVAL;
33905 ++	len -= 1;
33906 ++	intrv[len]++;
33907 ++}
33908 ++
33909 ++static int
33910 ++rndtest_runs_check(struct rndtest_state *rsp, int val, int *src)
33911 ++{
33912 ++	int i, rv = 0;
33913 ++
33914 ++	for (i = 0; i < RNDTEST_RUNS_NINTERVAL; i++) {
33915 ++		if (src[i] < rndtest_runs_tab[i].min ||
33916 ++		    src[i] > rndtest_runs_tab[i].max) {
33917 ++			rndtest_report(rsp, 1,
33918 ++			    "%s interval %d failed (%d, %d-%d)",
33919 ++			    val ? "ones" : "zeros",
33920 ++			    i + 1, src[i], rndtest_runs_tab[i].min,
33921 ++			    rndtest_runs_tab[i].max);
33922 ++			rv = -1;
33923 ++		} else {
33924 ++			rndtest_report(rsp, 0,
33925 ++			    "runs pass %s interval %d (%d < %d < %d)",
33926 ++			    val ? "ones" : "zeros",
33927 ++			    i + 1, rndtest_runs_tab[i].min, src[i],
33928 ++			    rndtest_runs_tab[i].max);
33929 ++		}
33930 ++	}
33931 ++	return (rv);
33932 ++}
33933 ++
33934 ++static int
33935 ++rndtest_longruns(struct rndtest_state *rsp)
33936 ++{
33937 ++	int i, j, ones = 0, zeros = 0, maxones = 0, maxzeros = 0;
33938 ++	u_int8_t c;
33939 ++
33940 ++	for (i = 0; i < RNDTEST_NBYTES; i++) {
33941 ++		c = rsp->rs_buf[i];
33942 ++		for (j = 0; j < 8; j++, c <<= 1) {
33943 ++			if (c & 0x80) {
33944 ++				zeros = 0;
33945 ++				ones++;
33946 ++				if (ones > maxones)
33947 ++					maxones = ones;
33948 ++			} else {
33949 ++				ones = 0;
33950 ++				zeros++;
33951 ++				if (zeros > maxzeros)
33952 ++					maxzeros = zeros;
33953 ++			}
33954 ++		}
33955 ++	}
33956 ++
33957 ++	if (maxones < 26 && maxzeros < 26) {
33958 ++		rndtest_report(rsp, 0, "longruns pass (%d ones, %d zeros)",
33959 ++			maxones, maxzeros);
33960 ++		return (0);
33961 ++	} else {
33962 ++		rndtest_report(rsp, 1, "longruns fail (%d ones, %d zeros)",
33963 ++			maxones, maxzeros);
33964 ++		rndstats.rst_longruns++;
33965 ++		return (-1);
33966 ++	}
33967 ++}
33968 ++
33969 ++/*
33970 ++ * chi^2 test over 4 bits: (this is called the poker test in FIPS 140-2,
33971 ++ * but it is really the chi^2 test over 4 bits (the poker test as described
33972 ++ * by Knuth vol 2 is something different, and I take him as authoritative
33973 ++ * on nomenclature over NIST).
33974 ++ */
33975 ++#define	RNDTEST_CHI4_K	16
33976 ++#define	RNDTEST_CHI4_K_MASK	(RNDTEST_CHI4_K - 1)
33977 ++
33978 ++/*
33979 ++ * The unnormalized values are used so that we don't have to worry about
33980 ++ * fractional precision.  The "real" value is found by:
33981 ++ *	(V - 1562500) * (16 / 5000) = Vn   (where V is the unnormalized value)
33982 ++ */
33983 ++#define	RNDTEST_CHI4_VMIN	1563181		/* 2.1792 */
33984 ++#define	RNDTEST_CHI4_VMAX	1576929		/* 46.1728 */
33985 ++
33986 ++static int
33987 ++rndtest_chi_4(struct rndtest_state *rsp)
33988 ++{
33989 ++	unsigned int freq[RNDTEST_CHI4_K], i, sum;
33990 ++
33991 ++	for (i = 0; i < RNDTEST_CHI4_K; i++)
33992 ++		freq[i] = 0;
33993 ++
33994 ++	/* Get number of occurances of each 4 bit pattern */
33995 ++	for (i = 0; i < RNDTEST_NBYTES; i++) {
33996 ++		freq[(rsp->rs_buf[i] >> 4) & RNDTEST_CHI4_K_MASK]++;
33997 ++		freq[(rsp->rs_buf[i] >> 0) & RNDTEST_CHI4_K_MASK]++;
33998 ++	}
33999 ++
34000 ++	for (i = 0, sum = 0; i < RNDTEST_CHI4_K; i++)
34001 ++		sum += freq[i] * freq[i];
34002 ++
34003 ++	if (sum >= 1563181 && sum <= 1576929) {
34004 ++		rndtest_report(rsp, 0, "chi^2(4): pass (sum %u)", sum);
34005 ++		return (0);
34006 ++	} else {
34007 ++		rndtest_report(rsp, 1, "chi^2(4): failed (sum %u)", sum);
34008 ++		rndstats.rst_chi++;
34009 ++		return (-1);
34010 ++	}
34011 ++}
34012 ++
34013 ++int
34014 ++rndtest_buf(unsigned char *buf)
34015 ++{
34016 ++	struct rndtest_state rsp;
34017 ++
34018 ++	memset(&rsp, 0, sizeof(rsp));
34019 ++	rsp.rs_buf = buf;
34020 ++	rndtest_test(&rsp);
34021 ++	return(rsp.rs_discard);
34022 ++}
34023 ++
34024 +diff -urN linux-2.6.23.16.old/crypto/ocf/rndtest.h linux-2.6.23.16/crypto/ocf/rndtest.h
34025 +--- linux-2.6.23.16.old/crypto/ocf/rndtest.h	1969-12-31 19:00:00.000000000 -0500
34026 ++++ linux-2.6.23.16/crypto/ocf/rndtest.h	2008-02-26 09:29:13.000000000 -0500
34027 +@@ -0,0 +1,54 @@
34028 ++/*	$FreeBSD: src/sys/dev/rndtest/rndtest.h,v 1.1 2003/03/11 22:54:44 sam Exp $	*/
34029 ++/*	$OpenBSD$	*/
34030 ++
34031 ++/*
34032 ++ * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
34033 ++ * All rights reserved.
34034 ++ *
34035 ++ * Redistribution and use in source and binary forms, with or without
34036 ++ * modification, are permitted provided that the following conditions
34037 ++ * are met:
34038 ++ * 1. Redistributions of source code must retain the above copyright
34039 ++ *    notice, this list of conditions and the following disclaimer.
34040 ++ * 2. Redistributions in binary form must reproduce the above copyright
34041 ++ *    notice, this list of conditions and the following disclaimer in the
34042 ++ *    documentation and/or other materials provided with the distribution.
34043 ++ * 3. All advertising materials mentioning features or use of this software
34044 ++ *    must display the following acknowledgement:
34045 ++ *	This product includes software developed by Jason L. Wright
34046 ++ * 4. The name of the author may not be used to endorse or promote products
34047 ++ *    derived from this software without specific prior written permission.
34048 ++ *
34049 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34050 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34051 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34052 ++ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
34053 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34054 ++ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34055 ++ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34056 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34057 ++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34058 ++ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34059 ++ * POSSIBILITY OF SUCH DAMAGE.
34060 ++ */
34061 ++
34062 ++
34063 ++/* Some of the tests depend on these values */
34064 ++#define	RNDTEST_NBYTES	2500
34065 ++#define	RNDTEST_NBITS	(8 * RNDTEST_NBYTES)
34066 ++
34067 ++struct rndtest_state {
34068 ++	int		rs_discard;	/* discard/accept random data */
34069 ++	u_int8_t	*rs_buf;
34070 ++};
34071 ++
34072 ++struct rndtest_stats {
34073 ++	u_int32_t	rst_discard;	/* number of bytes discarded */
34074 ++	u_int32_t	rst_tests;	/* number of test runs */
34075 ++	u_int32_t	rst_monobit;	/* monobit test failures */
34076 ++	u_int32_t	rst_runs;	/* 0/1 runs failures */
34077 ++	u_int32_t	rst_longruns;	/* longruns failures */
34078 ++	u_int32_t	rst_chi;	/* chi^2 failures */
34079 ++};
34080 ++
34081 ++extern int rndtest_buf(unsigned char *buf);
34082 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/Makefile linux-2.6.23.16/crypto/ocf/safe/Makefile
34083 +--- linux-2.6.23.16.old/crypto/ocf/safe/Makefile	1969-12-31 19:00:00.000000000 -0500
34084 ++++ linux-2.6.23.16/crypto/ocf/safe/Makefile	2008-02-26 09:29:13.000000000 -0500
34085 +@@ -0,0 +1,12 @@
34086 ++# for SGlinux builds
34087 ++-include $(ROOTDIR)/modules/.config
34088 ++
34089 ++obj-$(CONFIG_OCF_SAFE) += safe.o
34090 ++
34091 ++obj ?= .
34092 ++EXTRA_CFLAGS += -I$(obj)/.. -I$(obj)/
34093 ++
34094 ++ifdef TOPDIR
34095 ++-include $(TOPDIR)/Rules.make
34096 ++endif
34097 ++
34098 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/md5.c linux-2.6.23.16/crypto/ocf/safe/md5.c
34099 +--- linux-2.6.23.16.old/crypto/ocf/safe/md5.c	1969-12-31 19:00:00.000000000 -0500
34100 ++++ linux-2.6.23.16/crypto/ocf/safe/md5.c	2008-02-26 09:29:13.000000000 -0500
34101 +@@ -0,0 +1,308 @@
34102 ++/*	$KAME: md5.c,v 1.5 2000/11/08 06:13:08 itojun Exp $	*/
34103 ++/*
34104 ++ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
34105 ++ * All rights reserved.
34106 ++ *
34107 ++ * Redistribution and use in source and binary forms, with or without
34108 ++ * modification, are permitted provided that the following conditions
34109 ++ * are met:
34110 ++ * 1. Redistributions of source code must retain the above copyright
34111 ++ *    notice, this list of conditions and the following disclaimer.
34112 ++ * 2. Redistributions in binary form must reproduce the above copyright
34113 ++ *    notice, this list of conditions and the following disclaimer in the
34114 ++ *    documentation and/or other materials provided with the distribution.
34115 ++ * 3. Neither the name of the project nor the names of its contributors
34116 ++ *    may be used to endorse or promote products derived from this software
34117 ++ *    without specific prior written permission.
34118 ++ *
34119 ++ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
34120 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34121 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34122 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
34123 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34124 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34125 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34126 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34127 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34128 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34129 ++ * SUCH DAMAGE.
34130 ++ */
34131 ++
34132 ++#if 0
34133 ++#include <sys/cdefs.h>
34134 ++__FBSDID("$FreeBSD: src/sys/crypto/md5.c,v 1.9 2004/01/27 19:49:19 des Exp $");
34135 ++
34136 ++#include <sys/types.h>
34137 ++#include <sys/cdefs.h>
34138 ++#include <sys/time.h>
34139 ++#include <sys/systm.h>
34140 ++#include <crypto/md5.h>
34141 ++#endif
34142 ++
34143 ++#define SHIFT(X, s) (((X) << (s)) | ((X) >> (32 - (s))))
34144 ++
34145 ++#define F(X, Y, Z) (((X) & (Y)) | ((~X) & (Z)))
34146 ++#define G(X, Y, Z) (((X) & (Z)) | ((Y) & (~Z)))
34147 ++#define H(X, Y, Z) ((X) ^ (Y) ^ (Z))
34148 ++#define I(X, Y, Z) ((Y) ^ ((X) | (~Z)))
34149 ++
34150 ++#define ROUND1(a, b, c, d, k, s, i) { \
34151 ++	(a) = (a) + F((b), (c), (d)) + X[(k)] + T[(i)]; \
34152 ++	(a) = SHIFT((a), (s)); \
34153 ++	(a) = (b) + (a); \
34154 ++}
34155 ++
34156 ++#define ROUND2(a, b, c, d, k, s, i) { \
34157 ++	(a) = (a) + G((b), (c), (d)) + X[(k)] + T[(i)]; \
34158 ++	(a) = SHIFT((a), (s)); \
34159 ++	(a) = (b) + (a); \
34160 ++}
34161 ++
34162 ++#define ROUND3(a, b, c, d, k, s, i) { \
34163 ++	(a) = (a) + H((b), (c), (d)) + X[(k)] + T[(i)]; \
34164 ++	(a) = SHIFT((a), (s)); \
34165 ++	(a) = (b) + (a); \
34166 ++}
34167 ++
34168 ++#define ROUND4(a, b, c, d, k, s, i) { \
34169 ++	(a) = (a) + I((b), (c), (d)) + X[(k)] + T[(i)]; \
34170 ++	(a) = SHIFT((a), (s)); \
34171 ++	(a) = (b) + (a); \
34172 ++}
34173 ++
34174 ++#define Sa	 7
34175 ++#define Sb	12
34176 ++#define Sc	17
34177 ++#define Sd	22
34178 ++
34179 ++#define Se	 5
34180 ++#define Sf	 9
34181 ++#define Sg	14
34182 ++#define Sh	20
34183 ++
34184 ++#define Si	 4
34185 ++#define Sj	11
34186 ++#define Sk	16
34187 ++#define Sl	23
34188 ++
34189 ++#define Sm	 6
34190 ++#define Sn	10
34191 ++#define So	15
34192 ++#define Sp	21
34193 ++
34194 ++#define MD5_A0	0x67452301
34195 ++#define MD5_B0	0xefcdab89
34196 ++#define MD5_C0	0x98badcfe
34197 ++#define MD5_D0	0x10325476
34198 ++
34199 ++/* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
34200 ++static const u_int32_t T[65] = {
34201 ++	0,
34202 ++	0xd76aa478, 	0xe8c7b756,	0x242070db,	0xc1bdceee,
34203 ++	0xf57c0faf,	0x4787c62a, 	0xa8304613,	0xfd469501,
34204 ++	0x698098d8,	0x8b44f7af,	0xffff5bb1,	0x895cd7be,
34205 ++	0x6b901122, 	0xfd987193, 	0xa679438e,	0x49b40821,
34206 ++
34207 ++	0xf61e2562,	0xc040b340, 	0x265e5a51, 	0xe9b6c7aa,
34208 ++	0xd62f105d,	0x2441453,	0xd8a1e681,	0xe7d3fbc8,
34209 ++	0x21e1cde6,	0xc33707d6, 	0xf4d50d87, 	0x455a14ed,
34210 ++	0xa9e3e905,	0xfcefa3f8, 	0x676f02d9, 	0x8d2a4c8a,
34211 ++
34212 ++	0xfffa3942,	0x8771f681, 	0x6d9d6122, 	0xfde5380c,
34213 ++	0xa4beea44, 	0x4bdecfa9, 	0xf6bb4b60, 	0xbebfbc70,
34214 ++	0x289b7ec6, 	0xeaa127fa, 	0xd4ef3085,	0x4881d05,
34215 ++	0xd9d4d039, 	0xe6db99e5, 	0x1fa27cf8, 	0xc4ac5665,
34216 ++
34217 ++	0xf4292244, 	0x432aff97, 	0xab9423a7, 	0xfc93a039,
34218 ++	0x655b59c3, 	0x8f0ccc92, 	0xffeff47d, 	0x85845dd1,
34219 ++	0x6fa87e4f, 	0xfe2ce6e0, 	0xa3014314, 	0x4e0811a1,
34220 ++	0xf7537e82, 	0xbd3af235, 	0x2ad7d2bb, 	0xeb86d391,
34221 ++};
34222 ++
34223 ++static const u_int8_t md5_paddat[MD5_BUFLEN] = {
34224 ++	0x80,	0,	0,	0,	0,	0,	0,	0,
34225 ++	0,	0,	0,	0,	0,	0,	0,	0,
34226 ++	0,	0,	0,	0,	0,	0,	0,	0,
34227 ++	0,	0,	0,	0,	0,	0,	0,	0,
34228 ++	0,	0,	0,	0,	0,	0,	0,	0,
34229 ++	0,	0,	0,	0,	0,	0,	0,	0,
34230 ++	0,	0,	0,	0,	0,	0,	0,	0,
34231 ++	0,	0,	0,	0,	0,	0,	0,	0,	
34232 ++};
34233 ++
34234 ++static void md5_calc(u_int8_t *, md5_ctxt *);
34235 ++
34236 ++void md5_init(ctxt)
34237 ++	md5_ctxt *ctxt;
34238 ++{
34239 ++	ctxt->md5_n = 0;
34240 ++	ctxt->md5_i = 0;
34241 ++	ctxt->md5_sta = MD5_A0;
34242 ++	ctxt->md5_stb = MD5_B0;
34243 ++	ctxt->md5_stc = MD5_C0;
34244 ++	ctxt->md5_std = MD5_D0;
34245 ++	bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf));
34246 ++}
34247 ++
34248 ++void md5_loop(ctxt, input, len)
34249 ++	md5_ctxt *ctxt;
34250 ++	u_int8_t *input;
34251 ++	u_int len; /* number of bytes */
34252 ++{
34253 ++	u_int gap, i;
34254 ++
34255 ++	ctxt->md5_n += len * 8; /* byte to bit */
34256 ++	gap = MD5_BUFLEN - ctxt->md5_i;
34257 ++
34258 ++	if (len >= gap) {
34259 ++		bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
34260 ++			gap);
34261 ++		md5_calc(ctxt->md5_buf, ctxt);
34262 ++
34263 ++		for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN) {
34264 ++			md5_calc((u_int8_t *)(input + i), ctxt);
34265 ++		}
34266 ++		
34267 ++		ctxt->md5_i = len - i;
34268 ++		bcopy((void *)(input + i), (void *)ctxt->md5_buf, ctxt->md5_i);
34269 ++	} else {
34270 ++		bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
34271 ++			len);
34272 ++		ctxt->md5_i += len;
34273 ++	}
34274 ++}
34275 ++
34276 ++void md5_pad(ctxt)
34277 ++	md5_ctxt *ctxt;
34278 ++{
34279 ++	u_int gap;
34280 ++
34281 ++	/* Don't count up padding. Keep md5_n. */	
34282 ++	gap = MD5_BUFLEN - ctxt->md5_i;
34283 ++	if (gap > 8) {
34284 ++		bcopy(md5_paddat,
34285 ++		      (void *)(ctxt->md5_buf + ctxt->md5_i),
34286 ++		      gap - sizeof(ctxt->md5_n));
34287 ++	} else {
34288 ++		/* including gap == 8 */
34289 ++		bcopy(md5_paddat, (void *)(ctxt->md5_buf + ctxt->md5_i),
34290 ++			gap);
34291 ++		md5_calc(ctxt->md5_buf, ctxt);
34292 ++		bcopy((md5_paddat + gap),
34293 ++		      (void *)ctxt->md5_buf,
34294 ++		      MD5_BUFLEN - sizeof(ctxt->md5_n));
34295 ++	}
34296 ++
34297 ++	/* 8 byte word */	
34298 ++#if BYTE_ORDER == LITTLE_ENDIAN
34299 ++	bcopy(&ctxt->md5_n8[0], &ctxt->md5_buf[56], 8);
34300 ++#endif
34301 ++#if BYTE_ORDER == BIG_ENDIAN
34302 ++	ctxt->md5_buf[56] = ctxt->md5_n8[7];
34303 ++	ctxt->md5_buf[57] = ctxt->md5_n8[6];
34304 ++	ctxt->md5_buf[58] = ctxt->md5_n8[5];
34305 ++	ctxt->md5_buf[59] = ctxt->md5_n8[4];
34306 ++	ctxt->md5_buf[60] = ctxt->md5_n8[3];
34307 ++	ctxt->md5_buf[61] = ctxt->md5_n8[2];
34308 ++	ctxt->md5_buf[62] = ctxt->md5_n8[1];
34309 ++	ctxt->md5_buf[63] = ctxt->md5_n8[0];
34310 ++#endif
34311 ++
34312 ++	md5_calc(ctxt->md5_buf, ctxt);
34313 ++}
34314 ++
34315 ++void md5_result(digest, ctxt)
34316 ++	u_int8_t *digest;
34317 ++	md5_ctxt *ctxt;
34318 ++{
34319 ++	/* 4 byte words */
34320 ++#if BYTE_ORDER == LITTLE_ENDIAN
34321 ++	bcopy(&ctxt->md5_st8[0], digest, 16);
34322 ++#endif
34323 ++#if BYTE_ORDER == BIG_ENDIAN
34324 ++	digest[ 0] = ctxt->md5_st8[ 3]; digest[ 1] = ctxt->md5_st8[ 2];
34325 ++	digest[ 2] = ctxt->md5_st8[ 1]; digest[ 3] = ctxt->md5_st8[ 0];
34326 ++	digest[ 4] = ctxt->md5_st8[ 7]; digest[ 5] = ctxt->md5_st8[ 6];
34327 ++	digest[ 6] = ctxt->md5_st8[ 5]; digest[ 7] = ctxt->md5_st8[ 4];
34328 ++	digest[ 8] = ctxt->md5_st8[11]; digest[ 9] = ctxt->md5_st8[10];
34329 ++	digest[10] = ctxt->md5_st8[ 9]; digest[11] = ctxt->md5_st8[ 8];
34330 ++	digest[12] = ctxt->md5_st8[15]; digest[13] = ctxt->md5_st8[14];
34331 ++	digest[14] = ctxt->md5_st8[13]; digest[15] = ctxt->md5_st8[12];
34332 ++#endif
34333 ++}
34334 ++
34335 ++static void md5_calc(b64, ctxt)
34336 ++	u_int8_t *b64;
34337 ++	md5_ctxt *ctxt;
34338 ++{
34339 ++	u_int32_t A = ctxt->md5_sta;
34340 ++	u_int32_t B = ctxt->md5_stb;
34341 ++	u_int32_t C = ctxt->md5_stc;
34342 ++	u_int32_t D = ctxt->md5_std;
34343 ++#if BYTE_ORDER == LITTLE_ENDIAN
34344 ++	u_int32_t *X = (u_int32_t *)b64;
34345 ++#endif	
34346 ++#if BYTE_ORDER == BIG_ENDIAN
34347 ++	/* 4 byte words */
34348 ++	/* what a brute force but fast! */
34349 ++	u_int32_t X[16];
34350 ++	u_int8_t *y = (u_int8_t *)X;
34351 ++	y[ 0] = b64[ 3]; y[ 1] = b64[ 2]; y[ 2] = b64[ 1]; y[ 3] = b64[ 0];
34352 ++	y[ 4] = b64[ 7]; y[ 5] = b64[ 6]; y[ 6] = b64[ 5]; y[ 7] = b64[ 4];
34353 ++	y[ 8] = b64[11]; y[ 9] = b64[10]; y[10] = b64[ 9]; y[11] = b64[ 8];
34354 ++	y[12] = b64[15]; y[13] = b64[14]; y[14] = b64[13]; y[15] = b64[12];
34355 ++	y[16] = b64[19]; y[17] = b64[18]; y[18] = b64[17]; y[19] = b64[16];
34356 ++	y[20] = b64[23]; y[21] = b64[22]; y[22] = b64[21]; y[23] = b64[20];
34357 ++	y[24] = b64[27]; y[25] = b64[26]; y[26] = b64[25]; y[27] = b64[24];
34358 ++	y[28] = b64[31]; y[29] = b64[30]; y[30] = b64[29]; y[31] = b64[28];
34359 ++	y[32] = b64[35]; y[33] = b64[34]; y[34] = b64[33]; y[35] = b64[32];
34360 ++	y[36] = b64[39]; y[37] = b64[38]; y[38] = b64[37]; y[39] = b64[36];
34361 ++	y[40] = b64[43]; y[41] = b64[42]; y[42] = b64[41]; y[43] = b64[40];
34362 ++	y[44] = b64[47]; y[45] = b64[46]; y[46] = b64[45]; y[47] = b64[44];
34363 ++	y[48] = b64[51]; y[49] = b64[50]; y[50] = b64[49]; y[51] = b64[48];
34364 ++	y[52] = b64[55]; y[53] = b64[54]; y[54] = b64[53]; y[55] = b64[52];
34365 ++	y[56] = b64[59]; y[57] = b64[58]; y[58] = b64[57]; y[59] = b64[56];
34366 ++	y[60] = b64[63]; y[61] = b64[62]; y[62] = b64[61]; y[63] = b64[60];
34367 ++#endif
34368 ++
34369 ++	ROUND1(A, B, C, D,  0, Sa,  1); ROUND1(D, A, B, C,  1, Sb,  2);
34370 ++	ROUND1(C, D, A, B,  2, Sc,  3); ROUND1(B, C, D, A,  3, Sd,  4);
34371 ++	ROUND1(A, B, C, D,  4, Sa,  5); ROUND1(D, A, B, C,  5, Sb,  6);
34372 ++	ROUND1(C, D, A, B,  6, Sc,  7); ROUND1(B, C, D, A,  7, Sd,  8);
34373 ++	ROUND1(A, B, C, D,  8, Sa,  9); ROUND1(D, A, B, C,  9, Sb, 10);
34374 ++	ROUND1(C, D, A, B, 10, Sc, 11); ROUND1(B, C, D, A, 11, Sd, 12);
34375 ++	ROUND1(A, B, C, D, 12, Sa, 13); ROUND1(D, A, B, C, 13, Sb, 14);
34376 ++	ROUND1(C, D, A, B, 14, Sc, 15); ROUND1(B, C, D, A, 15, Sd, 16);
34377 ++	
34378 ++	ROUND2(A, B, C, D,  1, Se, 17); ROUND2(D, A, B, C,  6, Sf, 18);
34379 ++	ROUND2(C, D, A, B, 11, Sg, 19); ROUND2(B, C, D, A,  0, Sh, 20);
34380 ++	ROUND2(A, B, C, D,  5, Se, 21); ROUND2(D, A, B, C, 10, Sf, 22);
34381 ++	ROUND2(C, D, A, B, 15, Sg, 23); ROUND2(B, C, D, A,  4, Sh, 24);
34382 ++	ROUND2(A, B, C, D,  9, Se, 25); ROUND2(D, A, B, C, 14, Sf, 26);
34383 ++	ROUND2(C, D, A, B,  3, Sg, 27); ROUND2(B, C, D, A,  8, Sh, 28);
34384 ++	ROUND2(A, B, C, D, 13, Se, 29); ROUND2(D, A, B, C,  2, Sf, 30);
34385 ++	ROUND2(C, D, A, B,  7, Sg, 31); ROUND2(B, C, D, A, 12, Sh, 32);
34386 ++
34387 ++	ROUND3(A, B, C, D,  5, Si, 33); ROUND3(D, A, B, C,  8, Sj, 34);
34388 ++	ROUND3(C, D, A, B, 11, Sk, 35); ROUND3(B, C, D, A, 14, Sl, 36);
34389 ++	ROUND3(A, B, C, D,  1, Si, 37); ROUND3(D, A, B, C,  4, Sj, 38);
34390 ++	ROUND3(C, D, A, B,  7, Sk, 39); ROUND3(B, C, D, A, 10, Sl, 40);
34391 ++	ROUND3(A, B, C, D, 13, Si, 41); ROUND3(D, A, B, C,  0, Sj, 42);
34392 ++	ROUND3(C, D, A, B,  3, Sk, 43); ROUND3(B, C, D, A,  6, Sl, 44);
34393 ++	ROUND3(A, B, C, D,  9, Si, 45); ROUND3(D, A, B, C, 12, Sj, 46);
34394 ++	ROUND3(C, D, A, B, 15, Sk, 47); ROUND3(B, C, D, A,  2, Sl, 48);
34395 ++	
34396 ++	ROUND4(A, B, C, D,  0, Sm, 49); ROUND4(D, A, B, C,  7, Sn, 50);	
34397 ++	ROUND4(C, D, A, B, 14, So, 51); ROUND4(B, C, D, A,  5, Sp, 52);	
34398 ++	ROUND4(A, B, C, D, 12, Sm, 53); ROUND4(D, A, B, C,  3, Sn, 54);	
34399 ++	ROUND4(C, D, A, B, 10, So, 55); ROUND4(B, C, D, A,  1, Sp, 56);	
34400 ++	ROUND4(A, B, C, D,  8, Sm, 57); ROUND4(D, A, B, C, 15, Sn, 58);	
34401 ++	ROUND4(C, D, A, B,  6, So, 59); ROUND4(B, C, D, A, 13, Sp, 60);	
34402 ++	ROUND4(A, B, C, D,  4, Sm, 61); ROUND4(D, A, B, C, 11, Sn, 62);	
34403 ++	ROUND4(C, D, A, B,  2, So, 63); ROUND4(B, C, D, A,  9, Sp, 64);
34404 ++
34405 ++	ctxt->md5_sta += A;
34406 ++	ctxt->md5_stb += B;
34407 ++	ctxt->md5_stc += C;
34408 ++	ctxt->md5_std += D;
34409 ++}
34410 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/md5.h linux-2.6.23.16/crypto/ocf/safe/md5.h
34411 +--- linux-2.6.23.16.old/crypto/ocf/safe/md5.h	1969-12-31 19:00:00.000000000 -0500
34412 ++++ linux-2.6.23.16/crypto/ocf/safe/md5.h	2008-02-26 09:29:13.000000000 -0500
34413 +@@ -0,0 +1,76 @@
34414 ++/*	$FreeBSD: src/sys/crypto/md5.h,v 1.4 2002/03/20 05:13:50 alfred Exp $	*/
34415 ++/*	$KAME: md5.h,v 1.4 2000/03/27 04:36:22 sumikawa Exp $	*/
34416 ++
34417 ++/*
34418 ++ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
34419 ++ * All rights reserved.
34420 ++ *
34421 ++ * Redistribution and use in source and binary forms, with or without
34422 ++ * modification, are permitted provided that the following conditions
34423 ++ * are met:
34424 ++ * 1. Redistributions of source code must retain the above copyright
34425 ++ *    notice, this list of conditions and the following disclaimer.
34426 ++ * 2. Redistributions in binary form must reproduce the above copyright
34427 ++ *    notice, this list of conditions and the following disclaimer in the
34428 ++ *    documentation and/or other materials provided with the distribution.
34429 ++ * 3. Neither the name of the project nor the names of its contributors
34430 ++ *    may be used to endorse or promote products derived from this software
34431 ++ *    without specific prior written permission.
34432 ++ *
34433 ++ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
34434 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34435 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34436 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
34437 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34438 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34439 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34440 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34441 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34442 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34443 ++ * SUCH DAMAGE.
34444 ++ */
34445 ++
34446 ++#ifndef _NETINET6_MD5_H_
34447 ++#define _NETINET6_MD5_H_
34448 ++
34449 ++#define MD5_BUFLEN	64
34450 ++
34451 ++typedef struct {
34452 ++	union {
34453 ++		u_int32_t	md5_state32[4];
34454 ++		u_int8_t	md5_state8[16];
34455 ++	} md5_st;
34456 ++
34457 ++#define md5_sta		md5_st.md5_state32[0]
34458 ++#define md5_stb		md5_st.md5_state32[1]
34459 ++#define md5_stc		md5_st.md5_state32[2]
34460 ++#define md5_std		md5_st.md5_state32[3]
34461 ++#define md5_st8		md5_st.md5_state8
34462 ++
34463 ++	union {
34464 ++		u_int64_t	md5_count64;
34465 ++		u_int8_t	md5_count8[8];
34466 ++	} md5_count;
34467 ++#define md5_n	md5_count.md5_count64
34468 ++#define md5_n8	md5_count.md5_count8
34469 ++
34470 ++	u_int	md5_i;
34471 ++	u_int8_t	md5_buf[MD5_BUFLEN];
34472 ++} md5_ctxt;
34473 ++
34474 ++extern void md5_init(md5_ctxt *);
34475 ++extern void md5_loop(md5_ctxt *, u_int8_t *, u_int);
34476 ++extern void md5_pad(md5_ctxt *);
34477 ++extern void md5_result(u_int8_t *, md5_ctxt *);
34478 ++
34479 ++/* compatibility */
34480 ++#define MD5_CTX		md5_ctxt
34481 ++#define MD5Init(x)	md5_init((x))
34482 ++#define MD5Update(x, y, z)	md5_loop((x), (y), (z))
34483 ++#define MD5Final(x, y) \
34484 ++do {				\
34485 ++	md5_pad((y));		\
34486 ++	md5_result((x), (y));	\
34487 ++} while (0)
34488 ++
34489 ++#endif /* ! _NETINET6_MD5_H_*/
34490 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/safe.c linux-2.6.23.16/crypto/ocf/safe/safe.c
34491 +--- linux-2.6.23.16.old/crypto/ocf/safe/safe.c	1969-12-31 19:00:00.000000000 -0500
34492 ++++ linux-2.6.23.16/crypto/ocf/safe/safe.c	2008-02-26 09:29:13.000000000 -0500
34493 +@@ -0,0 +1,2288 @@
34494 ++/*-
34495 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
34496 ++ * Copyright (C) 2004-2007 David McCullough
34497 ++ * The license and original author are listed below.
34498 ++ *
34499 ++ * Copyright (c) 2003 Sam Leffler, Errno Consulting
34500 ++ * Copyright (c) 2003 Global Technology Associates, Inc.
34501 ++ * All rights reserved.
34502 ++ *
34503 ++ * Redistribution and use in source and binary forms, with or without
34504 ++ * modification, are permitted provided that the following conditions
34505 ++ * are met:
34506 ++ * 1. Redistributions of source code must retain the above copyright
34507 ++ *    notice, this list of conditions and the following disclaimer.
34508 ++ * 2. Redistributions in binary form must reproduce the above copyright
34509 ++ *    notice, this list of conditions and the following disclaimer in the
34510 ++ *    documentation and/or other materials provided with the distribution.
34511 ++ *
34512 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
34513 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34514 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34515 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34516 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34517 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34518 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34519 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34520 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34521 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34522 ++ * SUCH DAMAGE.
34523 ++ *
34524 ++__FBSDID("$FreeBSD: src/sys/dev/safe/safe.c,v 1.18 2007/03/21 03:42:50 sam Exp $");
34525 ++ */
34526 ++
34527 ++#ifndef AUTOCONF_INCLUDED
34528 ++#include <linux/config.h>
34529 ++#endif
34530 ++#include <linux/module.h>
34531 ++#include <linux/kernel.h>
34532 ++#include <linux/init.h>
34533 ++#include <linux/list.h>
34534 ++#include <linux/slab.h>
34535 ++#include <linux/wait.h>
34536 ++#include <linux/sched.h>
34537 ++#include <linux/pci.h>
34538 ++#include <linux/delay.h>
34539 ++#include <linux/interrupt.h>
34540 ++#include <linux/spinlock.h>
34541 ++#include <linux/random.h>
34542 ++#include <linux/version.h>
34543 ++#include <linux/skbuff.h>
34544 ++#include <asm/io.h>
34545 ++
34546 ++/*
34547 ++ * SafeNet SafeXcel-1141 hardware crypto accelerator
34548 ++ */
34549 ++
34550 ++#include <cryptodev.h>
34551 ++#include <uio.h>
34552 ++#include <safe/safereg.h>
34553 ++#include <safe/safevar.h>
34554 ++
34555 ++#if 1
34556 ++#define	DPRINTF(a)	do { \
34557 ++						if (debug) { \
34558 ++							printk("%s: ", sc ? \
34559 ++								device_get_nameunit(sc->sc_dev) : "safe"); \
34560 ++							printk a; \
34561 ++						} \
34562 ++					} while (0)
34563 ++#else
34564 ++#define	DPRINTF(a)
34565 ++#endif
34566 ++
34567 ++/*
34568 ++ * until we find a cleaner way, include the BSD md5/sha1 code
34569 ++ * here
34570 ++ */
34571 ++#define HMAC_HACK 1
34572 ++#ifdef HMAC_HACK
34573 ++#define LITTLE_ENDIAN 1234
34574 ++#define BIG_ENDIAN 4321
34575 ++#ifdef __LITTLE_ENDIAN
34576 ++#define BYTE_ORDER LITTLE_ENDIAN
34577 ++#endif
34578 ++#ifdef __BIG_ENDIAN
34579 ++#define BYTE_ORDER BIG_ENDIAN
34580 ++#endif
34581 ++#include <safe/md5.h>
34582 ++#include <safe/md5.c>
34583 ++#include <safe/sha1.h>
34584 ++#include <safe/sha1.c>
34585 ++
34586 ++u_int8_t hmac_ipad_buffer[64] = {
34587 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34588 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34589 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34590 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34591 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34592 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34593 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
34594 ++    0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
34595 ++};
34596 ++
34597 ++u_int8_t hmac_opad_buffer[64] = {
34598 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34599 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34600 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34601 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34602 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34603 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34604 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
34605 ++    0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
34606 ++};
34607 ++#endif /* HMAC_HACK */
34608 ++
34609 ++/* add proc entry for this */
34610 ++struct safe_stats safestats;
34611 ++
34612 ++#define debug safe_debug
34613 ++int safe_debug = 0;
34614 ++module_param(safe_debug, int, 0644);
34615 ++MODULE_PARM_DESC(safe_debug, "Enable debug");
34616 ++
34617 ++static	void safe_callback(struct safe_softc *, struct safe_ringentry *);
34618 ++static	void safe_feed(struct safe_softc *, struct safe_ringentry *);
34619 ++#if defined(CONFIG_OCF_RANDOMHARVEST) && !defined(SAFE_NO_RNG)
34620 ++static	void safe_rng_init(struct safe_softc *);
34621 ++int safe_rngbufsize = 8;		/* 32 bytes each read  */
34622 ++module_param(safe_rngbufsize, int, 0644);
34623 ++MODULE_PARM_DESC(safe_rngbufsize, "RNG polling buffer size (32-bit words)");
34624 ++int safe_rngmaxalarm = 8;		/* max alarms before reset */
34625 ++module_param(safe_rngmaxalarm, int, 0644);
34626 ++MODULE_PARM_DESC(safe_rngmaxalarm, "RNG max alarms before reset");
34627 ++#endif /* SAFE_NO_RNG */
34628 ++
34629 ++static void safe_totalreset(struct safe_softc *sc);
34630 ++static int safe_dmamap_aligned(struct safe_softc *sc, const struct safe_operand *op);
34631 ++static int safe_dmamap_uniform(struct safe_softc *sc, const struct safe_operand *op);
34632 ++static int safe_free_entry(struct safe_softc *sc, struct safe_ringentry *re);
34633 ++static int safe_kprocess(device_t dev, struct cryptkop *krp, int hint);
34634 ++static int safe_kstart(struct safe_softc *sc);
34635 ++static int safe_ksigbits(struct safe_softc *sc, struct crparam *cr);
34636 ++static void safe_kfeed(struct safe_softc *sc);
34637 ++static void safe_kpoll(unsigned long arg);
34638 ++static void safe_kload_reg(struct safe_softc *sc, u_int32_t off,
34639 ++								u_int32_t len, struct crparam *n);
34640 ++
34641 ++static	int safe_newsession(device_t, u_int32_t *, struct cryptoini *);
34642 ++static	int safe_freesession(device_t, u_int64_t);
34643 ++static	int safe_process(device_t, struct cryptop *, int);
34644 ++
34645 ++static device_method_t safe_methods = {
34646 ++	/* crypto device methods */
34647 ++	DEVMETHOD(cryptodev_newsession,	safe_newsession),
34648 ++	DEVMETHOD(cryptodev_freesession,safe_freesession),
34649 ++	DEVMETHOD(cryptodev_process,	safe_process),
34650 ++	DEVMETHOD(cryptodev_kprocess,	safe_kprocess),
34651 ++};
34652 ++
34653 ++#define	READ_REG(sc,r)			readl((sc)->sc_base_addr + (r))
34654 ++#define WRITE_REG(sc,r,val)		writel((val), (sc)->sc_base_addr + (r))
34655 ++
34656 ++#define SAFE_MAX_CHIPS 8
34657 ++static struct safe_softc *safe_chip_idx[SAFE_MAX_CHIPS];
34658 ++
34659 ++/*
34660 ++ * split our buffers up into safe DMAable byte fragments to avoid lockup
34661 ++ * bug in 1141 HW on rev 1.0.
34662 ++ */
34663 ++
34664 ++static int
34665 ++pci_map_linear(
34666 ++	struct safe_softc *sc,
34667 ++	struct safe_operand *buf,
34668 ++	void *addr,
34669 ++	int len)
34670 ++{
34671 ++	dma_addr_t tmp;
34672 ++	int chunk, tlen = len;
34673 ++
34674 ++	tmp = pci_map_single(sc->sc_pcidev, addr, len, PCI_DMA_BIDIRECTIONAL);
34675 ++
34676 ++	buf->mapsize += len;
34677 ++	while (len > 0) {
34678 ++		chunk = (len > sc->sc_max_dsize) ? sc->sc_max_dsize : len;
34679 ++		buf->segs[buf->nsegs].ds_addr = tmp;
34680 ++		buf->segs[buf->nsegs].ds_len  = chunk;
34681 ++		buf->segs[buf->nsegs].ds_tlen = tlen;
34682 ++		buf->nsegs++;
34683 ++		tmp  += chunk;
34684 ++		len  -= chunk;
34685 ++		tlen = 0;
34686 ++	}
34687 ++	return 0;
34688 ++}
34689 ++
34690 ++/*
34691 ++ * map in a given uio buffer (great on some arches :-)
34692 ++ */
34693 ++
34694 ++static int
34695 ++pci_map_uio(struct safe_softc *sc, struct safe_operand *buf, struct uio *uio)
34696 ++{
34697 ++	struct iovec *iov = uio->uio_iov;
34698 ++	int n;
34699 ++
34700 ++	DPRINTF(("%s()\n", __FUNCTION__));
34701 ++
34702 ++	buf->mapsize = 0;
34703 ++	buf->nsegs = 0;
34704 ++
34705 ++	for (n = 0; n < uio->uio_iovcnt; n++) {
34706 ++		pci_map_linear(sc, buf, iov->iov_base, iov->iov_len);
34707 ++		iov++;
34708 ++	}
34709 ++
34710 ++	/* identify this buffer by the first segment */
34711 ++	buf->map = (void *) buf->segs[0].ds_addr;
34712 ++	return(0);
34713 ++}
34714 ++
34715 ++/*
34716 ++ * map in a given sk_buff
34717 ++ */
34718 ++
34719 ++static int
34720 ++pci_map_skb(struct safe_softc *sc,struct safe_operand *buf,struct sk_buff *skb)
34721 ++{
34722 ++	int i;
34723 ++
34724 ++	DPRINTF(("%s()\n", __FUNCTION__));
34725 ++
34726 ++	buf->mapsize = 0;
34727 ++	buf->nsegs = 0;
34728 ++
34729 ++	pci_map_linear(sc, buf, skb->data, skb_headlen(skb));
34730 ++
34731 ++	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
34732 ++		pci_map_linear(sc, buf,
34733 ++				page_address(skb_shinfo(skb)->frags[i].page) +
34734 ++				                        skb_shinfo(skb)->frags[i].page_offset,
34735 ++				skb_shinfo(skb)->frags[i].size);
34736 ++	}
34737 ++
34738 ++	/* identify this buffer by the first segment */
34739 ++	buf->map = (void *) buf->segs[0].ds_addr;
34740 ++	return(0);
34741 ++}
34742 ++
34743 ++
34744 ++#if 0 /* not needed at this time */
34745 ++static void
34746 ++pci_sync_operand(struct safe_softc *sc, struct safe_operand *buf)
34747 ++{
34748 ++	int i;
34749 ++
34750 ++	DPRINTF(("%s()\n", __FUNCTION__));
34751 ++	for (i = 0; i < buf->nsegs; i++)
34752 ++		pci_dma_sync_single_for_cpu(sc->sc_pcidev, buf->segs[i].ds_addr,
34753 ++				buf->segs[i].ds_len, PCI_DMA_BIDIRECTIONAL);
34754 ++}
34755 ++#endif
34756 ++
34757 ++static void
34758 ++pci_unmap_operand(struct safe_softc *sc, struct safe_operand *buf)
34759 ++{
34760 ++	int i;
34761 ++	DPRINTF(("%s()\n", __FUNCTION__));
34762 ++	for (i = 0; i < buf->nsegs; i++) {
34763 ++		if (buf->segs[i].ds_tlen) {
34764 ++			DPRINTF(("%s - unmap %d 0x%x %d\n", __FUNCTION__, i, buf->segs[i].ds_addr, buf->segs[i].ds_tlen));
34765 ++			pci_unmap_single(sc->sc_pcidev, buf->segs[i].ds_addr,
34766 ++					buf->segs[i].ds_tlen, PCI_DMA_BIDIRECTIONAL);
34767 ++			DPRINTF(("%s - unmap %d 0x%x %d done\n", __FUNCTION__, i, buf->segs[i].ds_addr, buf->segs[i].ds_tlen));
34768 ++		}
34769 ++		buf->segs[i].ds_addr = 0;
34770 ++		buf->segs[i].ds_len = 0;
34771 ++		buf->segs[i].ds_tlen = 0;
34772 ++	}
34773 ++	buf->nsegs = 0;
34774 ++	buf->mapsize = 0;
34775 ++	buf->map = 0;
34776 ++}
34777 ++
34778 ++
34779 ++/*
34780 ++ * SafeXcel Interrupt routine
34781 ++ */
34782 ++static irqreturn_t
34783 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
34784 ++safe_intr(int irq, void *arg)
34785 ++#else
34786 ++safe_intr(int irq, void *arg, struct pt_regs *regs)
34787 ++#endif
34788 ++{
34789 ++	struct safe_softc *sc = arg;
34790 ++	int stat;
34791 ++	unsigned long flags;
34792 ++
34793 ++	stat = READ_REG(sc, SAFE_HM_STAT);
34794 ++
34795 ++	DPRINTF(("%s(stat=0x%x)\n", __FUNCTION__, stat));
34796 ++
34797 ++	if (stat == 0)		/* shared irq, not for us */
34798 ++		return IRQ_NONE;
34799 ++
34800 ++	WRITE_REG(sc, SAFE_HI_CLR, stat);	/* IACK */
34801 ++
34802 ++	if ((stat & SAFE_INT_PE_DDONE)) {
34803 ++		/*
34804 ++		 * Descriptor(s) done; scan the ring and
34805 ++		 * process completed operations.
34806 ++		 */
34807 ++		spin_lock_irqsave(&sc->sc_ringmtx, flags);
34808 ++		while (sc->sc_back != sc->sc_front) {
34809 ++			struct safe_ringentry *re = sc->sc_back;
34810 ++
34811 ++#ifdef SAFE_DEBUG
34812 ++			if (debug) {
34813 ++				safe_dump_ringstate(sc, __func__);
34814 ++				safe_dump_request(sc, __func__, re);
34815 ++			}
34816 ++#endif
34817 ++			/*
34818 ++			 * safe_process marks ring entries that were allocated
34819 ++			 * but not used with a csr of zero.  This insures the
34820 ++			 * ring front pointer never needs to be set backwards
34821 ++			 * in the event that an entry is allocated but not used
34822 ++			 * because of a setup error.
34823 ++			 */
34824 ++			DPRINTF(("%s re->re_desc.d_csr=0x%x\n", __FUNCTION__, re->re_desc.d_csr));
34825 ++			if (re->re_desc.d_csr != 0) {
34826 ++				if (!SAFE_PE_CSR_IS_DONE(re->re_desc.d_csr)) {
34827 ++					DPRINTF(("%s !CSR_IS_DONE\n", __FUNCTION__));
34828 ++					break;
34829 ++				}
34830 ++				if (!SAFE_PE_LEN_IS_DONE(re->re_desc.d_len)) {
34831 ++					DPRINTF(("%s !LEN_IS_DONE\n", __FUNCTION__));
34832 ++					break;
34833 ++				}
34834 ++				sc->sc_nqchip--;
34835 ++				safe_callback(sc, re);
34836 ++			}
34837 ++			if (++(sc->sc_back) == sc->sc_ringtop)
34838 ++				sc->sc_back = sc->sc_ring;
34839 ++		}
34840 ++		spin_unlock_irqrestore(&sc->sc_ringmtx, flags);
34841 ++	}
34842 ++
34843 ++	/*
34844 ++	 * Check to see if we got any DMA Error
34845 ++	 */
34846 ++	if (stat & SAFE_INT_PE_ERROR) {
34847 ++		printk("%s: dmaerr dmastat %08x\n", device_get_nameunit(sc->sc_dev),
34848 ++				(int)READ_REG(sc, SAFE_PE_DMASTAT));
34849 ++		safestats.st_dmaerr++;
34850 ++		safe_totalreset(sc);
34851 ++#if 0
34852 ++		safe_feed(sc);
34853 ++#endif
34854 ++	}
34855 ++
34856 ++	if (sc->sc_needwakeup) {		/* XXX check high watermark */
34857 ++		int wakeup = sc->sc_needwakeup & (CRYPTO_SYMQ|CRYPTO_ASYMQ);
34858 ++		DPRINTF(("%s: wakeup crypto %x\n", __func__,
34859 ++			sc->sc_needwakeup));
34860 ++		sc->sc_needwakeup &= ~wakeup;
34861 ++		crypto_unblock(sc->sc_cid, wakeup);
34862 ++	}
34863 ++	
34864 ++	return IRQ_HANDLED;
34865 ++}
34866 ++
34867 ++/*
34868 ++ * safe_feed() - post a request to chip
34869 ++ */
34870 ++static void
34871 ++safe_feed(struct safe_softc *sc, struct safe_ringentry *re)
34872 ++{
34873 ++	DPRINTF(("%s()\n", __FUNCTION__));
34874 ++#ifdef SAFE_DEBUG
34875 ++	if (debug) {
34876 ++		safe_dump_ringstate(sc, __func__);
34877 ++		safe_dump_request(sc, __func__, re);
34878 ++	}
34879 ++#endif
34880 ++	sc->sc_nqchip++;
34881 ++	if (sc->sc_nqchip > safestats.st_maxqchip)
34882 ++		safestats.st_maxqchip = sc->sc_nqchip;
34883 ++	/* poke h/w to check descriptor ring, any value can be written */
34884 ++	WRITE_REG(sc, SAFE_HI_RD_DESCR, 0);
34885 ++}
34886 ++
34887 ++#define	N(a)	(sizeof(a) / sizeof (a[0]))
34888 ++static void
34889 ++safe_setup_enckey(struct safe_session *ses, caddr_t key)
34890 ++{
34891 ++	int i;
34892 ++
34893 ++	bcopy(key, ses->ses_key, ses->ses_klen / 8);
34894 ++
34895 ++	/* PE is little-endian, insure proper byte order */
34896 ++	for (i = 0; i < N(ses->ses_key); i++)
34897 ++		ses->ses_key[i] = htole32(ses->ses_key[i]);
34898 ++}
34899 ++
34900 ++static void
34901 ++safe_setup_mackey(struct safe_session *ses, int algo, caddr_t key, int klen)
34902 ++{
34903 ++#ifdef HMAC_HACK
34904 ++	MD5_CTX md5ctx;
34905 ++	SHA1_CTX sha1ctx;
34906 ++	int i;
34907 ++
34908 ++
34909 ++	for (i = 0; i < klen; i++)
34910 ++		key[i] ^= HMAC_IPAD_VAL;
34911 ++
34912 ++	if (algo == CRYPTO_MD5_HMAC) {
34913 ++		MD5Init(&md5ctx);
34914 ++		MD5Update(&md5ctx, key, klen);
34915 ++		MD5Update(&md5ctx, hmac_ipad_buffer, MD5_HMAC_BLOCK_LEN - klen);
34916 ++		bcopy(md5ctx.md5_st8, ses->ses_hminner, sizeof(md5ctx.md5_st8));
34917 ++	} else {
34918 ++		SHA1Init(&sha1ctx);
34919 ++		SHA1Update(&sha1ctx, key, klen);
34920 ++		SHA1Update(&sha1ctx, hmac_ipad_buffer,
34921 ++		    SHA1_HMAC_BLOCK_LEN - klen);
34922 ++		bcopy(sha1ctx.h.b32, ses->ses_hminner, sizeof(sha1ctx.h.b32));
34923 ++	}
34924 ++
34925 ++	for (i = 0; i < klen; i++)
34926 ++		key[i] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL);
34927 ++
34928 ++	if (algo == CRYPTO_MD5_HMAC) {
34929 ++		MD5Init(&md5ctx);
34930 ++		MD5Update(&md5ctx, key, klen);
34931 ++		MD5Update(&md5ctx, hmac_opad_buffer, MD5_HMAC_BLOCK_LEN - klen);
34932 ++		bcopy(md5ctx.md5_st8, ses->ses_hmouter, sizeof(md5ctx.md5_st8));
34933 ++	} else {
34934 ++		SHA1Init(&sha1ctx);
34935 ++		SHA1Update(&sha1ctx, key, klen);
34936 ++		SHA1Update(&sha1ctx, hmac_opad_buffer,
34937 ++		    SHA1_HMAC_BLOCK_LEN - klen);
34938 ++		bcopy(sha1ctx.h.b32, ses->ses_hmouter, sizeof(sha1ctx.h.b32));
34939 ++	}
34940 ++
34941 ++	for (i = 0; i < klen; i++)
34942 ++		key[i] ^= HMAC_OPAD_VAL;
34943 ++
34944 ++#if 0
34945 ++	/*
34946 ++	 * this code prevents SHA working on a BE host,
34947 ++	 * so it is obviously wrong.  I think the byte
34948 ++	 * swap setup we do with the chip fixes this for us
34949 ++	 */
34950 ++
34951 ++	/* PE is little-endian, insure proper byte order */
34952 ++	for (i = 0; i < N(ses->ses_hminner); i++) {
34953 ++		ses->ses_hminner[i] = htole32(ses->ses_hminner[i]);
34954 ++		ses->ses_hmouter[i] = htole32(ses->ses_hmouter[i]);
34955 ++	}
34956 ++#endif
34957 ++#else /* HMAC_HACK */
34958 ++	printk("safe: md5/sha not implemented\n");
34959 ++#endif /* HMAC_HACK */
34960 ++}
34961 ++#undef N
34962 ++
34963 ++/*
34964 ++ * Allocate a new 'session' and return an encoded session id.  'sidp'
34965 ++ * contains our registration id, and should contain an encoded session
34966 ++ * id on successful allocation.
34967 ++ */
34968 ++static int
34969 ++safe_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
34970 ++{
34971 ++	struct safe_softc *sc = device_get_softc(dev);
34972 ++	struct cryptoini *c, *encini = NULL, *macini = NULL;
34973 ++	struct safe_session *ses = NULL;
34974 ++	int sesn;
34975 ++
34976 ++	DPRINTF(("%s()\n", __FUNCTION__));
34977 ++
34978 ++	if (sidp == NULL || cri == NULL || sc == NULL)
34979 ++		return (EINVAL);
34980 ++
34981 ++	for (c = cri; c != NULL; c = c->cri_next) {
34982 ++		if (c->cri_alg == CRYPTO_MD5_HMAC ||
34983 ++		    c->cri_alg == CRYPTO_SHA1_HMAC ||
34984 ++		    c->cri_alg == CRYPTO_NULL_HMAC) {
34985 ++			if (macini)
34986 ++				return (EINVAL);
34987 ++			macini = c;
34988 ++		} else if (c->cri_alg == CRYPTO_DES_CBC ||
34989 ++		    c->cri_alg == CRYPTO_3DES_CBC ||
34990 ++		    c->cri_alg == CRYPTO_AES_CBC ||
34991 ++		    c->cri_alg == CRYPTO_NULL_CBC) {
34992 ++			if (encini)
34993 ++				return (EINVAL);
34994 ++			encini = c;
34995 ++		} else
34996 ++			return (EINVAL);
34997 ++	}
34998 ++	if (encini == NULL && macini == NULL)
34999 ++		return (EINVAL);
35000 ++	if (encini) {			/* validate key length */
35001 ++		switch (encini->cri_alg) {
35002 ++		case CRYPTO_DES_CBC:
35003 ++			if (encini->cri_klen != 64)
35004 ++				return (EINVAL);
35005 ++			break;
35006 ++		case CRYPTO_3DES_CBC:
35007 ++			if (encini->cri_klen != 192)
35008 ++				return (EINVAL);
35009 ++			break;
35010 ++		case CRYPTO_AES_CBC:
35011 ++			if (encini->cri_klen != 128 &&
35012 ++			    encini->cri_klen != 192 &&
35013 ++			    encini->cri_klen != 256)
35014 ++				return (EINVAL);
35015 ++			break;
35016 ++		}
35017 ++	}
35018 ++
35019 ++	if (sc->sc_sessions == NULL) {
35020 ++		ses = sc->sc_sessions = (struct safe_session *)
35021 ++			kmalloc(sizeof(struct safe_session), SLAB_ATOMIC);
35022 ++		if (ses == NULL)
35023 ++			return (ENOMEM);
35024 ++		memset(ses, 0, sizeof(struct safe_session));
35025 ++		sesn = 0;
35026 ++		sc->sc_nsessions = 1;
35027 ++	} else {
35028 ++		for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
35029 ++			if (sc->sc_sessions[sesn].ses_used == 0) {
35030 ++				ses = &sc->sc_sessions[sesn];
35031 ++				break;
35032 ++			}
35033 ++		}
35034 ++
35035 ++		if (ses == NULL) {
35036 ++			sesn = sc->sc_nsessions;
35037 ++			ses = (struct safe_session *)
35038 ++				kmalloc((sesn + 1) * sizeof(struct safe_session), SLAB_ATOMIC);
35039 ++			if (ses == NULL)
35040 ++				return (ENOMEM);
35041 ++			memset(ses, 0, (sesn + 1) * sizeof(struct safe_session));
35042 ++			bcopy(sc->sc_sessions, ses, sesn *
35043 ++			    sizeof(struct safe_session));
35044 ++			bzero(sc->sc_sessions, sesn *
35045 ++			    sizeof(struct safe_session));
35046 ++			kfree(sc->sc_sessions);
35047 ++			sc->sc_sessions = ses;
35048 ++			ses = &sc->sc_sessions[sesn];
35049 ++			sc->sc_nsessions++;
35050 ++		}
35051 ++	}
35052 ++
35053 ++	bzero(ses, sizeof(struct safe_session));
35054 ++	ses->ses_used = 1;
35055 ++
35056 ++	if (encini) {
35057 ++		/* get an IV */
35058 ++		/* XXX may read fewer than requested */
35059 ++		read_random(ses->ses_iv, sizeof(ses->ses_iv));
35060 ++
35061 ++		ses->ses_klen = encini->cri_klen;
35062 ++		if (encini->cri_key != NULL)
35063 ++			safe_setup_enckey(ses, encini->cri_key);
35064 ++	}
35065 ++
35066 ++	if (macini) {
35067 ++		ses->ses_mlen = macini->cri_mlen;
35068 ++		if (ses->ses_mlen == 0) {
35069 ++			if (macini->cri_alg == CRYPTO_MD5_HMAC)
35070 ++				ses->ses_mlen = MD5_HASH_LEN;
35071 ++			else
35072 ++				ses->ses_mlen = SHA1_HASH_LEN;
35073 ++		}
35074 ++
35075 ++		if (macini->cri_key != NULL) {
35076 ++			safe_setup_mackey(ses, macini->cri_alg, macini->cri_key,
35077 ++			    macini->cri_klen / 8);
35078 ++		}
35079 ++	}
35080 ++
35081 ++	*sidp = SAFE_SID(device_get_unit(sc->sc_dev), sesn);
35082 ++	return (0);
35083 ++}
35084 ++
35085 ++/*
35086 ++ * Deallocate a session.
35087 ++ */
35088 ++static int
35089 ++safe_freesession(device_t dev, u_int64_t tid)
35090 ++{
35091 ++	struct safe_softc *sc = device_get_softc(dev);
35092 ++	int session, ret;
35093 ++	u_int32_t sid = ((u_int32_t) tid) & 0xffffffff;
35094 ++
35095 ++	DPRINTF(("%s()\n", __FUNCTION__));
35096 ++
35097 ++	if (sc == NULL)
35098 ++		return (EINVAL);
35099 ++
35100 ++	session = SAFE_SESSION(sid);
35101 ++	if (session < sc->sc_nsessions) {
35102 ++		bzero(&sc->sc_sessions[session], sizeof(sc->sc_sessions[session]));
35103 ++		ret = 0;
35104 ++	} else
35105 ++		ret = EINVAL;
35106 ++	return (ret);
35107 ++}
35108 ++
35109 ++
35110 ++static int
35111 ++safe_process(device_t dev, struct cryptop *crp, int hint)
35112 ++{
35113 ++	struct safe_softc *sc = device_get_softc(dev);
35114 ++	int err = 0, i, nicealign, uniform;
35115 ++	struct cryptodesc *crd1, *crd2, *maccrd, *enccrd;
35116 ++	int bypass, oplen, ivsize;
35117 ++	caddr_t iv;
35118 ++	int16_t coffset;
35119 ++	struct safe_session *ses;
35120 ++	struct safe_ringentry *re;
35121 ++	struct safe_sarec *sa;
35122 ++	struct safe_pdesc *pd;
35123 ++	u_int32_t cmd0, cmd1, staterec;
35124 ++	unsigned long flags;
35125 ++
35126 ++	DPRINTF(("%s()\n", __FUNCTION__));
35127 ++
35128 ++	if (crp == NULL || crp->crp_callback == NULL || sc == NULL) {
35129 ++		safestats.st_invalid++;
35130 ++		return (EINVAL);
35131 ++	}
35132 ++	if (SAFE_SESSION(crp->crp_sid) >= sc->sc_nsessions) {
35133 ++		safestats.st_badsession++;
35134 ++		return (EINVAL);
35135 ++	}
35136 ++
35137 ++	spin_lock_irqsave(&sc->sc_ringmtx, flags);
35138 ++	if (sc->sc_front == sc->sc_back && sc->sc_nqchip != 0) {
35139 ++		safestats.st_ringfull++;
35140 ++		sc->sc_needwakeup |= CRYPTO_SYMQ;
35141 ++		spin_unlock_irqrestore(&sc->sc_ringmtx, flags);
35142 ++		return (ERESTART);
35143 ++	}
35144 ++	re = sc->sc_front;
35145 ++
35146 ++	staterec = re->re_sa.sa_staterec;	/* save */
35147 ++	/* NB: zero everything but the PE descriptor */
35148 ++	bzero(&re->re_sa, sizeof(struct safe_ringentry) - sizeof(re->re_desc));
35149 ++	re->re_sa.sa_staterec = staterec;	/* restore */
35150 ++
35151 ++	re->re_crp = crp;
35152 ++	re->re_sesn = SAFE_SESSION(crp->crp_sid);
35153 ++
35154 ++	re->re_src.nsegs = 0;
35155 ++	re->re_dst.nsegs = 0;
35156 ++
35157 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
35158 ++		re->re_src_skb = (struct sk_buff *)crp->crp_buf;
35159 ++		re->re_dst_skb = (struct sk_buff *)crp->crp_buf;
35160 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
35161 ++		re->re_src_io = (struct uio *)crp->crp_buf;
35162 ++		re->re_dst_io = (struct uio *)crp->crp_buf;
35163 ++	} else {
35164 ++		safestats.st_badflags++;
35165 ++		err = EINVAL;
35166 ++		goto errout;	/* XXX we don't handle contiguous blocks! */
35167 ++	}
35168 ++
35169 ++	sa = &re->re_sa;
35170 ++	ses = &sc->sc_sessions[re->re_sesn];
35171 ++
35172 ++	crd1 = crp->crp_desc;
35173 ++	if (crd1 == NULL) {
35174 ++		safestats.st_nodesc++;
35175 ++		err = EINVAL;
35176 ++		goto errout;
35177 ++	}
35178 ++	crd2 = crd1->crd_next;
35179 ++
35180 ++	cmd0 = SAFE_SA_CMD0_BASIC;		/* basic group operation */
35181 ++	cmd1 = 0;
35182 ++	if (crd2 == NULL) {
35183 ++		if (crd1->crd_alg == CRYPTO_MD5_HMAC ||
35184 ++		    crd1->crd_alg == CRYPTO_SHA1_HMAC ||
35185 ++		    crd1->crd_alg == CRYPTO_NULL_HMAC) {
35186 ++			maccrd = crd1;
35187 ++			enccrd = NULL;
35188 ++			cmd0 |= SAFE_SA_CMD0_OP_HASH;
35189 ++		} else if (crd1->crd_alg == CRYPTO_DES_CBC ||
35190 ++		    crd1->crd_alg == CRYPTO_3DES_CBC ||
35191 ++		    crd1->crd_alg == CRYPTO_AES_CBC ||
35192 ++		    crd1->crd_alg == CRYPTO_NULL_CBC) {
35193 ++			maccrd = NULL;
35194 ++			enccrd = crd1;
35195 ++			cmd0 |= SAFE_SA_CMD0_OP_CRYPT;
35196 ++		} else {
35197 ++			safestats.st_badalg++;
35198 ++			err = EINVAL;
35199 ++			goto errout;
35200 ++		}
35201 ++	} else {
35202 ++		if ((crd1->crd_alg == CRYPTO_MD5_HMAC ||
35203 ++		    crd1->crd_alg == CRYPTO_SHA1_HMAC ||
35204 ++		    crd1->crd_alg == CRYPTO_NULL_HMAC) &&
35205 ++		    (crd2->crd_alg == CRYPTO_DES_CBC ||
35206 ++			crd2->crd_alg == CRYPTO_3DES_CBC ||
35207 ++		        crd2->crd_alg == CRYPTO_AES_CBC ||
35208 ++		        crd2->crd_alg == CRYPTO_NULL_CBC) &&
35209 ++		    ((crd2->crd_flags & CRD_F_ENCRYPT) == 0)) {
35210 ++			maccrd = crd1;
35211 ++			enccrd = crd2;
35212 ++		} else if ((crd1->crd_alg == CRYPTO_DES_CBC ||
35213 ++		    crd1->crd_alg == CRYPTO_3DES_CBC ||
35214 ++		    crd1->crd_alg == CRYPTO_AES_CBC ||
35215 ++		    crd1->crd_alg == CRYPTO_NULL_CBC) &&
35216 ++		    (crd2->crd_alg == CRYPTO_MD5_HMAC ||
35217 ++			crd2->crd_alg == CRYPTO_SHA1_HMAC ||
35218 ++			crd2->crd_alg == CRYPTO_NULL_HMAC) &&
35219 ++		    (crd1->crd_flags & CRD_F_ENCRYPT)) {
35220 ++			enccrd = crd1;
35221 ++			maccrd = crd2;
35222 ++		} else {
35223 ++			safestats.st_badalg++;
35224 ++			err = EINVAL;
35225 ++			goto errout;
35226 ++		}
35227 ++		cmd0 |= SAFE_SA_CMD0_OP_BOTH;
35228 ++	}
35229 ++
35230 ++	if (enccrd) {
35231 ++		if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT)
35232 ++			safe_setup_enckey(ses, enccrd->crd_key);
35233 ++
35234 ++		if (enccrd->crd_alg == CRYPTO_DES_CBC) {
35235 ++			cmd0 |= SAFE_SA_CMD0_DES;
35236 ++			cmd1 |= SAFE_SA_CMD1_CBC;
35237 ++			ivsize = 2*sizeof(u_int32_t);
35238 ++		} else if (enccrd->crd_alg == CRYPTO_3DES_CBC) {
35239 ++			cmd0 |= SAFE_SA_CMD0_3DES;
35240 ++			cmd1 |= SAFE_SA_CMD1_CBC;
35241 ++			ivsize = 2*sizeof(u_int32_t);
35242 ++		} else if (enccrd->crd_alg == CRYPTO_AES_CBC) {
35243 ++			cmd0 |= SAFE_SA_CMD0_AES;
35244 ++			cmd1 |= SAFE_SA_CMD1_CBC;
35245 ++			if (ses->ses_klen == 128)
35246 ++			     cmd1 |=  SAFE_SA_CMD1_AES128;
35247 ++			else if (ses->ses_klen == 192)
35248 ++			     cmd1 |=  SAFE_SA_CMD1_AES192;
35249 ++			else
35250 ++			     cmd1 |=  SAFE_SA_CMD1_AES256;
35251 ++			ivsize = 4*sizeof(u_int32_t);
35252 ++		} else {
35253 ++			cmd0 |= SAFE_SA_CMD0_CRYPT_NULL;
35254 ++			ivsize = 0;
35255 ++		}
35256 ++
35257 ++		/*
35258 ++		 * Setup encrypt/decrypt state.  When using basic ops
35259 ++		 * we can't use an inline IV because hash/crypt offset
35260 ++		 * must be from the end of the IV to the start of the
35261 ++		 * crypt data and this leaves out the preceding header
35262 ++		 * from the hash calculation.  Instead we place the IV
35263 ++		 * in the state record and set the hash/crypt offset to
35264 ++		 * copy both the header+IV.
35265 ++		 */
35266 ++		if (enccrd->crd_flags & CRD_F_ENCRYPT) {
35267 ++			cmd0 |= SAFE_SA_CMD0_OUTBOUND;
35268 ++
35269 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
35270 ++				iv = enccrd->crd_iv;
35271 ++			else
35272 ++				iv = (caddr_t) ses->ses_iv;
35273 ++			if ((enccrd->crd_flags & CRD_F_IV_PRESENT) == 0) {
35274 ++				crypto_copyback(crp->crp_flags, crp->crp_buf,
35275 ++				    enccrd->crd_inject, ivsize, iv);
35276 ++			}
35277 ++			bcopy(iv, re->re_sastate.sa_saved_iv, ivsize);
35278 ++			/* make iv LE */
35279 ++			for (i = 0; i < ivsize/sizeof(re->re_sastate.sa_saved_iv[0]); i++)
35280 ++				re->re_sastate.sa_saved_iv[i] =
35281 ++					cpu_to_le32(re->re_sastate.sa_saved_iv[i]);
35282 ++			cmd0 |= SAFE_SA_CMD0_IVLD_STATE | SAFE_SA_CMD0_SAVEIV;
35283 ++			re->re_flags |= SAFE_QFLAGS_COPYOUTIV;
35284 ++		} else {
35285 ++			cmd0 |= SAFE_SA_CMD0_INBOUND;
35286 ++
35287 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT) {
35288 ++				bcopy(enccrd->crd_iv,
35289 ++					re->re_sastate.sa_saved_iv, ivsize);
35290 ++			} else {
35291 ++				crypto_copydata(crp->crp_flags, crp->crp_buf,
35292 ++				    enccrd->crd_inject, ivsize,
35293 ++				    (caddr_t)re->re_sastate.sa_saved_iv);
35294 ++			}
35295 ++			/* make iv LE */
35296 ++			for (i = 0; i < ivsize/sizeof(re->re_sastate.sa_saved_iv[0]); i++)
35297 ++				re->re_sastate.sa_saved_iv[i] =
35298 ++					cpu_to_le32(re->re_sastate.sa_saved_iv[i]);
35299 ++			cmd0 |= SAFE_SA_CMD0_IVLD_STATE;
35300 ++		}
35301 ++		/*
35302 ++		 * For basic encryption use the zero pad algorithm.
35303 ++		 * This pads results to an 8-byte boundary and
35304 ++		 * suppresses padding verification for inbound (i.e.
35305 ++		 * decrypt) operations.
35306 ++		 *
35307 ++		 * NB: Not sure if the 8-byte pad boundary is a problem.
35308 ++		 */
35309 ++		cmd0 |= SAFE_SA_CMD0_PAD_ZERO;
35310 ++
35311 ++		/* XXX assert key bufs have the same size */
35312 ++		bcopy(ses->ses_key, sa->sa_key, sizeof(sa->sa_key));
35313 ++	}
35314 ++
35315 ++	if (maccrd) {
35316 ++		if (maccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
35317 ++			safe_setup_mackey(ses, maccrd->crd_alg,
35318 ++			    maccrd->crd_key, maccrd->crd_klen / 8);
35319 ++		}
35320 ++
35321 ++		if (maccrd->crd_alg == CRYPTO_MD5_HMAC) {
35322 ++			cmd0 |= SAFE_SA_CMD0_MD5;
35323 ++			cmd1 |= SAFE_SA_CMD1_HMAC;	/* NB: enable HMAC */
35324 ++		} else if (maccrd->crd_alg == CRYPTO_SHA1_HMAC) {
35325 ++			cmd0 |= SAFE_SA_CMD0_SHA1;
35326 ++			cmd1 |= SAFE_SA_CMD1_HMAC;	/* NB: enable HMAC */
35327 ++		} else {
35328 ++			cmd0 |= SAFE_SA_CMD0_HASH_NULL;
35329 ++		}
35330 ++		/*
35331 ++		 * Digest data is loaded from the SA and the hash
35332 ++		 * result is saved to the state block where we
35333 ++		 * retrieve it for return to the caller.
35334 ++		 */
35335 ++		/* XXX assert digest bufs have the same size */
35336 ++		bcopy(ses->ses_hminner, sa->sa_indigest,
35337 ++			sizeof(sa->sa_indigest));
35338 ++		bcopy(ses->ses_hmouter, sa->sa_outdigest,
35339 ++			sizeof(sa->sa_outdigest));
35340 ++
35341 ++		cmd0 |= SAFE_SA_CMD0_HSLD_SA | SAFE_SA_CMD0_SAVEHASH;
35342 ++		re->re_flags |= SAFE_QFLAGS_COPYOUTICV;
35343 ++	}
35344 ++
35345 ++	if (enccrd && maccrd) {
35346 ++		/*
35347 ++		 * The offset from hash data to the start of
35348 ++		 * crypt data is the difference in the skips.
35349 ++		 */
35350 ++		bypass = maccrd->crd_skip;
35351 ++		coffset = enccrd->crd_skip - maccrd->crd_skip;
35352 ++		if (coffset < 0) {
35353 ++			DPRINTF(("%s: hash does not precede crypt; "
35354 ++				"mac skip %u enc skip %u\n",
35355 ++				__func__, maccrd->crd_skip, enccrd->crd_skip));
35356 ++			safestats.st_skipmismatch++;
35357 ++			err = EINVAL;
35358 ++			goto errout;
35359 ++		}
35360 ++		oplen = enccrd->crd_skip + enccrd->crd_len;
35361 ++		if (maccrd->crd_skip + maccrd->crd_len != oplen) {
35362 ++			DPRINTF(("%s: hash amount %u != crypt amount %u\n",
35363 ++				__func__, maccrd->crd_skip + maccrd->crd_len,
35364 ++				oplen));
35365 ++			safestats.st_lenmismatch++;
35366 ++			err = EINVAL;
35367 ++			goto errout;
35368 ++		}
35369 ++#ifdef SAFE_DEBUG
35370 ++		if (debug) {
35371 ++			printf("mac: skip %d, len %d, inject %d\n",
35372 ++			    maccrd->crd_skip, maccrd->crd_len,
35373 ++			    maccrd->crd_inject);
35374 ++			printf("enc: skip %d, len %d, inject %d\n",
35375 ++			    enccrd->crd_skip, enccrd->crd_len,
35376 ++			    enccrd->crd_inject);
35377 ++			printf("bypass %d coffset %d oplen %d\n",
35378 ++				bypass, coffset, oplen);
35379 ++		}
35380 ++#endif
35381 ++		if (coffset & 3) {	/* offset must be 32-bit aligned */
35382 ++			DPRINTF(("%s: coffset %u misaligned\n",
35383 ++				__func__, coffset));
35384 ++			safestats.st_coffmisaligned++;
35385 ++			err = EINVAL;
35386 ++			goto errout;
35387 ++		}
35388 ++		coffset >>= 2;
35389 ++		if (coffset > 255) {	/* offset must be <256 dwords */
35390 ++			DPRINTF(("%s: coffset %u too big\n",
35391 ++				__func__, coffset));
35392 ++			safestats.st_cofftoobig++;
35393 ++			err = EINVAL;
35394 ++			goto errout;
35395 ++		}
35396 ++		/*
35397 ++		 * Tell the hardware to copy the header to the output.
35398 ++		 * The header is defined as the data from the end of
35399 ++		 * the bypass to the start of data to be encrypted. 
35400 ++		 * Typically this is the inline IV.  Note that you need
35401 ++		 * to do this even if src+dst are the same; it appears
35402 ++		 * that w/o this bit the crypted data is written
35403 ++		 * immediately after the bypass data.
35404 ++		 */
35405 ++		cmd1 |= SAFE_SA_CMD1_HDRCOPY;
35406 ++		/*
35407 ++		 * Disable IP header mutable bit handling.  This is
35408 ++		 * needed to get correct HMAC calculations.
35409 ++		 */
35410 ++		cmd1 |= SAFE_SA_CMD1_MUTABLE;
35411 ++	} else {
35412 ++		if (enccrd) {
35413 ++			bypass = enccrd->crd_skip;
35414 ++			oplen = bypass + enccrd->crd_len;
35415 ++		} else {
35416 ++			bypass = maccrd->crd_skip;
35417 ++			oplen = bypass + maccrd->crd_len;
35418 ++		}
35419 ++		coffset = 0;
35420 ++	}
35421 ++	/* XXX verify multiple of 4 when using s/g */
35422 ++	if (bypass > 96) {		/* bypass offset must be <= 96 bytes */
35423 ++		DPRINTF(("%s: bypass %u too big\n", __func__, bypass));
35424 ++		safestats.st_bypasstoobig++;
35425 ++		err = EINVAL;
35426 ++		goto errout;
35427 ++	}
35428 ++
35429 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
35430 ++		if (pci_map_skb(sc, &re->re_src, re->re_src_skb)) {
35431 ++			safestats.st_noload++;
35432 ++			err = ENOMEM;
35433 ++			goto errout;
35434 ++		}
35435 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
35436 ++		if (pci_map_uio(sc, &re->re_src, re->re_src_io)) {
35437 ++			safestats.st_noload++;
35438 ++			err = ENOMEM;
35439 ++			goto errout;
35440 ++		}
35441 ++	}
35442 ++	nicealign = safe_dmamap_aligned(sc, &re->re_src);
35443 ++	uniform = safe_dmamap_uniform(sc, &re->re_src);
35444 ++
35445 ++	DPRINTF(("src nicealign %u uniform %u nsegs %u\n",
35446 ++		nicealign, uniform, re->re_src.nsegs));
35447 ++	if (re->re_src.nsegs > 1) {
35448 ++		re->re_desc.d_src = sc->sc_spalloc.dma_paddr +
35449 ++			((caddr_t) sc->sc_spfree - (caddr_t) sc->sc_spring);
35450 ++		for (i = 0; i < re->re_src_nsegs; i++) {
35451 ++			/* NB: no need to check if there's space */
35452 ++			pd = sc->sc_spfree;
35453 ++			if (++(sc->sc_spfree) == sc->sc_springtop)
35454 ++				sc->sc_spfree = sc->sc_spring;
35455 ++
35456 ++			KASSERT((pd->pd_flags&3) == 0 ||
35457 ++				(pd->pd_flags&3) == SAFE_PD_DONE,
35458 ++				("bogus source particle descriptor; flags %x",
35459 ++				pd->pd_flags));
35460 ++			pd->pd_addr = re->re_src_segs[i].ds_addr;
35461 ++			pd->pd_size = re->re_src_segs[i].ds_len;
35462 ++			pd->pd_flags = SAFE_PD_READY;
35463 ++		}
35464 ++		cmd0 |= SAFE_SA_CMD0_IGATHER;
35465 ++	} else {
35466 ++		/*
35467 ++		 * No need for gather, reference the operand directly.
35468 ++		 */
35469 ++		re->re_desc.d_src = re->re_src_segs[0].ds_addr;
35470 ++	}
35471 ++
35472 ++	if (enccrd == NULL && maccrd != NULL) {
35473 ++		/*
35474 ++		 * Hash op; no destination needed.
35475 ++		 */
35476 ++	} else {
35477 ++		if (crp->crp_flags & (CRYPTO_F_IOV|CRYPTO_F_SKBUF)) {
35478 ++			if (!nicealign) {
35479 ++				safestats.st_iovmisaligned++;
35480 ++				err = EINVAL;
35481 ++				goto errout;
35482 ++			}
35483 ++			if (uniform != 1) {
35484 ++				device_printf(sc->sc_dev, "!uniform source\n");
35485 ++				if (!uniform) {
35486 ++					/*
35487 ++					 * There's no way to handle the DMA
35488 ++					 * requirements with this uio.  We
35489 ++					 * could create a separate DMA area for
35490 ++					 * the result and then copy it back,
35491 ++					 * but for now we just bail and return
35492 ++					 * an error.  Note that uio requests
35493 ++					 * > SAFE_MAX_DSIZE are handled because
35494 ++					 * the DMA map and segment list for the
35495 ++					 * destination wil result in a
35496 ++					 * destination particle list that does
35497 ++					 * the necessary scatter DMA.
35498 ++					 */ 
35499 ++					safestats.st_iovnotuniform++;
35500 ++					err = EINVAL;
35501 ++					goto errout;
35502 ++				}
35503 ++			} else
35504 ++				re->re_dst = re->re_src;
35505 ++		} else {
35506 ++			safestats.st_badflags++;
35507 ++			err = EINVAL;
35508 ++			goto errout;
35509 ++		}
35510 ++
35511 ++		if (re->re_dst.nsegs > 1) {
35512 ++			re->re_desc.d_dst = sc->sc_dpalloc.dma_paddr +
35513 ++			    ((caddr_t) sc->sc_dpfree - (caddr_t) sc->sc_dpring);
35514 ++			for (i = 0; i < re->re_dst_nsegs; i++) {
35515 ++				pd = sc->sc_dpfree;
35516 ++				KASSERT((pd->pd_flags&3) == 0 ||
35517 ++					(pd->pd_flags&3) == SAFE_PD_DONE,
35518 ++					("bogus dest particle descriptor; flags %x",
35519 ++						pd->pd_flags));
35520 ++				if (++(sc->sc_dpfree) == sc->sc_dpringtop)
35521 ++					sc->sc_dpfree = sc->sc_dpring;
35522 ++				pd->pd_addr = re->re_dst_segs[i].ds_addr;
35523 ++				pd->pd_flags = SAFE_PD_READY;
35524 ++			}
35525 ++			cmd0 |= SAFE_SA_CMD0_OSCATTER;
35526 ++		} else {
35527 ++			/*
35528 ++			 * No need for scatter, reference the operand directly.
35529 ++			 */
35530 ++			re->re_desc.d_dst = re->re_dst_segs[0].ds_addr;
35531 ++		}
35532 ++	}
35533 ++
35534 ++	/*
35535 ++	 * All done with setup; fillin the SA command words
35536 ++	 * and the packet engine descriptor.  The operation
35537 ++	 * is now ready for submission to the hardware.
35538 ++	 */
35539 ++	sa->sa_cmd0 = cmd0 | SAFE_SA_CMD0_IPCI | SAFE_SA_CMD0_OPCI;
35540 ++	sa->sa_cmd1 = cmd1
35541 ++		    | (coffset << SAFE_SA_CMD1_OFFSET_S)
35542 ++		    | SAFE_SA_CMD1_SAREV1	/* Rev 1 SA data structure */
35543 ++		    | SAFE_SA_CMD1_SRPCI
35544 ++		    ;
35545 ++	/*
35546 ++	 * NB: the order of writes is important here.  In case the
35547 ++	 * chip is scanning the ring because of an outstanding request
35548 ++	 * it might nab this one too.  In that case we need to make
35549 ++	 * sure the setup is complete before we write the length
35550 ++	 * field of the descriptor as it signals the descriptor is
35551 ++	 * ready for processing.
35552 ++	 */
35553 ++	re->re_desc.d_csr = SAFE_PE_CSR_READY | SAFE_PE_CSR_SAPCI;
35554 ++	if (maccrd)
35555 ++		re->re_desc.d_csr |= SAFE_PE_CSR_LOADSA | SAFE_PE_CSR_HASHFINAL;
35556 ++	wmb();
35557 ++	re->re_desc.d_len = oplen
35558 ++			  | SAFE_PE_LEN_READY
35559 ++			  | (bypass << SAFE_PE_LEN_BYPASS_S)
35560 ++			  ;
35561 ++
35562 ++	safestats.st_ipackets++;
35563 ++	safestats.st_ibytes += oplen;
35564 ++
35565 ++	if (++(sc->sc_front) == sc->sc_ringtop)
35566 ++		sc->sc_front = sc->sc_ring;
35567 ++
35568 ++	/* XXX honor batching */
35569 ++	safe_feed(sc, re);
35570 ++	spin_unlock_irqrestore(&sc->sc_ringmtx, flags);
35571 ++	return (0);
35572 ++
35573 ++errout:
35574 ++	if (re->re_src.map != re->re_dst.map)
35575 ++		pci_unmap_operand(sc, &re->re_dst);
35576 ++	if (re->re_src.map)
35577 ++		pci_unmap_operand(sc, &re->re_src);
35578 ++	spin_unlock_irqrestore(&sc->sc_ringmtx, flags);
35579 ++	if (err != ERESTART) {
35580 ++		crp->crp_etype = err;
35581 ++		crypto_done(crp);
35582 ++	} else {
35583 ++		sc->sc_needwakeup |= CRYPTO_SYMQ;
35584 ++	}
35585 ++	return (err);
35586 ++}
35587 ++
35588 ++static void
35589 ++safe_callback(struct safe_softc *sc, struct safe_ringentry *re)
35590 ++{
35591 ++	struct cryptop *crp = (struct cryptop *)re->re_crp;
35592 ++	struct cryptodesc *crd;
35593 ++
35594 ++	DPRINTF(("%s()\n", __FUNCTION__));
35595 ++
35596 ++	safestats.st_opackets++;
35597 ++	safestats.st_obytes += re->re_dst.mapsize;
35598 ++
35599 ++	if (re->re_desc.d_csr & SAFE_PE_CSR_STATUS) {
35600 ++		device_printf(sc->sc_dev, "csr 0x%x cmd0 0x%x cmd1 0x%x\n",
35601 ++			re->re_desc.d_csr,
35602 ++			re->re_sa.sa_cmd0, re->re_sa.sa_cmd1);
35603 ++		safestats.st_peoperr++;
35604 ++		crp->crp_etype = EIO;		/* something more meaningful? */
35605 ++	}
35606 ++
35607 ++	if (re->re_dst.map != NULL && re->re_dst.map != re->re_src.map)
35608 ++		pci_unmap_operand(sc, &re->re_dst);
35609 ++	pci_unmap_operand(sc, &re->re_src);
35610 ++
35611 ++	/* 
35612 ++	 * If result was written to a differet mbuf chain, swap
35613 ++	 * it in as the return value and reclaim the original.
35614 ++	 */
35615 ++	if ((crp->crp_flags & CRYPTO_F_SKBUF) && re->re_src_skb != re->re_dst_skb) {
35616 ++		device_printf(sc->sc_dev, "no CRYPTO_F_SKBUF swapping support\n");
35617 ++		/* kfree_skb(skb) */
35618 ++		/* crp->crp_buf = (caddr_t)re->re_dst_skb */
35619 ++		return;
35620 ++	}
35621 ++
35622 ++	if (re->re_flags & SAFE_QFLAGS_COPYOUTIV) {
35623 ++		/* copy out IV for future use */
35624 ++		for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
35625 ++			int i;
35626 ++			int ivsize;
35627 ++
35628 ++			if (crd->crd_alg == CRYPTO_DES_CBC ||
35629 ++			    crd->crd_alg == CRYPTO_3DES_CBC) {
35630 ++				ivsize = 2*sizeof(u_int32_t);
35631 ++			} else if (crd->crd_alg == CRYPTO_AES_CBC) {
35632 ++				ivsize = 4*sizeof(u_int32_t);
35633 ++			} else
35634 ++				continue;
35635 ++			crypto_copydata(crp->crp_flags, crp->crp_buf,
35636 ++			    crd->crd_skip + crd->crd_len - ivsize, ivsize,
35637 ++			    (caddr_t)sc->sc_sessions[re->re_sesn].ses_iv);
35638 ++			for (i = 0;
35639 ++					i < ivsize/sizeof(sc->sc_sessions[re->re_sesn].ses_iv[0]);
35640 ++					i++)
35641 ++				sc->sc_sessions[re->re_sesn].ses_iv[i] =
35642 ++					cpu_to_le32(sc->sc_sessions[re->re_sesn].ses_iv[i]);
35643 ++			break;
35644 ++		}
35645 ++	}
35646 ++
35647 ++	if (re->re_flags & SAFE_QFLAGS_COPYOUTICV) {
35648 ++		/* copy out ICV result */
35649 ++		for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
35650 ++			if (!(crd->crd_alg == CRYPTO_MD5_HMAC ||
35651 ++			    crd->crd_alg == CRYPTO_SHA1_HMAC ||
35652 ++			    crd->crd_alg == CRYPTO_NULL_HMAC))
35653 ++				continue;
35654 ++			if (crd->crd_alg == CRYPTO_SHA1_HMAC) {
35655 ++				/*
35656 ++				 * SHA-1 ICV's are byte-swapped; fix 'em up
35657 ++				 * before copy them to their destination.
35658 ++				 */
35659 ++				re->re_sastate.sa_saved_indigest[0] =
35660 ++					cpu_to_be32(re->re_sastate.sa_saved_indigest[0]);
35661 ++				re->re_sastate.sa_saved_indigest[1] = 
35662 ++					cpu_to_be32(re->re_sastate.sa_saved_indigest[1]);
35663 ++				re->re_sastate.sa_saved_indigest[2] =
35664 ++					cpu_to_be32(re->re_sastate.sa_saved_indigest[2]);
35665 ++			} else {
35666 ++				re->re_sastate.sa_saved_indigest[0] =
35667 ++					cpu_to_le32(re->re_sastate.sa_saved_indigest[0]);
35668 ++				re->re_sastate.sa_saved_indigest[1] = 
35669 ++					cpu_to_le32(re->re_sastate.sa_saved_indigest[1]);
35670 ++				re->re_sastate.sa_saved_indigest[2] =
35671 ++					cpu_to_le32(re->re_sastate.sa_saved_indigest[2]);
35672 ++			}
35673 ++			crypto_copyback(crp->crp_flags, crp->crp_buf,
35674 ++			    crd->crd_inject,
35675 ++			    sc->sc_sessions[re->re_sesn].ses_mlen,
35676 ++			    (caddr_t)re->re_sastate.sa_saved_indigest);
35677 ++			break;
35678 ++		}
35679 ++	}
35680 ++	crypto_done(crp);
35681 ++}
35682 ++
35683 ++
35684 ++#if defined(CONFIG_OCF_RANDOMHARVEST) && !defined(SAFE_NO_RNG)
35685 ++#define	SAFE_RNG_MAXWAIT	1000
35686 ++
35687 ++static void
35688 ++safe_rng_init(struct safe_softc *sc)
35689 ++{
35690 ++	u_int32_t w, v;
35691 ++	int i;
35692 ++
35693 ++	DPRINTF(("%s()\n", __FUNCTION__));
35694 ++
35695 ++	WRITE_REG(sc, SAFE_RNG_CTRL, 0);
35696 ++	/* use default value according to the manual */
35697 ++	WRITE_REG(sc, SAFE_RNG_CNFG, 0x834);	/* magic from SafeNet */
35698 ++	WRITE_REG(sc, SAFE_RNG_ALM_CNT, 0);
35699 ++
35700 ++	/*
35701 ++	 * There is a bug in rev 1.0 of the 1140 that when the RNG
35702 ++	 * is brought out of reset the ready status flag does not
35703 ++	 * work until the RNG has finished its internal initialization.
35704 ++	 *
35705 ++	 * So in order to determine the device is through its
35706 ++	 * initialization we must read the data register, using the
35707 ++	 * status reg in the read in case it is initialized.  Then read
35708 ++	 * the data register until it changes from the first read.
35709 ++	 * Once it changes read the data register until it changes
35710 ++	 * again.  At this time the RNG is considered initialized. 
35711 ++	 * This could take between 750ms - 1000ms in time.
35712 ++	 */
35713 ++	i = 0;
35714 ++	w = READ_REG(sc, SAFE_RNG_OUT);
35715 ++	do {
35716 ++		v = READ_REG(sc, SAFE_RNG_OUT);
35717 ++		if (v != w) {
35718 ++			w = v;
35719 ++			break;
35720 ++		}
35721 ++		DELAY(10);
35722 ++	} while (++i < SAFE_RNG_MAXWAIT);
35723 ++
35724 ++	/* Wait Until data changes again */
35725 ++	i = 0;
35726 ++	do {
35727 ++		v = READ_REG(sc, SAFE_RNG_OUT);
35728 ++		if (v != w)
35729 ++			break;
35730 ++		DELAY(10);
35731 ++	} while (++i < SAFE_RNG_MAXWAIT);
35732 ++}
35733 ++
35734 ++static __inline void
35735 ++safe_rng_disable_short_cycle(struct safe_softc *sc)
35736 ++{
35737 ++	DPRINTF(("%s()\n", __FUNCTION__));
35738 ++
35739 ++	WRITE_REG(sc, SAFE_RNG_CTRL,
35740 ++		READ_REG(sc, SAFE_RNG_CTRL) &~ SAFE_RNG_CTRL_SHORTEN);
35741 ++}
35742 ++
35743 ++static __inline void
35744 ++safe_rng_enable_short_cycle(struct safe_softc *sc)
35745 ++{
35746 ++	DPRINTF(("%s()\n", __FUNCTION__));
35747 ++
35748 ++	WRITE_REG(sc, SAFE_RNG_CTRL, 
35749 ++		READ_REG(sc, SAFE_RNG_CTRL) | SAFE_RNG_CTRL_SHORTEN);
35750 ++}
35751 ++
35752 ++static __inline u_int32_t
35753 ++safe_rng_read(struct safe_softc *sc)
35754 ++{
35755 ++	int i;
35756 ++
35757 ++	i = 0;
35758 ++	while (READ_REG(sc, SAFE_RNG_STAT) != 0 && ++i < SAFE_RNG_MAXWAIT)
35759 ++		;
35760 ++	return READ_REG(sc, SAFE_RNG_OUT);
35761 ++}
35762 ++
35763 ++static int
35764 ++safe_read_random(void *arg, u_int32_t *buf, int maxwords)
35765 ++{
35766 ++	struct safe_softc *sc = (struct safe_softc *) arg;
35767 ++	int i, rc;
35768 ++
35769 ++	DPRINTF(("%s()\n", __FUNCTION__));
35770 ++	
35771 ++	safestats.st_rng++;
35772 ++	/*
35773 ++	 * Fetch the next block of data.
35774 ++	 */
35775 ++	if (maxwords > safe_rngbufsize)
35776 ++		maxwords = safe_rngbufsize;
35777 ++	if (maxwords > SAFE_RNG_MAXBUFSIZ)
35778 ++		maxwords = SAFE_RNG_MAXBUFSIZ;
35779 ++retry:
35780 ++	/* read as much as we can */
35781 ++	for (rc = 0; rc < maxwords; rc++) {
35782 ++		if (READ_REG(sc, SAFE_RNG_STAT) != 0)
35783 ++			break;
35784 ++		buf[rc] = READ_REG(sc, SAFE_RNG_OUT);
35785 ++	}
35786 ++	if (rc == 0)
35787 ++		return 0;
35788 ++	/*
35789 ++	 * Check the comparator alarm count and reset the h/w if
35790 ++	 * it exceeds our threshold.  This guards against the
35791 ++	 * hardware oscillators resonating with external signals.
35792 ++	 */
35793 ++	if (READ_REG(sc, SAFE_RNG_ALM_CNT) > safe_rngmaxalarm) {
35794 ++		u_int32_t freq_inc, w;
35795 ++
35796 ++		DPRINTF(("%s: alarm count %u exceeds threshold %u\n", __func__,
35797 ++			(unsigned)READ_REG(sc, SAFE_RNG_ALM_CNT), safe_rngmaxalarm));
35798 ++		safestats.st_rngalarm++;
35799 ++		safe_rng_enable_short_cycle(sc);
35800 ++		freq_inc = 18;
35801 ++		for (i = 0; i < 64; i++) {
35802 ++			w = READ_REG(sc, SAFE_RNG_CNFG);
35803 ++			freq_inc = ((w + freq_inc) & 0x3fL);
35804 ++			w = ((w & ~0x3fL) | freq_inc);
35805 ++			WRITE_REG(sc, SAFE_RNG_CNFG, w);
35806 ++
35807 ++			WRITE_REG(sc, SAFE_RNG_ALM_CNT, 0);
35808 ++
35809 ++			(void) safe_rng_read(sc);
35810 ++			DELAY(25);
35811 ++
35812 ++			if (READ_REG(sc, SAFE_RNG_ALM_CNT) == 0) {
35813 ++				safe_rng_disable_short_cycle(sc);
35814 ++				goto retry;
35815 ++			}
35816 ++			freq_inc = 1;
35817 ++		}
35818 ++		safe_rng_disable_short_cycle(sc);
35819 ++	} else
35820 ++		WRITE_REG(sc, SAFE_RNG_ALM_CNT, 0);
35821 ++
35822 ++	return(rc);
35823 ++}
35824 ++#endif /* defined(CONFIG_OCF_RANDOMHARVEST) && !defined(SAFE_NO_RNG) */
35825 ++
35826 ++
35827 ++/*
35828 ++ * Resets the board.  Values in the regesters are left as is
35829 ++ * from the reset (i.e. initial values are assigned elsewhere).
35830 ++ */
35831 ++static void
35832 ++safe_reset_board(struct safe_softc *sc)
35833 ++{
35834 ++	u_int32_t v;
35835 ++	/*
35836 ++	 * Reset the device.  The manual says no delay
35837 ++	 * is needed between marking and clearing reset.
35838 ++	 */
35839 ++	DPRINTF(("%s()\n", __FUNCTION__));
35840 ++
35841 ++	v = READ_REG(sc, SAFE_PE_DMACFG) &~
35842 ++		(SAFE_PE_DMACFG_PERESET | SAFE_PE_DMACFG_PDRRESET |
35843 ++		 SAFE_PE_DMACFG_SGRESET);
35844 ++	WRITE_REG(sc, SAFE_PE_DMACFG, v
35845 ++				    | SAFE_PE_DMACFG_PERESET
35846 ++				    | SAFE_PE_DMACFG_PDRRESET
35847 ++				    | SAFE_PE_DMACFG_SGRESET);
35848 ++	WRITE_REG(sc, SAFE_PE_DMACFG, v);
35849 ++}
35850 ++
35851 ++/*
35852 ++ * Initialize registers we need to touch only once.
35853 ++ */
35854 ++static void
35855 ++safe_init_board(struct safe_softc *sc)
35856 ++{
35857 ++	u_int32_t v, dwords;
35858 ++
35859 ++	DPRINTF(("%s()\n", __FUNCTION__));
35860 ++
35861 ++	v = READ_REG(sc, SAFE_PE_DMACFG);
35862 ++	v &=~ (   SAFE_PE_DMACFG_PEMODE
35863 ++			| SAFE_PE_DMACFG_FSENA		/* failsafe enable */
35864 ++			| SAFE_PE_DMACFG_GPRPCI		/* gather ring on PCI */
35865 ++			| SAFE_PE_DMACFG_SPRPCI		/* scatter ring on PCI */
35866 ++			| SAFE_PE_DMACFG_ESDESC		/* endian-swap descriptors */
35867 ++			| SAFE_PE_DMACFG_ESPDESC	/* endian-swap part. desc's */
35868 ++			| SAFE_PE_DMACFG_ESSA		/* endian-swap SA's */
35869 ++			| SAFE_PE_DMACFG_ESPACKET	/* swap the packet data */
35870 ++		  );
35871 ++	v |= SAFE_PE_DMACFG_FSENA		/* failsafe enable */
35872 ++	  |  SAFE_PE_DMACFG_GPRPCI		/* gather ring on PCI */
35873 ++	  |  SAFE_PE_DMACFG_SPRPCI		/* scatter ring on PCI */
35874 ++	  |  SAFE_PE_DMACFG_ESDESC		/* endian-swap descriptors */
35875 ++	  |  SAFE_PE_DMACFG_ESPDESC		/* endian-swap part. desc's */
35876 ++	  |  SAFE_PE_DMACFG_ESSA		/* endian-swap SA's */
35877 ++#if 0
35878 ++	  |  SAFE_PE_DMACFG_ESPACKET    /* swap the packet data */
35879 ++#endif
35880 ++	  ;
35881 ++	WRITE_REG(sc, SAFE_PE_DMACFG, v);
35882 ++
35883 ++#ifdef __BIG_ENDIAN
35884 ++	/* tell the safenet that we are 4321 and not 1234 */
35885 ++	WRITE_REG(sc, SAFE_ENDIAN, 0xe4e41b1b);
35886 ++#endif
35887 ++
35888 ++	if (sc->sc_chiprev == SAFE_REV(1,0)) {
35889 ++		/*
35890 ++		 * Avoid large PCI DMA transfers.  Rev 1.0 has a bug where
35891 ++		 * "target mode transfers" done while the chip is DMA'ing
35892 ++		 * >1020 bytes cause the hardware to lockup.  To avoid this
35893 ++		 * we reduce the max PCI transfer size and use small source
35894 ++		 * particle descriptors (<= 256 bytes).
35895 ++		 */
35896 ++		WRITE_REG(sc, SAFE_DMA_CFG, 256);
35897 ++		device_printf(sc->sc_dev,
35898 ++			"Reduce max DMA size to %u words for rev %u.%u WAR\n",
35899 ++			(unsigned) ((READ_REG(sc, SAFE_DMA_CFG)>>2) & 0xff),
35900 ++			(unsigned) SAFE_REV_MAJ(sc->sc_chiprev),
35901 ++			(unsigned) SAFE_REV_MIN(sc->sc_chiprev));
35902 ++		sc->sc_max_dsize = 256;
35903 ++	} else {
35904 ++		sc->sc_max_dsize = SAFE_MAX_DSIZE;
35905 ++	}
35906 ++
35907 ++	/* NB: operands+results are overlaid */
35908 ++	WRITE_REG(sc, SAFE_PE_PDRBASE, sc->sc_ringalloc.dma_paddr);
35909 ++	WRITE_REG(sc, SAFE_PE_RDRBASE, sc->sc_ringalloc.dma_paddr);
35910 ++	/*
35911 ++	 * Configure ring entry size and number of items in the ring.
35912 ++	 */
35913 ++	KASSERT((sizeof(struct safe_ringentry) % sizeof(u_int32_t)) == 0,
35914 ++		("PE ring entry not 32-bit aligned!"));
35915 ++	dwords = sizeof(struct safe_ringentry) / sizeof(u_int32_t);
35916 ++	WRITE_REG(sc, SAFE_PE_RINGCFG,
35917 ++		(dwords << SAFE_PE_RINGCFG_OFFSET_S) | SAFE_MAX_NQUEUE);
35918 ++	WRITE_REG(sc, SAFE_PE_RINGPOLL, 0);	/* disable polling */
35919 ++
35920 ++	WRITE_REG(sc, SAFE_PE_GRNGBASE, sc->sc_spalloc.dma_paddr);
35921 ++	WRITE_REG(sc, SAFE_PE_SRNGBASE, sc->sc_dpalloc.dma_paddr);
35922 ++	WRITE_REG(sc, SAFE_PE_PARTSIZE,
35923 ++		(SAFE_TOTAL_DPART<<16) | SAFE_TOTAL_SPART);
35924 ++	/*
35925 ++	 * NB: destination particles are fixed size.  We use
35926 ++	 *     an mbuf cluster and require all results go to
35927 ++	 *     clusters or smaller.
35928 ++	 */
35929 ++	WRITE_REG(sc, SAFE_PE_PARTCFG, sc->sc_max_dsize);
35930 ++
35931 ++	/* it's now safe to enable PE mode, do it */
35932 ++	WRITE_REG(sc, SAFE_PE_DMACFG, v | SAFE_PE_DMACFG_PEMODE);
35933 ++
35934 ++	/*
35935 ++	 * Configure hardware to use level-triggered interrupts and
35936 ++	 * to interrupt after each descriptor is processed.
35937 ++	 */
35938 ++	WRITE_REG(sc, SAFE_HI_CFG, SAFE_HI_CFG_LEVEL);
35939 ++	WRITE_REG(sc, SAFE_HI_CLR, 0xffffffff);
35940 ++	WRITE_REG(sc, SAFE_HI_DESC_CNT, 1);
35941 ++	WRITE_REG(sc, SAFE_HI_MASK, SAFE_INT_PE_DDONE | SAFE_INT_PE_ERROR);
35942 ++}
35943 ++
35944 ++
35945 ++/*
35946 ++ * Clean up after a chip crash.
35947 ++ * It is assumed that the caller in splimp()
35948 ++ */
35949 ++static void
35950 ++safe_cleanchip(struct safe_softc *sc)
35951 ++{
35952 ++	DPRINTF(("%s()\n", __FUNCTION__));
35953 ++
35954 ++	if (sc->sc_nqchip != 0) {
35955 ++		struct safe_ringentry *re = sc->sc_back;
35956 ++
35957 ++		while (re != sc->sc_front) {
35958 ++			if (re->re_desc.d_csr != 0)
35959 ++				safe_free_entry(sc, re);
35960 ++			if (++re == sc->sc_ringtop)
35961 ++				re = sc->sc_ring;
35962 ++		}
35963 ++		sc->sc_back = re;
35964 ++		sc->sc_nqchip = 0;
35965 ++	}
35966 ++}
35967 ++
35968 ++/*
35969 ++ * free a safe_q
35970 ++ * It is assumed that the caller is within splimp().
35971 ++ */
35972 ++static int
35973 ++safe_free_entry(struct safe_softc *sc, struct safe_ringentry *re)
35974 ++{
35975 ++	struct cryptop *crp;
35976 ++
35977 ++	DPRINTF(("%s()\n", __FUNCTION__));
35978 ++
35979 ++	/*
35980 ++	 * Free header MCR
35981 ++	 */
35982 ++	if ((re->re_dst_skb != NULL) && (re->re_src_skb != re->re_dst_skb))
35983 ++#ifdef NOTYET
35984 ++		m_freem(re->re_dst_m);
35985 ++#else
35986 ++		printk("%s,%d: SKB not supported\n", __FILE__, __LINE__);
35987 ++#endif
35988 ++
35989 ++	crp = (struct cryptop *)re->re_crp;
35990 ++	
35991 ++	re->re_desc.d_csr = 0;
35992 ++	
35993 ++	crp->crp_etype = EFAULT;
35994 ++	crypto_done(crp);
35995 ++	return(0);
35996 ++}
35997 ++
35998 ++/*
35999 ++ * Routine to reset the chip and clean up.
36000 ++ * It is assumed that the caller is in splimp()
36001 ++ */
36002 ++static void
36003 ++safe_totalreset(struct safe_softc *sc)
36004 ++{
36005 ++	DPRINTF(("%s()\n", __FUNCTION__));
36006 ++
36007 ++	safe_reset_board(sc);
36008 ++	safe_init_board(sc);
36009 ++	safe_cleanchip(sc);
36010 ++}
36011 ++
36012 ++/*
36013 ++ * Is the operand suitable aligned for direct DMA.  Each
36014 ++ * segment must be aligned on a 32-bit boundary and all
36015 ++ * but the last segment must be a multiple of 4 bytes.
36016 ++ */
36017 ++static int
36018 ++safe_dmamap_aligned(struct safe_softc *sc, const struct safe_operand *op)
36019 ++{
36020 ++	int i;
36021 ++
36022 ++	DPRINTF(("%s()\n", __FUNCTION__));
36023 ++
36024 ++	for (i = 0; i < op->nsegs; i++) {
36025 ++		if (op->segs[i].ds_addr & 3)
36026 ++			return (0);
36027 ++		if (i != (op->nsegs - 1) && (op->segs[i].ds_len & 3))
36028 ++			return (0);
36029 ++	}
36030 ++	return (1);
36031 ++}
36032 ++
36033 ++/*
36034 ++ * Is the operand suitable for direct DMA as the destination
36035 ++ * of an operation.  The hardware requires that each ``particle''
36036 ++ * but the last in an operation result have the same size.  We
36037 ++ * fix that size at SAFE_MAX_DSIZE bytes.  This routine returns
36038 ++ * 0 if some segment is not a multiple of of this size, 1 if all
36039 ++ * segments are exactly this size, or 2 if segments are at worst
36040 ++ * a multple of this size.
36041 ++ */
36042 ++static int
36043 ++safe_dmamap_uniform(struct safe_softc *sc, const struct safe_operand *op)
36044 ++{
36045 ++	int result = 1;
36046 ++
36047 ++	DPRINTF(("%s()\n", __FUNCTION__));
36048 ++
36049 ++	if (op->nsegs > 0) {
36050 ++		int i;
36051 ++
36052 ++		for (i = 0; i < op->nsegs-1; i++) {
36053 ++			if (op->segs[i].ds_len % sc->sc_max_dsize)
36054 ++				return (0);
36055 ++			if (op->segs[i].ds_len != sc->sc_max_dsize)
36056 ++				result = 2;
36057 ++		}
36058 ++	}
36059 ++	return (result);
36060 ++}
36061 ++
36062 ++static int
36063 ++safe_kprocess(device_t dev, struct cryptkop *krp, int hint)
36064 ++{
36065 ++	struct safe_softc *sc = device_get_softc(dev);
36066 ++	struct safe_pkq *q;
36067 ++	unsigned long flags;
36068 ++
36069 ++	DPRINTF(("%s()\n", __FUNCTION__));
36070 ++
36071 ++	if (sc == NULL) {
36072 ++		krp->krp_status = EINVAL;
36073 ++		goto err;
36074 ++	}
36075 ++
36076 ++	if (krp->krp_op != CRK_MOD_EXP) {
36077 ++		krp->krp_status = EOPNOTSUPP;
36078 ++		goto err;
36079 ++	}
36080 ++
36081 ++	q = (struct safe_pkq *) kmalloc(sizeof(*q), GFP_KERNEL);
36082 ++	if (q == NULL) {
36083 ++		krp->krp_status = ENOMEM;
36084 ++		goto err;
36085 ++	}
36086 ++	memset(q, 0, sizeof(*q));
36087 ++	q->pkq_krp = krp;
36088 ++	INIT_LIST_HEAD(&q->pkq_list);
36089 ++
36090 ++	spin_lock_irqsave(&sc->sc_pkmtx, flags);
36091 ++	list_add_tail(&q->pkq_list, &sc->sc_pkq);
36092 ++	safe_kfeed(sc);
36093 ++	spin_unlock_irqrestore(&sc->sc_pkmtx, flags);
36094 ++	return (0);
36095 ++
36096 ++err:
36097 ++	crypto_kdone(krp);
36098 ++	return (0);
36099 ++}
36100 ++
36101 ++#define	SAFE_CRK_PARAM_BASE	0
36102 ++#define	SAFE_CRK_PARAM_EXP	1
36103 ++#define	SAFE_CRK_PARAM_MOD	2
36104 ++
36105 ++static int
36106 ++safe_kstart(struct safe_softc *sc)
36107 ++{
36108 ++	struct cryptkop *krp = sc->sc_pkq_cur->pkq_krp;
36109 ++	int exp_bits, mod_bits, base_bits;
36110 ++	u_int32_t op, a_off, b_off, c_off, d_off;
36111 ++
36112 ++	DPRINTF(("%s()\n", __FUNCTION__));
36113 ++
36114 ++	if (krp->krp_iparams < 3 || krp->krp_oparams != 1) {
36115 ++		krp->krp_status = EINVAL;
36116 ++		return (1);
36117 ++	}
36118 ++
36119 ++	base_bits = safe_ksigbits(sc, &krp->krp_param[SAFE_CRK_PARAM_BASE]);
36120 ++	if (base_bits > 2048)
36121 ++		goto too_big;
36122 ++	if (base_bits <= 0)		/* 5. base not zero */
36123 ++		goto too_small;
36124 ++
36125 ++	exp_bits = safe_ksigbits(sc, &krp->krp_param[SAFE_CRK_PARAM_EXP]);
36126 ++	if (exp_bits > 2048)
36127 ++		goto too_big;
36128 ++	if (exp_bits <= 0)		/* 1. exponent word length > 0 */
36129 ++		goto too_small;		/* 4. exponent not zero */
36130 ++
36131 ++	mod_bits = safe_ksigbits(sc, &krp->krp_param[SAFE_CRK_PARAM_MOD]);
36132 ++	if (mod_bits > 2048)
36133 ++		goto too_big;
36134 ++	if (mod_bits <= 32)		/* 2. modulus word length > 1 */
36135 ++		goto too_small;		/* 8. MSW of modulus != zero */
36136 ++	if (mod_bits < exp_bits)	/* 3 modulus len >= exponent len */
36137 ++		goto too_small;
36138 ++	if ((krp->krp_param[SAFE_CRK_PARAM_MOD].crp_p[0] & 1) == 0)
36139 ++		goto bad_domain;	/* 6. modulus is odd */
36140 ++	if (mod_bits > krp->krp_param[krp->krp_iparams].crp_nbits)
36141 ++		goto too_small;		/* make sure result will fit */
36142 ++
36143 ++	/* 7. modulus > base */
36144 ++	if (mod_bits < base_bits)
36145 ++		goto too_small;
36146 ++	if (mod_bits == base_bits) {
36147 ++		u_int8_t *basep, *modp;
36148 ++		int i;
36149 ++
36150 ++		basep = krp->krp_param[SAFE_CRK_PARAM_BASE].crp_p +
36151 ++		    ((base_bits + 7) / 8) - 1;
36152 ++		modp = krp->krp_param[SAFE_CRK_PARAM_MOD].crp_p +
36153 ++		    ((mod_bits + 7) / 8) - 1;
36154 ++		
36155 ++		for (i = 0; i < (mod_bits + 7) / 8; i++, basep--, modp--) {
36156 ++			if (*modp < *basep)
36157 ++				goto too_small;
36158 ++			if (*modp > *basep)
36159 ++				break;
36160 ++		}
36161 ++	}
36162 ++
36163 ++	/* And on the 9th step, he rested. */
36164 ++
36165 ++	WRITE_REG(sc, SAFE_PK_A_LEN, (exp_bits + 31) / 32);
36166 ++	WRITE_REG(sc, SAFE_PK_B_LEN, (mod_bits + 31) / 32);
36167 ++	if (mod_bits > 1024) {
36168 ++		op = SAFE_PK_FUNC_EXP4;
36169 ++		a_off = 0x000;
36170 ++		b_off = 0x100;
36171 ++		c_off = 0x200;
36172 ++		d_off = 0x300;
36173 ++	} else {
36174 ++		op = SAFE_PK_FUNC_EXP16;
36175 ++		a_off = 0x000;
36176 ++		b_off = 0x080;
36177 ++		c_off = 0x100;
36178 ++		d_off = 0x180;
36179 ++	}
36180 ++	sc->sc_pk_reslen = b_off - a_off;
36181 ++	sc->sc_pk_resoff = d_off;
36182 ++
36183 ++	/* A is exponent, B is modulus, C is base, D is result */
36184 ++	safe_kload_reg(sc, a_off, b_off - a_off,
36185 ++	    &krp->krp_param[SAFE_CRK_PARAM_EXP]);
36186 ++	WRITE_REG(sc, SAFE_PK_A_ADDR, a_off >> 2);
36187 ++	safe_kload_reg(sc, b_off, b_off - a_off,
36188 ++	    &krp->krp_param[SAFE_CRK_PARAM_MOD]);
36189 ++	WRITE_REG(sc, SAFE_PK_B_ADDR, b_off >> 2);
36190 ++	safe_kload_reg(sc, c_off, b_off - a_off,
36191 ++	    &krp->krp_param[SAFE_CRK_PARAM_BASE]);
36192 ++	WRITE_REG(sc, SAFE_PK_C_ADDR, c_off >> 2);
36193 ++	WRITE_REG(sc, SAFE_PK_D_ADDR, d_off >> 2);
36194 ++
36195 ++	WRITE_REG(sc, SAFE_PK_FUNC, op | SAFE_PK_FUNC_RUN);
36196 ++
36197 ++	return (0);
36198 ++
36199 ++too_big:
36200 ++	krp->krp_status = E2BIG;
36201 ++	return (1);
36202 ++too_small:
36203 ++	krp->krp_status = ERANGE;
36204 ++	return (1);
36205 ++bad_domain:
36206 ++	krp->krp_status = EDOM;
36207 ++	return (1);
36208 ++}
36209 ++
36210 ++static int
36211 ++safe_ksigbits(struct safe_softc *sc, struct crparam *cr)
36212 ++{
36213 ++	u_int plen = (cr->crp_nbits + 7) / 8;
36214 ++	int i, sig = plen * 8;
36215 ++	u_int8_t c, *p = cr->crp_p;
36216 ++
36217 ++	DPRINTF(("%s()\n", __FUNCTION__));
36218 ++
36219 ++	for (i = plen - 1; i >= 0; i--) {
36220 ++		c = p[i];
36221 ++		if (c != 0) {
36222 ++			while ((c & 0x80) == 0) {
36223 ++				sig--;
36224 ++				c <<= 1;
36225 ++			}
36226 ++			break;
36227 ++		}
36228 ++		sig -= 8;
36229 ++	}
36230 ++	return (sig);
36231 ++}
36232 ++
36233 ++static void
36234 ++safe_kfeed(struct safe_softc *sc)
36235 ++{
36236 ++	struct safe_pkq *q, *tmp;
36237 ++
36238 ++	DPRINTF(("%s()\n", __FUNCTION__));
36239 ++
36240 ++	if (list_empty(&sc->sc_pkq) && sc->sc_pkq_cur == NULL)
36241 ++		return;
36242 ++	if (sc->sc_pkq_cur != NULL)
36243 ++		return;
36244 ++	list_for_each_entry_safe(q, tmp, &sc->sc_pkq, pkq_list) {
36245 ++		sc->sc_pkq_cur = q;
36246 ++		list_del(&q->pkq_list);
36247 ++		if (safe_kstart(sc) != 0) {
36248 ++			crypto_kdone(q->pkq_krp);
36249 ++			kfree(q);
36250 ++			sc->sc_pkq_cur = NULL;
36251 ++		} else {
36252 ++			/* op started, start polling */
36253 ++			mod_timer(&sc->sc_pkto, jiffies + 1);
36254 ++			break;
36255 ++		}
36256 ++	}
36257 ++}
36258 ++
36259 ++static void
36260 ++safe_kpoll(unsigned long arg)
36261 ++{
36262 ++	struct safe_softc *sc = NULL;
36263 ++	struct safe_pkq *q;
36264 ++	struct crparam *res;
36265 ++	int i;
36266 ++	u_int32_t buf[64];
36267 ++	unsigned long flags;
36268 ++
36269 ++	DPRINTF(("%s()\n", __FUNCTION__));
36270 ++
36271 ++	if (arg >= SAFE_MAX_CHIPS)
36272 ++		return;
36273 ++	sc = safe_chip_idx[arg];
36274 ++	if (!sc) {
36275 ++		DPRINTF(("%s() - bad callback\n", __FUNCTION__));
36276 ++		return;
36277 ++	}
36278 ++
36279 ++	spin_lock_irqsave(&sc->sc_pkmtx, flags);
36280 ++	if (sc->sc_pkq_cur == NULL)
36281 ++		goto out;
36282 ++	if (READ_REG(sc, SAFE_PK_FUNC) & SAFE_PK_FUNC_RUN) {
36283 ++		/* still running, check back later */
36284 ++		mod_timer(&sc->sc_pkto, jiffies + 1);
36285 ++		goto out;
36286 ++	}
36287 ++
36288 ++	q = sc->sc_pkq_cur;
36289 ++	res = &q->pkq_krp->krp_param[q->pkq_krp->krp_iparams];
36290 ++	bzero(buf, sizeof(buf));
36291 ++	bzero(res->crp_p, (res->crp_nbits + 7) / 8);
36292 ++	for (i = 0; i < sc->sc_pk_reslen >> 2; i++)
36293 ++		buf[i] = le32_to_cpu(READ_REG(sc, SAFE_PK_RAM_START +
36294 ++		    sc->sc_pk_resoff + (i << 2)));
36295 ++	bcopy(buf, res->crp_p, (res->crp_nbits + 7) / 8);
36296 ++	/*
36297 ++	 * reduce the bits that need copying if possible
36298 ++	 */
36299 ++	res->crp_nbits = min(res->crp_nbits,sc->sc_pk_reslen * 8);
36300 ++	res->crp_nbits = safe_ksigbits(sc, res);
36301 ++
36302 ++	for (i = SAFE_PK_RAM_START; i < SAFE_PK_RAM_END; i += 4)
36303 ++		WRITE_REG(sc, i, 0);
36304 ++
36305 ++	crypto_kdone(q->pkq_krp);
36306 ++	kfree(q);
36307 ++	sc->sc_pkq_cur = NULL;
36308 ++
36309 ++	safe_kfeed(sc);
36310 ++out:
36311 ++	spin_unlock_irqrestore(&sc->sc_pkmtx, flags);
36312 ++}
36313 ++
36314 ++static void
36315 ++safe_kload_reg(struct safe_softc *sc, u_int32_t off, u_int32_t len,
36316 ++    struct crparam *n)
36317 ++{
36318 ++	u_int32_t buf[64], i;
36319 ++
36320 ++	DPRINTF(("%s()\n", __FUNCTION__));
36321 ++
36322 ++	bzero(buf, sizeof(buf));
36323 ++	bcopy(n->crp_p, buf, (n->crp_nbits + 7) / 8);
36324 ++
36325 ++	for (i = 0; i < len >> 2; i++)
36326 ++		WRITE_REG(sc, SAFE_PK_RAM_START + off + (i << 2),
36327 ++		    cpu_to_le32(buf[i]));
36328 ++}
36329 ++
36330 ++#ifdef SAFE_DEBUG
36331 ++static void
36332 ++safe_dump_dmastatus(struct safe_softc *sc, const char *tag)
36333 ++{
36334 ++	printf("%s: ENDIAN 0x%x SRC 0x%x DST 0x%x STAT 0x%x\n"
36335 ++		, tag
36336 ++		, READ_REG(sc, SAFE_DMA_ENDIAN)
36337 ++		, READ_REG(sc, SAFE_DMA_SRCADDR)
36338 ++		, READ_REG(sc, SAFE_DMA_DSTADDR)
36339 ++		, READ_REG(sc, SAFE_DMA_STAT)
36340 ++	);
36341 ++}
36342 ++
36343 ++static void
36344 ++safe_dump_intrstate(struct safe_softc *sc, const char *tag)
36345 ++{
36346 ++	printf("%s: HI_CFG 0x%x HI_MASK 0x%x HI_DESC_CNT 0x%x HU_STAT 0x%x HM_STAT 0x%x\n"
36347 ++		, tag
36348 ++		, READ_REG(sc, SAFE_HI_CFG)
36349 ++		, READ_REG(sc, SAFE_HI_MASK)
36350 ++		, READ_REG(sc, SAFE_HI_DESC_CNT)
36351 ++		, READ_REG(sc, SAFE_HU_STAT)
36352 ++		, READ_REG(sc, SAFE_HM_STAT)
36353 ++	);
36354 ++}
36355 ++
36356 ++static void
36357 ++safe_dump_ringstate(struct safe_softc *sc, const char *tag)
36358 ++{
36359 ++	u_int32_t estat = READ_REG(sc, SAFE_PE_ERNGSTAT);
36360 ++
36361 ++	/* NB: assume caller has lock on ring */
36362 ++	printf("%s: ERNGSTAT %x (next %u) back %lu front %lu\n",
36363 ++		tag,
36364 ++		estat, (estat >> SAFE_PE_ERNGSTAT_NEXT_S),
36365 ++		(unsigned long)(sc->sc_back - sc->sc_ring),
36366 ++		(unsigned long)(sc->sc_front - sc->sc_ring));
36367 ++}
36368 ++
36369 ++static void
36370 ++safe_dump_request(struct safe_softc *sc, const char* tag, struct safe_ringentry *re)
36371 ++{
36372 ++	int ix, nsegs;
36373 ++
36374 ++	ix = re - sc->sc_ring;
36375 ++	printf("%s: %p (%u): csr %x src %x dst %x sa %x len %x\n"
36376 ++		, tag
36377 ++		, re, ix
36378 ++		, re->re_desc.d_csr
36379 ++		, re->re_desc.d_src
36380 ++		, re->re_desc.d_dst
36381 ++		, re->re_desc.d_sa
36382 ++		, re->re_desc.d_len
36383 ++	);
36384 ++	if (re->re_src.nsegs > 1) {
36385 ++		ix = (re->re_desc.d_src - sc->sc_spalloc.dma_paddr) /
36386 ++			sizeof(struct safe_pdesc);
36387 ++		for (nsegs = re->re_src.nsegs; nsegs; nsegs--) {
36388 ++			printf(" spd[%u] %p: %p size %u flags %x"
36389 ++				, ix, &sc->sc_spring[ix]
36390 ++				, (caddr_t)(uintptr_t) sc->sc_spring[ix].pd_addr
36391 ++				, sc->sc_spring[ix].pd_size
36392 ++				, sc->sc_spring[ix].pd_flags
36393 ++			);
36394 ++			if (sc->sc_spring[ix].pd_size == 0)
36395 ++				printf(" (zero!)");
36396 ++			printf("\n");
36397 ++			if (++ix == SAFE_TOTAL_SPART)
36398 ++				ix = 0;
36399 ++		}
36400 ++	}
36401 ++	if (re->re_dst.nsegs > 1) {
36402 ++		ix = (re->re_desc.d_dst - sc->sc_dpalloc.dma_paddr) /
36403 ++			sizeof(struct safe_pdesc);
36404 ++		for (nsegs = re->re_dst.nsegs; nsegs; nsegs--) {
36405 ++			printf(" dpd[%u] %p: %p flags %x\n"
36406 ++				, ix, &sc->sc_dpring[ix]
36407 ++				, (caddr_t)(uintptr_t) sc->sc_dpring[ix].pd_addr
36408 ++				, sc->sc_dpring[ix].pd_flags
36409 ++			);
36410 ++			if (++ix == SAFE_TOTAL_DPART)
36411 ++				ix = 0;
36412 ++		}
36413 ++	}
36414 ++	printf("sa: cmd0 %08x cmd1 %08x staterec %x\n",
36415 ++		re->re_sa.sa_cmd0, re->re_sa.sa_cmd1, re->re_sa.sa_staterec);
36416 ++	printf("sa: key %x %x %x %x %x %x %x %x\n"
36417 ++		, re->re_sa.sa_key[0]
36418 ++		, re->re_sa.sa_key[1]
36419 ++		, re->re_sa.sa_key[2]
36420 ++		, re->re_sa.sa_key[3]
36421 ++		, re->re_sa.sa_key[4]
36422 ++		, re->re_sa.sa_key[5]
36423 ++		, re->re_sa.sa_key[6]
36424 ++		, re->re_sa.sa_key[7]
36425 ++	);
36426 ++	printf("sa: indigest %x %x %x %x %x\n"
36427 ++		, re->re_sa.sa_indigest[0]
36428 ++		, re->re_sa.sa_indigest[1]
36429 ++		, re->re_sa.sa_indigest[2]
36430 ++		, re->re_sa.sa_indigest[3]
36431 ++		, re->re_sa.sa_indigest[4]
36432 ++	);
36433 ++	printf("sa: outdigest %x %x %x %x %x\n"
36434 ++		, re->re_sa.sa_outdigest[0]
36435 ++		, re->re_sa.sa_outdigest[1]
36436 ++		, re->re_sa.sa_outdigest[2]
36437 ++		, re->re_sa.sa_outdigest[3]
36438 ++		, re->re_sa.sa_outdigest[4]
36439 ++	);
36440 ++	printf("sr: iv %x %x %x %x\n"
36441 ++		, re->re_sastate.sa_saved_iv[0]
36442 ++		, re->re_sastate.sa_saved_iv[1]
36443 ++		, re->re_sastate.sa_saved_iv[2]
36444 ++		, re->re_sastate.sa_saved_iv[3]
36445 ++	);
36446 ++	printf("sr: hashbc %u indigest %x %x %x %x %x\n"
36447 ++		, re->re_sastate.sa_saved_hashbc
36448 ++		, re->re_sastate.sa_saved_indigest[0]
36449 ++		, re->re_sastate.sa_saved_indigest[1]
36450 ++		, re->re_sastate.sa_saved_indigest[2]
36451 ++		, re->re_sastate.sa_saved_indigest[3]
36452 ++		, re->re_sastate.sa_saved_indigest[4]
36453 ++	);
36454 ++}
36455 ++
36456 ++static void
36457 ++safe_dump_ring(struct safe_softc *sc, const char *tag)
36458 ++{
36459 ++	unsigned long flags;
36460 ++
36461 ++	spin_lock_irqsave(&sc->sc_ringmtx, flags);
36462 ++	printf("\nSafeNet Ring State:\n");
36463 ++	safe_dump_intrstate(sc, tag);
36464 ++	safe_dump_dmastatus(sc, tag);
36465 ++	safe_dump_ringstate(sc, tag);
36466 ++	if (sc->sc_nqchip) {
36467 ++		struct safe_ringentry *re = sc->sc_back;
36468 ++		do {
36469 ++			safe_dump_request(sc, tag, re);
36470 ++			if (++re == sc->sc_ringtop)
36471 ++				re = sc->sc_ring;
36472 ++		} while (re != sc->sc_front);
36473 ++	}
36474 ++	spin_unlock_irqrestore(&sc->sc_ringmtx, flags);
36475 ++}
36476 ++#endif /* SAFE_DEBUG */
36477 ++
36478 ++
36479 ++static int safe_probe(struct pci_dev *dev, const struct pci_device_id *ent)
36480 ++{
36481 ++	struct safe_softc *sc = NULL;
36482 ++	u32 mem_start, mem_len, cmd;
36483 ++	int i, rc, devinfo;
36484 ++	dma_addr_t raddr;
36485 ++	static int num_chips = 0;
36486 ++
36487 ++	DPRINTF(("%s()\n", __FUNCTION__));
36488 ++
36489 ++	if (pci_enable_device(dev) < 0)
36490 ++		return(-ENODEV);
36491 ++
36492 ++	if (!dev->irq) {
36493 ++		printk("safe: found device with no IRQ assigned. check BIOS settings!");
36494 ++		pci_disable_device(dev);
36495 ++		return(-ENODEV);
36496 ++	}
36497 ++
36498 ++	if (pci_set_mwi(dev)) {
36499 ++		printk("safe: pci_set_mwi failed!");
36500 ++		return(-ENODEV);
36501 ++	}
36502 ++
36503 ++	sc = (struct safe_softc *) kmalloc(sizeof(*sc), GFP_KERNEL);
36504 ++	if (!sc)
36505 ++		return(-ENOMEM);
36506 ++	memset(sc, 0, sizeof(*sc));
36507 ++
36508 ++	softc_device_init(sc, "safe", num_chips, safe_methods);
36509 ++
36510 ++	sc->sc_irq = -1;
36511 ++	sc->sc_cid = -1;
36512 ++	sc->sc_pcidev = dev;
36513 ++	if (num_chips < SAFE_MAX_CHIPS) {
36514 ++		safe_chip_idx[device_get_unit(sc->sc_dev)] = sc;
36515 ++		num_chips++;
36516 ++	}
36517 ++
36518 ++	INIT_LIST_HEAD(&sc->sc_pkq);
36519 ++	spin_lock_init(&sc->sc_pkmtx);
36520 ++
36521 ++	pci_set_drvdata(sc->sc_pcidev, sc);
36522 ++
36523 ++	/* we read its hardware registers as memory */
36524 ++	mem_start = pci_resource_start(sc->sc_pcidev, 0);
36525 ++	mem_len   = pci_resource_len(sc->sc_pcidev, 0);
36526 ++
36527 ++	sc->sc_base_addr = (ocf_iomem_t) ioremap(mem_start, mem_len);
36528 ++	if (!sc->sc_base_addr) {
36529 ++		device_printf(sc->sc_dev, "failed to ioremap 0x%x-0x%x\n",
36530 ++				mem_start, mem_start + mem_len - 1);
36531 ++		goto out;
36532 ++	}
36533 ++
36534 ++	/* fix up the bus size */
36535 ++	if (pci_set_dma_mask(sc->sc_pcidev, DMA_32BIT_MASK)) {
36536 ++		device_printf(sc->sc_dev, "No usable DMA configuration, aborting.\n");
36537 ++		goto out;
36538 ++	}
36539 ++	if (pci_set_consistent_dma_mask(sc->sc_pcidev, DMA_32BIT_MASK)) {
36540 ++		device_printf(sc->sc_dev, "No usable consistent DMA configuration, aborting.\n");
36541 ++		goto out;
36542 ++	}
36543 ++
36544 ++	pci_set_master(sc->sc_pcidev);
36545 ++
36546 ++	pci_read_config_dword(sc->sc_pcidev, PCI_COMMAND, &cmd);
36547 ++
36548 ++	if (!(cmd & PCI_COMMAND_MEMORY)) {
36549 ++		device_printf(sc->sc_dev, "failed to enable memory mapping\n");
36550 ++		goto out;
36551 ++	}
36552 ++
36553 ++	if (!(cmd & PCI_COMMAND_MASTER)) {
36554 ++		device_printf(sc->sc_dev, "failed to enable bus mastering\n");
36555 ++		goto out;
36556 ++	}
36557 ++
36558 ++	rc = request_irq(dev->irq, safe_intr, IRQF_SHARED, "safe", sc);
36559 ++	if (rc) {
36560 ++		device_printf(sc->sc_dev, "failed to hook irq %d\n", sc->sc_irq);
36561 ++		goto out;
36562 ++	}
36563 ++	sc->sc_irq = dev->irq;
36564 ++
36565 ++	sc->sc_chiprev = READ_REG(sc, SAFE_DEVINFO) &
36566 ++			(SAFE_DEVINFO_REV_MAJ | SAFE_DEVINFO_REV_MIN);
36567 ++
36568 ++	/*
36569 ++	 * Allocate packet engine descriptors.
36570 ++	 */
36571 ++	sc->sc_ringalloc.dma_vaddr = pci_alloc_consistent(sc->sc_pcidev,
36572 ++			SAFE_MAX_NQUEUE * sizeof (struct safe_ringentry),
36573 ++			&sc->sc_ringalloc.dma_paddr);
36574 ++	if (!sc->sc_ringalloc.dma_vaddr) {
36575 ++		device_printf(sc->sc_dev, "cannot allocate PE descriptor ring\n");
36576 ++		goto out;
36577 ++	}
36578 ++
36579 ++	/*
36580 ++	 * Hookup the static portion of all our data structures.
36581 ++	 */
36582 ++	sc->sc_ring = (struct safe_ringentry *) sc->sc_ringalloc.dma_vaddr;
36583 ++	sc->sc_ringtop = sc->sc_ring + SAFE_MAX_NQUEUE;
36584 ++	sc->sc_front = sc->sc_ring;
36585 ++	sc->sc_back = sc->sc_ring;
36586 ++	raddr = sc->sc_ringalloc.dma_paddr;
36587 ++	bzero(sc->sc_ring, SAFE_MAX_NQUEUE * sizeof(struct safe_ringentry));
36588 ++	for (i = 0; i < SAFE_MAX_NQUEUE; i++) {
36589 ++		struct safe_ringentry *re = &sc->sc_ring[i];
36590 ++
36591 ++		re->re_desc.d_sa = raddr +
36592 ++			offsetof(struct safe_ringentry, re_sa);
36593 ++		re->re_sa.sa_staterec = raddr +
36594 ++			offsetof(struct safe_ringentry, re_sastate);
36595 ++
36596 ++		raddr += sizeof (struct safe_ringentry);
36597 ++	}
36598 ++	spin_lock_init(&sc->sc_ringmtx);
36599 ++
36600 ++	/*
36601 ++	 * Allocate scatter and gather particle descriptors.
36602 ++	 */
36603 ++	sc->sc_spalloc.dma_vaddr = pci_alloc_consistent(sc->sc_pcidev,
36604 ++			SAFE_TOTAL_SPART * sizeof (struct safe_pdesc),
36605 ++			&sc->sc_spalloc.dma_paddr);
36606 ++	if (!sc->sc_spalloc.dma_vaddr) {
36607 ++		device_printf(sc->sc_dev, "cannot allocate source particle descriptor ring\n");
36608 ++		goto out;
36609 ++	}
36610 ++	sc->sc_spring = (struct safe_pdesc *) sc->sc_spalloc.dma_vaddr;
36611 ++	sc->sc_springtop = sc->sc_spring + SAFE_TOTAL_SPART;
36612 ++	sc->sc_spfree = sc->sc_spring;
36613 ++	bzero(sc->sc_spring, SAFE_TOTAL_SPART * sizeof(struct safe_pdesc));
36614 ++
36615 ++	sc->sc_dpalloc.dma_vaddr = pci_alloc_consistent(sc->sc_pcidev,
36616 ++			SAFE_TOTAL_DPART * sizeof (struct safe_pdesc),
36617 ++			&sc->sc_dpalloc.dma_paddr);
36618 ++	if (!sc->sc_dpalloc.dma_vaddr) {
36619 ++		device_printf(sc->sc_dev, "cannot allocate destination particle descriptor ring\n");
36620 ++		goto out;
36621 ++	}
36622 ++	sc->sc_dpring = (struct safe_pdesc *) sc->sc_dpalloc.dma_vaddr;
36623 ++	sc->sc_dpringtop = sc->sc_dpring + SAFE_TOTAL_DPART;
36624 ++	sc->sc_dpfree = sc->sc_dpring;
36625 ++	bzero(sc->sc_dpring, SAFE_TOTAL_DPART * sizeof(struct safe_pdesc));
36626 ++
36627 ++	sc->sc_cid = crypto_get_driverid(softc_get_device(sc), CRYPTOCAP_F_HARDWARE);
36628 ++	if (sc->sc_cid < 0) {
36629 ++		device_printf(sc->sc_dev, "could not get crypto driver id\n");
36630 ++		goto out;
36631 ++	}
36632 ++
36633 ++	printf("%s:", device_get_nameunit(sc->sc_dev));
36634 ++
36635 ++	devinfo = READ_REG(sc, SAFE_DEVINFO);
36636 ++	if (devinfo & SAFE_DEVINFO_RNG) {
36637 ++		sc->sc_flags |= SAFE_FLAGS_RNG;
36638 ++		printf(" rng");
36639 ++	}
36640 ++	if (devinfo & SAFE_DEVINFO_PKEY) {
36641 ++		printf(" key");
36642 ++		sc->sc_flags |= SAFE_FLAGS_KEY;
36643 ++		crypto_kregister(sc->sc_cid, CRK_MOD_EXP, 0);
36644 ++#if 0
36645 ++		crypto_kregister(sc->sc_cid, CRK_MOD_EXP_CRT, 0);
36646 ++#endif
36647 ++		init_timer(&sc->sc_pkto);
36648 ++		sc->sc_pkto.function = safe_kpoll;
36649 ++		sc->sc_pkto.data = (unsigned long) device_get_unit(sc->sc_dev);
36650 ++	}
36651 ++	if (devinfo & SAFE_DEVINFO_DES) {
36652 ++		printf(" des/3des");
36653 ++		crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
36654 ++		crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0);
36655 ++	}
36656 ++	if (devinfo & SAFE_DEVINFO_AES) {
36657 ++		printf(" aes");
36658 ++		crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0);
36659 ++	}
36660 ++	if (devinfo & SAFE_DEVINFO_MD5) {
36661 ++		printf(" md5");
36662 ++		crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0);
36663 ++	}
36664 ++	if (devinfo & SAFE_DEVINFO_SHA1) {
36665 ++		printf(" sha1");
36666 ++		crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0);
36667 ++	}
36668 ++	printf(" null");
36669 ++	crypto_register(sc->sc_cid, CRYPTO_NULL_CBC, 0, 0);
36670 ++	crypto_register(sc->sc_cid, CRYPTO_NULL_HMAC, 0, 0);
36671 ++	/* XXX other supported algorithms */
36672 ++	printf("\n");
36673 ++
36674 ++	safe_reset_board(sc);		/* reset h/w */
36675 ++	safe_init_board(sc);		/* init h/w */
36676 ++
36677 ++#if defined(CONFIG_OCF_RANDOMHARVEST) && !defined(SAFE_NO_RNG)
36678 ++	if (sc->sc_flags & SAFE_FLAGS_RNG) {
36679 ++		safe_rng_init(sc);
36680 ++		crypto_rregister(sc->sc_cid, safe_read_random, sc);
36681 ++	}
36682 ++#endif /* SAFE_NO_RNG */
36683 ++
36684 ++	return (0);
36685 ++
36686 ++out:
36687 ++	if (sc->sc_cid >= 0)
36688 ++		crypto_unregister_all(sc->sc_cid);
36689 ++	if (sc->sc_irq != -1)
36690 ++		free_irq(sc->sc_irq, sc);
36691 ++	if (sc->sc_ringalloc.dma_vaddr)
36692 ++		pci_free_consistent(sc->sc_pcidev,
36693 ++				SAFE_MAX_NQUEUE * sizeof (struct safe_ringentry),
36694 ++				sc->sc_ringalloc.dma_vaddr, sc->sc_ringalloc.dma_paddr);
36695 ++	if (sc->sc_spalloc.dma_vaddr)
36696 ++		pci_free_consistent(sc->sc_pcidev,
36697 ++				SAFE_TOTAL_DPART * sizeof (struct safe_pdesc),
36698 ++				sc->sc_spalloc.dma_vaddr, sc->sc_spalloc.dma_paddr);
36699 ++	if (sc->sc_dpalloc.dma_vaddr)
36700 ++		pci_free_consistent(sc->sc_pcidev,
36701 ++				SAFE_TOTAL_DPART * sizeof (struct safe_pdesc),
36702 ++				sc->sc_dpalloc.dma_vaddr, sc->sc_dpalloc.dma_paddr);
36703 ++	kfree(sc);
36704 ++	return(-ENODEV);
36705 ++}
36706 ++
36707 ++static void safe_remove(struct pci_dev *dev)
36708 ++{
36709 ++	struct safe_softc *sc = pci_get_drvdata(dev);
36710 ++
36711 ++	DPRINTF(("%s()\n", __FUNCTION__));
36712 ++
36713 ++	/* XXX wait/abort active ops */
36714 ++
36715 ++	WRITE_REG(sc, SAFE_HI_MASK, 0);		/* disable interrupts */
36716 ++
36717 ++	del_timer_sync(&sc->sc_pkto);
36718 ++
36719 ++	crypto_unregister_all(sc->sc_cid);
36720 ++
36721 ++	safe_cleanchip(sc);
36722 ++
36723 ++	if (sc->sc_irq != -1)
36724 ++		free_irq(sc->sc_irq, sc);
36725 ++	if (sc->sc_ringalloc.dma_vaddr)
36726 ++		pci_free_consistent(sc->sc_pcidev,
36727 ++				SAFE_MAX_NQUEUE * sizeof (struct safe_ringentry),
36728 ++				sc->sc_ringalloc.dma_vaddr, sc->sc_ringalloc.dma_paddr);
36729 ++	if (sc->sc_spalloc.dma_vaddr)
36730 ++		pci_free_consistent(sc->sc_pcidev,
36731 ++				SAFE_TOTAL_DPART * sizeof (struct safe_pdesc),
36732 ++				sc->sc_spalloc.dma_vaddr, sc->sc_spalloc.dma_paddr);
36733 ++	if (sc->sc_dpalloc.dma_vaddr)
36734 ++		pci_free_consistent(sc->sc_pcidev,
36735 ++				SAFE_TOTAL_DPART * sizeof (struct safe_pdesc),
36736 ++				sc->sc_dpalloc.dma_vaddr, sc->sc_dpalloc.dma_paddr);
36737 ++	sc->sc_irq = -1;
36738 ++	sc->sc_ringalloc.dma_vaddr = NULL;
36739 ++	sc->sc_spalloc.dma_vaddr = NULL;
36740 ++	sc->sc_dpalloc.dma_vaddr = NULL;
36741 ++}
36742 ++
36743 ++static struct pci_device_id safe_pci_tbl[] = {
36744 ++	{ PCI_VENDOR_SAFENET, PCI_PRODUCT_SAFEXCEL,
36745 ++	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, },
36746 ++	{ },
36747 ++};
36748 ++MODULE_DEVICE_TABLE(pci, safe_pci_tbl);
36749 ++
36750 ++static struct pci_driver safe_driver = {
36751 ++	.name         = "safe",
36752 ++	.id_table     = safe_pci_tbl,
36753 ++	.probe        =	safe_probe,
36754 ++	.remove       = safe_remove,
36755 ++	/* add PM stuff here one day */
36756 ++};
36757 ++
36758 ++static int __init safe_init (void)
36759 ++{
36760 ++	struct safe_softc *sc = NULL;
36761 ++	int rc;
36762 ++
36763 ++	DPRINTF(("%s(%p)\n", __FUNCTION__, safe_init));
36764 ++
36765 ++	rc = pci_register_driver(&safe_driver);
36766 ++	pci_register_driver_compat(&safe_driver, rc);
36767 ++
36768 ++	return rc;
36769 ++}
36770 ++
36771 ++static void __exit safe_exit (void)
36772 ++{
36773 ++	pci_unregister_driver(&safe_driver);
36774 ++}
36775 ++
36776 ++module_init(safe_init);
36777 ++module_exit(safe_exit);
36778 ++
36779 ++MODULE_LICENSE("BSD");
36780 ++MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
36781 ++MODULE_DESCRIPTION("OCF driver for safenet PCI crypto devices");
36782 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/safereg.h linux-2.6.23.16/crypto/ocf/safe/safereg.h
36783 +--- linux-2.6.23.16.old/crypto/ocf/safe/safereg.h	1969-12-31 19:00:00.000000000 -0500
36784 ++++ linux-2.6.23.16/crypto/ocf/safe/safereg.h	2008-02-26 09:29:13.000000000 -0500
36785 +@@ -0,0 +1,421 @@
36786 ++/*-
36787 ++ * Copyright (c) 2003 Sam Leffler, Errno Consulting
36788 ++ * Copyright (c) 2003 Global Technology Associates, Inc.
36789 ++ * All rights reserved.
36790 ++ *
36791 ++ * Redistribution and use in source and binary forms, with or without
36792 ++ * modification, are permitted provided that the following conditions
36793 ++ * are met:
36794 ++ * 1. Redistributions of source code must retain the above copyright
36795 ++ *    notice, this list of conditions and the following disclaimer.
36796 ++ * 2. Redistributions in binary form must reproduce the above copyright
36797 ++ *    notice, this list of conditions and the following disclaimer in the
36798 ++ *    documentation and/or other materials provided with the distribution.
36799 ++ *
36800 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36801 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36802 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36803 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
36804 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36805 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36806 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36807 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36808 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36809 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36810 ++ * SUCH DAMAGE.
36811 ++ *
36812 ++ * $FreeBSD: src/sys/dev/safe/safereg.h,v 1.1 2003/07/21 21:46:07 sam Exp $
36813 ++ */
36814 ++#ifndef _SAFE_SAFEREG_H_
36815 ++#define	_SAFE_SAFEREG_H_
36816 ++
36817 ++/*
36818 ++ * Register definitions for SafeNet SafeXcel-1141 crypto device.
36819 ++ * Definitions from revision 1.3 (Nov 6 2002) of the User's Manual.
36820 ++ */
36821 ++
36822 ++#define BS_BAR			0x10	/* DMA base address register */
36823 ++#define	BS_TRDY_TIMEOUT		0x40	/* TRDY timeout */
36824 ++#define	BS_RETRY_TIMEOUT	0x41	/* DMA retry timeout */
36825 ++
36826 ++#define	PCI_VENDOR_SAFENET	0x16ae		/* SafeNet, Inc. */
36827 ++
36828 ++/* SafeNet */
36829 ++#define	PCI_PRODUCT_SAFEXCEL	0x1141		/* 1141 */
36830 ++
36831 ++#define	SAFE_PE_CSR		0x0000	/* Packet Enginge Ctrl/Status */
36832 ++#define	SAFE_PE_SRC		0x0004	/* Packet Engine Source */
36833 ++#define	SAFE_PE_DST		0x0008	/* Packet Engine Destination */
36834 ++#define	SAFE_PE_SA		0x000c	/* Packet Engine SA */
36835 ++#define	SAFE_PE_LEN		0x0010	/* Packet Engine Length */
36836 ++#define	SAFE_PE_DMACFG		0x0040	/* Packet Engine DMA Configuration */
36837 ++#define	SAFE_PE_DMASTAT		0x0044	/* Packet Engine DMA Status */
36838 ++#define	SAFE_PE_PDRBASE		0x0048	/* Packet Engine Descriptor Ring Base */
36839 ++#define	SAFE_PE_RDRBASE		0x004c	/* Packet Engine Result Ring Base */
36840 ++#define	SAFE_PE_RINGCFG		0x0050	/* Packet Engine Ring Configuration */
36841 ++#define	SAFE_PE_RINGPOLL	0x0054	/* Packet Engine Ring Poll */
36842 ++#define	SAFE_PE_IRNGSTAT	0x0058	/* Packet Engine Internal Ring Status */
36843 ++#define	SAFE_PE_ERNGSTAT	0x005c	/* Packet Engine External Ring Status */
36844 ++#define	SAFE_PE_IOTHRESH	0x0060	/* Packet Engine I/O Threshold */
36845 ++#define	SAFE_PE_GRNGBASE	0x0064	/* Packet Engine Gather Ring Base */
36846 ++#define	SAFE_PE_SRNGBASE	0x0068	/* Packet Engine Scatter Ring Base */
36847 ++#define	SAFE_PE_PARTSIZE	0x006c	/* Packet Engine Particlar Ring Size */
36848 ++#define	SAFE_PE_PARTCFG		0x0070	/* Packet Engine Particle Ring Config */
36849 ++#define	SAFE_CRYPTO_CTRL	0x0080	/* Crypto Control */
36850 ++#define	SAFE_DEVID		0x0084	/* Device ID */
36851 ++#define	SAFE_DEVINFO		0x0088	/* Device Info */
36852 ++#define	SAFE_HU_STAT		0x00a0	/* Host Unmasked Status */
36853 ++#define	SAFE_HM_STAT		0x00a4	/* Host Masked Status (read-only) */
36854 ++#define	SAFE_HI_CLR		0x00a4	/* Host Clear Interrupt (write-only) */
36855 ++#define	SAFE_HI_MASK		0x00a8	/* Host Mask Control */
36856 ++#define	SAFE_HI_CFG		0x00ac	/* Interrupt Configuration */
36857 ++#define	SAFE_HI_RD_DESCR	0x00b4	/* Force Descriptor Read */
36858 ++#define	SAFE_HI_DESC_CNT	0x00b8	/* Host Descriptor Done Count */
36859 ++#define	SAFE_DMA_ENDIAN		0x00c0	/* Master Endian Status */
36860 ++#define	SAFE_DMA_SRCADDR	0x00c4	/* DMA Source Address Status */
36861 ++#define	SAFE_DMA_DSTADDR	0x00c8	/* DMA Destination Address Status */
36862 ++#define	SAFE_DMA_STAT		0x00cc	/* DMA Current Status */
36863 ++#define	SAFE_DMA_CFG		0x00d4	/* DMA Configuration/Status */
36864 ++#define	SAFE_ENDIAN		0x00e0	/* Endian Configuration */
36865 ++#define	SAFE_PK_A_ADDR		0x0800	/* Public Key A Address */
36866 ++#define	SAFE_PK_B_ADDR		0x0804	/* Public Key B Address */
36867 ++#define	SAFE_PK_C_ADDR		0x0808	/* Public Key C Address */
36868 ++#define	SAFE_PK_D_ADDR		0x080c	/* Public Key D Address */
36869 ++#define	SAFE_PK_A_LEN		0x0810	/* Public Key A Length */
36870 ++#define	SAFE_PK_B_LEN		0x0814	/* Public Key B Length */
36871 ++#define	SAFE_PK_SHIFT		0x0818	/* Public Key Shift */
36872 ++#define	SAFE_PK_FUNC		0x081c	/* Public Key Function */
36873 ++#define SAFE_PK_RAM_START	0x1000	/* Public Key RAM start address */
36874 ++#define SAFE_PK_RAM_END		0x1fff	/* Public Key RAM end address */
36875 ++
36876 ++#define	SAFE_RNG_OUT		0x0100	/* RNG Output */
36877 ++#define	SAFE_RNG_STAT		0x0104	/* RNG Status */
36878 ++#define	SAFE_RNG_CTRL		0x0108	/* RNG Control */
36879 ++#define	SAFE_RNG_A		0x010c	/* RNG A */
36880 ++#define	SAFE_RNG_B		0x0110	/* RNG B */
36881 ++#define	SAFE_RNG_X_LO		0x0114	/* RNG X [31:0] */
36882 ++#define	SAFE_RNG_X_MID		0x0118	/* RNG X [63:32] */
36883 ++#define	SAFE_RNG_X_HI		0x011c	/* RNG X [80:64] */
36884 ++#define	SAFE_RNG_X_CNTR		0x0120	/* RNG Counter */
36885 ++#define	SAFE_RNG_ALM_CNT	0x0124	/* RNG Alarm Count */
36886 ++#define	SAFE_RNG_CNFG		0x0128	/* RNG Configuration */
36887 ++#define	SAFE_RNG_LFSR1_LO	0x012c	/* RNG LFSR1 [31:0] */
36888 ++#define	SAFE_RNG_LFSR1_HI	0x0130	/* RNG LFSR1 [47:32] */
36889 ++#define	SAFE_RNG_LFSR2_LO	0x0134	/* RNG LFSR1 [31:0] */
36890 ++#define	SAFE_RNG_LFSR2_HI	0x0138	/* RNG LFSR1 [47:32] */
36891 ++
36892 ++#define	SAFE_PE_CSR_READY	0x00000001	/* ready for processing */
36893 ++#define	SAFE_PE_CSR_DONE	0x00000002	/* h/w completed processing */
36894 ++#define	SAFE_PE_CSR_LOADSA	0x00000004	/* load SA digests */
36895 ++#define	SAFE_PE_CSR_HASHFINAL	0x00000010	/* do hash pad & write result */
36896 ++#define	SAFE_PE_CSR_SABUSID	0x000000c0	/* bus id for SA */
36897 ++#define	SAFE_PE_CSR_SAPCI	0x00000040	/* PCI bus id for SA */
36898 ++#define	SAFE_PE_CSR_NXTHDR	0x0000ff00	/* next hdr value for IPsec */
36899 ++#define	SAFE_PE_CSR_FPAD	0x0000ff00	/* fixed pad for basic ops */
36900 ++#define	SAFE_PE_CSR_STATUS	0x00ff0000	/* operation result status */
36901 ++#define	SAFE_PE_CSR_AUTH_FAIL	0x00010000	/* ICV mismatch (inbound) */
36902 ++#define	SAFE_PE_CSR_PAD_FAIL	0x00020000	/* pad verify fail (inbound) */
36903 ++#define	SAFE_PE_CSR_SEQ_FAIL	0x00040000	/* sequence number (inbound) */
36904 ++#define	SAFE_PE_CSR_XERROR	0x00080000	/* extended error follows */
36905 ++#define	SAFE_PE_CSR_XECODE	0x00f00000	/* extended error code */
36906 ++#define	SAFE_PE_CSR_XECODE_S	20
36907 ++#define	SAFE_PE_CSR_XECODE_BADCMD	0	/* invalid command */
36908 ++#define	SAFE_PE_CSR_XECODE_BADALG	1	/* invalid algorithm */
36909 ++#define	SAFE_PE_CSR_XECODE_ALGDIS	2	/* algorithm disabled */
36910 ++#define	SAFE_PE_CSR_XECODE_ZEROLEN	3	/* zero packet length */
36911 ++#define	SAFE_PE_CSR_XECODE_DMAERR	4	/* bus DMA error */
36912 ++#define	SAFE_PE_CSR_XECODE_PIPEABORT	5	/* secondary bus DMA error */
36913 ++#define	SAFE_PE_CSR_XECODE_BADSPI	6	/* IPsec SPI mismatch */
36914 ++#define	SAFE_PE_CSR_XECODE_TIMEOUT	10	/* failsafe timeout */
36915 ++#define	SAFE_PE_CSR_PAD		0xff000000	/* ESP padding control/status */
36916 ++#define	SAFE_PE_CSR_PAD_MIN	0x00000000	/* minimum IPsec padding */
36917 ++#define	SAFE_PE_CSR_PAD_16	0x08000000	/* pad to 16-byte boundary */
36918 ++#define	SAFE_PE_CSR_PAD_32	0x10000000	/* pad to 32-byte boundary */
36919 ++#define	SAFE_PE_CSR_PAD_64	0x20000000	/* pad to 64-byte boundary */
36920 ++#define	SAFE_PE_CSR_PAD_128	0x40000000	/* pad to 128-byte boundary */
36921 ++#define	SAFE_PE_CSR_PAD_256	0x80000000	/* pad to 256-byte boundary */
36922 ++
36923 ++/*
36924 ++ * Check the CSR to see if the PE has returned ownership to
36925 ++ * the host.  Note that before processing a descriptor this
36926 ++ * must be done followed by a check of the SAFE_PE_LEN register
36927 ++ * status bits to avoid premature processing of a descriptor
36928 ++ * on its way back to the host.
36929 ++ */
36930 ++#define	SAFE_PE_CSR_IS_DONE(_csr) \
36931 ++    (((_csr) & (SAFE_PE_CSR_READY | SAFE_PE_CSR_DONE)) == SAFE_PE_CSR_DONE)
36932 ++
36933 ++#define	SAFE_PE_LEN_LENGTH	0x000fffff	/* total length (bytes) */
36934 ++#define	SAFE_PE_LEN_READY	0x00400000	/* ready for processing */
36935 ++#define	SAFE_PE_LEN_DONE	0x00800000	/* h/w completed processing */
36936 ++#define	SAFE_PE_LEN_BYPASS	0xff000000	/* bypass offset (bytes) */
36937 ++#define	SAFE_PE_LEN_BYPASS_S	24
36938 ++
36939 ++#define	SAFE_PE_LEN_IS_DONE(_len) \
36940 ++    (((_len) & (SAFE_PE_LEN_READY | SAFE_PE_LEN_DONE)) == SAFE_PE_LEN_DONE)
36941 ++
36942 ++/* NB: these apply to HU_STAT, HM_STAT, HI_CLR, and HI_MASK */
36943 ++#define	SAFE_INT_PE_CDONE	0x00000002	/* PE context done */
36944 ++#define	SAFE_INT_PE_DDONE	0x00000008	/* PE descriptor done */
36945 ++#define	SAFE_INT_PE_ERROR	0x00000010	/* PE error */
36946 ++#define	SAFE_INT_PE_ODONE	0x00000020	/* PE operation done */
36947 ++
36948 ++#define	SAFE_HI_CFG_PULSE	0x00000001	/* use pulse interrupt */
36949 ++#define	SAFE_HI_CFG_LEVEL	0x00000000	/* use level interrupt */
36950 ++#define	SAFE_HI_CFG_AUTOCLR	0x00000002	/* auto-clear pulse interrupt */
36951 ++
36952 ++#define	SAFE_ENDIAN_PASS	0x000000e4	/* straight pass-thru */
36953 ++#define	SAFE_ENDIAN_SWAB	0x0000001b	/* swap bytes in 32-bit word */
36954 ++
36955 ++#define	SAFE_PE_DMACFG_PERESET	0x00000001	/* reset packet engine */
36956 ++#define	SAFE_PE_DMACFG_PDRRESET	0x00000002	/* reset PDR counters/ptrs */
36957 ++#define	SAFE_PE_DMACFG_SGRESET	0x00000004	/* reset scatter/gather cache */
36958 ++#define	SAFE_PE_DMACFG_FSENA	0x00000008	/* enable failsafe reset */
36959 ++#define	SAFE_PE_DMACFG_PEMODE	0x00000100	/* packet engine mode */
36960 ++#define	SAFE_PE_DMACFG_SAPREC	0x00000200	/* SA precedes packet */
36961 ++#define	SAFE_PE_DMACFG_PKFOLL	0x00000400	/* packet follows descriptor */
36962 ++#define	SAFE_PE_DMACFG_GPRBID	0x00003000	/* gather particle ring busid */
36963 ++#define	SAFE_PE_DMACFG_GPRPCI	0x00001000	/* PCI gather particle ring */
36964 ++#define	SAFE_PE_DMACFG_SPRBID	0x0000c000	/* scatter part. ring busid */
36965 ++#define	SAFE_PE_DMACFG_SPRPCI	0x00004000	/* PCI scatter part. ring */
36966 ++#define	SAFE_PE_DMACFG_ESDESC	0x00010000	/* endian swap descriptors */
36967 ++#define	SAFE_PE_DMACFG_ESSA	0x00020000	/* endian swap SA data */
36968 ++#define	SAFE_PE_DMACFG_ESPACKET	0x00040000	/* endian swap packet data */
36969 ++#define	SAFE_PE_DMACFG_ESPDESC	0x00080000	/* endian swap particle desc. */
36970 ++#define	SAFE_PE_DMACFG_NOPDRUP	0x00100000	/* supp. PDR ownership update */
36971 ++#define	SAFE_PD_EDMACFG_PCIMODE	0x01000000	/* PCI target mode */
36972 ++
36973 ++#define	SAFE_PE_DMASTAT_PEIDONE	0x00000001	/* PE core input done */
36974 ++#define	SAFE_PE_DMASTAT_PEODONE	0x00000002	/* PE core output done */
36975 ++#define	SAFE_PE_DMASTAT_ENCDONE	0x00000004	/* encryption done */
36976 ++#define	SAFE_PE_DMASTAT_IHDONE	0x00000008	/* inner hash done */
36977 ++#define	SAFE_PE_DMASTAT_OHDONE	0x00000010	/* outer hash (HMAC) done */
36978 ++#define	SAFE_PE_DMASTAT_PADFLT	0x00000020	/* crypto pad fault */
36979 ++#define	SAFE_PE_DMASTAT_ICVFLT	0x00000040	/* ICV fault */
36980 ++#define	SAFE_PE_DMASTAT_SPIMIS	0x00000080	/* SPI mismatch */
36981 ++#define	SAFE_PE_DMASTAT_CRYPTO	0x00000100	/* crypto engine timeout */
36982 ++#define	SAFE_PE_DMASTAT_CQACT	0x00000200	/* command queue active */
36983 ++#define	SAFE_PE_DMASTAT_IRACT	0x00000400	/* input request active */
36984 ++#define	SAFE_PE_DMASTAT_ORACT	0x00000800	/* output request active */
36985 ++#define	SAFE_PE_DMASTAT_PEISIZE	0x003ff000	/* PE input size:32-bit words */
36986 ++#define	SAFE_PE_DMASTAT_PEOSIZE	0xffc00000	/* PE out. size:32-bit words */
36987 ++
36988 ++#define	SAFE_PE_RINGCFG_SIZE	0x000003ff	/* ring size (descriptors) */
36989 ++#define	SAFE_PE_RINGCFG_OFFSET	0xffff0000	/* offset btw desc's (dwords) */
36990 ++#define	SAFE_PE_RINGCFG_OFFSET_S	16
36991 ++
36992 ++#define	SAFE_PE_RINGPOLL_POLL	0x00000fff	/* polling frequency/divisor */
36993 ++#define	SAFE_PE_RINGPOLL_RETRY	0x03ff0000	/* polling frequency/divisor */
36994 ++#define	SAFE_PE_RINGPOLL_CONT	0x80000000	/* continuously poll */
36995 ++
36996 ++#define	SAFE_PE_IRNGSTAT_CQAVAIL 0x00000001	/* command queue available */
36997 ++
36998 ++#define	SAFE_PE_ERNGSTAT_NEXT	0x03ff0000	/* index of next packet desc. */
36999 ++#define	SAFE_PE_ERNGSTAT_NEXT_S	16
37000 ++
37001 ++#define	SAFE_PE_IOTHRESH_INPUT	0x000003ff	/* input threshold (dwords) */
37002 ++#define	SAFE_PE_IOTHRESH_OUTPUT	0x03ff0000	/* output threshold (dwords) */
37003 ++
37004 ++#define	SAFE_PE_PARTCFG_SIZE	0x0000ffff	/* scatter particle size */
37005 ++#define	SAFE_PE_PARTCFG_GBURST	0x00030000	/* gather particle burst */
37006 ++#define	SAFE_PE_PARTCFG_GBURST_2	0x00000000
37007 ++#define	SAFE_PE_PARTCFG_GBURST_4	0x00010000
37008 ++#define	SAFE_PE_PARTCFG_GBURST_8	0x00020000
37009 ++#define	SAFE_PE_PARTCFG_GBURST_16	0x00030000
37010 ++#define	SAFE_PE_PARTCFG_SBURST	0x000c0000	/* scatter particle burst */
37011 ++#define	SAFE_PE_PARTCFG_SBURST_2	0x00000000
37012 ++#define	SAFE_PE_PARTCFG_SBURST_4	0x00040000
37013 ++#define	SAFE_PE_PARTCFG_SBURST_8	0x00080000
37014 ++#define	SAFE_PE_PARTCFG_SBURST_16	0x000c0000
37015 ++
37016 ++#define	SAFE_PE_PARTSIZE_SCAT	0xffff0000	/* scatter particle ring size */
37017 ++#define	SAFE_PE_PARTSIZE_GATH	0x0000ffff	/* gather particle ring size */
37018 ++
37019 ++#define	SAFE_CRYPTO_CTRL_3DES	0x00000001	/* enable 3DES support */
37020 ++#define	SAFE_CRYPTO_CTRL_PKEY	0x00010000	/* enable public key support */
37021 ++#define	SAFE_CRYPTO_CTRL_RNG	0x00020000	/* enable RNG support */
37022 ++
37023 ++#define	SAFE_DEVINFO_REV_MIN	0x0000000f	/* minor rev for chip */
37024 ++#define	SAFE_DEVINFO_REV_MAJ	0x000000f0	/* major rev for chip */
37025 ++#define	SAFE_DEVINFO_REV_MAJ_S	4
37026 ++#define	SAFE_DEVINFO_DES	0x00000100	/* DES/3DES support present */
37027 ++#define	SAFE_DEVINFO_ARC4	0x00000200	/* ARC4 support present */
37028 ++#define	SAFE_DEVINFO_AES	0x00000400	/* AES support present */
37029 ++#define	SAFE_DEVINFO_MD5	0x00001000	/* MD5 support present */
37030 ++#define	SAFE_DEVINFO_SHA1	0x00002000	/* SHA-1 support present */
37031 ++#define	SAFE_DEVINFO_RIPEMD	0x00004000	/* RIPEMD support present */
37032 ++#define	SAFE_DEVINFO_DEFLATE	0x00010000	/* Deflate support present */
37033 ++#define	SAFE_DEVINFO_SARAM	0x00100000	/* on-chip SA RAM present */
37034 ++#define	SAFE_DEVINFO_EMIBUS	0x00200000	/* EMI bus present */
37035 ++#define	SAFE_DEVINFO_PKEY	0x00400000	/* public key support present */
37036 ++#define	SAFE_DEVINFO_RNG	0x00800000	/* RNG present */
37037 ++
37038 ++#define	SAFE_REV(_maj, _min)	(((_maj) << SAFE_DEVINFO_REV_MAJ_S) | (_min))
37039 ++#define	SAFE_REV_MAJ(_chiprev) \
37040 ++	(((_chiprev) & SAFE_DEVINFO_REV_MAJ) >> SAFE_DEVINFO_REV_MAJ_S)
37041 ++#define	SAFE_REV_MIN(_chiprev)	((_chiprev) & SAFE_DEVINFO_REV_MIN)
37042 ++
37043 ++#define	SAFE_PK_FUNC_MULT	0x00000001	/* Multiply function */
37044 ++#define	SAFE_PK_FUNC_SQUARE	0x00000004	/* Square function */
37045 ++#define	SAFE_PK_FUNC_ADD	0x00000010	/* Add function */
37046 ++#define	SAFE_PK_FUNC_SUB	0x00000020	/* Subtract function */
37047 ++#define	SAFE_PK_FUNC_LSHIFT	0x00000040	/* Left-shift function */
37048 ++#define	SAFE_PK_FUNC_RSHIFT	0x00000080	/* Right-shift function */
37049 ++#define	SAFE_PK_FUNC_DIV	0x00000100	/* Divide function */
37050 ++#define	SAFE_PK_FUNC_CMP	0x00000400	/* Compare function */
37051 ++#define	SAFE_PK_FUNC_COPY	0x00000800	/* Copy function */
37052 ++#define	SAFE_PK_FUNC_EXP16	0x00002000	/* Exponentiate (4-bit ACT) */
37053 ++#define	SAFE_PK_FUNC_EXP4	0x00004000	/* Exponentiate (2-bit ACT) */
37054 ++#define	SAFE_PK_FUNC_RUN	0x00008000	/* start/status */
37055 ++
37056 ++#define	SAFE_RNG_STAT_BUSY	0x00000001	/* busy, data not valid */
37057 ++
37058 ++#define	SAFE_RNG_CTRL_PRE_LFSR	0x00000001	/* enable output pre-LFSR */
37059 ++#define	SAFE_RNG_CTRL_TST_MODE	0x00000002	/* enable test mode */
37060 ++#define	SAFE_RNG_CTRL_TST_RUN	0x00000004	/* start test state machine */
37061 ++#define	SAFE_RNG_CTRL_ENA_RING1	0x00000008	/* test entropy oscillator #1 */
37062 ++#define	SAFE_RNG_CTRL_ENA_RING2	0x00000010	/* test entropy oscillator #2 */
37063 ++#define	SAFE_RNG_CTRL_DIS_ALARM	0x00000020	/* disable RNG alarm reports */
37064 ++#define	SAFE_RNG_CTRL_TST_CLOCK	0x00000040	/* enable test clock */
37065 ++#define	SAFE_RNG_CTRL_SHORTEN	0x00000080	/* shorten state timers */
37066 ++#define	SAFE_RNG_CTRL_TST_ALARM	0x00000100	/* simulate alarm state */
37067 ++#define	SAFE_RNG_CTRL_RST_LFSR	0x00000200	/* reset LFSR */
37068 ++
37069 ++/*
37070 ++ * Packet engine descriptor.  Note that d_csr is a copy of the
37071 ++ * SAFE_PE_CSR register and all definitions apply, and d_len
37072 ++ * is a copy of the SAFE_PE_LEN register and all definitions apply.
37073 ++ * d_src and d_len may point directly to contiguous data or to a
37074 ++ * list of ``particle descriptors'' when using scatter/gather i/o.
37075 ++ */
37076 ++struct safe_desc {
37077 ++	u_int32_t	d_csr;			/* per-packet control/status */
37078 ++	u_int32_t	d_src;			/* source address */
37079 ++	u_int32_t	d_dst;			/* destination address */
37080 ++	u_int32_t	d_sa;			/* SA address */
37081 ++	u_int32_t	d_len;			/* length, bypass, status */
37082 ++};
37083 ++
37084 ++/*
37085 ++ * Scatter/Gather particle descriptor.
37086 ++ *
37087 ++ * NB: scatter descriptors do not specify a size; this is fixed
37088 ++ *     by the setting of the SAFE_PE_PARTCFG register.
37089 ++ */
37090 ++struct safe_pdesc {
37091 ++	u_int32_t	pd_addr;		/* particle address */
37092 ++#ifdef __BIG_ENDIAN
37093 ++	u_int16_t	pd_flags;		/* control word */
37094 ++	u_int16_t	pd_size;		/* particle size (bytes) */
37095 ++#else
37096 ++	u_int16_t	pd_flags;		/* control word */
37097 ++	u_int16_t	pd_size;		/* particle size (bytes) */
37098 ++#endif
37099 ++};
37100 ++
37101 ++#define	SAFE_PD_READY	0x0001			/* ready for processing */
37102 ++#define	SAFE_PD_DONE	0x0002			/* h/w completed processing */
37103 ++
37104 ++/*
37105 ++ * Security Association (SA) Record (Rev 1).  One of these is
37106 ++ * required for each operation processed by the packet engine.
37107 ++ */
37108 ++struct safe_sarec {
37109 ++	u_int32_t	sa_cmd0;
37110 ++	u_int32_t	sa_cmd1;
37111 ++	u_int32_t	sa_resv0;
37112 ++	u_int32_t	sa_resv1;
37113 ++	u_int32_t	sa_key[8];		/* DES/3DES/AES key */
37114 ++	u_int32_t	sa_indigest[5];		/* inner digest */
37115 ++	u_int32_t	sa_outdigest[5];	/* outer digest */
37116 ++	u_int32_t	sa_spi;			/* SPI */
37117 ++	u_int32_t	sa_seqnum;		/* sequence number */
37118 ++	u_int32_t	sa_seqmask[2];		/* sequence number mask */
37119 ++	u_int32_t	sa_resv2;
37120 ++	u_int32_t	sa_staterec;		/* address of state record */
37121 ++	u_int32_t	sa_resv3[2];
37122 ++	u_int32_t	sa_samgmt0;		/* SA management field 0 */
37123 ++	u_int32_t	sa_samgmt1;		/* SA management field 0 */
37124 ++};
37125 ++
37126 ++#define	SAFE_SA_CMD0_OP		0x00000007	/* operation code */
37127 ++#define	SAFE_SA_CMD0_OP_CRYPT	0x00000000	/* encrypt/decrypt (basic) */
37128 ++#define	SAFE_SA_CMD0_OP_BOTH	0x00000001	/* encrypt-hash/hash-decrypto */
37129 ++#define	SAFE_SA_CMD0_OP_HASH	0x00000003	/* hash (outbound-only) */
37130 ++#define	SAFE_SA_CMD0_OP_ESP	0x00000000	/* ESP in/out (proto) */
37131 ++#define	SAFE_SA_CMD0_OP_AH	0x00000001	/* AH in/out (proto) */
37132 ++#define	SAFE_SA_CMD0_INBOUND	0x00000008	/* inbound operation */
37133 ++#define	SAFE_SA_CMD0_OUTBOUND	0x00000000	/* outbound operation */
37134 ++#define	SAFE_SA_CMD0_GROUP	0x00000030	/* operation group */
37135 ++#define	SAFE_SA_CMD0_BASIC	0x00000000	/* basic operation */
37136 ++#define	SAFE_SA_CMD0_PROTO	0x00000010	/* protocol/packet operation */
37137 ++#define	SAFE_SA_CMD0_BUNDLE	0x00000020	/* bundled operation (resvd) */
37138 ++#define	SAFE_SA_CMD0_PAD	0x000000c0	/* crypto pad method */
37139 ++#define	SAFE_SA_CMD0_PAD_IPSEC	0x00000000	/* IPsec padding */
37140 ++#define	SAFE_SA_CMD0_PAD_PKCS7	0x00000040	/* PKCS#7 padding */
37141 ++#define	SAFE_SA_CMD0_PAD_CONS	0x00000080	/* constant padding */
37142 ++#define	SAFE_SA_CMD0_PAD_ZERO	0x000000c0	/* zero padding */
37143 ++#define	SAFE_SA_CMD0_CRYPT_ALG	0x00000f00	/* symmetric crypto algorithm */
37144 ++#define	SAFE_SA_CMD0_DES	0x00000000	/* DES crypto algorithm */
37145 ++#define	SAFE_SA_CMD0_3DES	0x00000100	/* 3DES crypto algorithm */
37146 ++#define	SAFE_SA_CMD0_AES	0x00000300	/* AES crypto algorithm */
37147 ++#define	SAFE_SA_CMD0_CRYPT_NULL	0x00000f00	/* null crypto algorithm */
37148 ++#define	SAFE_SA_CMD0_HASH_ALG	0x0000f000	/* hash algorithm */
37149 ++#define	SAFE_SA_CMD0_MD5	0x00000000	/* MD5 hash algorithm */
37150 ++#define	SAFE_SA_CMD0_SHA1	0x00001000	/* SHA-1 hash algorithm */
37151 ++#define	SAFE_SA_CMD0_HASH_NULL	0x0000f000	/* null hash algorithm */
37152 ++#define	SAFE_SA_CMD0_HDR_PROC	0x00080000	/* header processing */
37153 ++#define	SAFE_SA_CMD0_IBUSID	0x00300000	/* input bus id */
37154 ++#define	SAFE_SA_CMD0_IPCI	0x00100000	/* PCI input bus id */
37155 ++#define	SAFE_SA_CMD0_OBUSID	0x00c00000	/* output bus id */
37156 ++#define	SAFE_SA_CMD0_OPCI	0x00400000	/* PCI output bus id */
37157 ++#define	SAFE_SA_CMD0_IVLD	0x03000000	/* IV loading */
37158 ++#define	SAFE_SA_CMD0_IVLD_NONE	0x00000000	/* IV no load (reuse) */
37159 ++#define	SAFE_SA_CMD0_IVLD_IBUF	0x01000000	/* IV load from input buffer */
37160 ++#define	SAFE_SA_CMD0_IVLD_STATE	0x02000000	/* IV load from state */
37161 ++#define	SAFE_SA_CMD0_HSLD	0x0c000000	/* hash state loading */
37162 ++#define	SAFE_SA_CMD0_HSLD_SA	0x00000000	/* hash state load from SA */
37163 ++#define	SAFE_SA_CMD0_HSLD_STATE	0x08000000	/* hash state load from state */
37164 ++#define	SAFE_SA_CMD0_HSLD_NONE	0x0c000000	/* hash state no load */
37165 ++#define	SAFE_SA_CMD0_SAVEIV	0x10000000	/* save IV */
37166 ++#define	SAFE_SA_CMD0_SAVEHASH	0x20000000	/* save hash state */
37167 ++#define	SAFE_SA_CMD0_IGATHER	0x40000000	/* input gather */
37168 ++#define	SAFE_SA_CMD0_OSCATTER	0x80000000	/* output scatter */
37169 ++
37170 ++#define	SAFE_SA_CMD1_HDRCOPY	0x00000002	/* copy header to output */
37171 ++#define	SAFE_SA_CMD1_PAYCOPY	0x00000004	/* copy payload to output */
37172 ++#define	SAFE_SA_CMD1_PADCOPY	0x00000008	/* copy pad to output */
37173 ++#define	SAFE_SA_CMD1_IPV4	0x00000000	/* IPv4 protocol */
37174 ++#define	SAFE_SA_CMD1_IPV6	0x00000010	/* IPv6 protocol */
37175 ++#define	SAFE_SA_CMD1_MUTABLE	0x00000020	/* mutable bit processing */
37176 ++#define	SAFE_SA_CMD1_SRBUSID	0x000000c0	/* state record bus id */
37177 ++#define	SAFE_SA_CMD1_SRPCI	0x00000040	/* state record from PCI */
37178 ++#define	SAFE_SA_CMD1_CRMODE	0x00000300	/* crypto mode */
37179 ++#define	SAFE_SA_CMD1_ECB	0x00000000	/* ECB crypto mode */
37180 ++#define	SAFE_SA_CMD1_CBC	0x00000100	/* CBC crypto mode */
37181 ++#define	SAFE_SA_CMD1_OFB	0x00000200	/* OFB crypto mode */
37182 ++#define	SAFE_SA_CMD1_CFB	0x00000300	/* CFB crypto mode */
37183 ++#define	SAFE_SA_CMD1_CRFEEDBACK	0x00000c00	/* crypto feedback mode */
37184 ++#define	SAFE_SA_CMD1_64BIT	0x00000000	/* 64-bit crypto feedback */
37185 ++#define	SAFE_SA_CMD1_8BIT	0x00000400	/* 8-bit crypto feedback */
37186 ++#define	SAFE_SA_CMD1_1BIT	0x00000800	/* 1-bit crypto feedback */
37187 ++#define	SAFE_SA_CMD1_128BIT	0x00000c00	/* 128-bit crypto feedback */
37188 ++#define	SAFE_SA_CMD1_OPTIONS	0x00001000	/* HMAC/options mutable bit */
37189 ++#define	SAFE_SA_CMD1_HMAC	SAFE_SA_CMD1_OPTIONS
37190 ++#define	SAFE_SA_CMD1_SAREV1	0x00008000	/* SA Revision 1 */
37191 ++#define	SAFE_SA_CMD1_OFFSET	0x00ff0000	/* hash/crypto offset(dwords) */
37192 ++#define	SAFE_SA_CMD1_OFFSET_S	16
37193 ++#define	SAFE_SA_CMD1_AESKEYLEN	0x0f000000	/* AES key length */
37194 ++#define	SAFE_SA_CMD1_AES128	0x02000000	/* 128-bit AES key */
37195 ++#define	SAFE_SA_CMD1_AES192	0x03000000	/* 192-bit AES key */
37196 ++#define	SAFE_SA_CMD1_AES256	0x04000000	/* 256-bit AES key */
37197 ++
37198 ++/* 
37199 ++ * Security Associate State Record (Rev 1).
37200 ++ */
37201 ++struct safe_sastate {
37202 ++	u_int32_t	sa_saved_iv[4];		/* saved IV (DES/3DES/AES) */
37203 ++	u_int32_t	sa_saved_hashbc;	/* saved hash byte count */
37204 ++	u_int32_t	sa_saved_indigest[5];	/* saved inner digest */
37205 ++};
37206 ++#endif /* _SAFE_SAFEREG_H_ */
37207 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/safevar.h linux-2.6.23.16/crypto/ocf/safe/safevar.h
37208 +--- linux-2.6.23.16.old/crypto/ocf/safe/safevar.h	1969-12-31 19:00:00.000000000 -0500
37209 ++++ linux-2.6.23.16/crypto/ocf/safe/safevar.h	2008-02-26 09:29:13.000000000 -0500
37210 +@@ -0,0 +1,230 @@
37211 ++/*-
37212 ++ * The linux port of this code done by David McCullough
37213 ++ * Copyright (C) 2004-2007 David McCullough <david_mccullough@securecomputing.com>
37214 ++ * The license and original author are listed below.
37215 ++ *
37216 ++ * Copyright (c) 2003 Sam Leffler, Errno Consulting
37217 ++ * Copyright (c) 2003 Global Technology Associates, Inc.
37218 ++ * All rights reserved.
37219 ++ *
37220 ++ * Redistribution and use in source and binary forms, with or without
37221 ++ * modification, are permitted provided that the following conditions
37222 ++ * are met:
37223 ++ * 1. Redistributions of source code must retain the above copyright
37224 ++ *    notice, this list of conditions and the following disclaimer.
37225 ++ * 2. Redistributions in binary form must reproduce the above copyright
37226 ++ *    notice, this list of conditions and the following disclaimer in the
37227 ++ *    documentation and/or other materials provided with the distribution.
37228 ++ *
37229 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37230 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37231 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37232 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
37233 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37234 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37235 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37236 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37237 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37238 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37239 ++ * SUCH DAMAGE.
37240 ++ *
37241 ++ * $FreeBSD: src/sys/dev/safe/safevar.h,v 1.2 2006/05/17 18:34:26 pjd Exp $
37242 ++ */
37243 ++#ifndef _SAFE_SAFEVAR_H_
37244 ++#define	_SAFE_SAFEVAR_H_
37245 ++
37246 ++/* Maximum queue length */
37247 ++#ifndef SAFE_MAX_NQUEUE
37248 ++#define SAFE_MAX_NQUEUE	60
37249 ++#endif
37250 ++
37251 ++#define	SAFE_MAX_PART		64	/* Maximum scatter/gather depth */
37252 ++#define	SAFE_DMA_BOUNDARY	0	/* No boundary for source DMA ops */
37253 ++#define	SAFE_MAX_DSIZE		2048 /* MCLBYTES Fixed scatter particle size */
37254 ++#define	SAFE_MAX_SSIZE		0x0ffff	/* Maximum gather particle size */
37255 ++#define	SAFE_MAX_DMA		0xfffff	/* Maximum PE operand size (20 bits) */
37256 ++/* total src+dst particle descriptors */
37257 ++#define	SAFE_TOTAL_DPART	(SAFE_MAX_NQUEUE * SAFE_MAX_PART)
37258 ++#define	SAFE_TOTAL_SPART	(SAFE_MAX_NQUEUE * SAFE_MAX_PART)
37259 ++
37260 ++#define	SAFE_RNG_MAXBUFSIZ	128	/* 32-bit words */
37261 ++
37262 ++#define	SAFE_CARD(sid)		(((sid) & 0xf0000000) >> 28)
37263 ++#define	SAFE_SESSION(sid)	( (sid) & 0x0fffffff)
37264 ++#define	SAFE_SID(crd, sesn)	(((crd) << 28) | ((sesn) & 0x0fffffff))
37265 ++
37266 ++#define SAFE_DEF_RTY		0xff	/* PCI Retry Timeout */
37267 ++#define SAFE_DEF_TOUT		0xff	/* PCI TRDY Timeout */
37268 ++#define SAFE_DEF_CACHELINE	0x01	/* Cache Line setting */
37269 ++
37270 ++#ifdef __KERNEL__
37271 ++/*
37272 ++ * State associated with the allocation of each chunk
37273 ++ * of memory setup for DMA.
37274 ++ */
37275 ++struct safe_dma_alloc {
37276 ++	dma_addr_t		dma_paddr;
37277 ++	void			*dma_vaddr;
37278 ++};
37279 ++
37280 ++/*
37281 ++ * Cryptographic operand state.  One of these exists for each
37282 ++ * source and destination operand passed in from the crypto
37283 ++ * subsystem.  When possible source and destination operands
37284 ++ * refer to the same memory.  More often they are distinct.
37285 ++ * We track the virtual address of each operand as well as
37286 ++ * where each is mapped for DMA.
37287 ++ */
37288 ++struct safe_operand {
37289 ++	union {
37290 ++		struct sk_buff *skb;
37291 ++		struct uio *io;
37292 ++	} u;
37293 ++	void			*map;
37294 ++	int				mapsize;	/* total number of bytes in segs */
37295 ++	struct {
37296 ++		dma_addr_t	ds_addr;
37297 ++		int			ds_len;
37298 ++		int			ds_tlen;
37299 ++	} segs[SAFE_MAX_PART];
37300 ++	int				nsegs;
37301 ++};
37302 ++
37303 ++/*
37304 ++ * Packet engine ring entry and cryptographic operation state.
37305 ++ * The packet engine requires a ring of descriptors that contain
37306 ++ * pointers to various cryptographic state.  However the ring
37307 ++ * configuration register allows you to specify an arbitrary size
37308 ++ * for ring entries.  We use this feature to collect most of the
37309 ++ * state for each cryptographic request into one spot.  Other than
37310 ++ * ring entries only the ``particle descriptors'' (scatter/gather
37311 ++ * lists) and the actual operand data are kept separate.  The
37312 ++ * particle descriptors must also be organized in rings.  The
37313 ++ * operand data can be located aribtrarily (modulo alignment constraints).
37314 ++ *
37315 ++ * Note that the descriptor ring is mapped onto the PCI bus so
37316 ++ * the hardware can DMA data.  This means the entire ring must be
37317 ++ * contiguous.
37318 ++ */
37319 ++struct safe_ringentry {
37320 ++	struct safe_desc	re_desc;	/* command descriptor */
37321 ++	struct safe_sarec	re_sa;		/* SA record */
37322 ++	struct safe_sastate	re_sastate;	/* SA state record */
37323 ++
37324 ++	struct cryptop		*re_crp;	/* crypto operation */
37325 ++
37326 ++	struct safe_operand	re_src;		/* source operand */
37327 ++	struct safe_operand	re_dst;		/* destination operand */
37328 ++
37329 ++	int			re_sesn;	/* crypto session ID */
37330 ++	int			re_flags;
37331 ++#define	SAFE_QFLAGS_COPYOUTIV	0x1		/* copy back on completion */
37332 ++#define	SAFE_QFLAGS_COPYOUTICV	0x2		/* copy back on completion */
37333 ++};
37334 ++
37335 ++#define	re_src_skb	re_src.u.skb
37336 ++#define	re_src_io	re_src.u.io
37337 ++#define	re_src_map	re_src.map
37338 ++#define	re_src_nsegs	re_src.nsegs
37339 ++#define	re_src_segs	re_src.segs
37340 ++#define	re_src_mapsize	re_src.mapsize
37341 ++
37342 ++#define	re_dst_skb	re_dst.u.skb
37343 ++#define	re_dst_io	re_dst.u.io
37344 ++#define	re_dst_map	re_dst.map
37345 ++#define	re_dst_nsegs	re_dst.nsegs
37346 ++#define	re_dst_segs	re_dst.segs
37347 ++#define	re_dst_mapsize	re_dst.mapsize
37348 ++
37349 ++struct rndstate_test;
37350 ++
37351 ++struct safe_session {
37352 ++	u_int32_t	ses_used;
37353 ++	u_int32_t	ses_klen;		/* key length in bits */
37354 ++	u_int32_t	ses_key[8];		/* DES/3DES/AES key */
37355 ++	u_int32_t	ses_mlen;		/* hmac length in bytes */
37356 ++	u_int32_t	ses_hminner[5];		/* hmac inner state */
37357 ++	u_int32_t	ses_hmouter[5];		/* hmac outer state */
37358 ++	u_int32_t	ses_iv[4];		/* DES/3DES/AES iv */
37359 ++};
37360 ++
37361 ++struct safe_pkq {
37362 ++	struct list_head	pkq_list;
37363 ++	struct cryptkop		*pkq_krp;
37364 ++};
37365 ++
37366 ++struct safe_softc {
37367 ++	softc_device_decl	sc_dev;
37368 ++	u32			sc_irq;
37369 ++
37370 ++	struct pci_dev		*sc_pcidev;
37371 ++	ocf_iomem_t		sc_base_addr;
37372 ++
37373 ++	u_int			sc_chiprev;	/* major/minor chip revision */
37374 ++	int			sc_flags;	/* device specific flags */
37375 ++#define	SAFE_FLAGS_KEY		0x01		/* has key accelerator */
37376 ++#define	SAFE_FLAGS_RNG		0x02		/* hardware rng */
37377 ++	int			sc_suspended;
37378 ++	int			sc_needwakeup;	/* notify crypto layer */
37379 ++	int32_t			sc_cid;		/* crypto tag */
37380 ++
37381 ++	struct safe_dma_alloc	sc_ringalloc;	/* PE ring allocation state */
37382 ++	struct safe_ringentry	*sc_ring;	/* PE ring */
37383 ++	struct safe_ringentry	*sc_ringtop;	/* PE ring top */
37384 ++	struct safe_ringentry	*sc_front;	/* next free entry */
37385 ++	struct safe_ringentry	*sc_back;	/* next pending entry */
37386 ++	int			sc_nqchip;	/* # passed to chip */
37387 ++	spinlock_t		sc_ringmtx;	/* PE ring lock */
37388 ++	struct safe_pdesc	*sc_spring;	/* src particle ring */
37389 ++	struct safe_pdesc	*sc_springtop;	/* src particle ring top */
37390 ++	struct safe_pdesc	*sc_spfree;	/* next free src particle */
37391 ++	struct safe_dma_alloc	sc_spalloc;	/* src particle ring state */
37392 ++	struct safe_pdesc	*sc_dpring;	/* dest particle ring */
37393 ++	struct safe_pdesc	*sc_dpringtop;	/* dest particle ring top */
37394 ++	struct safe_pdesc	*sc_dpfree;	/* next free dest particle */
37395 ++	struct safe_dma_alloc	sc_dpalloc;	/* dst particle ring state */
37396 ++	int			sc_nsessions;	/* # of sessions */
37397 ++	struct safe_session	*sc_sessions;	/* sessions */
37398 ++
37399 ++	struct timer_list	sc_pkto;	/* PK polling */
37400 ++	spinlock_t		sc_pkmtx;	/* PK lock */
37401 ++	struct list_head	sc_pkq;		/* queue of PK requests */
37402 ++	struct safe_pkq		*sc_pkq_cur;	/* current processing request */
37403 ++	u_int32_t		sc_pk_reslen, sc_pk_resoff;
37404 ++
37405 ++	int			sc_max_dsize;	/* maximum safe DMA size */
37406 ++};
37407 ++#endif /* __KERNEL__ */
37408 ++
37409 ++struct safe_stats {
37410 ++	u_int64_t st_ibytes;
37411 ++	u_int64_t st_obytes;
37412 ++	u_int32_t st_ipackets;
37413 ++	u_int32_t st_opackets;
37414 ++	u_int32_t st_invalid;		/* invalid argument */
37415 ++	u_int32_t st_badsession;	/* invalid session id */
37416 ++	u_int32_t st_badflags;		/* flags indicate !(mbuf | uio) */
37417 ++	u_int32_t st_nodesc;		/* op submitted w/o descriptors */
37418 ++	u_int32_t st_badalg;		/* unsupported algorithm */
37419 ++	u_int32_t st_ringfull;		/* PE descriptor ring full */
37420 ++	u_int32_t st_peoperr;		/* PE marked error */
37421 ++	u_int32_t st_dmaerr;		/* PE DMA error */
37422 ++	u_int32_t st_bypasstoobig;	/* bypass > 96 bytes */
37423 ++	u_int32_t st_skipmismatch;	/* enc part begins before auth part */
37424 ++	u_int32_t st_lenmismatch;	/* enc length different auth length */
37425 ++	u_int32_t st_coffmisaligned;	/* crypto offset not 32-bit aligned */
37426 ++	u_int32_t st_cofftoobig;	/* crypto offset > 255 words */
37427 ++	u_int32_t st_iovmisaligned;	/* iov op not aligned */
37428 ++	u_int32_t st_iovnotuniform;	/* iov op not suitable */
37429 ++	u_int32_t st_unaligned;		/* unaligned src caused copy */
37430 ++	u_int32_t st_notuniform;	/* non-uniform src caused copy */
37431 ++	u_int32_t st_nomap;		/* bus_dmamap_create failed */
37432 ++	u_int32_t st_noload;		/* bus_dmamap_load_* failed */
37433 ++	u_int32_t st_nombuf;		/* MGET* failed */
37434 ++	u_int32_t st_nomcl;		/* MCLGET* failed */
37435 ++	u_int32_t st_maxqchip;		/* max mcr1 ops out for processing */
37436 ++	u_int32_t st_rng;		/* RNG requests */
37437 ++	u_int32_t st_rngalarm;		/* RNG alarm requests */
37438 ++	u_int32_t st_noicvcopy;		/* ICV data copies suppressed */
37439 ++};
37440 ++#endif /* _SAFE_SAFEVAR_H_ */
37441 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/sha1.c linux-2.6.23.16/crypto/ocf/safe/sha1.c
37442 +--- linux-2.6.23.16.old/crypto/ocf/safe/sha1.c	1969-12-31 19:00:00.000000000 -0500
37443 ++++ linux-2.6.23.16/crypto/ocf/safe/sha1.c	2008-02-26 09:29:13.000000000 -0500
37444 +@@ -0,0 +1,279 @@
37445 ++/*	$KAME: sha1.c,v 1.5 2000/11/08 06:13:08 itojun Exp $	*/
37446 ++/*
37447 ++ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
37448 ++ * All rights reserved.
37449 ++ *
37450 ++ * Redistribution and use in source and binary forms, with or without
37451 ++ * modification, are permitted provided that the following conditions
37452 ++ * are met:
37453 ++ * 1. Redistributions of source code must retain the above copyright
37454 ++ *    notice, this list of conditions and the following disclaimer.
37455 ++ * 2. Redistributions in binary form must reproduce the above copyright
37456 ++ *    notice, this list of conditions and the following disclaimer in the
37457 ++ *    documentation and/or other materials provided with the distribution.
37458 ++ * 3. Neither the name of the project nor the names of its contributors
37459 ++ *    may be used to endorse or promote products derived from this software
37460 ++ *    without specific prior written permission.
37461 ++ *
37462 ++ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
37463 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37464 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37465 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
37466 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37467 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37468 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37469 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37470 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37471 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37472 ++ * SUCH DAMAGE.
37473 ++ */
37474 ++
37475 ++/*
37476 ++ * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
37477 ++ * based on: http://csrc.nist.gov/fips/fip180-1.txt
37478 ++ * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
37479 ++ */
37480 ++
37481 ++#if 0
37482 ++#include <sys/cdefs.h>
37483 ++__FBSDID("$FreeBSD: src/sys/crypto/sha1.c,v 1.9 2003/06/10 21:36:57 obrien Exp $");
37484 ++
37485 ++#include <sys/types.h>
37486 ++#include <sys/cdefs.h>
37487 ++#include <sys/time.h>
37488 ++#include <sys/systm.h>
37489 ++
37490 ++#include <crypto/sha1.h>
37491 ++#endif
37492 ++
37493 ++/* sanity check */
37494 ++#if BYTE_ORDER != BIG_ENDIAN
37495 ++# if BYTE_ORDER != LITTLE_ENDIAN
37496 ++#  define unsupported 1
37497 ++# endif
37498 ++#endif
37499 ++
37500 ++#ifndef unsupported
37501 ++
37502 ++/* constant table */
37503 ++static u_int32_t _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
37504 ++#define	K(t)	_K[(t) / 20]
37505 ++
37506 ++#define	F0(b, c, d)	(((b) & (c)) | ((~(b)) & (d)))
37507 ++#define	F1(b, c, d)	(((b) ^ (c)) ^ (d))
37508 ++#define	F2(b, c, d)	(((b) & (c)) | ((b) & (d)) | ((c) & (d)))
37509 ++#define	F3(b, c, d)	(((b) ^ (c)) ^ (d))
37510 ++
37511 ++#define	S(n, x)		(((x) << (n)) | ((x) >> (32 - n)))
37512 ++
37513 ++#undef H
37514 ++#define	H(n)	(ctxt->h.b32[(n)])
37515 ++#define	COUNT	(ctxt->count)
37516 ++#define	BCOUNT	(ctxt->c.b64[0] / 8)
37517 ++#define	W(n)	(ctxt->m.b32[(n)])
37518 ++
37519 ++#define	PUTBYTE(x)	{ \
37520 ++	ctxt->m.b8[(COUNT % 64)] = (x);		\
37521 ++	COUNT++;				\
37522 ++	COUNT %= 64;				\
37523 ++	ctxt->c.b64[0] += 8;			\
37524 ++	if (COUNT % 64 == 0)			\
37525 ++		sha1_step(ctxt);		\
37526 ++     }
37527 ++
37528 ++#define	PUTPAD(x)	{ \
37529 ++	ctxt->m.b8[(COUNT % 64)] = (x);		\
37530 ++	COUNT++;				\
37531 ++	COUNT %= 64;				\
37532 ++	if (COUNT % 64 == 0)			\
37533 ++		sha1_step(ctxt);		\
37534 ++     }
37535 ++
37536 ++static void sha1_step(struct sha1_ctxt *);
37537 ++
37538 ++static void
37539 ++sha1_step(ctxt)
37540 ++	struct sha1_ctxt *ctxt;
37541 ++{
37542 ++	u_int32_t	a, b, c, d, e;
37543 ++	size_t t, s;
37544 ++	u_int32_t	tmp;
37545 ++
37546 ++#if BYTE_ORDER == LITTLE_ENDIAN
37547 ++	struct sha1_ctxt tctxt;
37548 ++	bcopy(&ctxt->m.b8[0], &tctxt.m.b8[0], 64);
37549 ++	ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
37550 ++	ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0];
37551 ++	ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6];
37552 ++	ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4];
37553 ++	ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10];
37554 ++	ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8];
37555 ++	ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14];
37556 ++	ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12];
37557 ++	ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18];
37558 ++	ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16];
37559 ++	ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22];
37560 ++	ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20];
37561 ++	ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26];
37562 ++	ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24];
37563 ++	ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30];
37564 ++	ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28];
37565 ++	ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34];
37566 ++	ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32];
37567 ++	ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38];
37568 ++	ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36];
37569 ++	ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42];
37570 ++	ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40];
37571 ++	ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46];
37572 ++	ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44];
37573 ++	ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50];
37574 ++	ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48];
37575 ++	ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54];
37576 ++	ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52];
37577 ++	ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58];
37578 ++	ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56];
37579 ++	ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62];
37580 ++	ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60];
37581 ++#endif
37582 ++
37583 ++	a = H(0); b = H(1); c = H(2); d = H(3); e = H(4);
37584 ++
37585 ++	for (t = 0; t < 20; t++) {
37586 ++		s = t & 0x0f;
37587 ++		if (t >= 16) {
37588 ++			W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
37589 ++		}
37590 ++		tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t);
37591 ++		e = d; d = c; c = S(30, b); b = a; a = tmp;
37592 ++	}
37593 ++	for (t = 20; t < 40; t++) {
37594 ++		s = t & 0x0f;
37595 ++		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
37596 ++		tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t);
37597 ++		e = d; d = c; c = S(30, b); b = a; a = tmp;
37598 ++	}
37599 ++	for (t = 40; t < 60; t++) {
37600 ++		s = t & 0x0f;
37601 ++		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
37602 ++		tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t);
37603 ++		e = d; d = c; c = S(30, b); b = a; a = tmp;
37604 ++	}
37605 ++	for (t = 60; t < 80; t++) {
37606 ++		s = t & 0x0f;
37607 ++		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
37608 ++		tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t);
37609 ++		e = d; d = c; c = S(30, b); b = a; a = tmp;
37610 ++	}
37611 ++
37612 ++	H(0) = H(0) + a;
37613 ++	H(1) = H(1) + b;
37614 ++	H(2) = H(2) + c;
37615 ++	H(3) = H(3) + d;
37616 ++	H(4) = H(4) + e;
37617 ++
37618 ++	bzero(&ctxt->m.b8[0], 64);
37619 ++}
37620 ++
37621 ++/*------------------------------------------------------------*/
37622 ++
37623 ++void
37624 ++sha1_init(ctxt)
37625 ++	struct sha1_ctxt *ctxt;
37626 ++{
37627 ++	bzero(ctxt, sizeof(struct sha1_ctxt));
37628 ++	H(0) = 0x67452301;
37629 ++	H(1) = 0xefcdab89;
37630 ++	H(2) = 0x98badcfe;
37631 ++	H(3) = 0x10325476;
37632 ++	H(4) = 0xc3d2e1f0;
37633 ++}
37634 ++
37635 ++void
37636 ++sha1_pad(ctxt)
37637 ++	struct sha1_ctxt *ctxt;
37638 ++{
37639 ++	size_t padlen;		/*pad length in bytes*/
37640 ++	size_t padstart;
37641 ++
37642 ++	PUTPAD(0x80);
37643 ++
37644 ++	padstart = COUNT % 64;
37645 ++	padlen = 64 - padstart;
37646 ++	if (padlen < 8) {
37647 ++		bzero(&ctxt->m.b8[padstart], padlen);
37648 ++		COUNT += padlen;
37649 ++		COUNT %= 64;
37650 ++		sha1_step(ctxt);
37651 ++		padstart = COUNT % 64;	/* should be 0 */
37652 ++		padlen = 64 - padstart;	/* should be 64 */
37653 ++	}
37654 ++	bzero(&ctxt->m.b8[padstart], padlen - 8);
37655 ++	COUNT += (padlen - 8);
37656 ++	COUNT %= 64;
37657 ++#if BYTE_ORDER == BIG_ENDIAN
37658 ++	PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
37659 ++	PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
37660 ++	PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
37661 ++	PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]);
37662 ++#else
37663 ++	PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]);
37664 ++	PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]);
37665 ++	PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]);
37666 ++	PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]);
37667 ++#endif
37668 ++}
37669 ++
37670 ++void
37671 ++sha1_loop(ctxt, input, len)
37672 ++	struct sha1_ctxt *ctxt;
37673 ++	const u_int8_t *input;
37674 ++	size_t len;
37675 ++{
37676 ++	size_t gaplen;
37677 ++	size_t gapstart;
37678 ++	size_t off;
37679 ++	size_t copysiz;
37680 ++
37681 ++	off = 0;
37682 ++
37683 ++	while (off < len) {
37684 ++		gapstart = COUNT % 64;
37685 ++		gaplen = 64 - gapstart;
37686 ++
37687 ++		copysiz = (gaplen < len - off) ? gaplen : len - off;
37688 ++		bcopy(&input[off], &ctxt->m.b8[gapstart], copysiz);
37689 ++		COUNT += copysiz;
37690 ++		COUNT %= 64;
37691 ++		ctxt->c.b64[0] += copysiz * 8;
37692 ++		if (COUNT % 64 == 0)
37693 ++			sha1_step(ctxt);
37694 ++		off += copysiz;
37695 ++	}
37696 ++}
37697 ++
37698 ++void
37699 ++sha1_result(ctxt, digest0)
37700 ++	struct sha1_ctxt *ctxt;
37701 ++	caddr_t digest0;
37702 ++{
37703 ++	u_int8_t *digest;
37704 ++
37705 ++	digest = (u_int8_t *)digest0;
37706 ++	sha1_pad(ctxt);
37707 ++#if BYTE_ORDER == BIG_ENDIAN
37708 ++	bcopy(&ctxt->h.b8[0], digest, 20);
37709 ++#else
37710 ++	digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
37711 ++	digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0];
37712 ++	digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6];
37713 ++	digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4];
37714 ++	digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10];
37715 ++	digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8];
37716 ++	digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14];
37717 ++	digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12];
37718 ++	digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18];
37719 ++	digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16];
37720 ++#endif
37721 ++}
37722 ++
37723 ++#endif /*unsupported*/
37724 +diff -urN linux-2.6.23.16.old/crypto/ocf/safe/sha1.h linux-2.6.23.16/crypto/ocf/safe/sha1.h
37725 +--- linux-2.6.23.16.old/crypto/ocf/safe/sha1.h	1969-12-31 19:00:00.000000000 -0500
37726 ++++ linux-2.6.23.16/crypto/ocf/safe/sha1.h	2008-02-26 09:29:13.000000000 -0500
37727 +@@ -0,0 +1,72 @@
37728 ++/*	$FreeBSD: src/sys/crypto/sha1.h,v 1.8 2002/03/20 05:13:50 alfred Exp $	*/
37729 ++/*	$KAME: sha1.h,v 1.5 2000/03/27 04:36:23 sumikawa Exp $	*/
37730 ++
37731 ++/*
37732 ++ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
37733 ++ * All rights reserved.
37734 ++ *
37735 ++ * Redistribution and use in source and binary forms, with or without
37736 ++ * modification, are permitted provided that the following conditions
37737 ++ * are met:
37738 ++ * 1. Redistributions of source code must retain the above copyright
37739 ++ *    notice, this list of conditions and the following disclaimer.
37740 ++ * 2. Redistributions in binary form must reproduce the above copyright
37741 ++ *    notice, this list of conditions and the following disclaimer in the
37742 ++ *    documentation and/or other materials provided with the distribution.
37743 ++ * 3. Neither the name of the project nor the names of its contributors
37744 ++ *    may be used to endorse or promote products derived from this software
37745 ++ *    without specific prior written permission.
37746 ++ *
37747 ++ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
37748 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37749 ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37750 ++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
37751 ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37752 ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37753 ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37754 ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37755 ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37756 ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37757 ++ * SUCH DAMAGE.
37758 ++ */
37759 ++/*
37760 ++ * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
37761 ++ * based on: http://csrc.nist.gov/fips/fip180-1.txt
37762 ++ * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
37763 ++ */
37764 ++
37765 ++#ifndef _NETINET6_SHA1_H_
37766 ++#define _NETINET6_SHA1_H_
37767 ++
37768 ++struct sha1_ctxt {
37769 ++	union {
37770 ++		u_int8_t	b8[20];
37771 ++		u_int32_t	b32[5];
37772 ++	} h;
37773 ++	union {
37774 ++		u_int8_t	b8[8];
37775 ++		u_int64_t	b64[1];
37776 ++	} c;
37777 ++	union {
37778 ++		u_int8_t	b8[64];
37779 ++		u_int32_t	b32[16];
37780 ++	} m;
37781 ++	u_int8_t	count;
37782 ++};
37783 ++
37784 ++#ifdef __KERNEL__
37785 ++extern void sha1_init(struct sha1_ctxt *);
37786 ++extern void sha1_pad(struct sha1_ctxt *);
37787 ++extern void sha1_loop(struct sha1_ctxt *, const u_int8_t *, size_t);
37788 ++extern void sha1_result(struct sha1_ctxt *, caddr_t);
37789 ++
37790 ++/* compatibilty with other SHA1 source codes */
37791 ++typedef struct sha1_ctxt SHA1_CTX;
37792 ++#define SHA1Init(x)		sha1_init((x))
37793 ++#define SHA1Update(x, y, z)	sha1_loop((x), (y), (z))
37794 ++#define SHA1Final(x, y)		sha1_result((y), (x))
37795 ++#endif /* __KERNEL__ */
37796 ++
37797 ++#define	SHA1_RESULTLEN	(160/8)
37798 ++
37799 ++#endif /*_NETINET6_SHA1_H_*/
37800 +diff -urN linux-2.6.23.16.old/crypto/ocf/talitos/Makefile linux-2.6.23.16/crypto/ocf/talitos/Makefile
37801 +--- linux-2.6.23.16.old/crypto/ocf/talitos/Makefile	1969-12-31 19:00:00.000000000 -0500
37802 ++++ linux-2.6.23.16/crypto/ocf/talitos/Makefile	2008-02-26 09:29:13.000000000 -0500
37803 +@@ -0,0 +1,12 @@
37804 ++# for SGlinux builds
37805 ++-include $(ROOTDIR)/modules/.config
37806 ++
37807 ++obj-$(CONFIG_OCF_TALITOS) += talitos.o
37808 ++
37809 ++obj ?= .
37810 ++EXTRA_CFLAGS += -I$(obj)/.. -I$(obj)/
37811 ++
37812 ++ifdef TOPDIR
37813 ++-include $(TOPDIR)/Rules.make
37814 ++endif
37815 ++
37816 +diff -urN linux-2.6.23.16.old/crypto/ocf/talitos/talitos.c linux-2.6.23.16/crypto/ocf/talitos/talitos.c
37817 +--- linux-2.6.23.16.old/crypto/ocf/talitos/talitos.c	1969-12-31 19:00:00.000000000 -0500
37818 ++++ linux-2.6.23.16/crypto/ocf/talitos/talitos.c	2008-02-26 09:29:13.000000000 -0500
37819 +@@ -0,0 +1,1341 @@
37820 ++/*
37821 ++ * crypto/ocf/talitos/talitos.c
37822 ++ *
37823 ++ * An OCF-Linux module that uses Freescale's SEC to do the crypto.
37824 ++ * Based on crypto/ocf/hifn and crypto/ocf/safe OCF drivers
37825 ++ *
37826 ++ * Copyright (c) 2006 Freescale Semiconductor, Inc.
37827 ++ *
37828 ++ * This code written by Kim A. B. Phillips <kim.phillips@freescale.com>
37829 ++ * some code copied from files with the following:
37830 ++ * Copyright (C) 2004-2007 David McCullough <david_mccullough@securecomputing.com
37831 ++ *
37832 ++ * Redistribution and use in source and binary forms, with or without
37833 ++ * modification, are permitted provided that the following conditions
37834 ++ * are met:
37835 ++ *
37836 ++ * 1. Redistributions of source code must retain the above copyright
37837 ++ *    notice, this list of conditions and the following disclaimer.
37838 ++ * 2. Redistributions in binary form must reproduce the above copyright
37839 ++ *    notice, this list of conditions and the following disclaimer in the
37840 ++ *    documentation and/or other materials provided with the distribution.
37841 ++ * 3. The name of the author may not be used to endorse or promote products
37842 ++ *    derived from this software without specific prior written permission.
37843 ++ *
37844 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
37845 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37846 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
37847 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37848 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37849 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37850 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37851 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37852 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37853 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37854 ++ *
37855 ++ * ---------------------------------------------------------------------------
37856 ++ *
37857 ++ * NOTES:
37858 ++ *
37859 ++ * The Freescale SEC (also known as 'talitos') resides on the
37860 ++ * internal bus, and runs asynchronous to the processor core.  It has
37861 ++ * a wide gamut of cryptographic acceleration features, including single-
37862 ++ * pass IPsec (also known as algorithm chaining).  To properly utilize 
37863 ++ * all of the SEC's performance enhancing features, further reworking 
37864 ++ * of higher level code (framework, applications) will be necessary.
37865 ++ *
37866 ++ * The following table shows which SEC version is present in which devices:
37867 ++ * 
37868 ++ * Devices       SEC version
37869 ++ *
37870 ++ * 8272, 8248    SEC 1.0
37871 ++ * 885, 875      SEC 1.2
37872 ++ * 8555E, 8541E  SEC 2.0
37873 ++ * 8349E         SEC 2.01
37874 ++ * 8548E         SEC 2.1
37875 ++ *
37876 ++ * The following table shows the features offered by each SEC version:
37877 ++ *
37878 ++ * 	                       Max.   chan-
37879 ++ * version  Bus I/F       Clock  nels  DEU AESU AFEU MDEU PKEU RNG KEU
37880 ++ *
37881 ++ * SEC 1.0  internal 64b  100MHz   4     1    1    1    1    1   1   0
37882 ++ * SEC 1.2  internal 32b   66MHz   1     1    1    0    1    0   0   0
37883 ++ * SEC 2.0  internal 64b  166MHz   4     1    1    1    1    1   1   0
37884 ++ * SEC 2.01 internal 64b  166MHz   4     1    1    1    1    1   1   0
37885 ++ * SEC 2.1  internal 64b  333MHz   4     1    1    1    1    1   1   1
37886 ++ *
37887 ++ * Each execution unit in the SEC has two modes of execution; channel and
37888 ++ * slave/debug.  This driver employs the channel infrastructure in the
37889 ++ * device for convenience.  Only the RNG is directly accessed due to the
37890 ++ * convenience of its random fifo pool.  The relationship between the
37891 ++ * channels and execution units is depicted in the following diagram:
37892 ++ *
37893 ++ *    -------   ------------
37894 ++ * ---| ch0 |---|          |
37895 ++ *    -------   |          |
37896 ++ *              |          |------+-------+-------+-------+------------
37897 ++ *    -------   |          |      |       |       |       |           |
37898 ++ * ---| ch1 |---|          |      |       |       |       |           |
37899 ++ *    -------   |          |   ------  ------  ------  ------      ------
37900 ++ *              |controller|   |DEU |  |AESU|  |MDEU|  |PKEU| ...  |RNG |
37901 ++ *    -------   |          |   ------  ------  ------  ------      ------
37902 ++ * ---| ch2 |---|          |      |       |       |       |           |
37903 ++ *    -------   |          |      |       |       |       |           |
37904 ++ *              |          |------+-------+-------+-------+------------
37905 ++ *    -------   |          |
37906 ++ * ---| ch3 |---|          |
37907 ++ *    -------   ------------
37908 ++ *
37909 ++ * Channel ch0 may drive an aes operation to the aes unit (AESU),
37910 ++ * and, at the same time, ch1 may drive a message digest operation
37911 ++ * to the mdeu. Each channel has an input descriptor FIFO, and the 
37912 ++ * FIFO can contain, e.g. on the 8541E, up to 24 entries, before a
37913 ++ * a buffer overrun error is triggered. The controller is responsible
37914 ++ * for fetching the data from descriptor pointers, and passing the 
37915 ++ * data to the appropriate EUs. The controller also writes the 
37916 ++ * cryptographic operation's result to memory. The SEC notifies 
37917 ++ * completion by triggering an interrupt and/or setting the 1st byte 
37918 ++ * of the hdr field to 0xff.
37919 ++ *
37920 ++ * TODO:
37921 ++ * o support more algorithms
37922 ++ * o support more versions of the SEC
37923 ++ * o add support for linux 2.4
37924 ++ * o scatter-gather (sg) support
37925 ++ * o add support for public key ops (PKEU)
37926 ++ * o add statistics
37927 ++ */
37928 ++
37929 ++#ifndef AUTOCONF_INCLUDED
37930 ++#include <linux/config.h>
37931 ++#endif
37932 ++#include <linux/module.h>
37933 ++#include <linux/init.h>
37934 ++#include <linux/interrupt.h>
37935 ++#include <linux/spinlock.h>
37936 ++#include <linux/random.h>
37937 ++#include <linux/skbuff.h>
37938 ++#include <asm/scatterlist.h>
37939 ++#include <linux/dma-mapping.h>  /* dma_map_single() */
37940 ++#include <linux/moduleparam.h>
37941 ++
37942 ++#include <linux/version.h>
37943 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
37944 ++#include <linux/platform_device.h>
37945 ++#endif
37946 ++
37947 ++#include <cryptodev.h>
37948 ++#include <uio.h>
37949 ++
37950 ++#define DRV_NAME "talitos" 
37951 ++
37952 ++#include "talitos_dev.h"
37953 ++#include "talitos_soft.h"
37954 ++
37955 ++#define read_random(p,l) get_random_bytes(p,l)
37956 ++
37957 ++const char talitos_driver_name[] = "Talitos OCF";
37958 ++const char talitos_driver_version[] = "0.2";
37959 ++
37960 ++static int talitos_newsession(device_t dev, u_int32_t *sidp,
37961 ++								struct cryptoini *cri);
37962 ++static int talitos_freesession(device_t dev, u_int64_t tid);
37963 ++static int talitos_process(device_t dev, struct cryptop *crp, int hint);
37964 ++static void dump_talitos_status(struct talitos_softc *sc);
37965 ++static int talitos_submit(struct talitos_softc *sc, struct talitos_desc *td, 
37966 ++								int chsel);
37967 ++static void talitos_doneprocessing(struct talitos_softc *sc);
37968 ++static void talitos_init_device(struct talitos_softc *sc);
37969 ++static void talitos_reset_device_master(struct talitos_softc *sc);
37970 ++static void talitos_reset_device(struct talitos_softc *sc);
37971 ++static void talitos_errorprocessing(struct talitos_softc *sc);
37972 ++static int talitos_probe(struct platform_device *pdev);
37973 ++static int talitos_remove(struct platform_device *pdev);
37974 ++#ifdef CONFIG_OCF_RANDOMHARVEST
37975 ++static int talitos_read_random(void *arg, u_int32_t *buf, int maxwords);
37976 ++static void talitos_rng_init(struct talitos_softc *sc);
37977 ++#endif
37978 ++
37979 ++static device_method_t talitos_methods = {
37980 ++	/* crypto device methods */
37981 ++	DEVMETHOD(cryptodev_newsession,	talitos_newsession),
37982 ++	DEVMETHOD(cryptodev_freesession,talitos_freesession),
37983 ++	DEVMETHOD(cryptodev_process,	talitos_process),
37984 ++};
37985 ++
37986 ++#define debug talitos_debug
37987 ++int talitos_debug = 0;
37988 ++module_param(talitos_debug, int, 0644);
37989 ++MODULE_PARM_DESC(talitos_debug, "Enable debug");
37990 ++
37991 ++static inline void talitos_write(volatile unsigned *addr, u32 val)
37992 ++{
37993 ++        out_be32(addr, val);
37994 ++}
37995 ++
37996 ++static inline u32 talitos_read(volatile unsigned *addr)
37997 ++{
37998 ++        u32 val;
37999 ++        val = in_be32(addr);
38000 ++        return val;
38001 ++}
38002 ++
38003 ++static void dump_talitos_status(struct talitos_softc *sc)
38004 ++{
38005 ++	unsigned int v, v_hi, i, *ptr;
38006 ++	v = talitos_read(sc->sc_base_addr + TALITOS_MCR);
38007 ++	v_hi = talitos_read(sc->sc_base_addr + TALITOS_MCR_HI);
38008 ++	printk(KERN_INFO "%s: MCR          0x%08x_%08x\n",
38009 ++			device_get_nameunit(sc->sc_cdev), v, v_hi);
38010 ++	v = talitos_read(sc->sc_base_addr + TALITOS_IMR);
38011 ++	v_hi = talitos_read(sc->sc_base_addr + TALITOS_IMR_HI);
38012 ++	printk(KERN_INFO "%s: IMR          0x%08x_%08x\n",
38013 ++			device_get_nameunit(sc->sc_cdev), v, v_hi);
38014 ++	v = talitos_read(sc->sc_base_addr + TALITOS_ISR);
38015 ++	v_hi = talitos_read(sc->sc_base_addr + TALITOS_ISR_HI);
38016 ++	printk(KERN_INFO "%s: ISR          0x%08x_%08x\n",
38017 ++			device_get_nameunit(sc->sc_cdev), v, v_hi);
38018 ++	for (i = 0; i < sc->sc_num_channels; i++) { 
38019 ++		v = talitos_read(sc->sc_base_addr + i*TALITOS_CH_OFFSET + 
38020 ++			TALITOS_CH_CDPR);
38021 ++		v_hi = talitos_read(sc->sc_base_addr + i*TALITOS_CH_OFFSET + 
38022 ++			TALITOS_CH_CDPR_HI);
38023 ++		printk(KERN_INFO "%s: CDPR     ch%d 0x%08x_%08x\n", 
38024 ++				device_get_nameunit(sc->sc_cdev), i, v, v_hi);
38025 ++	}
38026 ++	for (i = 0; i < sc->sc_num_channels; i++) { 
38027 ++		v = talitos_read(sc->sc_base_addr + i*TALITOS_CH_OFFSET + 
38028 ++			TALITOS_CH_CCPSR);
38029 ++		v_hi = talitos_read(sc->sc_base_addr + i*TALITOS_CH_OFFSET + 
38030 ++			TALITOS_CH_CCPSR_HI);
38031 ++		printk(KERN_INFO "%s: CCPSR    ch%d 0x%08x_%08x\n", 
38032 ++				device_get_nameunit(sc->sc_cdev), i, v, v_hi);
38033 ++	}
38034 ++	ptr = sc->sc_base_addr + TALITOS_CH_DESCBUF;
38035 ++	for (i = 0; i < 16; i++) { 
38036 ++		v = talitos_read(ptr++); v_hi = talitos_read(ptr++);
38037 ++		printk(KERN_INFO "%s: DESCBUF  ch0 0x%08x_%08x (tdp%02d)\n", 
38038 ++				device_get_nameunit(sc->sc_cdev), v, v_hi, i);
38039 ++	}
38040 ++	return;
38041 ++}
38042 ++
38043 ++
38044 ++#ifdef CONFIG_OCF_RANDOMHARVEST
38045 ++/* 
38046 ++ * pull random numbers off the RNG FIFO, not exceeding amount available
38047 ++ */
38048 ++static int
38049 ++talitos_read_random(void *arg, u_int32_t *buf, int maxwords)
38050 ++{
38051 ++	struct talitos_softc *sc = (struct talitos_softc *) arg;
38052 ++	int rc;
38053 ++	u_int32_t v;
38054 ++
38055 ++	DPRINTF("%s()\n", __FUNCTION__);
38056 ++
38057 ++	/* check for things like FIFO underflow */
38058 ++	v = talitos_read(sc->sc_base_addr + TALITOS_RNGISR_HI);
38059 ++	if (unlikely(v)) {
38060 ++		printk(KERN_ERR "%s: RNGISR_HI error %08x\n",
38061 ++				device_get_nameunit(sc->sc_cdev), v);
38062 ++		return 0;
38063 ++	}
38064 ++	/*
38065 ++	 * OFL is number of available 64-bit words, 
38066 ++	 * shift and convert to a 32-bit word count
38067 ++	 */
38068 ++	v = talitos_read(sc->sc_base_addr + TALITOS_RNGSR_HI);
38069 ++	v = (v & TALITOS_RNGSR_HI_OFL) >> (16 - 1);
38070 ++	if (maxwords > v)
38071 ++		maxwords = v;
38072 ++	for (rc = 0; rc < maxwords; rc++) {
38073 ++		buf[rc] = talitos_read(sc->sc_base_addr + 
38074 ++			TALITOS_RNG_FIFO + rc*sizeof(u_int32_t));
38075 ++	}
38076 ++	if (maxwords & 1) {
38077 ++		/* 
38078 ++		 * RNG will complain with an AE in the RNGISR
38079 ++		 * if we don't complete the pairs of 32-bit reads
38080 ++		 * to its 64-bit register based FIFO
38081 ++		 */
38082 ++		v = talitos_read(sc->sc_base_addr + 
38083 ++			TALITOS_RNG_FIFO + rc*sizeof(u_int32_t));
38084 ++	}
38085 ++
38086 ++	return rc;
38087 ++}
38088 ++
38089 ++static void
38090 ++talitos_rng_init(struct talitos_softc *sc)
38091 ++{
38092 ++	u_int32_t v;
38093 ++
38094 ++	DPRINTF("%s()\n", __FUNCTION__);
38095 ++	/* reset RNG EU */
38096 ++	v = talitos_read(sc->sc_base_addr + TALITOS_RNGRCR_HI);
38097 ++	v |= TALITOS_RNGRCR_HI_SR;
38098 ++	talitos_write(sc->sc_base_addr + TALITOS_RNGRCR_HI, v);
38099 ++	while ((talitos_read(sc->sc_base_addr + TALITOS_RNGSR_HI) 
38100 ++		& TALITOS_RNGSR_HI_RD) == 0)
38101 ++			cpu_relax();
38102 ++	/*
38103 ++	 * we tell the RNG to start filling the RNG FIFO
38104 ++	 * by writing the RNGDSR 
38105 ++	 */
38106 ++	v = talitos_read(sc->sc_base_addr + TALITOS_RNGDSR_HI);
38107 ++	talitos_write(sc->sc_base_addr + TALITOS_RNGDSR_HI, v);
38108 ++	/*
38109 ++	 * 64 bits of data will be pushed onto the FIFO every 
38110 ++	 * 256 SEC cycles until the FIFO is full.  The RNG then 
38111 ++	 * attempts to keep the FIFO full.
38112 ++	 */
38113 ++	v = talitos_read(sc->sc_base_addr + TALITOS_RNGISR_HI);
38114 ++	if (v) {
38115 ++		printk(KERN_ERR "%s: RNGISR_HI error %08x\n",
38116 ++			device_get_nameunit(sc->sc_cdev), v);
38117 ++		return;
38118 ++	}
38119 ++	/*
38120 ++	 * n.b. we need to add a FIPS test here - if the RNG is going 
38121 ++	 * to fail, it's going to fail at reset time
38122 ++	 */
38123 ++	return;
38124 ++}
38125 ++#endif /* CONFIG_OCF_RANDOMHARVEST */
38126 ++
38127 ++/*
38128 ++ * Generate a new software session.
38129 ++ */
38130 ++static int
38131 ++talitos_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
38132 ++{
38133 ++	struct cryptoini *c, *encini = NULL, *macini = NULL;
38134 ++	struct talitos_softc *sc = device_get_softc(dev);
38135 ++	struct talitos_session *ses = NULL;
38136 ++	int sesn;
38137 ++
38138 ++	DPRINTF("%s()\n", __FUNCTION__);
38139 ++	if (sidp == NULL || cri == NULL || sc == NULL) {
38140 ++		DPRINTF("%s,%d - EINVAL\n", __FILE__, __LINE__);
38141 ++		return EINVAL;
38142 ++	}
38143 ++	for (c = cri; c != NULL; c = c->cri_next) {
38144 ++		if (c->cri_alg == CRYPTO_MD5 ||
38145 ++		    c->cri_alg == CRYPTO_MD5_HMAC ||
38146 ++		    c->cri_alg == CRYPTO_SHA1 ||
38147 ++		    c->cri_alg == CRYPTO_SHA1_HMAC ||
38148 ++		    c->cri_alg == CRYPTO_NULL_HMAC) {
38149 ++			if (macini)
38150 ++				return EINVAL;
38151 ++			macini = c;
38152 ++		} else if (c->cri_alg == CRYPTO_DES_CBC ||
38153 ++		    c->cri_alg == CRYPTO_3DES_CBC ||
38154 ++		    c->cri_alg == CRYPTO_AES_CBC ||
38155 ++		    c->cri_alg == CRYPTO_NULL_CBC) {
38156 ++			if (encini)
38157 ++				return EINVAL;
38158 ++			encini = c;
38159 ++		} else {
38160 ++			DPRINTF("UNKNOWN c->cri_alg %d\n", encini->cri_alg);
38161 ++			return EINVAL;
38162 ++		}
38163 ++	}
38164 ++	if (encini == NULL && macini == NULL)
38165 ++		return EINVAL;
38166 ++	if (encini) {	
38167 ++		/* validate key length */
38168 ++		switch (encini->cri_alg) {
38169 ++		case CRYPTO_DES_CBC:
38170 ++			if (encini->cri_klen != 64)
38171 ++				return EINVAL;
38172 ++			break;
38173 ++		case CRYPTO_3DES_CBC:
38174 ++			if (encini->cri_klen != 192) {
38175 ++				return EINVAL;
38176 ++			}
38177 ++			break;
38178 ++		case CRYPTO_AES_CBC:
38179 ++			if (encini->cri_klen != 128 &&
38180 ++			    encini->cri_klen != 192 &&
38181 ++			    encini->cri_klen != 256)
38182 ++				return EINVAL;
38183 ++			break;
38184 ++		default:
38185 ++			DPRINTF("UNKNOWN encini->cri_alg %d\n", 
38186 ++				encini->cri_alg);
38187 ++			return EINVAL;
38188 ++		}
38189 ++	}
38190 ++
38191 ++	if (sc->sc_sessions == NULL) {
38192 ++		ses = sc->sc_sessions = (struct talitos_session *)
38193 ++			kmalloc(sizeof(struct talitos_session), SLAB_ATOMIC);
38194 ++		if (ses == NULL)
38195 ++			return ENOMEM;
38196 ++		memset(ses, 0, sizeof(struct talitos_session));
38197 ++		sesn = 0;
38198 ++		sc->sc_nsessions = 1;
38199 ++	} else {
38200 ++		for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
38201 ++			if (sc->sc_sessions[sesn].ses_used == 0) {
38202 ++				ses = &sc->sc_sessions[sesn];
38203 ++				break;
38204 ++			}
38205 ++		}
38206 ++
38207 ++		if (ses == NULL) {
38208 ++			/* allocating session */
38209 ++			sesn = sc->sc_nsessions;
38210 ++			ses = (struct talitos_session *) kmalloc(
38211 ++				(sesn + 1) * sizeof(struct talitos_session), 
38212 ++				SLAB_ATOMIC);
38213 ++			if (ses == NULL)
38214 ++				return ENOMEM;
38215 ++			memset(ses, 0,
38216 ++				(sesn + 1) * sizeof(struct talitos_session));
38217 ++			memcpy(ses, sc->sc_sessions, 
38218 ++				sesn * sizeof(struct talitos_session));
38219 ++			memset(sc->sc_sessions, 0,
38220 ++				sesn * sizeof(struct talitos_session));
38221 ++			kfree(sc->sc_sessions);
38222 ++			sc->sc_sessions = ses;
38223 ++			ses = &sc->sc_sessions[sesn];
38224 ++			sc->sc_nsessions++;
38225 ++		}
38226 ++	}
38227 ++
38228 ++	ses->ses_used = 1;
38229 ++
38230 ++	if (encini) {
38231 ++		/* get an IV */
38232 ++		/* XXX may read fewer than requested */
38233 ++		read_random(ses->ses_iv, sizeof(ses->ses_iv));
38234 ++
38235 ++		ses->ses_klen = (encini->cri_klen + 7) / 8;
38236 ++		memcpy(ses->ses_key, encini->cri_key, ses->ses_klen);
38237 ++		if (macini) {
38238 ++			/* doing hash on top of cipher */
38239 ++			ses->ses_hmac_len = (macini->cri_klen + 7) / 8;
38240 ++			memcpy(ses->ses_hmac, macini->cri_key,
38241 ++				ses->ses_hmac_len);
38242 ++		}
38243 ++	} else if (macini) {
38244 ++		/* doing hash */
38245 ++		ses->ses_klen = (macini->cri_klen + 7) / 8;
38246 ++		memcpy(ses->ses_key, macini->cri_key, ses->ses_klen);
38247 ++	}
38248 ++
38249 ++	/* back compat way of determining MSC result len */
38250 ++	if (macini) {
38251 ++		ses->ses_mlen = macini->cri_mlen;
38252 ++		if (ses->ses_mlen == 0) {
38253 ++			if (macini->cri_alg == CRYPTO_MD5_HMAC)
38254 ++				ses->ses_mlen = MD5_HASH_LEN;
38255 ++			else
38256 ++				ses->ses_mlen = SHA1_HASH_LEN;
38257 ++		}
38258 ++	}
38259 ++
38260 ++	/* really should make up a template td here, 
38261 ++	 * and only fill things like i/o and direction in process() */
38262 ++
38263 ++	/* assign session ID */
38264 ++	*sidp = TALITOS_SID(sc->sc_num, sesn);
38265 ++	return 0;
38266 ++}
38267 ++
38268 ++/*
38269 ++ * Deallocate a session.
38270 ++ */
38271 ++static int
38272 ++talitos_freesession(device_t dev, u_int64_t tid)
38273 ++{
38274 ++	struct talitos_softc *sc = device_get_softc(dev);
38275 ++	int session, ret;
38276 ++	u_int32_t sid = ((u_int32_t) tid) & 0xffffffff;
38277 ++
38278 ++	if (sc == NULL)
38279 ++		return EINVAL;
38280 ++	session = TALITOS_SESSION(sid);
38281 ++	if (session < sc->sc_nsessions) {
38282 ++		memset(&sc->sc_sessions[session], 0,
38283 ++			sizeof(sc->sc_sessions[session]));
38284 ++		ret = 0;
38285 ++	} else
38286 ++		ret = EINVAL;
38287 ++	return ret;
38288 ++}
38289 ++
38290 ++/*
38291 ++ * launch device processing - it will come back with done notification 
38292 ++ * in the form of an interrupt and/or HDR_DONE_BITS in header 
38293 ++ */
38294 ++static int 
38295 ++talitos_submit(
38296 ++	struct talitos_softc *sc,
38297 ++	struct talitos_desc *td,
38298 ++	int chsel)
38299 ++{
38300 ++	u_int32_t v;
38301 ++
38302 ++	v = dma_map_single(NULL, td, sizeof(*td), DMA_TO_DEVICE);
38303 ++	talitos_write(sc->sc_base_addr + 
38304 ++		chsel*TALITOS_CH_OFFSET + TALITOS_CH_FF, 0);
38305 ++	talitos_write(sc->sc_base_addr + 
38306 ++		chsel*TALITOS_CH_OFFSET + TALITOS_CH_FF_HI, v);
38307 ++	return 0;
38308 ++}
38309 ++
38310 ++static int
38311 ++talitos_process(device_t dev, struct cryptop *crp, int hint)
38312 ++{
38313 ++	int i, err = 0, ivsize;
38314 ++	struct talitos_softc *sc = device_get_softc(dev);
38315 ++	struct cryptodesc *crd1, *crd2, *maccrd, *enccrd;
38316 ++	caddr_t iv;
38317 ++	struct talitos_session *ses;
38318 ++	struct talitos_desc *td;
38319 ++	unsigned long flags;
38320 ++	/* descriptor mappings */
38321 ++	int hmac_key, hmac_data, cipher_iv, cipher_key, 
38322 ++		in_fifo, out_fifo, cipher_iv_out;
38323 ++	static int chsel = -1;
38324 ++
38325 ++	DPRINTF("%s()\n", __FUNCTION__);
38326 ++
38327 ++	if (crp == NULL || crp->crp_callback == NULL || sc == NULL) {
38328 ++		return EINVAL;
38329 ++	}
38330 ++	crp->crp_etype = 0;
38331 ++	if (TALITOS_SESSION(crp->crp_sid) >= sc->sc_nsessions) {
38332 ++		return EINVAL;
38333 ++	}
38334 ++
38335 ++	ses = &sc->sc_sessions[TALITOS_SESSION(crp->crp_sid)];
38336 ++
38337 ++        /* enter the channel scheduler */ 
38338 ++	spin_lock_irqsave(&sc->sc_chnfifolock[sc->sc_num_channels], flags);
38339 ++
38340 ++	/* reuse channel that already had/has requests for the required EU */
38341 ++	for (i = 0; i < sc->sc_num_channels; i++) {
38342 ++		if (sc->sc_chnlastalg[i] == crp->crp_desc->crd_alg)
38343 ++			break;
38344 ++	}
38345 ++	if (i == sc->sc_num_channels) {
38346 ++		/*
38347 ++		 * haven't seen this algo the last sc_num_channels or more
38348 ++		 * use round robin in this case
38349 ++	 	 * nb: sc->sc_num_channels must be power of 2 
38350 ++		 */
38351 ++		chsel = (chsel + 1) & (sc->sc_num_channels - 1);
38352 ++	} else {
38353 ++		/*
38354 ++		 * matches channel with same target execution unit; 
38355 ++		 * use same channel in this case
38356 ++		 */
38357 ++		chsel = i;
38358 ++	}
38359 ++	sc->sc_chnlastalg[chsel] = crp->crp_desc->crd_alg;
38360 ++
38361 ++        /* release the channel scheduler lock */ 
38362 ++	spin_unlock_irqrestore(&sc->sc_chnfifolock[sc->sc_num_channels], flags);
38363 ++
38364 ++	/* acquire the selected channel fifo lock */
38365 ++	spin_lock_irqsave(&sc->sc_chnfifolock[chsel], flags);
38366 ++
38367 ++	/* find and reserve next available descriptor-cryptop pair */
38368 ++	for (i = 0; i < sc->sc_chfifo_len; i++) {
38369 ++		if (sc->sc_chnfifo[chsel][i].cf_desc.hdr == 0) {
38370 ++			/* 
38371 ++			 * ensure correct descriptor formation by
38372 ++			 * avoiding inadvertently setting "optional" entries
38373 ++			 * e.g. not using "optional" dptr2 for MD/HMAC descs
38374 ++			 */
38375 ++			memset(&sc->sc_chnfifo[chsel][i].cf_desc,
38376 ++				0, sizeof(*td));
38377 ++			/* reserve it with done notification request bit */
38378 ++			sc->sc_chnfifo[chsel][i].cf_desc.hdr |= 
38379 ++				TALITOS_DONE_NOTIFY;
38380 ++			break;
38381 ++		}
38382 ++	}
38383 ++	spin_unlock_irqrestore(&sc->sc_chnfifolock[chsel], flags);
38384 ++
38385 ++	if (i == sc->sc_chfifo_len) {
38386 ++		/* fifo full */
38387 ++		err = ERESTART;
38388 ++		goto errout;
38389 ++	}
38390 ++	
38391 ++	td = &sc->sc_chnfifo[chsel][i].cf_desc;
38392 ++	sc->sc_chnfifo[chsel][i].cf_crp = crp;
38393 ++
38394 ++	crd1 = crp->crp_desc;
38395 ++	if (crd1 == NULL) {
38396 ++		err = EINVAL;
38397 ++		goto errout;
38398 ++	}
38399 ++	crd2 = crd1->crd_next;
38400 ++	/* prevent compiler warning */
38401 ++	hmac_key = 0;
38402 ++	hmac_data = 0;
38403 ++	if (crd2 == NULL) {
38404 ++		td->hdr |= TD_TYPE_COMMON_NONSNOOP_NO_AFEU;
38405 ++		/* assign descriptor dword ptr mappings for this desc. type */
38406 ++		cipher_iv = 1;
38407 ++		cipher_key = 2;
38408 ++		in_fifo = 3;
38409 ++		cipher_iv_out = 5;
38410 ++		if (crd1->crd_alg == CRYPTO_MD5_HMAC ||
38411 ++		    crd1->crd_alg == CRYPTO_SHA1_HMAC ||
38412 ++		    crd1->crd_alg == CRYPTO_SHA1 ||
38413 ++		    crd1->crd_alg == CRYPTO_MD5) {
38414 ++			out_fifo = 5;
38415 ++			maccrd = crd1;
38416 ++			enccrd = NULL;
38417 ++		} else if (crd1->crd_alg == CRYPTO_DES_CBC ||
38418 ++		    crd1->crd_alg == CRYPTO_3DES_CBC ||
38419 ++		    crd1->crd_alg == CRYPTO_AES_CBC ||
38420 ++		    crd1->crd_alg == CRYPTO_ARC4) {
38421 ++			out_fifo = 4;
38422 ++			maccrd = NULL;
38423 ++			enccrd = crd1;
38424 ++		} else {
38425 ++			DPRINTF("UNKNOWN crd1->crd_alg %d\n", crd1->crd_alg);
38426 ++			err = EINVAL;
38427 ++			goto errout;
38428 ++		}
38429 ++	} else {
38430 ++		if (sc->sc_desc_types & TALITOS_HAS_DT_IPSEC_ESP) {
38431 ++			td->hdr |= TD_TYPE_IPSEC_ESP;
38432 ++		} else {
38433 ++			DPRINTF("unimplemented: multiple descriptor ipsec\n");
38434 ++			err = EINVAL;
38435 ++			goto errout;
38436 ++		}
38437 ++		/* assign descriptor dword ptr mappings for this desc. type */
38438 ++		hmac_key = 0;
38439 ++		hmac_data = 1;
38440 ++		cipher_iv = 2;
38441 ++		cipher_key = 3;
38442 ++		in_fifo = 4;
38443 ++		out_fifo = 5;
38444 ++		cipher_iv_out = 6;
38445 ++		if ((crd1->crd_alg == CRYPTO_MD5_HMAC ||
38446 ++                     crd1->crd_alg == CRYPTO_SHA1_HMAC ||
38447 ++                     crd1->crd_alg == CRYPTO_MD5 ||
38448 ++                     crd1->crd_alg == CRYPTO_SHA1) &&
38449 ++		    (crd2->crd_alg == CRYPTO_DES_CBC ||
38450 ++		     crd2->crd_alg == CRYPTO_3DES_CBC ||
38451 ++		     crd2->crd_alg == CRYPTO_AES_CBC ||
38452 ++		     crd2->crd_alg == CRYPTO_ARC4) &&
38453 ++		    ((crd2->crd_flags & CRD_F_ENCRYPT) == 0)) {
38454 ++			maccrd = crd1;
38455 ++			enccrd = crd2;
38456 ++		} else if ((crd1->crd_alg == CRYPTO_DES_CBC ||
38457 ++		     crd1->crd_alg == CRYPTO_ARC4 ||
38458 ++		     crd1->crd_alg == CRYPTO_3DES_CBC ||
38459 ++		     crd1->crd_alg == CRYPTO_AES_CBC) &&
38460 ++		    (crd2->crd_alg == CRYPTO_MD5_HMAC ||
38461 ++                     crd2->crd_alg == CRYPTO_SHA1_HMAC ||
38462 ++                     crd2->crd_alg == CRYPTO_MD5 ||
38463 ++                     crd2->crd_alg == CRYPTO_SHA1) &&
38464 ++		    (crd1->crd_flags & CRD_F_ENCRYPT)) {
38465 ++			enccrd = crd1;
38466 ++			maccrd = crd2;
38467 ++		} else {
38468 ++			/* We cannot order the SEC as requested */
38469 ++			printk("%s: cannot do the order\n",
38470 ++					device_get_nameunit(sc->sc_cdev));
38471 ++			err = EINVAL;
38472 ++			goto errout;
38473 ++		}
38474 ++	}
38475 ++	/* assign in_fifo and out_fifo based on input/output struct type */
38476 ++	if (crp->crp_flags & CRYPTO_F_SKBUF) {
38477 ++		/* using SKB buffers */
38478 ++		struct sk_buff *skb = (struct sk_buff *)crp->crp_buf;
38479 ++		if (skb_shinfo(skb)->nr_frags) {
38480 ++			printk("%s: skb frags unimplemented\n",
38481 ++					device_get_nameunit(sc->sc_cdev));
38482 ++			err = EINVAL;
38483 ++			goto errout;
38484 ++		}
38485 ++		td->ptr[in_fifo].ptr = dma_map_single(NULL, skb->data, 
38486 ++			skb->len, DMA_TO_DEVICE);
38487 ++		td->ptr[in_fifo].len = skb->len;
38488 ++		td->ptr[out_fifo].ptr = dma_map_single(NULL, skb->data, 
38489 ++			skb->len, DMA_TO_DEVICE);
38490 ++		td->ptr[out_fifo].len = skb->len;
38491 ++		td->ptr[hmac_data].ptr = dma_map_single(NULL, skb->data,
38492 ++			skb->len, DMA_TO_DEVICE);
38493 ++	} else if (crp->crp_flags & CRYPTO_F_IOV) {
38494 ++		/* using IOV buffers */
38495 ++		struct uio *uiop = (struct uio *)crp->crp_buf;
38496 ++		if (uiop->uio_iovcnt > 1) {
38497 ++			printk("%s: iov frags unimplemented\n",
38498 ++					device_get_nameunit(sc->sc_cdev));
38499 ++			err = EINVAL;
38500 ++			goto errout;
38501 ++		}
38502 ++		td->ptr[in_fifo].ptr = dma_map_single(NULL,
38503 ++			uiop->uio_iov->iov_base, crp->crp_ilen, DMA_TO_DEVICE);
38504 ++		td->ptr[in_fifo].len = crp->crp_ilen;
38505 ++		/* crp_olen is never set; always use crp_ilen */
38506 ++		td->ptr[out_fifo].ptr = dma_map_single(NULL,
38507 ++			uiop->uio_iov->iov_base,
38508 ++			crp->crp_ilen, DMA_TO_DEVICE);
38509 ++		td->ptr[out_fifo].len = crp->crp_ilen;
38510 ++	} else {
38511 ++		/* using contig buffers */
38512 ++		td->ptr[in_fifo].ptr = dma_map_single(NULL,
38513 ++			crp->crp_buf, crp->crp_ilen, DMA_TO_DEVICE);
38514 ++		td->ptr[in_fifo].len = crp->crp_ilen;
38515 ++		td->ptr[out_fifo].ptr = dma_map_single(NULL,
38516 ++			crp->crp_buf, crp->crp_ilen, DMA_TO_DEVICE);
38517 ++		td->ptr[out_fifo].len = crp->crp_ilen;
38518 ++	}
38519 ++	if (enccrd) {
38520 ++		switch (enccrd->crd_alg) {
38521 ++		case CRYPTO_3DES_CBC:
38522 ++			td->hdr |= TALITOS_MODE0_DEU_3DES;
38523 ++			/* FALLTHROUGH */
38524 ++		case CRYPTO_DES_CBC:
38525 ++			td->hdr |= TALITOS_SEL0_DEU
38526 ++				|  TALITOS_MODE0_DEU_CBC;
38527 ++			if (enccrd->crd_flags & CRD_F_ENCRYPT)
38528 ++				td->hdr |= TALITOS_MODE0_DEU_ENC;
38529 ++			ivsize = 2*sizeof(u_int32_t);
38530 ++			DPRINTF("%cDES ses %d ch %d len %d\n",
38531 ++				(td->hdr & TALITOS_MODE0_DEU_3DES)?'3':'1',
38532 ++				(u32)TALITOS_SESSION(crp->crp_sid),
38533 ++				chsel, td->ptr[in_fifo].len);
38534 ++			break;
38535 ++		case CRYPTO_AES_CBC:
38536 ++			td->hdr |= TALITOS_SEL0_AESU
38537 ++				|  TALITOS_MODE0_AESU_CBC;
38538 ++			if (enccrd->crd_flags & CRD_F_ENCRYPT)
38539 ++				td->hdr |= TALITOS_MODE0_AESU_ENC;
38540 ++			ivsize = 4*sizeof(u_int32_t);
38541 ++			DPRINTF("AES  ses %d ch %d len %d\n",
38542 ++				(u32)TALITOS_SESSION(crp->crp_sid),
38543 ++				chsel, td->ptr[in_fifo].len);
38544 ++			break;
38545 ++		default:
38546 ++			printk("%s: unimplemented enccrd->crd_alg %d\n",
38547 ++					device_get_nameunit(sc->sc_cdev), enccrd->crd_alg);
38548 ++			err = EINVAL;
38549 ++			goto errout;
38550 ++		}
38551 ++		/*
38552 ++		 * Setup encrypt/decrypt state.  When using basic ops
38553 ++		 * we can't use an inline IV because hash/crypt offset
38554 ++		 * must be from the end of the IV to the start of the
38555 ++		 * crypt data and this leaves out the preceding header
38556 ++		 * from the hash calculation.  Instead we place the IV
38557 ++		 * in the state record and set the hash/crypt offset to
38558 ++		 * copy both the header+IV.
38559 ++		 */
38560 ++		if (enccrd->crd_flags & CRD_F_ENCRYPT) {
38561 ++			td->hdr |= TALITOS_DIR_OUTBOUND; 
38562 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT)
38563 ++				iv = enccrd->crd_iv;
38564 ++			else
38565 ++				iv = (caddr_t) ses->ses_iv;
38566 ++			if ((enccrd->crd_flags & CRD_F_IV_PRESENT) == 0) {
38567 ++				crypto_copyback(crp->crp_flags, crp->crp_buf,
38568 ++				    enccrd->crd_inject, ivsize, iv);
38569 ++			}
38570 ++		} else {
38571 ++			td->hdr |= TALITOS_DIR_INBOUND; 
38572 ++			if (enccrd->crd_flags & CRD_F_IV_EXPLICIT) {
38573 ++				iv = enccrd->crd_iv;
38574 ++				bcopy(enccrd->crd_iv, iv, ivsize);
38575 ++			} else {
38576 ++				iv = (caddr_t) ses->ses_iv;
38577 ++				crypto_copydata(crp->crp_flags, crp->crp_buf,
38578 ++				    enccrd->crd_inject, ivsize, iv);
38579 ++			}
38580 ++		}
38581 ++		td->ptr[cipher_iv].ptr = dma_map_single(NULL, iv, ivsize, 
38582 ++			DMA_TO_DEVICE);
38583 ++		td->ptr[cipher_iv].len = ivsize;
38584 ++		/*
38585 ++		 * we don't need the cipher iv out length/pointer
38586 ++		 * field to do ESP IPsec. Therefore we set the len field as 0,
38587 ++		 * which tells the SEC not to do anything with this len/ptr
38588 ++		 * field. Previously, when length/pointer as pointing to iv,
38589 ++		 * it gave us corruption of packets.
38590 ++		 */
38591 ++		td->ptr[cipher_iv_out].len = 0;
38592 ++	}
38593 ++	if (enccrd && maccrd) {
38594 ++		/* this is ipsec only for now */
38595 ++		td->hdr |= TALITOS_SEL1_MDEU
38596 ++			|  TALITOS_MODE1_MDEU_INIT
38597 ++			|  TALITOS_MODE1_MDEU_PAD;
38598 ++		switch (maccrd->crd_alg) {
38599 ++			case	CRYPTO_MD5:	
38600 ++				td->hdr |= TALITOS_MODE1_MDEU_MD5;
38601 ++				break;
38602 ++			case	CRYPTO_MD5_HMAC:	
38603 ++				td->hdr |= TALITOS_MODE1_MDEU_MD5_HMAC;
38604 ++				break;
38605 ++			case	CRYPTO_SHA1:	
38606 ++				td->hdr |= TALITOS_MODE1_MDEU_SHA1;
38607 ++				break;
38608 ++			case	CRYPTO_SHA1_HMAC:	
38609 ++				td->hdr |= TALITOS_MODE1_MDEU_SHA1_HMAC;
38610 ++				break;
38611 ++			default:
38612 ++				/* We cannot order the SEC as requested */
38613 ++				printk("%s: cannot do the order\n",
38614 ++						device_get_nameunit(sc->sc_cdev));
38615 ++				err = EINVAL;
38616 ++				goto errout;
38617 ++		}
38618 ++		if ((maccrd->crd_alg == CRYPTO_MD5_HMAC) ||
38619 ++		   (maccrd->crd_alg == CRYPTO_SHA1_HMAC)) {
38620 ++			/*
38621 ++			 * The offset from hash data to the start of
38622 ++			 * crypt data is the difference in the skips.
38623 ++			 */
38624 ++			/* ipsec only for now */
38625 ++			td->ptr[hmac_key].ptr = dma_map_single(NULL, 
38626 ++				ses->ses_hmac, ses->ses_hmac_len, DMA_TO_DEVICE);
38627 ++			td->ptr[hmac_key].len = ses->ses_hmac_len;
38628 ++			td->ptr[in_fifo].ptr  += enccrd->crd_skip;
38629 ++			td->ptr[in_fifo].len  =  enccrd->crd_len;
38630 ++			td->ptr[out_fifo].ptr += enccrd->crd_skip;
38631 ++			td->ptr[out_fifo].len =  enccrd->crd_len;
38632 ++			/* bytes of HMAC to postpend to ciphertext */
38633 ++			td->ptr[out_fifo].extent =  ses->ses_mlen;
38634 ++			td->ptr[hmac_data].ptr += maccrd->crd_skip; 
38635 ++			td->ptr[hmac_data].len = enccrd->crd_skip - maccrd->crd_skip;
38636 ++		}
38637 ++		if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
38638 ++			printk("%s: CRD_F_KEY_EXPLICIT unimplemented\n",
38639 ++					device_get_nameunit(sc->sc_cdev));
38640 ++		}
38641 ++	}
38642 ++	if (!enccrd && maccrd) {
38643 ++		/* single MD5 or SHA */
38644 ++		td->hdr |= TALITOS_SEL0_MDEU
38645 ++				|  TALITOS_MODE0_MDEU_INIT
38646 ++				|  TALITOS_MODE0_MDEU_PAD;
38647 ++		switch (maccrd->crd_alg) {
38648 ++			case	CRYPTO_MD5:	
38649 ++				td->hdr |= TALITOS_MODE0_MDEU_MD5;
38650 ++				DPRINTF("MD5  ses %d ch %d len %d\n",
38651 ++					(u32)TALITOS_SESSION(crp->crp_sid), 
38652 ++					chsel, td->ptr[in_fifo].len);
38653 ++				break;
38654 ++			case	CRYPTO_MD5_HMAC:	
38655 ++				td->hdr |= TALITOS_MODE0_MDEU_MD5_HMAC;
38656 ++				break;
38657 ++			case	CRYPTO_SHA1:	
38658 ++				td->hdr |= TALITOS_MODE0_MDEU_SHA1;
38659 ++				DPRINTF("SHA1 ses %d ch %d len %d\n",
38660 ++					(u32)TALITOS_SESSION(crp->crp_sid), 
38661 ++					chsel, td->ptr[in_fifo].len);
38662 ++				break;
38663 ++			case	CRYPTO_SHA1_HMAC:	
38664 ++				td->hdr |= TALITOS_MODE0_MDEU_SHA1_HMAC;
38665 ++				break;
38666 ++			default:
38667 ++				/* We cannot order the SEC as requested */
38668 ++				DPRINTF("cannot do the order\n");
38669 ++				err = EINVAL;
38670 ++				goto errout;
38671 ++		}
38672 ++
38673 ++		if (crp->crp_flags & CRYPTO_F_IOV)
38674 ++			td->ptr[out_fifo].ptr += maccrd->crd_inject;
38675 ++
38676 ++		if ((maccrd->crd_alg == CRYPTO_MD5_HMAC) ||
38677 ++		   (maccrd->crd_alg == CRYPTO_SHA1_HMAC)) {
38678 ++			td->ptr[hmac_key].ptr = dma_map_single(NULL, 
38679 ++				ses->ses_hmac, ses->ses_hmac_len, 
38680 ++				DMA_TO_DEVICE);
38681 ++			td->ptr[hmac_key].len = ses->ses_hmac_len;
38682 ++		}
38683 ++	} 
38684 ++	else {
38685 ++		/* using process key (session data has duplicate) */
38686 ++		td->ptr[cipher_key].ptr = dma_map_single(NULL, 
38687 ++			enccrd->crd_key, (enccrd->crd_klen + 7) / 8, 
38688 ++			DMA_TO_DEVICE);
38689 ++		td->ptr[cipher_key].len = (enccrd->crd_klen + 7) / 8;
38690 ++	}
38691 ++	/* descriptor complete - GO! */
38692 ++	return talitos_submit(sc, td, chsel);
38693 ++
38694 ++errout:
38695 ++	if (err != ERESTART) {
38696 ++		crp->crp_etype = err;
38697 ++		crypto_done(crp);
38698 ++	}
38699 ++	return err;
38700 ++}
38701 ++
38702 ++/* go through all channels descriptors, notifying OCF what has 
38703 ++ * _and_hasn't_ successfully completed and reset the device 
38704 ++ * (otherwise it's up to decoding desc hdrs!)
38705 ++ */
38706 ++static void talitos_errorprocessing(struct talitos_softc *sc)
38707 ++{
38708 ++	unsigned long flags;
38709 ++	int i, j;
38710 ++
38711 ++	/* disable further scheduling until under control */
38712 ++	spin_lock_irqsave(&sc->sc_chnfifolock[sc->sc_num_channels], flags);
38713 ++
38714 ++	if (debug) dump_talitos_status(sc);
38715 ++	/* go through descriptors, try and salvage those successfully done, 
38716 ++	 * and EIO those that weren't
38717 ++	 */
38718 ++	for (i = 0; i < sc->sc_num_channels; i++) {
38719 ++		spin_lock_irqsave(&sc->sc_chnfifolock[i], flags);
38720 ++		for (j = 0; j < sc->sc_chfifo_len; j++) {
38721 ++			if (sc->sc_chnfifo[i][j].cf_desc.hdr) {
38722 ++				if ((sc->sc_chnfifo[i][j].cf_desc.hdr 
38723 ++					& TALITOS_HDR_DONE_BITS) 
38724 ++					!= TALITOS_HDR_DONE_BITS) {
38725 ++					/* this one didn't finish */
38726 ++					/* signify in crp->etype */
38727 ++					sc->sc_chnfifo[i][j].cf_crp->crp_etype 
38728 ++						= EIO;
38729 ++				}
38730 ++			} else
38731 ++				continue; /* free entry */
38732 ++			/* either way, notify ocf */
38733 ++			crypto_done(sc->sc_chnfifo[i][j].cf_crp);
38734 ++			/* and tag it available again
38735 ++			 *
38736 ++			 * memset to ensure correct descriptor formation by
38737 ++			 * avoiding inadvertently setting "optional" entries
38738 ++			 * e.g. not using "optional" dptr2 MD/HMAC processing
38739 ++			 */
38740 ++			memset(&sc->sc_chnfifo[i][j].cf_desc,
38741 ++				0, sizeof(struct talitos_desc));
38742 ++		}
38743 ++		spin_unlock_irqrestore(&sc->sc_chnfifolock[i], flags);
38744 ++	}
38745 ++	/* reset and initialize the SEC h/w device */
38746 ++	talitos_reset_device(sc);
38747 ++	talitos_init_device(sc);
38748 ++#ifdef CONFIG_OCF_RANDOMHARVEST
38749 ++	if (sc->sc_exec_units & TALITOS_HAS_EU_RNG)
38750 ++		talitos_rng_init(sc);
38751 ++#endif
38752 ++
38753 ++	/* Okay. Stand by. */
38754 ++	spin_unlock_irqrestore(&sc->sc_chnfifolock[sc->sc_num_channels], flags);
38755 ++
38756 ++	return;
38757 ++}
38758 ++
38759 ++/* go through all channels descriptors, notifying OCF what's been done */
38760 ++static void talitos_doneprocessing(struct talitos_softc *sc)
38761 ++{
38762 ++	unsigned long flags;
38763 ++	int i, j;
38764 ++
38765 ++	/* go through descriptors looking for done bits */
38766 ++	for (i = 0; i < sc->sc_num_channels; i++) {
38767 ++		spin_lock_irqsave(&sc->sc_chnfifolock[i], flags);
38768 ++		for (j = 0; j < sc->sc_chfifo_len; j++) {
38769 ++			/* descriptor has done bits set? */
38770 ++			if ((sc->sc_chnfifo[i][j].cf_desc.hdr 
38771 ++				& TALITOS_HDR_DONE_BITS) 
38772 ++				== TALITOS_HDR_DONE_BITS) {
38773 ++				/* notify ocf */
38774 ++				crypto_done(sc->sc_chnfifo[i][j].cf_crp);
38775 ++				/* and tag it available again
38776 ++				 *
38777 ++				 * memset to ensure correct descriptor formation by
38778 ++				 * avoiding inadvertently setting "optional" entries
38779 ++				 * e.g. not using "optional" dptr2 MD/HMAC processing
38780 ++				 */
38781 ++				memset(&sc->sc_chnfifo[i][j].cf_desc,
38782 ++					0, sizeof(struct talitos_desc));
38783 ++			}
38784 ++		}
38785 ++		spin_unlock_irqrestore(&sc->sc_chnfifolock[i], flags);
38786 ++	}
38787 ++	return;
38788 ++}
38789 ++
38790 ++static irqreturn_t
38791 ++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
38792 ++talitos_intr(int irq, void *arg)
38793 ++#else
38794 ++talitos_intr(int irq, void *arg, struct pt_regs *regs)
38795 ++#endif
38796 ++{
38797 ++	struct talitos_softc *sc = arg;
38798 ++	u_int32_t v, v_hi;
38799 ++	
38800 ++	/* ack */
38801 ++	v = talitos_read(sc->sc_base_addr + TALITOS_ISR);
38802 ++	v_hi = talitos_read(sc->sc_base_addr + TALITOS_ISR_HI);
38803 ++	talitos_write(sc->sc_base_addr + TALITOS_ICR, v);
38804 ++	talitos_write(sc->sc_base_addr + TALITOS_ICR_HI, v_hi);
38805 ++
38806 ++	if (unlikely(v & TALITOS_ISR_ERROR)) {
38807 ++		/* Okay, Houston, we've had a problem here. */
38808 ++		printk(KERN_DEBUG "%s: got error interrupt - ISR 0x%08x_%08x\n",
38809 ++				device_get_nameunit(sc->sc_cdev), v, v_hi);
38810 ++		talitos_errorprocessing(sc);
38811 ++	} else
38812 ++	if (likely(v & TALITOS_ISR_DONE)) {
38813 ++		talitos_doneprocessing(sc);
38814 ++	}
38815 ++	return IRQ_HANDLED;
38816 ++}
38817 ++
38818 ++/*
38819 ++ * Initialize registers we need to touch only once.
38820 ++ */
38821 ++static void
38822 ++talitos_init_device(struct talitos_softc *sc)
38823 ++{
38824 ++	u_int32_t v;
38825 ++	int i;
38826 ++
38827 ++	DPRINTF("%s()\n", __FUNCTION__);
38828 ++
38829 ++	/* init all channels */
38830 ++	for (i = 0; i < sc->sc_num_channels; i++) {
38831 ++		v = talitos_read(sc->sc_base_addr + 
38832 ++			i*TALITOS_CH_OFFSET + TALITOS_CH_CCCR_HI);
38833 ++		v |= TALITOS_CH_CCCR_HI_CDWE
38834 ++		  |  TALITOS_CH_CCCR_HI_CDIE;  /* invoke interrupt if done */
38835 ++		talitos_write(sc->sc_base_addr + 
38836 ++			i*TALITOS_CH_OFFSET + TALITOS_CH_CCCR_HI, v);
38837 ++	}
38838 ++	/* enable all interrupts */
38839 ++	v = talitos_read(sc->sc_base_addr + TALITOS_IMR);
38840 ++	v |= TALITOS_IMR_ALL;
38841 ++	talitos_write(sc->sc_base_addr + TALITOS_IMR, v);
38842 ++	v = talitos_read(sc->sc_base_addr + TALITOS_IMR_HI);
38843 ++	v |= TALITOS_IMR_HI_ERRONLY;
38844 ++	talitos_write(sc->sc_base_addr + TALITOS_IMR_HI, v);
38845 ++	return;
38846 ++}
38847 ++
38848 ++/*
38849 ++ * set the master reset bit on the device.
38850 ++ */
38851 ++static void
38852 ++talitos_reset_device_master(struct talitos_softc *sc)
38853 ++{
38854 ++	u_int32_t v;
38855 ++
38856 ++	/* Reset the device by writing 1 to MCR:SWR and waiting 'til cleared */
38857 ++	v = talitos_read(sc->sc_base_addr + TALITOS_MCR);
38858 ++	talitos_write(sc->sc_base_addr + TALITOS_MCR, v | TALITOS_MCR_SWR);
38859 ++
38860 ++	while (talitos_read(sc->sc_base_addr + TALITOS_MCR) & TALITOS_MCR_SWR)
38861 ++		cpu_relax();
38862 ++
38863 ++	return;
38864 ++}
38865 ++
38866 ++/*
38867 ++ * Resets the device.  Values in the registers are left as is
38868 ++ * from the reset (i.e. initial values are assigned elsewhere).
38869 ++ */
38870 ++static void
38871 ++talitos_reset_device(struct talitos_softc *sc)
38872 ++{
38873 ++	u_int32_t v;
38874 ++	int i;
38875 ++
38876 ++	DPRINTF("%s()\n", __FUNCTION__);
38877 ++
38878 ++	/*
38879 ++	 * Master reset
38880 ++	 * errata documentation: warning: certain SEC interrupts 
38881 ++	 * are not fully cleared by writing the MCR:SWR bit, 
38882 ++	 * set bit twice to completely reset 
38883 ++	 */
38884 ++	talitos_reset_device_master(sc);	/* once */
38885 ++	talitos_reset_device_master(sc);	/* and once again */
38886 ++	
38887 ++	/* reset all channels */
38888 ++	for (i = 0; i < sc->sc_num_channels; i++) {
38889 ++		v = talitos_read(sc->sc_base_addr + i*TALITOS_CH_OFFSET +
38890 ++			TALITOS_CH_CCCR);
38891 ++		talitos_write(sc->sc_base_addr + i*TALITOS_CH_OFFSET +
38892 ++			TALITOS_CH_CCCR, v | TALITOS_CH_CCCR_RESET);
38893 ++	}
38894 ++}
38895 ++
38896 ++/* Set up the crypto device structure, private data,
38897 ++ * and anything else we need before we start */
38898 ++#ifdef CONFIG_PPC_MERGE
38899 ++static int talitos_probe(struct of_device *ofdev, const struct of_device_id *match)
38900 ++#else
38901 ++static int talitos_probe(struct platform_device *pdev)
38902 ++#endif
38903 ++{
38904 ++	struct talitos_softc *sc = NULL;
38905 ++	struct resource *r;
38906 ++#ifdef CONFIG_PPC_MERGE
38907 ++	struct device *device = &ofdev->dev;
38908 ++	struct device_node *np = ofdev->node;
38909 ++	const unsigned int *prop;
38910 ++#endif
38911 ++	static int num_chips = 0;
38912 ++	int rc;
38913 ++	int i;
38914 ++
38915 ++	DPRINTF("%s()\n", __FUNCTION__);
38916 ++
38917 ++	sc = (struct talitos_softc *) kmalloc(sizeof(*sc), GFP_KERNEL);
38918 ++	if (!sc)
38919 ++		return -ENOMEM;
38920 ++	memset(sc, 0, sizeof(*sc));
38921 ++
38922 ++	softc_device_init(sc, DRV_NAME, num_chips, talitos_methods);
38923 ++
38924 ++	sc->sc_irq = -1;
38925 ++	sc->sc_cid = -1;
38926 ++#ifdef CONFIG_PPC_MERGE
38927 ++	sc->sc_dev = device;
38928 ++#else
38929 ++	sc->sc_dev = pdev;
38930 ++#endif
38931 ++	sc->sc_num = num_chips++;
38932 ++
38933 ++#ifdef CONFIG_PPC_MERGE
38934 ++	dev_set_drvdata(device, sc);
38935 ++#else
38936 ++	platform_set_drvdata(sc->sc_dev, sc);
38937 ++#endif
38938 ++
38939 ++	/* get the irq line */
38940 ++#ifdef CONFIG_PPC_MERGE
38941 ++	err = of_address_to_resource(np, 0, &res);
38942 ++	if (err)
38943 ++		return -EINVAL;
38944 ++
38945 ++	sc->sc_irq = irq_of_parse_and_map(np, 0);
38946 ++#else
38947 ++	/* get a pointer to the register memory */
38948 ++	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
38949 ++
38950 ++	sc->sc_irq = platform_get_irq(pdev, 0);
38951 ++#endif
38952 ++	rc = request_irq(sc->sc_irq, talitos_intr, 0,
38953 ++			device_get_nameunit(sc->sc_cdev), sc);
38954 ++	if (rc) {
38955 ++		printk(KERN_ERR "%s: failed to hook irq %d\n", 
38956 ++				device_get_nameunit(sc->sc_cdev), sc->sc_irq);
38957 ++		sc->sc_irq = -1;
38958 ++		goto out;
38959 ++	}
38960 ++
38961 ++	sc->sc_base_addr = (ocf_iomem_t) ioremap(r->start, (r->end - r->start));
38962 ++	if (!sc->sc_base_addr) {
38963 ++		printk(KERN_ERR "%s: failed to ioremap\n",
38964 ++				device_get_nameunit(sc->sc_cdev));
38965 ++		goto out;
38966 ++	}
38967 ++
38968 ++	/* figure out our SEC's properties and capabilities */
38969 ++	sc->sc_chiprev = (u64)talitos_read(sc->sc_base_addr + TALITOS_ID) << 32
38970 ++		 | talitos_read(sc->sc_base_addr + TALITOS_ID_HI);
38971 ++	DPRINTF("sec id 0x%llx\n", sc->sc_chiprev);
38972 ++
38973 ++#ifdef CONFIG_PPC_MERGE
38974 ++	/* get SEC properties from device tree, defaulting to SEC 2.0 */
38975 ++
38976 ++	prop = of_get_property(np, "num-channels", NULL);
38977 ++	sc->sc_num_channels = prop ? *prop : TALITOS_NCHANNELS_SEC_2_0;
38978 ++
38979 ++	prop = of_get_property(np, "channel-fifo-len", NULL);
38980 ++	sc->sc_chfifo_len = prop ? *prop : TALITOS_CHFIFOLEN_SEC_2_0;
38981 ++
38982 ++	prop = of_get_property(np, "exec-units-mask", NULL);
38983 ++	sc->sc_exec_units = prop ? *prop : TALITOS_HAS_EUS_SEC_2_0;
38984 ++
38985 ++	prop = of_get_property(np, "descriptor-types-mask", NULL);
38986 ++	sc->sc_desc_types = prop ? *prop : TALITOS_HAS_DESCTYPES_SEC_2_0;
38987 ++#else
38988 ++	/* bulk should go away with openfirmware flat device tree support */
38989 ++	if (sc->sc_chiprev & TALITOS_ID_SEC_2_0) {
38990 ++		sc->sc_num_channels = TALITOS_NCHANNELS_SEC_2_0;
38991 ++		sc->sc_chfifo_len = TALITOS_CHFIFOLEN_SEC_2_0;
38992 ++		sc->sc_exec_units = TALITOS_HAS_EUS_SEC_2_0;
38993 ++		sc->sc_desc_types = TALITOS_HAS_DESCTYPES_SEC_2_0;
38994 ++	} else {
38995 ++		printk(KERN_ERR "%s: failed to id device\n",
38996 ++				device_get_nameunit(sc->sc_cdev));
38997 ++		goto out;
38998 ++	}
38999 ++#endif
39000 ++
39001 ++	/* + 1 is for the meta-channel lock used by the channel scheduler */
39002 ++	sc->sc_chnfifolock = (spinlock_t *) kmalloc(
39003 ++		(sc->sc_num_channels + 1) * sizeof(spinlock_t), GFP_KERNEL);
39004 ++	if (!sc->sc_chnfifolock)
39005 ++		goto out;
39006 ++	for (i = 0; i < sc->sc_num_channels + 1; i++) {
39007 ++		spin_lock_init(&sc->sc_chnfifolock[i]);
39008 ++	}
39009 ++
39010 ++	sc->sc_chnlastalg = (int *) kmalloc(
39011 ++		sc->sc_num_channels * sizeof(int), GFP_KERNEL);
39012 ++	if (!sc->sc_chnlastalg)
39013 ++		goto out;
39014 ++	memset(sc->sc_chnlastalg, 0, sc->sc_num_channels * sizeof(int));
39015 ++
39016 ++	sc->sc_chnfifo = (struct desc_cryptop_pair **) kmalloc(
39017 ++		sc->sc_num_channels * sizeof(struct desc_cryptop_pair *), 
39018 ++		GFP_KERNEL);
39019 ++	if (!sc->sc_chnfifo)
39020 ++		goto out;
39021 ++	for (i = 0; i < sc->sc_num_channels; i++) {
39022 ++		sc->sc_chnfifo[i] = (struct desc_cryptop_pair *) kmalloc(
39023 ++			sc->sc_chfifo_len * sizeof(struct desc_cryptop_pair), 
39024 ++			GFP_KERNEL);
39025 ++		if (!sc->sc_chnfifo[i])
39026 ++			goto out;
39027 ++		memset(sc->sc_chnfifo[i], 0, 
39028 ++			sc->sc_chfifo_len * sizeof(struct desc_cryptop_pair));
39029 ++	}
39030 ++
39031 ++	/* reset and initialize the SEC h/w device */
39032 ++	talitos_reset_device(sc);
39033 ++	talitos_init_device(sc);
39034 ++
39035 ++	sc->sc_cid = crypto_get_driverid(softc_get_device(sc),CRYPTOCAP_F_HARDWARE);
39036 ++	if (sc->sc_cid < 0) {
39037 ++		printk(KERN_ERR "%s: could not get crypto driver id\n",
39038 ++				device_get_nameunit(sc->sc_cdev));
39039 ++		goto out;
39040 ++	}
39041 ++
39042 ++	/* register algorithms with the framework */
39043 ++	printk("%s:", device_get_nameunit(sc->sc_cdev));
39044 ++
39045 ++	if (sc->sc_exec_units & TALITOS_HAS_EU_RNG)  {
39046 ++		printk(" rng");
39047 ++#ifdef CONFIG_OCF_RANDOMHARVEST
39048 ++		talitos_rng_init(sc);
39049 ++		crypto_rregister(sc->sc_cid, talitos_read_random, sc);
39050 ++#endif
39051 ++	}
39052 ++	if (sc->sc_exec_units & TALITOS_HAS_EU_DEU) {
39053 ++		printk(" des/3des");
39054 ++		crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
39055 ++		crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0);
39056 ++	}
39057 ++	if (sc->sc_exec_units & TALITOS_HAS_EU_AESU) {
39058 ++		printk(" aes");
39059 ++		crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0);
39060 ++	}
39061 ++	if (sc->sc_exec_units & TALITOS_HAS_EU_MDEU) {
39062 ++		printk(" md5");
39063 ++		crypto_register(sc->sc_cid, CRYPTO_MD5, 0, 0);
39064 ++		/* HMAC support only with IPsec for now */
39065 ++		crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0);
39066 ++		printk(" sha1");
39067 ++		crypto_register(sc->sc_cid, CRYPTO_SHA1, 0, 0);
39068 ++		/* HMAC support only with IPsec for now */
39069 ++		crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0);
39070 ++	}
39071 ++	printk("\n");
39072 ++	return 0;
39073 ++
39074 ++out:
39075 ++#ifndef CONFIG_PPC_MERGE
39076 ++	talitos_remove(pdev);
39077 ++#endif
39078 ++	return -ENOMEM;
39079 ++}
39080 ++
39081 ++static int talitos_remove(struct platform_device *pdev)
39082 ++{
39083 ++	struct talitos_softc *sc = platform_get_drvdata(pdev);
39084 ++	int i;
39085 ++
39086 ++	DPRINTF("%s()\n", __FUNCTION__);
39087 ++	if (sc->sc_cid >= 0)
39088 ++		crypto_unregister_all(sc->sc_cid);
39089 ++	if (sc->sc_chnfifo) {
39090 ++		for (i = 0; i < sc->sc_num_channels; i++)
39091 ++			if (sc->sc_chnfifo[i])
39092 ++				kfree(sc->sc_chnfifo[i]);
39093 ++		kfree(sc->sc_chnfifo);
39094 ++	}
39095 ++	if (sc->sc_chnlastalg)
39096 ++		kfree(sc->sc_chnlastalg);
39097 ++	if (sc->sc_chnfifolock)
39098 ++		kfree(sc->sc_chnfifolock);
39099 ++	if (sc->sc_irq != -1)
39100 ++		free_irq(sc->sc_irq, sc);
39101 ++	if (sc->sc_base_addr)
39102 ++		iounmap((void *) sc->sc_base_addr);
39103 ++	kfree(sc);
39104 ++	return 0;
39105 ++}
39106 ++
39107 ++#ifdef CONFIG_PPC_MERGE
39108 ++static struct of_device_id talitos_match[] = {
39109 ++	{
39110 ++		.type = "crypto",
39111 ++		.compatible = "talitos",
39112 ++	},
39113 ++	{},
39114 ++};
39115 ++
39116 ++MODULE_DEVICE_TABLE(of, talitos_match);
39117 ++
39118 ++static struct of_platform_driver talitos_driver = {
39119 ++	.name		= DRV_NAME,
39120 ++	.match_table	= talitos_match,
39121 ++	.probe		= talitos_probe,
39122 ++	.remove		= talitos_remove,
39123 ++};
39124 ++
39125 ++static int __init talitos_init(void)
39126 ++{
39127 ++	return of_platform_driver_register(&talitos_driver);
39128 ++}
39129 ++
39130 ++static void __exit talitos_exit(void)
39131 ++{
39132 ++	of_platform_driver_unregister(&talitos_driver);
39133 ++}
39134 ++#else
39135 ++/* Structure for a platform device driver */
39136 ++static struct platform_driver talitos_driver = {
39137 ++	.probe = talitos_probe,
39138 ++	.remove = talitos_remove,
39139 ++	.driver = {
39140 ++		.name = "fsl-sec2",
39141 ++	}
39142 ++};
39143 ++
39144 ++static int __init talitos_init(void)
39145 ++{
39146 ++	return platform_driver_register(&talitos_driver);
39147 ++}
39148 ++
39149 ++static void __exit talitos_exit(void)
39150 ++{
39151 ++	platform_driver_unregister(&talitos_driver);
39152 ++}
39153 ++#endif
39154 ++
39155 ++module_init(talitos_init);
39156 ++module_exit(talitos_exit);
39157 ++
39158 ++MODULE_LICENSE("Dual BSD/GPL");
39159 ++MODULE_AUTHOR("kim.phillips@freescale.com");
39160 ++MODULE_DESCRIPTION("OCF driver for Freescale SEC (talitos)");
39161 +diff -urN linux-2.6.23.16.old/crypto/ocf/talitos/talitos_dev.h linux-2.6.23.16/crypto/ocf/talitos/talitos_dev.h
39162 +--- linux-2.6.23.16.old/crypto/ocf/talitos/talitos_dev.h	1969-12-31 19:00:00.000000000 -0500
39163 ++++ linux-2.6.23.16/crypto/ocf/talitos/talitos_dev.h	2008-02-26 09:29:13.000000000 -0500
39164 +@@ -0,0 +1,277 @@
39165 ++/*
39166 ++ * Freescale SEC (talitos) device dependent data structures
39167 ++ *
39168 ++ * Copyright (c) 2006 Freescale Semiconductor, Inc.
39169 ++ *
39170 ++ * Redistribution and use in source and binary forms, with or without
39171 ++ * modification, are permitted provided that the following conditions
39172 ++ * are met:
39173 ++ *
39174 ++ * 1. Redistributions of source code must retain the above copyright
39175 ++ *    notice, this list of conditions and the following disclaimer.
39176 ++ * 2. Redistributions in binary form must reproduce the above copyright
39177 ++ *    notice, this list of conditions and the following disclaimer in the
39178 ++ *    documentation and/or other materials provided with the distribution.
39179 ++ * 3. The name of the author may not be used to endorse or promote products
39180 ++ *    derived from this software without specific prior written permission.
39181 ++ *
39182 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39183 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39184 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39185 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
39186 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
39187 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39188 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39189 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39190 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39191 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39192 ++ *
39193 ++ */
39194 ++
39195 ++/* device ID register values */
39196 ++#define TALITOS_ID_SEC_2_0	0x40
39197 ++#define TALITOS_ID_SEC_2_1	0x40 /* cross ref with IP block revision reg */
39198 ++
39199 ++/*
39200 ++ * following num_channels, channel-fifo-depth, exec-unit-mask, and 
39201 ++ * descriptor-types-mask are for forward-compatibility with openfirmware
39202 ++ * flat device trees
39203 ++ */
39204 ++
39205 ++/*
39206 ++ *  num_channels : the number of channels available in each SEC version.
39207 ++ */
39208 ++
39209 ++/* n.b. this driver requires these values be a power of 2 */
39210 ++#define TALITOS_NCHANNELS_SEC_1_0	4
39211 ++#define TALITOS_NCHANNELS_SEC_1_2	1
39212 ++#define TALITOS_NCHANNELS_SEC_2_0	4
39213 ++#define TALITOS_NCHANNELS_SEC_2_01	4
39214 ++#define TALITOS_NCHANNELS_SEC_2_1	4
39215 ++#define TALITOS_NCHANNELS_SEC_2_4	4
39216 ++
39217 ++/*
39218 ++ *  channel-fifo-depth : The number of descriptor
39219 ++ *  pointers a channel fetch fifo can hold.
39220 ++ */
39221 ++#define TALITOS_CHFIFOLEN_SEC_1_0	1
39222 ++#define TALITOS_CHFIFOLEN_SEC_1_2	1
39223 ++#define TALITOS_CHFIFOLEN_SEC_2_0	24
39224 ++#define TALITOS_CHFIFOLEN_SEC_2_01	24
39225 ++#define TALITOS_CHFIFOLEN_SEC_2_1	24
39226 ++#define TALITOS_CHFIFOLEN_SEC_2_4	24
39227 ++
39228 ++/* 
39229 ++ *  exec-unit-mask : The bitmask representing what Execution Units (EUs)
39230 ++ *  are available. EU information should be encoded following the SEC's 
39231 ++ *  EU_SEL0 bitfield documentation, i.e. as follows:
39232 ++ * 
39233 ++ *    bit 31 = set if SEC permits no-EU selection (should be always set)
39234 ++ *    bit 30 = set if SEC has the ARC4 EU (AFEU)
39235 ++ *    bit 29 = set if SEC has the des/3des EU (DEU)
39236 ++ *    bit 28 = set if SEC has the message digest EU (MDEU)
39237 ++ *    bit 27 = set if SEC has the random number generator EU (RNG)
39238 ++ *    bit 26 = set if SEC has the public key EU (PKEU)
39239 ++ *    bit 25 = set if SEC has the aes EU (AESU)
39240 ++ *    bit 24 = set if SEC has the Kasumi EU (KEU)
39241 ++ * 
39242 ++ */
39243 ++#define TALITOS_HAS_EU_NONE		(1<<0)
39244 ++#define TALITOS_HAS_EU_AFEU		(1<<1)
39245 ++#define TALITOS_HAS_EU_DEU		(1<<2)
39246 ++#define TALITOS_HAS_EU_MDEU		(1<<3)
39247 ++#define TALITOS_HAS_EU_RNG		(1<<4)
39248 ++#define TALITOS_HAS_EU_PKEU		(1<<5)
39249 ++#define TALITOS_HAS_EU_AESU		(1<<6)
39250 ++#define TALITOS_HAS_EU_KEU		(1<<7)
39251 ++
39252 ++/* the corresponding masks for each SEC version */
39253 ++#define TALITOS_HAS_EUS_SEC_1_0		0x7f
39254 ++#define TALITOS_HAS_EUS_SEC_1_2		0x4d
39255 ++#define TALITOS_HAS_EUS_SEC_2_0		0x7f
39256 ++#define TALITOS_HAS_EUS_SEC_2_01	0x7f
39257 ++#define TALITOS_HAS_EUS_SEC_2_1		0xff
39258 ++#define TALITOS_HAS_EUS_SEC_2_4		0x7f
39259 ++
39260 ++/*
39261 ++ *  descriptor-types-mask : The bitmask representing what descriptors
39262 ++ *  are available. Descriptor type information should be encoded 
39263 ++ *  following the SEC's Descriptor Header Dword DESC_TYPE field 
39264 ++ *  documentation, i.e. as follows:
39265 ++ *
39266 ++ *    bit 0  = set if SEC supports the aesu_ctr_nonsnoop desc. type
39267 ++ *    bit 1  = set if SEC supports the ipsec_esp descriptor type
39268 ++ *    bit 2  = set if SEC supports the common_nonsnoop desc. type
39269 ++ *    bit 3  = set if SEC supports the 802.11i AES ccmp desc. type
39270 ++ *    bit 4  = set if SEC supports the hmac_snoop_no_afeu desc. type
39271 ++ *    bit 5  = set if SEC supports the srtp descriptor type
39272 ++ *    bit 6  = set if SEC supports the non_hmac_snoop_no_afeu desc.type
39273 ++ *    bit 7  = set if SEC supports the pkeu_assemble descriptor type
39274 ++ *    bit 8  = set if SEC supports the aesu_key_expand_output desc.type
39275 ++ *    bit 9  = set if SEC supports the pkeu_ptmul descriptor type
39276 ++ *    bit 10 = set if SEC supports the common_nonsnoop_afeu desc. type
39277 ++ *    bit 11 = set if SEC supports the pkeu_ptadd_dbl descriptor type
39278 ++ *
39279 ++ *  ..and so on and so forth.
39280 ++ */
39281 ++#define TALITOS_HAS_DT_AESU_CTR_NONSNOOP	(1<<0)
39282 ++#define TALITOS_HAS_DT_IPSEC_ESP		(1<<1)
39283 ++#define TALITOS_HAS_DT_COMMON_NONSNOOP		(1<<2)
39284 ++
39285 ++/* the corresponding masks for each SEC version */
39286 ++#define TALITOS_HAS_DESCTYPES_SEC_2_0	0x01010ebf
39287 ++#define TALITOS_HAS_DESCTYPES_SEC_2_1	0x012b0ebf
39288 ++
39289 ++/* 
39290 ++ * a TALITOS_xxx_HI address points to the low data bits (32-63) of the register
39291 ++ */
39292 ++
39293 ++/* global register offset addresses */
39294 ++#define TALITOS_ID		0x1020
39295 ++#define TALITOS_ID_HI		0x1024
39296 ++#define TALITOS_MCR		0x1030		/* master control register */
39297 ++#define TALITOS_MCR_HI		0x1038		/* master control register */
39298 ++#define TALITOS_MCR_SWR		0x1
39299 ++#define TALITOS_IMR		0x1008		/* interrupt mask register */
39300 ++#define TALITOS_IMR_ALL		0x00010fff	/* enable all interrupts mask */
39301 ++#define TALITOS_IMR_ERRONLY	0x00010aaa	/* enable error interrupts */
39302 ++#define TALITOS_IMR_HI		0x100C		/* interrupt mask register */
39303 ++#define TALITOS_IMR_HI_ALL	0x00323333	/* enable all interrupts mask */
39304 ++#define TALITOS_IMR_HI_ERRONLY	0x00222222	/* enable error interrupts */
39305 ++#define TALITOS_ISR		0x1010		/* interrupt status register */
39306 ++#define TALITOS_ISR_ERROR	0x00010faa	/* errors mask */
39307 ++#define TALITOS_ISR_DONE	0x00000055	/* channel(s) done mask */
39308 ++#define TALITOS_ISR_HI		0x1014		/* interrupt status register */
39309 ++#define TALITOS_ICR		0x1018		/* interrupt clear register */
39310 ++#define TALITOS_ICR_HI		0x101C		/* interrupt clear register */
39311 ++
39312 ++/* channel register address stride */
39313 ++#define TALITOS_CH_OFFSET	0x100
39314 ++
39315 ++/* channel register offset addresses and bits */
39316 ++#define TALITOS_CH_CCCR		0x1108	/* Crypto-Channel Config Register */
39317 ++#define TALITOS_CH_CCCR_RESET	0x1	/* Channel Reset bit */
39318 ++#define TALITOS_CH_CCCR_HI	0x110c	/* Crypto-Channel Config Register */
39319 ++#define TALITOS_CH_CCCR_HI_CDWE	0x10	/* Channel done writeback enable bit */
39320 ++#define TALITOS_CH_CCCR_HI_NT	0x4	/* Notification type bit */
39321 ++#define TALITOS_CH_CCCR_HI_CDIE	0x2	/* Channel Done Interrupt Enable bit */
39322 ++#define TALITOS_CH_CCPSR	0x1110	/* Crypto-Channel Pointer Status Reg */
39323 ++#define TALITOS_CH_CCPSR_HI	0x1114	/* Crypto-Channel Pointer Status Reg */
39324 ++#define TALITOS_CH_FF		0x1148	/* Fetch FIFO */
39325 ++#define TALITOS_CH_FF_HI	0x114c	/* Fetch FIFO's FETCH_ADRS */
39326 ++#define TALITOS_CH_CDPR		0x1140	/* Crypto-Channel Pointer Status Reg */
39327 ++#define TALITOS_CH_CDPR_HI	0x1144	/* Crypto-Channel Pointer Status Reg */
39328 ++#define TALITOS_CH_DESCBUF	0x1180	/* (thru 11bf) Crypto-Channel 
39329 ++					 * Descriptor Buffer (debug) */
39330 ++
39331 ++/* execution unit register offset addresses and bits */
39332 ++#define TALITOS_DEUSR		0x2028	/* DEU status register */
39333 ++#define TALITOS_DEUSR_HI	0x202c	/* DEU status register */
39334 ++#define TALITOS_DEUISR		0x2030	/* DEU interrupt status register */
39335 ++#define TALITOS_DEUISR_HI	0x2034	/* DEU interrupt status register */
39336 ++#define TALITOS_DEUICR		0x2038	/* DEU interrupt control register */
39337 ++#define TALITOS_DEUICR_HI	0x203c	/* DEU interrupt control register */
39338 ++#define TALITOS_AESUISR		0x4030	/* AESU interrupt status register */
39339 ++#define TALITOS_AESUISR_HI	0x4034	/* AESU interrupt status register */
39340 ++#define TALITOS_AESUICR		0x4038	/* AESU interrupt control register */
39341 ++#define TALITOS_AESUICR_HI	0x403c	/* AESU interrupt control register */
39342 ++#define TALITOS_MDEUISR		0x6030	/* MDEU interrupt status register */
39343 ++#define TALITOS_MDEUISR_HI	0x6034	/* MDEU interrupt status register */
39344 ++#define TALITOS_RNGSR		0xa028	/* RNG status register */
39345 ++#define TALITOS_RNGSR_HI	0xa02c	/* RNG status register */
39346 ++#define TALITOS_RNGSR_HI_RD	0x1	/* RNG Reset done */
39347 ++#define TALITOS_RNGSR_HI_OFL	0xff0000/* number of dwords in RNG output FIFO*/
39348 ++#define TALITOS_RNGDSR		0xa010	/* RNG data size register */
39349 ++#define TALITOS_RNGDSR_HI	0xa014	/* RNG data size register */
39350 ++#define TALITOS_RNG_FIFO	0xa800	/* RNG FIFO - pool of random numbers */
39351 ++#define TALITOS_RNGISR		0xa030	/* RNG Interrupt status register */
39352 ++#define TALITOS_RNGISR_HI	0xa034	/* RNG Interrupt status register */
39353 ++#define TALITOS_RNGRCR		0xa018	/* RNG Reset control register */
39354 ++#define TALITOS_RNGRCR_HI	0xa01c	/* RNG Reset control register */
39355 ++#define TALITOS_RNGRCR_HI_SR	0x1	/* RNG RNGRCR:Software Reset */
39356 ++
39357 ++/* descriptor pointer entry */
39358 ++struct talitos_desc_ptr {
39359 ++	u16	len;		/* length */
39360 ++	u8	extent;		/* jump (to s/g link table) and extent */
39361 ++	u8	res;		/* reserved */
39362 ++	u32	ptr;		/* pointer */
39363 ++};
39364 ++
39365 ++/* descriptor */
39366 ++struct talitos_desc {
39367 ++	u32	hdr;				/* header */
39368 ++	u32	res;				/* reserved */
39369 ++	struct talitos_desc_ptr		ptr[7];	/* ptr/len pair array */
39370 ++};
39371 ++
39372 ++/* talitos descriptor header (hdr) bits */
39373 ++
39374 ++/* primary execution unit select */
39375 ++#define	TALITOS_SEL0_AFEU	0x10000000
39376 ++#define	TALITOS_SEL0_DEU	0x20000000
39377 ++#define	TALITOS_SEL0_MDEU	0x30000000
39378 ++#define	TALITOS_SEL0_RNG	0x40000000
39379 ++#define	TALITOS_SEL0_PKEU	0x50000000
39380 ++#define	TALITOS_SEL0_AESU	0x60000000
39381 ++
39382 ++/* primary execution unit mode (MODE0) and derivatives */
39383 ++#define	TALITOS_MODE0_AESU_CBC		0x00200000
39384 ++#define	TALITOS_MODE0_AESU_ENC		0x00100000
39385 ++#define	TALITOS_MODE0_DEU_CBC		0x00400000
39386 ++#define	TALITOS_MODE0_DEU_3DES		0x00200000
39387 ++#define	TALITOS_MODE0_DEU_ENC		0x00100000
39388 ++#define	TALITOS_MODE0_MDEU_INIT		0x01000000	/* init starting regs */
39389 ++#define	TALITOS_MODE0_MDEU_HMAC		0x00800000
39390 ++#define	TALITOS_MODE0_MDEU_PAD		0x00400000	/* PD */
39391 ++#define	TALITOS_MODE0_MDEU_MD5		0x00200000
39392 ++#define	TALITOS_MODE0_MDEU_SHA256	0x00100000
39393 ++#define	TALITOS_MODE0_MDEU_SHA1		0x00000000	/* SHA-160 */
39394 ++#define	TALITOS_MODE0_MDEU_MD5_HMAC	\
39395 ++		(TALITOS_MODE0_MDEU_MD5 | TALITOS_MODE0_MDEU_HMAC)
39396 ++#define	TALITOS_MODE0_MDEU_SHA256_HMAC	\
39397 ++		(TALITOS_MODE0_MDEU_SHA256 | TALITOS_MODE0_MDEU_HMAC)
39398 ++#define	TALITOS_MODE0_MDEU_SHA1_HMAC	\
39399 ++		(TALITOS_MODE0_MDEU_SHA1 | TALITOS_MODE0_MDEU_HMAC)
39400 ++
39401 ++/* secondary execution unit select (SEL1) */
39402 ++/* it's MDEU or nothing */
39403 ++#define	TALITOS_SEL1_MDEU	0x00030000
39404 ++
39405 ++/* secondary execution unit mode (MODE1) and derivatives */
39406 ++#define	TALITOS_MODE1_MDEU_INIT		0x00001000	/* init starting regs */
39407 ++#define	TALITOS_MODE1_MDEU_HMAC		0x00000800
39408 ++#define	TALITOS_MODE1_MDEU_PAD		0x00000400	/* PD */
39409 ++#define	TALITOS_MODE1_MDEU_MD5		0x00000200
39410 ++#define	TALITOS_MODE1_MDEU_SHA256	0x00000100
39411 ++#define	TALITOS_MODE1_MDEU_SHA1		0x00000000	/* SHA-160 */
39412 ++#define	TALITOS_MODE1_MDEU_MD5_HMAC	\
39413 ++	(TALITOS_MODE1_MDEU_MD5 | TALITOS_MODE1_MDEU_HMAC)
39414 ++#define	TALITOS_MODE1_MDEU_SHA256_HMAC	\
39415 ++	(TALITOS_MODE1_MDEU_SHA256 | TALITOS_MODE1_MDEU_HMAC)
39416 ++#define	TALITOS_MODE1_MDEU_SHA1_HMAC	\
39417 ++	(TALITOS_MODE1_MDEU_SHA1 | TALITOS_MODE1_MDEU_HMAC)
39418 ++
39419 ++/* direction of overall data flow (DIR) */
39420 ++#define	TALITOS_DIR_OUTBOUND	0x00000000
39421 ++#define	TALITOS_DIR_INBOUND	0x00000002
39422 ++
39423 ++/* done notification (DN) */
39424 ++#define	TALITOS_DONE_NOTIFY	0x00000001
39425 ++
39426 ++/* descriptor types */
39427 ++/* odd numbers here are valid on SEC2 and greater only (e.g. ipsec_esp) */
39428 ++#define TD_TYPE_AESU_CTR_NONSNOOP	(0 << 3)
39429 ++#define TD_TYPE_IPSEC_ESP		(1 << 3)
39430 ++#define TD_TYPE_COMMON_NONSNOOP_NO_AFEU	(2 << 3)
39431 ++#define TD_TYPE_HMAC_SNOOP_NO_AFEU	(4 << 3)
39432 ++
39433 ++#define TALITOS_HDR_DONE_BITS	0xff000000
39434 ++
39435 ++#define	DPRINTF(a...)	do { \
39436 ++						if (debug) { \
39437 ++							printk("%s: ", sc ? \
39438 ++								device_get_nameunit(sc->sc_cdev) : "talitos"); \
39439 ++							printk(a); \
39440 ++						} \
39441 ++					} while (0)
39442 +diff -urN linux-2.6.23.16.old/crypto/ocf/talitos/talitos_soft.h linux-2.6.23.16/crypto/ocf/talitos/talitos_soft.h
39443 +--- linux-2.6.23.16.old/crypto/ocf/talitos/talitos_soft.h	1969-12-31 19:00:00.000000000 -0500
39444 ++++ linux-2.6.23.16/crypto/ocf/talitos/talitos_soft.h	2008-02-26 09:29:13.000000000 -0500
39445 +@@ -0,0 +1,77 @@
39446 ++/*
39447 ++ * Freescale SEC data structures for integration with ocf-linux
39448 ++ *
39449 ++ * Copyright (c) 2006 Freescale Semiconductor, Inc.
39450 ++ *
39451 ++ * Redistribution and use in source and binary forms, with or without
39452 ++ * modification, are permitted provided that the following conditions
39453 ++ * are met:
39454 ++ *
39455 ++ * 1. Redistributions of source code must retain the above copyright
39456 ++ *    notice, this list of conditions and the following disclaimer.
39457 ++ * 2. Redistributions in binary form must reproduce the above copyright
39458 ++ *    notice, this list of conditions and the following disclaimer in the
39459 ++ *    documentation and/or other materials provided with the distribution.
39460 ++ * 3. The name of the author may not be used to endorse or promote products
39461 ++ *    derived from this software without specific prior written permission.
39462 ++ *
39463 ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39464 ++ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39465 ++ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39466 ++ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
39467 ++ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
39468 ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39469 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39470 ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39471 ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39472 ++ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39473 ++ */
39474 ++
39475 ++/*
39476 ++ * paired descriptor and associated crypto operation
39477 ++ */
39478 ++struct desc_cryptop_pair {
39479 ++	struct talitos_desc	cf_desc;	/* descriptor ptr */
39480 ++	struct cryptop		*cf_crp;	/* cryptop ptr */
39481 ++};
39482 ++
39483 ++/*
39484 ++ * Holds data specific to a single talitos device.
39485 ++ */
39486 ++struct talitos_softc {
39487 ++	softc_device_decl	sc_cdev;
39488 ++	struct platform_device	*sc_dev;	/* device backpointer */
39489 ++	ocf_iomem_t		sc_base_addr;
39490 ++	int			sc_irq;
39491 ++	int			sc_num;		/* if we have multiple chips */
39492 ++	int32_t			sc_cid;		/* crypto tag */
39493 ++	u64			sc_chiprev;	/* major/minor chip revision */
39494 ++	int			sc_nsessions;
39495 ++	struct talitos_session	*sc_sessions;
39496 ++	int			sc_num_channels;/* number of crypto channels */
39497 ++	int			sc_chfifo_len;	/* channel fetch fifo len */
39498 ++	int			sc_exec_units;	/* execution units mask */
39499 ++	int			sc_desc_types;	/* descriptor types mask */
39500 ++	/*
39501 ++	 * mutual exclusion for intra-channel resources, e.g. fetch fifos
39502 ++	 * the last entry is a meta-channel lock used by the channel scheduler
39503 ++	 */
39504 ++	spinlock_t		*sc_chnfifolock;
39505 ++	/* sc_chnlastalgo contains last algorithm for that channel */
39506 ++	int			*sc_chnlastalg;
39507 ++	/* sc_chnfifo holds pending descriptor--crypto operation pairs */
39508 ++	struct desc_cryptop_pair	**sc_chnfifo;
39509 ++};
39510 ++
39511 ++struct talitos_session {
39512 ++	u_int32_t	ses_used;
39513 ++	u_int32_t	ses_klen;		/* key length in bits */
39514 ++	u_int32_t	ses_key[8];		/* DES/3DES/AES key */
39515 ++	u_int32_t	ses_hmac[5];		/* hmac inner state */
39516 ++	u_int32_t	ses_hmac_len;		/* hmac length */
39517 ++	u_int32_t	ses_iv[4];		/* DES/3DES/AES iv */
39518 ++	u_int32_t	ses_mlen;		/* desired hash result len (12=ipsec or 16) */
39519 ++};
39520 ++
39521 ++#define	TALITOS_SESSION(sid)	((sid) & 0x0fffffff)
39522 ++#define	TALITOS_SID(crd, sesn)	(((crd) << 28) | ((sesn) & 0x0fffffff))
39523 +diff -urN linux-2.6.23.16.old/crypto/ocf/uio.h linux-2.6.23.16/crypto/ocf/uio.h
39524 +--- linux-2.6.23.16.old/crypto/ocf/uio.h	1969-12-31 19:00:00.000000000 -0500
39525 ++++ linux-2.6.23.16/crypto/ocf/uio.h	2008-02-26 09:29:13.000000000 -0500
39526 +@@ -0,0 +1,54 @@
39527 ++#ifndef _OCF_UIO_H_
39528 ++#define _OCF_UIO_H_
39529 ++
39530 ++#include <linux/uio.h>
39531 ++
39532 ++/*
39533 ++ * The linux uio.h doesn't have all we need.  To be fully api compatible
39534 ++ * with the BSD cryptodev,  we need to keep this around.  Perhaps this can
39535 ++ * be moved back into the linux/uio.h
39536 ++ *
39537 ++ * Linux port done by David McCullough <david_mccullough@securecomputing.com>
39538 ++ * Copyright (C) 2006-2007 David McCullough
39539 ++ * Copyright (C) 2004-2005 Intel Corporation.
39540 ++ *
39541 ++ * LICENSE TERMS
39542 ++ *
39543 ++ * The free distribution and use of this software in both source and binary
39544 ++ * form is allowed (with or without changes) provided that:
39545 ++ *
39546 ++ *   1. distributions of this source code include the above copyright
39547 ++ *      notice, this list of conditions and the following disclaimer;
39548 ++ *
39549 ++ *   2. distributions in binary form include the above copyright
39550 ++ *      notice, this list of conditions and the following disclaimer
39551 ++ *      in the documentation and/or other associated materials;
39552 ++ *
39553 ++ *   3. the copyright holder's name is not used to endorse products
39554 ++ *      built using this software without specific written permission.
39555 ++ *
39556 ++ * ALTERNATIVELY, provided that this notice is retained in full, this product
39557 ++ * may be distributed under the terms of the GNU General Public License (GPL),
39558 ++ * in which case the provisions of the GPL apply INSTEAD OF those given above.
39559 ++ *
39560 ++ * DISCLAIMER
39561 ++ *
39562 ++ * This software is provided 'as is' with no explicit or implied warranties
39563 ++ * in respect of its properties, including, but not limited to, correctness
39564 ++ * and/or fitness for purpose.
39565 ++ * ---------------------------------------------------------------------------
39566 ++ */
39567 ++
39568 ++struct uio {
39569 ++	struct	iovec *uio_iov;
39570 ++	int		uio_iovcnt;
39571 ++	off_t	uio_offset;
39572 ++	int		uio_resid;
39573 ++#if 0
39574 ++	enum	uio_seg uio_segflg;
39575 ++	enum	uio_rw uio_rw;
39576 ++	struct  thread *uio_td;
39577 ++#endif
39578 ++};
39579 ++
39580 ++#endif
39581 +diff -urN linux-2.6.23.16.old/drivers/char/random.c linux-2.6.23.16/drivers/char/random.c
39582 +--- linux-2.6.23.16.old/drivers/char/random.c	2008-02-26 09:27:00.000000000 -0500
39583 ++++ linux-2.6.23.16/drivers/char/random.c	2008-02-26 09:29:13.000000000 -0500
39584 +@@ -129,6 +129,9 @@
39585 +  *                                unsigned int value);
39586 +  * 	void add_interrupt_randomness(int irq);
39587 +  *
39588 ++ *      void random_input_words(__u32 *buf, size_t wordcount, int ent_count)
39589 ++ *      int random_input_wait(void);
39590 ++ *
39591 +  * add_input_randomness() uses the input layer interrupt timing, as well as
39592 +  * the event type information from the hardware.
39593 +  *
39594 +@@ -140,6 +143,13 @@
39595 +  * a better measure, since the timing of the disk interrupts are more
39596 +  * unpredictable.
39597 +  *
39598 ++ * random_input_words() just provides a raw block of entropy to the input
39599 ++ * pool, such as from a hardware entropy generator.
39600 ++ *
39601 ++ * random_input_wait() suspends the caller until such time as the
39602 ++ * entropy pool falls below the write threshold, and returns a count of how
39603 ++ * much entropy (in bits) is needed to sustain the pool.
39604 ++ *
39605 +  * All of these routines try to estimate how many bits of randomness a
39606 +  * particular randomness source.  They do this by keeping track of the
39607 +  * first and second order deltas of the event timings.
39608 +@@ -671,6 +681,61 @@
39609 + EXPORT_SYMBOL(add_disk_randomness);
39610 + #endif
39611 + 
39612 ++/*
39613 ++ * random_input_words - add bulk entropy to pool
39614 ++ *
39615 ++ * @buf: buffer to add
39616 ++ * @wordcount: number of __u32 words to add
39617 ++ * @ent_count: total amount of entropy (in bits) to credit
39618 ++ *
39619 ++ * this provides bulk input of entropy to the input pool
39620 ++ *
39621 ++ */
39622 ++void random_input_words(__u32 *buf, size_t wordcount, int ent_count)
39623 ++{
39624 ++	add_entropy_words(&input_pool, buf, wordcount);
39625 ++
39626 ++	credit_entropy_store(&input_pool, ent_count);
39627 ++
39628 ++	DEBUG_ENT("crediting %d bits => %d\n",
39629 ++		  ent_count, input_pool.entropy_count);
39630 ++	/*
39631 ++	 * Wake up waiting processes if we have enough
39632 ++	 * entropy.
39633 ++	 */
39634 ++	if (input_pool.entropy_count >= random_read_wakeup_thresh)
39635 ++		wake_up_interruptible(&random_read_wait);
39636 ++}
39637 ++EXPORT_SYMBOL(random_input_words);
39638 ++
39639 ++/*
39640 ++ * random_input_wait - wait until random needs entropy
39641 ++ *
39642 ++ * this function sleeps until the /dev/random subsystem actually
39643 ++ * needs more entropy, and then return the amount of entropy
39644 ++ * that it would be nice to have added to the system.
39645 ++ */
39646 ++int random_input_wait(void)
39647 ++{
39648 ++	int count;
39649 ++
39650 ++	wait_event_interruptible(random_write_wait, 
39651 ++			 input_pool.entropy_count < random_write_wakeup_thresh);
39652 ++
39653 ++	count = random_write_wakeup_thresh - input_pool.entropy_count;
39654 ++
39655 ++        /* likely we got woken up due to a signal */
39656 ++	if (count <= 0) count = random_read_wakeup_thresh; 
39657 ++
39658 ++	DEBUG_ENT("requesting %d bits from input_wait()er %d<%d\n",
39659 ++		  count,
39660 ++		  input_pool.entropy_count, random_write_wakeup_thresh);
39661 ++
39662 ++	return count;
39663 ++}
39664 ++EXPORT_SYMBOL(random_input_wait);
39665 ++
39666 ++
39667 + #define EXTRACT_SIZE 10
39668 + 
39669 + /*********************************************************************
39670 +diff -urN linux-2.6.23.16.old/fs/fcntl.c linux-2.6.23.16/fs/fcntl.c
39671 +--- linux-2.6.23.16.old/fs/fcntl.c	2008-02-26 09:26:41.000000000 -0500
39672 ++++ linux-2.6.23.16/fs/fcntl.c	2008-02-26 09:29:13.000000000 -0500
39673 +@@ -198,6 +198,7 @@
39674 + 		ret = dupfd(file, 0);
39675 + 	return ret;
39676 + }
39677 ++EXPORT_SYMBOL(sys_dup);
39678 + 
39679 + #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | FASYNC | O_DIRECT | O_NOATIME)
39680 + 
39681 +diff -urN linux-2.6.23.16.old/include/linux/miscdevice.h linux-2.6.23.16/include/linux/miscdevice.h
39682 +--- linux-2.6.23.16.old/include/linux/miscdevice.h	2008-02-26 09:26:42.000000000 -0500
39683 ++++ linux-2.6.23.16/include/linux/miscdevice.h	2008-02-26 09:29:13.000000000 -0500
39684 +@@ -12,6 +12,7 @@
39685 + #define APOLLO_MOUSE_MINOR 7
39686 + #define PC110PAD_MINOR 9
39687 + /*#define ADB_MOUSE_MINOR 10	FIXME OBSOLETE */
39688 ++#define CRYPTODEV_MINOR		70	/* /dev/crypto */
39689 + #define WATCHDOG_MINOR		130	/* Watchdog timer     */
39690 + #define TEMP_MINOR		131	/* Temperature Sensor */
39691 + #define RTC_MINOR 135
39692 +diff -urN linux-2.6.23.16.old/include/linux/random.h linux-2.6.23.16/include/linux/random.h
39693 +--- linux-2.6.23.16.old/include/linux/random.h	2008-02-26 09:26:42.000000000 -0500
39694 ++++ linux-2.6.23.16/include/linux/random.h	2008-02-26 09:29:13.000000000 -0500
39695 +@@ -8,6 +8,7 @@
39696 + #define _LINUX_RANDOM_H
39697 + 
39698 + #include <linux/ioctl.h>
39699 ++#include <linux/types.h> /* for __u32 in user space */
39700 + 
39701 + /* ioctl()'s for the random number generator */
39702 + 
39703 +@@ -48,6 +49,10 @@
39704 + 				 unsigned int value);
39705 + extern void add_interrupt_randomness(int irq);
39706 + 
39707 ++extern void random_input_words(__u32 *buf, size_t wordcount, int ent_count);
39708 ++extern int random_input_wait(void);
39709 ++#define HAS_RANDOM_INPUT_WAIT 1
39710 ++
39711 + extern void get_random_bytes(void *buf, int nbytes);
39712 + void generate_random_uuid(unsigned char uuid_out[16]);
39713 + 
39714 diff -Nur kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/411-geode_aes-corrupted_mac.patch kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/411-geode_aes-corrupted_mac.patch
39715 --- kamikaze_7.09.orig/target/linux/generic-2.6/patches-2.6.22/411-geode_aes-corrupted_mac.patch	1970-01-01 01:00:00.000000000 +0100
39716 +++ kamikaze_7.09/target/linux/generic-2.6/patches-2.6.22/411-geode_aes-corrupted_mac.patch	2008-06-19 17:34:17.000000000 +0200
39717 @@ -0,0 +1,34 @@
39718 +diff -urN linux-2.6.23.16.old/drivers/crypto/geode-aes.c linux-2.6.23.16/drivers/crypto/geode-aes.c
39719 +--- linux-2.6.23.16.old/drivers/crypto/geode-aes.c	2008-02-26 11:48:45.000000000 -0500
39720 ++++ linux-2.6.23.16/drivers/crypto/geode-aes.c	2008-02-26 11:50:23.000000000 -0500
39721 +@@ -87,9 +87,10 @@
39722 + 	/* Start the operation */
39723 + 	iowrite32(AES_CTRL_START | flags, _iobase + AES_CTRLA_REG);
39724 + 
39725 +-	do
39726 ++	do {
39727 + 		status = ioread32(_iobase + AES_INTR_REG);
39728 +-	while(!(status & AES_INTRA_PENDING) && --counter);
39729 ++		cpu_relax();
39730 ++	} while(!(status & AES_INTRA_PENDING) && --counter);
39731 + 
39732 + 	/* Clear the event */
39733 + 	iowrite32((status & 0xFF) | AES_INTRA_PENDING, _iobase + AES_INTR_REG);
39734 +@@ -101,6 +102,7 @@
39735 + {
39736 + 	u32 flags = 0;
39737 + 	unsigned long iflags;
39738 ++	int ret;
39739 + 
39740 + 	if (op->len == 0)
39741 + 		return 0;
39742 +@@ -129,7 +131,8 @@
39743 + 		_writefield(AES_WRITEKEY0_REG, op->key);
39744 + 	}
39745 + 
39746 +-	do_crypt(op->src, op->dst, op->len, flags);
39747 ++	ret = do_crypt(op->src, op->dst, op->len, flags);
39748 ++	BUG_ON(ret);
39749 + 
39750 + 	if (op->mode == AES_MODE_CBC)
39751 + 		_readfield(AES_WRITEIV0_REG, op->iv);
39752 diff -Nur kamikaze_7.09.orig/target/linux/x86-2.6/config/default kamikaze_7.09/target/linux/x86-2.6/config/default
39753 --- kamikaze_7.09.orig/target/linux/x86-2.6/config/default	2007-09-20 10:54:17.000000000 +0200
39754 +++ kamikaze_7.09/target/linux/x86-2.6/config/default	2008-06-19 17:34:17.000000000 +0200
39755 @@ -65,6 +65,7 @@
39756  CONFIG_CPU_FREQ_STAT_DETAILS=y
39757  CONFIG_CPU_FREQ_TABLE=y
39758  CONFIG_CRYPTO_AES_586=m
39759 +CONFIG_CRYPTO_HW=y
39760  CONFIG_CRYPTO_DEV_GEODE=m
39761  # CONFIG_CRYPTO_DEV_PADLOCK is not set
39762  CONFIG_CRYPTO_TWOFISH_586=m
39763 @@ -115,9 +116,9 @@
39764  CONFIG_HW_CONSOLE=y
39765  CONFIG_HW_RANDOM=y
39766  # CONFIG_HW_RANDOM_AMD is not set
39767 -CONFIG_HW_RANDOM_GEODE=y
39768 +CONFIG_HW_RANDOM_GEODE=m
39769  # CONFIG_HW_RANDOM_INTEL is not set
39770 -CONFIG_HW_RANDOM_VIA=y
39771 +CONFIG_HW_RANDOM_VIA=m
39772  CONFIG_I2C=m
39773  CONFIG_I2C_ALGOBIT=m
39774  CONFIG_I2C_BOARDINFO=y
39775 @@ -170,6 +171,7 @@
39776  CONFIG_LEDS_NET48XX=m
39777  # CONFIG_LEDS_TRIGGER_IDE_DISK is not set
39778  # CONFIG_LEDS_WRAP is not set
39779 +CONFIG_LEDS_ALIX=m
39780  # CONFIG_LIBERTAS is not set
39781  # CONFIG_M386 is not set
39782  CONFIG_M486=y
39783 @@ -424,3 +426,17 @@
39784  # CONFIG_X86_VOYAGER is not set
39785  CONFIG_X86_WP_WORKS_OK=y
39786  CONFIG_X86_XADD=y
39787 +CONFIG_OCF_OCF=m
39788 +CONFIG_OCF_CRYPTODEV=m
39789 +CONFIG_OCF_CRYPTOSOFT=m
39790 +# CONFIG_OCF_RANDOMHARVEST is not set
39791 +# CONFIG_OCF_FIPS is not set
39792 +# CONFIG_OCF_SAFE is not set
39793 +# CONFIG_OCF_IXP4XX is not set
39794 +# CONFIG_OCF_IXP4XX_SHA1_MD5 is not set
39795 +# CONFIG_OCF_HIFN is not set
39796 +# CONFIG_OCF_HIFNHIPP is not set
39797 +# CONFIG_OCF_TALITOS is not set
39798 +# CONFIG_OCF_OCFNULL is not set
39799 +# CONFIG_OCF_BENCH is not set
39800 +
39801 diff -Nur kamikaze_7.09.orig/target/linux/x86-2.6/image/grub/menu.lst kamikaze_7.09/target/linux/x86-2.6/image/grub/menu.lst
39802 --- kamikaze_7.09.orig/target/linux/x86-2.6/image/grub/menu.lst	2007-09-20 10:54:12.000000000 +0200
39803 +++ kamikaze_7.09/target/linux/x86-2.6/image/grub/menu.lst	2008-06-19 17:34:17.000000000 +0200
39804 @@ -1,15 +1,15 @@
39805  serial --unit=0 --speed=@BAUDRATE@ --word=8 --parity=no --stop=1
39806 -terminal --timeout=10 console serial
39807 +terminal --timeout=3 serial
39808  
39809  default 0
39810  timeout 5
39811  
39812  title   OpenWrt
39813  root    (hd0,0)
39814 -kernel  /boot/vmlinuz @CMDLINE@ noinitrd console=tty0 console=ttyS0,@BAUDRATE@n8 reboot=bios
39815 +kernel  /boot/vmlinuz @CMDLINE@ ro noinitrd console=ttyS0,@BAUDRATE@n8 reboot=bios
39816  boot
39817  
39818  title	OpenWrt (failsafe)
39819  root	(hd0,0)
39820 -kernel  /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd console=tty0 console=ttyS0,@BAUDRATE@n8 reboot=bios
39821 +kernel  /boot/vmlinuz failsafe=true @CMDLINE@ ro noinitrd console=ttyS0,@BAUDRATE@n8 reboot=bios
39822  boot
39823 diff -Nur kamikaze_7.09.orig/target/linux/x86-2.6/profiles/Alix.mk kamikaze_7.09/target/linux/x86-2.6/profiles/Alix.mk
39824 --- kamikaze_7.09.orig/target/linux/x86-2.6/profiles/Alix.mk	1970-01-01 01:00:00.000000000 +0100
39825 +++ kamikaze_7.09/target/linux/x86-2.6/profiles/Alix.mk	2008-06-19 17:34:17.000000000 +0200
39826 @@ -0,0 +1,16 @@
39827 +#
39828 +# Copyright (C) 2007 OpenWrt.org
39829 +#
39830 +# This is free software, licensed under the GNU General Public License v2.
39831 +# See /LICENSE for more information.
39832 +#
39833 +
39834 +define Profile/Alix
39835 +  NAME:=PCEngines Alix 2 and 3 boards
39836 +  PACKAGES:=kmod-via-rhine kmod-leds-alix kmod-hw-rng kmod-hw-crypto kmod-linux-ocf libopenssl-cryptodev
39837 +endef
39838 +
39839 +define Profile/Alix/Description
39840 +        Package set compatible with the PCEngines ALIX 2 and 3 boards. Contains VIA Rhine III VT6105M, LED, and Crytpo support
39841 +endef
39842 +$(eval $(call Profile,Alix))
39843 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-06-06 00:03:01, 126.6 KB) [[attachment:kamikaze_7.09-for-alix-0xff-01.patch]]
  • [get | view] (2009-06-06 00:03:01, 1310.0 KB) [[attachment:kamikaze_7.09-for-alix-0xff-02.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.