Commit Graph

146 Commits

Author SHA1 Message Date
Warner Losh
8e5f761422 On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:

cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)

All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.

Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
Warner Losh
8bf007e1e6 Add a rather obnoxious warning if you don't have NEW_PCIB defined
since it's a total crap shoot if things will work.
2015-01-14 05:41:31 +00:00
Hans Petter Selasky
af3b2549c4 Pull in r267961 and r267973 again. Fix for issues reported will follow. 2014-06-28 03:56:17 +00:00
Glen Barber
37a107a407 Revert r267961, r267973:
These changes prevent sysctl(8) from returning proper output,
such as:

 1) no output from sysctl(8)
 2) erroneously returning ENOMEM with tools like truss(1)
    or uname(1)
 truss: can not get etype: Cannot allocate memory
2014-06-27 22:05:21 +00:00
Hans Petter Selasky
3da1cf1e88 Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after:	2 weeks
Sponsored by:	Mellanox Technologies
2014-06-27 16:33:43 +00:00
John Baldwin
4edef187b8 Add support for managing PCI bus numbers. As with BARs and PCI-PCI bridge
I/O windows, the default is to preserve the firmware-assigned resources.
PCI bus numbers are only managed if NEW_PCIB is enabled and the architecture
defines a PCI_RES_BUS resource type.
- Add a helper API to create top-level PCI bus resource managers for each
  PCI domain/segment.  Host-PCI bridge drivers use this API to allocate
  bus numbers from their associated domain.
- Change the PCI bus and CardBus drivers to allocate a bus resource for
  their bus number from the parent PCI bridge device.
- Change the PCI-PCI and PCI-CardBus bridge drivers to allocate the
  full range of bus numbers from secbus to subbus from their parent bridge.
  The drivers also always program their primary bus register.  The bridge
  drivers also support growing their bus range by extending the bus resource
  and updating subbus to match the larger range.
- Add support for managing PCI bus resources to the Host-PCI bridge drivers
  used for amd64 and i386 (acpi_pcib, mptable_pcib, legacy_pcib, and qpi_pcib).
- Define a PCI_RES_BUS resource type for amd64 and i386.

Reviewed by:	imp
MFC after:	1 month
2014-02-12 04:30:37 +00:00
John Baldwin
1b1596a3b3 - Add a bus_dma tag to each PCI bus that is a child of a Host-PCI bridge.
The tag enforces a single restriction that all DMA transactions must not
  cross a 4GB boundary.  Note that while this restriction technically only
  applies to PCI-express, this change applies it to all PCI devices as it
  is simpler to implement that way and errs on the side of caution.
- Add a softc structure for PCI bus devices to hold the bus_dma tag and
  a new pci_attach_common() routine that performs actions common to the
  attach phase of all PCI bus drivers.  Right now this only consists of
  a bootverbose printf and the allocate of a bus_dma tag if necessary.
- Adjust all PCI bus drivers to allocate a PCI bus softc and to call
  pci_attach_common() from their attach routines.

MFC after:	2 weeks
2012-03-02 20:38:04 +00:00
Ed Schouten
6472ac3d8a Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.
The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.
2011-11-07 15:43:11 +00:00
John Baldwin
06c9ee053d Partially revert 222753: If a CardBus card stores its CIS in a BAR, delete
the BAR after parsing the CIS.  This forces the resource range to be
reallocated if the BAR is reused by the device.

Submitted by:	deischen
Reviewed by:	imp
Approved by:	re (kib)
2011-09-12 15:21:52 +00:00
Warner Losh
4089559520 Minor cleanup:
o Consider No CIS a normal event and stop whining about it so much
  (too many cards are like this, espeically usb/firewire cards).
o Add comments to the cis reading code.
o Made the read from config space a smidge easier to read and eliminate
  a loop that can be done mathematically.
2011-06-21 22:45:31 +00:00
John Baldwin
0d439b5f93 More properly handle Cardbus cards that that store their CIS in a BAR after
the recent changes to track BAR state explicitly.  The code would now
attempt to add the same BAR twice in this case.  Instead, change this so
that it recognizes this case and only adds it once and do not delete the
BAR outright after parsing the CIS.

Tested by:	bschmidt
2011-06-06 13:21:11 +00:00
John Baldwin
8d43fea45f Don't explicitly list pci_write_ivar() for bus_write_ivar, the method is
already inherited from the PCI bus driver.
2011-05-02 15:01:28 +00:00
John Baldwin
af827f9642 Move the PCI-specific logic of removing a cardbus device into a
pci_delete_child() function called by the cardbus driver.  The new function
uses resource_list_unreserve() to release the BARs decoded by the device
being removed.

