Commit graph

43997 commits

Author SHA1 Message Date
Bill Paul 53947bb732 Rework mbuf<->ndis_packet/ndis_packet<->mbuf translation a little to
make it more robust. This should fix problems with crashes under
heavy traffic loads that have been reported. Also add a 'query done'
callback handler to satisfy the e100bex.sys sample Intel driver.
2003-12-14 21:31:32 +00:00
Jeff Roberson 86e1c22aa4 - Assign the ke_cpu field in kseq_notify() so that all of our callers do not
have to do it.
 - Set the ke_runq to NULL in sched_add() before calling kseq_notify().
   Otherwise we may panic in sched_add() if INVARIANTS is on.
2003-12-14 02:06:29 +00:00
Marcel Moolenaar a8434283fc In set_mcontext(), take into account that kse_switchin(2) will
eventually be passed an async. context as well as a syscall
context.
While here, fix a serious bug in that if the trapframe is a
syscall frame, but we're restoring an async context, we need
to clear the FRAME_SYSCALL flag so that we leave the kernel
via exception_restore.
2003-12-14 01:59:31 +00:00
Bill Paul ba102043bc Implement a few new NDIS routines: NdisInitAnsiString(),
NdisAnsiStringToUnicodeString(), NdisWriteConfiguration().

Also add stubs for NdisMGetDeviceProperty(), NdisTerminateWrapper(),
NdisOpenConfigurationKeyByName(), NdisOpenConfigurationKeyByIndex()
and NdisMGetDeviceProperty().
2003-12-14 00:43:40 +00:00
Poul-Henning Kamp 0a93720637 Fix a locking problem with MD_ROOT_SIZE.
Retire md(4)'s static major number.
2003-12-13 18:12:58 +00:00
Hidetoshi Shimokawa c54d1fe2bd Fix panic.
- Don't call sbp_targ_status_FIFO() twice for LOGIN error.
- Don't access login if it's NULL.
2003-12-13 15:33:45 +00:00
Bill Paul fc2ada1918 Correct the implementation of NDIS_BUFFER_TO_SPAN_PAGES(). 2003-12-13 09:07:35 +00:00
Paul Saab 591d10119e White space cleanup 2003-12-13 07:54:07 +00:00
Bill Paul d3eb09f083 subr_ndis.c:
- fix ndis_time() so that it returns a time based on the proper
  epoch (wacky though it may be)
- implement NdisInitializeString() and NdisFreeString(), and add
  stub for NdisMRemoveMiniport()

ntoskrnl_var.h:
- add missing member to the general_lookaside struct (gl_listentry)

subr_ntoskrnl.c:
- Fix arguments to the interlocked push/pop routines: 'head' is an
  slist_header *, not an slist_entry *
- Kludge up _fastcall support for the push/pop routines. The _fastcall
  convention is similar to _stdcall, except the first two available
  DWORD-sized arguments are passed in %ecx and %edx, respectively.
  One kludge for this __attribute__ ((regparm(3))), however this
  isn't entirely right, as it assumes %eax, %ecx and %edx will be
  used (regparm(2) assumes %eax and %edx). Another kludge is to
  declare the two fastcall-ed args as local register variables and
  explicitly assign them to %ecx and %edx, but experimentation showed
  that gcc would not guard %ecx and %edx against being clobbered.
  Thus, I came up with a 3rd kludge, which is to use some inline
  assembly of the form:

	void		*arg1;
	void		*arg2;

	__asm__("movl %%ecx, %%ecx" : "=c" (arg1));
	__asm__("movl %%edx, %%edx" : "=d" (arg2));

  This lets gcc know that we're going to reference %ecx and %edx and
  that it should make an effort not to let it get trampled. This wastes
  an instruction (movl %reg, %reg is a no-op) but insures proper
  behavior. It's possible there's a better way to do this though:
  this is the first time I've used inline assembler in this fashion.

The above fixes to ntoskrnl_var.h an subr_ntoskrnl.c make lookaside
lists work for the two drivers I have that use them, one of which
is an NDIS 5.0 miniport and another which is 5.1.
2003-12-13 07:41:12 +00:00
Bill Paul 7359dfc0b1 Implement some more NDIS and ntoskrnl API calls:
subr_ndis.c: NdisGetCurrentSystemTime() which, according to the
Microsoft documentation returns "the number of 100 nanosecond
intervals since January 1, 1601." I have no idea what's so special
about that epoch or why they chose 100 nanosecond ticks. I don't
know the proper offset to convert nanotime() from the UNIX epoch
to January 1, 1601, so for now I'm just doing the unit convertion
to 100s of nanoseconds.

