Skip to contentSkip to conversation

Fix PCI error token awkward value

PATCH In review Linas Vepstas 2 participants 3 messages Jul 6, 2006 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix PCI error token awkward value

The pci channel state token currently has a poor choice of values; there are two ways of indicating that "everything's OK": 0 and 1. This is a bit of a burden.

If a devce driver wants to check if the pci channel is in a working or a disconnected state, the driver writer must perform checks similar to

   if((pdev->error_state != 0) &&
      (pdev->error_state != pci_channel_io_normal)) {
         whatever();
   }

which is rather akward. The first check is needed because stuct pci_dev is inited to all-zeros. The scond is needed because the error recovery will set the state to pci_channel_io_normal (which is not zero).

This patch fixes this awkwardness.

----

 include/linux/pci.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci.h +1 -1
Index: linux-2.6.17-mm3/include/linux/pci.h
===================================================================
@@ -85,7 +85,7 @@ typedef unsigned int __bitwise pci_chann
 
 enum pci_channel_state {
 	/* I/O channel is in normal state */
-	pci_channel_io_normal = (__force pci_channel_state_t) 1,
+	pci_channel_io_normal = (__force pci_channel_state_t) 0,
 
 	/* I/O to channel is blocked */
 	pci_channel_io_frozen = (__force pci_channel_state_t) 2,
#1 lore raw
Quoted 16 lines · [email protected] (Linas Vepstas) wrote:

The pci channel state token currently has a poor choice of values; there are two ways of indicating that "everything's OK": 0 and 1. This is a bit of a burden.

If a devce driver wants to check if the pci channel is in a working or a disconnected state, the driver writer must perform checks similar to

   if((pdev->error_state != 0) &&
      (pdev->error_state != pci_channel_io_normal)) {
         whatever();
   }
Quoted 7 lines

which is rather akward. The first check is needed because stuct pci_dev is inited to all-zeros. The scond is needed because the error recovery will set the state to pci_channel_io_normal (which is not zero).

This patch fixes this awkwardness.

eww.

Quoted 6 lines

Index: linux-2.6.17-mm3/include/linux/pci.h
===================================================================

include/linux/pci.h typedef unsigned int __bitwise pci_chann · line 91

Quoted 8 lines
include/linux/pci.h +1 -1
@@ -85,7 +85,7 @@ typedef unsigned int __bitwise pci_chann
 
 enum pci_channel_state {
 	/* I/O channel is in normal state */
-	pci_channel_io_normal = (__force pci_channel_state_t) 1,
+	pci_channel_io_normal = (__force pci_channel_state_t) 0,
 
 	/* I/O to channel is blocked */
 	pci_channel_io_frozen = (__force pci_channel_state_t) 2,

It needs a comment to prevent people from breaking it in the future, and to help people who are trying to work out why the heck the kernel is looking for a particular state in something which hasn't been set to that state.

Also, it's a bit odd that we've gone and left a hole in the enum space.

Wouldn't it be better to sort out our initialisation so we don't actually need this memset-equals-pci_channel_io_normal trick? pci_scan_device() looks like a good place..

#2 lore raw
Quoted 4 lines · Andrew Morton

Wouldn't it be better to sort out our initialisation so we don't actually need this memset-equals-pci_channel_io_normal trick? pci_scan_device() looks like a good place..

OK, revised patch below. That's more typical of "application style coding", where the apps waste a few extra cycles by zeroing a struct and then immediately initializing struct members to non-zero values (it seems that CPU designers have noticed that Java does this a lot). But I thought the kernel philosophy was "everythings zero its safe to assume everything's zero, don't waste cycles on such silliness". which is why you got the ewww pach.

--linas

Subject: [PATCH] Initialize struct_pci error state

The pci channel state is currently uninitialized, thus there are two ways of indicating that "everything's OK": 0 and 1. This is a bit of a burden.

If a devce driver wants to check if the pci channel is in a working or a disconnected state, the driver writer must perform checks similar to

   if((pdev->error_state != 0) &&
      (pdev->error_state != pci_channel_io_normal)) {
         whatever();
   }

which is rather akward. The first check is needed because stuct pci_dev is inited to all-zeros. The scond is needed because the error recovery will set the state to pci_channel_io_normal (which is not zero).

This patch fixes this awkwardness.

----

 drivers/pci/probe.c |    1 +
 1 file changed, 1 insertion(+)
drivers/pci/probe.c +1 -0
Index: linux-2.6.17-mm3/drivers/pci/probe.c
===================================================================
@@ -815,6 +815,7 @@ pci_scan_device(struct pci_bus *bus, int
 	dev->vendor = l & 0xffff;
 	dev->device = (l >> 16) & 0xffff;
 	dev->cfg_size = pci_cfg_space_size(dev);
+	dev->error_state = pci_channel_io_normal;
 
 	/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
 	   set this higher, assuming the system even supports it.  */