Reviewed by:	imp
Tested by:	brooks
2010-01-05 20:42:25 +00:00
John Baldwin
3a6b4b04ab Fix an error case I missed in the previous change so that the CIS resource
is fully cleaned up if we fail to find the CIS in the devices ROM.
2009-12-30 22:34:26 +00:00
John Baldwin
767dff0ac9 Delete the CIS resource after releasing it. This is needed when the CIS is
stored in a BAR since the CIS BAR is mapped before the PCI bus driver
enumerates all the BARs.  Without this change, the PCI bus driver would
attempt to initialize a BAR that was already allocated resulting in a panic.
2009-12-30 20:49:13 +00:00
John Baldwin
4e8790e943 Teach the PCI bus driver to handle PCIR_BIOS BARs properly and remove special
handling for the PCIR_BIOS decoding enable bit from the cardbus driver.
The PCIR_BIOS BAR does include type bits like other BARs.  Instead, it is
always a 32-bit non-prefetchable memory BAR where the low bit is used as a
flag to enable decoding.

Reviewed by:	imp
2009-12-30 20:47:14 +00:00
John Baldwin
f26d7f8e95 Use bus_*() rather than bus_space_*(). 2009-12-30 20:42:07 +00:00
Warner Losh
e6d3b1bd2a Minorly improved debugging. Use the DEVPRINTF macro and report the
offset for memory when mapping in the CIS.
2009-03-13 05:31:27 +00:00
Warner Losh
afb1ec6d56 Move the deactivation of the device's BAR to before the loop where we
turn deactivate the resources.  While this likely doesn't matter, it
is likely to be safer.
2009-03-12 08:42:27 +00:00
Warner Losh
41f0c91517 Restore blank line removed when fixing my earlier botch. Never do
just one last change before bed...

Pointy had to: imp
2009-03-10 22:04:52 +00:00
George V. Neville-Neil
7b77311219 Complete removal of cardbus_write_ivar which was left hanging. 2009-03-10 17:54:04 +00:00
Warner Losh
161832a1cf When freeing all the resources of the card, it is better to turn off
the PORTEN and MEMEN bits in the command register than to zero the
bars.

Use pci_write_ivar directly instead of a one-line wrapper that adds no
value.

Track verbosity changes in pci.

Remove a stray blank line.
2009-03-10 12:10:50 +00:00
Wojciech A. Koszek
172ab3e96e Remove unused variable.
Found with:	Coverity Prevent(tm)
CID:		4138
2009-02-06 00:55:19 +00:00
John Baldwin
ba8d936dd2 Goof, catch up to constant rename (I renamed it to match the overall PCI
style of having register offsets start with PCIR_* rather than PCI_*).

Submitted by:	rss
2009-02-02 22:06:20 +00:00
Warner Losh
a84736bdf6 When no driver attaches to a card, don't power down the card. We can
now read config registers of cardbus cards that are inserted, but
aren't attached to a driver.
Also, add a power related comment...
2008-12-31 07:41:42 +00:00
Warner Losh
7d0fb1f7ef Don't call destroy_dev on the alias. This fixes half a dozen PRs I think. 2008-12-02 04:54:31 +00:00
Warner Losh
db8deb424e Create a /dev/cardbus%d.cis, to be compatible with older versions of
the software.  This is a trivial amount of code to keep wireless
monitoring software working...  I plan on removing it in 9.0.
2008-11-21 03:03:57 +00:00
Warner Losh
a7de0b74a7 Overhaul of CIS parsing, next step: keep a cached copy of the CIS,
read before we configure the card, so we can implement
/dev/cardbus*.cis.  Also, do this on a per-child basis, so we now have
a different name than before.  I think i'll have to fix that for some
legacy tools to keep working.

I can now do a dumpcis on my running atheros card and have it still work!
2008-11-17 01:32:29 +00:00
Warner Losh
e371fa4547 First step in cleaning up CIS parsing and /dev/cardbus*.cis: remove
redundant malloc/free.  Add comments about how this should really be
done.  Fix an overly verbose comment about under 1MB mapping: go ahead
and set the bits, but we ignore them.
2008-11-15 05:22:06 +00:00
Warner Losh
714cb2219c Turns out this isn't even used at all... The bogon that I was tracing was
in code from my p4 tree, not -current.  Delete it here.
2008-11-03 06:37:59 +00:00
Warner Losh
89558ee870 Use child (the card) in preference to cbdev (the bridge) when
allocating resources to read the CIS.  I'm not sure when this changed,
but it is totally wrong.  Also, add a minor improvement to the
debugging.

This should help everybody trying to run dumpcis on atheros wireless
card as well.

MFC after:	2 days
2008-11-03 06:06:22 +00:00
Warner Losh
6e39a203de We can't mask out the higher order bits and have the size come out
right...  Good thing the size was ignored...