subr_ntoskrnl.c: memcpy(), memset(), ExInterlockedPopEntrySList(),
ExInterlockedPushEntrySList().

The latter two are different from InterlockedPopEntrySList()
and InterlockedPushEntrySList() in that they accept a spinlock to
hold while executing, whereas the non-Ex routines use a lock
internal to ntoskrnl. I also modified ExInitializePagedLookasideList()
and ExInitializeNPagedLookasideList() to initialize mutex locks
within the lookaside structures. It seems that in NDIS 5.0,
the lookaside allocate/free routines ExInterlockedPopEntrySList()
and ExInterlockedPushEntrySList(), which require the use of the
per-lookaside spinlock, whereas in NDIS 5.1, the per-lookaside
spinlock is deprecated. We need to support both cases.

Note that I appear to be doing something wrong with
ExInterlockedPopEntrySList() and ExInterlockedPushEntrySList():
they don't appear to obtain proper pointers to their arguments,
so I'm probably doing something wrong in terms of their calling
convention (they're declared to be FASTCALL in Widnows, and I'm
not sure what that means for gcc). It happens that in my stub
lookaside implementation, they don't need to do any work anyway,
so for now I've hacked them to always return NULL, which avoids
corrupting the stack. I need to do this right though.
2003-12-12 22:35:13 +00:00
Robert Watson 09a4a69c1d Although sometimes to the uninitiated, it may seem like goup, KSEGOUP
is actually spelt KSEGROUP.  Go figure.

Reported by:	samy@kerneled.com
2003-12-12 21:25:56 +00:00
Robert Watson 43ad78e751 Spell btkr as bktr.
Pointy hat to:	obrien
Reported by:	Martin <nakal@web.de>
2003-12-12 21:18:04 +00:00
Nate Lawson b279c35a4f Fix throttling to use the proper mask. The bug resulted in only two
throttling values being available regardless of the CPU's capabilities.
This has been broken since rev 1.1.  Also clarify a comment.

Submitted by:	Taku YAMAMATO <taku@cent.saitama-u.ac.jp>
2003-12-12 19:42:16 +00:00
Poul-Henning Kamp 8a1a55ec29 DUH!
Write 100 times for tomorrow:
	I will never again free(9) a modified pointer.

Pointy Hat:	yeah, yeah, yeah, can you just put it in the pile over there...
2003-12-12 12:17:28 +00:00
Poul-Henning Kamp 48529e81e4 Attempt to get the short cable fix to work better on the if_sis:
Only do short-cable on revisions that need it.

Move generic initialization before short-cable fix, in order to not
clobber short cable fix register setting.
2003-12-12 10:15:39 +00:00
Peter Grehan 2abd35bc59 - accept device_type of "block", which is how psim/gdb6.0 defines
disks. continue to accept "disk" for psim/gdb5.x users.
- remove unneeded ofwd_identify
2003-12-12 09:54:39 +00:00
Bill Paul 8f0387a278 Correct the behavior of ndis_adjust_buflen(): the NDIS spec says
it's an error to set the buffer bytecount to anything larger than
the buffer's original allocation size, but anything less than that
is ok.

Also, in ndis_ptom(), use the same logic: if the bytecount is
larger than the allocation size, consider the bytecount invalid
and the allocation size as the packet fragment length (m_len)
instead of the bytecount.

This corrects a consistency problem between the Broadcom wireless
driver and some of the ethernet drivers I've tested: the ethernet
drivers all report the packet frag sizes in buf->nb_bytecount, but
the Broadcom wireless driver reports them in buf->nb_size. This
seems like a bug to me, but it clearly must work in Windows, so
we have to deal with it here too.
2003-12-12 08:54:48 +00:00
Jeff Roberson cac77d0422 - Now that we have kseq groups, balance them seperately.
- The new sched_balance_groups() function does intra-group balancing while
   sched_balance() balances the available groups.
 - Pick a random time between 0 ticks and hz * 2 ticks to restart each
   balancing process.  Each balancer has its own timeout.
 - Pick a random place in the list of groups to start the search for lowest
   and highest group loads.  This prevents us from prefering a group based on
   numeric position.
 - Use a nasty hack to stop us from preferring cpu 0.  The problem is that
   softclock always runs on cpu 0, so it always has a little extra load.  We
   ignore this load in the balancer for now.  In the future softclock should
   run on a random cpu and these hacks can go away.
2003-12-12 07:33:51 +00:00
Bill Paul d7e92f7b85 In NDIS 5.1 miniport drivers, the shutdown handler function pointer
is provided to NDIS via the the miniport characteristics structure
supplied in the call to NdisMRegisterMiniport(). But in NDIS 5.0
and earlier, you had to call NdisMRegisterAdapterShutdownHandler()
and supply both a function pointer and context pointer.

We try to handle both cases in ndis_shutdown_nic(). If the
driver registered a shutdown routine and a context,then used
that context, otherwise pass it the adapter context from
NdisMSetAttributesEx().

This fixes a panic on shutdown with the sample Intel 82559 e100bex.sys
driver from the Windows DDK.
function pointer
2003-12-12 05:27:58 +00:00
Bill Paul c42411d56f Turn off build of if_ndis.ko by default, since it depends on an
autogenerated file (ndis_driver_data.h) which by definition can't
be available unless the user creates it.
2003-12-12 04:45:15 +00:00
Bill Paul 87feaafc5b Grrr. Put the right .PATH statements in the right Makefiles. 2003-12-11 23:22:44 +00:00
Bill Paul 940311dc21 Ack! Only build if_ndis.ko and ndis.ko if arch == i386. 2003-12-11 23:06:54 +00:00
John Baldwin acbf8a8d4a - Change the lookup() function to report success or failure using the carry
flag rather than explicitly halting if a lookup failed.
- Add a loop around the call to lookup() to traverse an array of
  nul-terminated strings for possible paths to the boot loader.  A double
  nul character denotes the end of the list.
- Add a new message to say that the boot failed if all of the path lookups
  for a boot loader file failed.
- Add '/boot/loader' as a second boot path.  If you build an ISO using
  risky options to mkisofs such as -U then the loader will be called
  '/boot/loader' rather than '/BOOT/LOADER;0'.  This allows cdboot to work
  with such risky ISO images.
- Bump version to 1.2 to denote added functionality.

The basic idea as well as some of the code were provided by the submitter,
but I added some extra code to use a loop rather than hard-code just 2
possible paths.

PR:		misc/43543
Submitted by:	kientzle
MFC after:	1 week
2003-12-11 22:42:50 +00:00
Bill Paul c854fc1092 Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.

This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:

sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.

sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.

usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)

ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.

This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:

# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis

All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.

An example usage of the Broadcom wireless driver would be:

# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up

Things to be done:

- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
  NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
John Baldwin bb17adda46 Properly fix a typo that the previous revision made even worse. 2003-12-11 20:40:12 +00:00
Alfred Perlstein 49ebf4cb75 This patch fixes two little portability (to !GCC compilers) problems:
1. Use C99-style variable argument macros rather than GNU ones.
2. Don't cast id to ident_t.  Its type is already ident_t and casting to
   a union type is a constraint violation.

Submitted by: Stefan Farfeleder <stefan@fafoe.narf.at>
2003-12-11 11:30:26 +00:00
Alfred Perlstein de75fd6d2b Significantly reduce the "jitter" that is typical for PS/2 mice
when using a KVM.

There is no actual solution possible, but this gets us pretty close.

Typically when switching back to a FreeBSD box and moving the mouse
wild data is produced, because the protocol's validation/checksum
system is extremely weak it is impossible to determine that we're
out of sync before dropping several bogus packets to user land.

The actual solution that appears to offer the best clamping of
jitter is to buffer the mouse packets if we've not seen mouse
activity for more than .5 seconds.  Then waiting to flush that data
for 1/20th of a second.  If within that 20th of a second we get any
packets that do fail the weak test we drop the entire queue and
back off accepting data from the mouse for 2 seconds and then repeat
the whole deal.

You can still get _some_ jitter, notably if you switch to the FreeBSD
box, then move the mouse just enough to generate one or two packets.
Those packets may be bogus, but may still pass the validity check.

One way to finally kill the problem once and for all is to check
the initial packets for "wild" values.  Typically one sees packets
in the +/-60 range during normal operation, however when bogus data
is generated it's typically near the outer range of +/-120 or more,
those packets would be a good candidate for dropping or clamping.

I've been running with this for several weeks now and it has
significantly helped me stay sane even with a piece of junk Belkin
KVM causing wild jitter each and every time I switch.

Lastly I'd like to note that my experience with Windows shows me that
somehow the Microsoft PS/2 driver typically avoids this problem, but
that may only be possible when running the mouse in a dumb-ed down PS/2
mode that Belkin recommends on their site.
2003-12-11 11:28:11 +00:00
Jeff Roberson 2e227f0406 - Don't let the pctcpu rate limiter throttle us if we have recorded over
SCHED_CPU_TICKS ticks.  This was allowing processes to display
   (1/SCHED_CPU_TIME * 100) % more cpu than they had used.