Where this macro is used, there's no reason to do it anyway.  There
seems to have been some old-time confusion between the CIS pointer
definition, and the BAR definitions at the base of this bug.
2008-11-03 05:52:43 +00:00
Marius Strobl
55aaf894e8 Make the PCI code aware of PCI domains (aka PCI segments) so we can
support machines having multiple independently numbered PCI domains
and don't support reenumeration without ambiguity amongst the
devices as seen by the OS and represented by PCI location strings.
This includes introducing a function pci_find_dbsf(9) which works
like pci_find_bsf(9) but additionally takes a domain number argument
and limiting pci_find_bsf(9) to only search devices in domain 0 (the
only domain in single-domain systems). Bge(4) and ofw_pcibus(4) are
changed to use pci_find_dbsf(9) instead of pci_find_bsf(9) in order
to no longer report false positives when searching for siblings and
dupe devices in the same domain respectively.
Along with this change the sole host-PCI bridge driver converted to
actually make use of PCI domain support is uninorth(4), the others
continue to use domain 0 only for now and need to be converted as
appropriate later on.
Note that this means that the format of the location strings as used
by pciconf(8) has been changed and that consumers of <sys/pciio.h>
potentially need to be recompiled.

Suggested by:	jhb
Reviewed by:	grehan, jhb, marcel
Approved by:	re (kensmith), jhb (PCI maintainer hat)
2007-09-30 11:05:18 +00:00
Warner Losh
17ee700be6 gcc 4.2 thinks that tupleid is uninitialized. Or might be used
uninitialized.  It gets passed into other routines that initialize
it...  Cope by initializing.

Submitted by: mjacob
2007-06-08 04:03:57 +00:00
John Baldwin
d193b870a5 Fix interrupt routing for some cards after the previous fix to clear BARs
in cardbus cards: update the saved copy of the PCIR_INTLINE register in
the PCI ivars in addition to the actual register.

Reviewed by:	imp
2007-05-16 23:40:08 +00:00
Warner Losh
cfd1374177 Write 0 to all the bars in cardbus_cardbus_setup_regs. This is needed
because on at least my dc based cards there's garbage in there.  The
recent changes in the resource code appears to have unmasked this
problem...  At least dc now probes/attaches better than it did before.

Also, we no longer need to write to the cfg for the other registers.
2007-05-16 20:00:36 +00:00
Warner Losh
4b3337405d Change PCIM_CIS_ASI_TUPLE to _CONFIG.
Add PCI_MAX_BAR_0
minor style nit.
Add PCIM_CIS_CONFIG_MASK
2007-05-16 18:42:38 +00:00
Warner Losh
7e2ff8bbff Cope gracefully with device_get_children returning an error.
Obtained from: Hans Petter Selasky
P4: http://perforce.freebsd.org/chv.cgi?CH=112957
2007-01-19 08:49:28 +00:00
Warner Losh
1acd1e20a1 Minor cleanup of CIS parsing. 2006-06-12 03:28:42 +00:00
Warner Losh
9dfcc6624c Better error message when the CIS is a non-standards conforming '0'. 2006-06-12 03:20:44 +00:00
Warner Losh
a63eba960f When we can't parse the CIS, note with a warning that the bogus CIS
was ignored, rather than freaking out.  In the past, it wasn't possible
to not parse the CIS, so this changes no behavior.
2006-06-12 03:17:24 +00:00
John Baldwin
5aa58b3e8f Make the 'pci_devclass' pointer variable private (drivers really shouldn't
share devclass pointers, a mistake I've encouraged in the past) and
move the declaration of the pci_driver kobj class from cardbus.c to
pci_private.h so that other drivers can inherit from pci_driver.
2006-01-20 22:00:50 +00:00
Warner Losh
bee89c7386 Use the child to allocate the resource rather than bridge, since we're
allocating a resource that's in the card itself.

Remove more now-redundant resource_list_add, and now-redunant code
that lives in the pci layer.

# This fixes the atheros card that I have which had its CIS in one of
# the BARs.  Don't know yet if this fixes the amd64 issues reported.
2006-01-03 03:36:17 +00:00
Warner Losh
c732cf3b2c Minor style(9) hacking, plus use a macro in place of (struct resource *)~0UL
(what the heck does that mean?).
2006-01-03 03:16:53 +00:00
Tai-hwa Liang
93d9fd1136 Fixing build bustage. 2005-12-31 01:45:40 +00:00
Warner Losh
388395ccaa Remove now-obsolete printf warning. 2005-12-30 19:38:47 +00:00
Warner Losh
ef5cc9accd Move all of the resource allocation into the pci layer. The resource
allocation here just duplicated it (badly).
2005-12-30 19:25:04 +00:00
Warner Losh
f3d3468db3 The RID2BAR macro returns a number, not a bitmask. Fix this.
Spotted by: ru, jhb
2005-12-30 19:23:32 +00:00
Gleb Smirnoff
6afb2250fb - Retire BARBIT in favor of new PCI_RID2BAR.
- Fix build.
2005-12-30 11:31:47 +00:00
Warner Losh
3cd242d123 Retire BARBIT in favor of new PCI_RID2BAR. 2005-12-29 23:41:29 +00:00