2003-12-11 04:23:39 +00:00
Jeff Roberson b11fdad0fc - In sched_switch(), if a thread has been assigned, don't touch the runqueues
or load.  These things have already been taken care of in sched_bind()
   which should be the only place that we're switching in an assigned thread.
2003-12-11 04:00:49 +00:00
Jeff Roberson 80f86c9f88 - Add support for CPU groups to ule. All SMT cores on the same physical
cpu are added to a group.
 - Don't place a cpu into the kseq_idle bitmask until all cpus in that group
   have idled.
 - Prefer idle groups over idle group members in the new kseq_transfer()
   function.  In this way we will prefer to balance load across full cores
   rather than add further load a partial core.
 - Before a cpu goes idle, check the other group members for threads.  Since
   SMT cpus may freely share threads, this is cheap.
 - SMT cores may be individually pinned and bound to now.  This contrasts the
   old mechanism where binding or pinning would have allowed a thread to run
   on any available cpu.
 - Remove some unnecessary logic from sched_switch().  Priority propagation
   should be properly taken care of in sched_prio() now.
2003-12-11 03:57:10 +00:00
Jeff Roberson 7085b1c597 - Call mp_topology() after all CPUs have been probed. 2003-12-11 03:49:02 +00:00
Jeff Roberson 59f3a8e626 - Add the mp_topology() function to mp_machdep.c. This function builds up
the smp_topology structure to reflect the layout of HTT enabled machines.
 - Add a prototype for mp_topology() in smp.h
2003-12-11 03:48:31 +00:00
Hidetoshi Shimokawa a73ff5105c MFp4:
- Introduce sbp_targ_login instead of sbp_targ_istate.
- Implement reconnection and logout.
- Freeze simq while bus reset.
2003-12-11 03:42:40 +00:00
Peter Wemm d50c65bfce MFi386: remove APIC_IRQ* defines that are no longer used. 2003-12-11 02:48:25 +00:00
Peter Wemm bf342084e5 MFi386: (jhb): Deal with MAXCPU etc correctly 2003-12-11 02:47:35 +00:00
Peter Wemm 65365aa0c6 regen 2003-12-11 02:36:37 +00:00
Peter Wemm ca40b45fb7 Mark freebsd32_gettimeofday() as mpsafe 2003-12-11 02:36:07 +00:00
Peter Wemm 4eeb271ab4 Just implementing a 32 bit version of gettimeofday() was smaller than
the wrapper code.  And it doesn't use the stackgap as a bonus.
2003-12-11 02:34:49 +00:00
Peter Wemm f11e46c5ed Move the ia32_sigtramp.S file back under amd64/. This interfaces closely
with the sendsig code in the MD area.  It is not safe to assume that all
the register conventions will be the same.  Also, the way of producing
32 bit code (.code32 directives) in this file is amd64 specific.
2003-12-11 01:09:51 +00:00
Peter Wemm 64d85faa1c Assimilate ia64 back into the fold with the common freebsd32/ia32 code.
The split-up code is derived from the ia64 code originally.

Note that I have only compile-tested this, not actually run-tested it.
The ia64 side of the force is missing some significant chunks of signal
delivery code.
2003-12-11 01:05:09 +00:00
Peter Wemm 7f3a56a41a Use the correct syscall table limit 2003-12-10 23:16:32 +00:00
Søren Schmidt b9e240face Finetune last commit, we need to take care of empty channels. 2003-12-10 23:06:24 +00:00
Peter Wemm ba3fa22e8c Fix last second typo. 2003-12-10 22:59:03 +00:00
Peter Wemm 419d43c635 Use gcc's superior ffs() builtin. 2003-12-10 22:51:40 +00:00
Peter Wemm a80f5f272c Use ffs(x) == popcnt(x ^ (x - 1)) to implement 64 bit ffsl(). gcc's
ffs() builtin uses this already but truncates the upper 32 bits.
2003-12-10 22:47:02 +00:00
Peter Wemm d8411ca6b7 Regen 2003-12-10 22:33:45 +00:00
Peter Wemm 76b88a1439 Add missing extattr_list_fd(), extattr_list_file(), extattr_list_link()
and kse_switchin() syscall slots.
2003-12-10 22:33:27 +00:00
Peter Wemm 33dc7aa421 The osigpending, oaccept, orecvfrom and ogetdirentries entries were
accidently being compiled in as standard.  These are part of the
set of unimplemented COMPAT_43 syscall set.
2003-12-10 22:31:46 +00:00
Peter Wemm 5be4b10c89 Regen 2003-12-10 22:18:54 +00:00
Peter Wemm 5352eb6bb1 Update file locations for syscall tables to copy to. 2003-12-10 22:08:37 +00:00