mib: add net to TCP_ADD_STATS_USER
[safe/jmp/linux-2.6] / drivers / pcmcia / pcmcia_resource.c
index f4dcea6..1d128fb 100644 (file)
@@ -48,7 +48,6 @@ static u8 pcmcia_used_irq[NR_IRQS];
 
 #ifdef DEBUG
 extern int ds_pc_debug;
-#define cs_socket_name(skt)    ((skt)->dev.class_id)
 
 #define ds_dbg(skt, lvl, fmt, arg...) do {                     \
        if (ds_pc_debug >= lvl)                                 \
@@ -66,29 +65,28 @@ extern int ds_pc_debug;
  * Special stuff for managing IO windows, because they are scarce
  */
 
-static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
-                         ioaddr_t num, u_int lines)
+static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
+                         unsigned int *base, unsigned int num, u_int lines)
 {
        int i;
-       kio_addr_t try, align;
+       unsigned int try, align;
 
        align = (*base) ? (lines ? 1<<lines : 0) : 1;
        if (align && (align < num)) {
                if (*base) {
-                       ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
+                       ds_dbg(s, 0, "odd IO request: num %#x align %#x\n",
                               num, align);
                        align = 0;
                } else
                        while (align && (align < num)) align <<= 1;
        }
        if (*base & ~(align-1)) {
-               ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
+               ds_dbg(s, 0, "odd IO request: base %#x align %#x\n",
                       *base, align);
                align = 0;
        }
        if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
                *base = s->io_offset | (*base & 0x0fff);
-               s->io[0].res->flags = (s->io[0].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
                return 0;
        }
        /* Check for an already-allocated window that must conflict with
@@ -96,7 +94,7 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
         * potential conflicts, just the most obvious ones.
         */
        for (i = 0; i < MAX_IO_WIN; i++)
-               if ((s->io[i].res) &&
+               if ((s->io[i].res) && *base &&
                    ((s->io[i].res->start & (align-1)) == *base))
                        return 1;
        for (i = 0; i < MAX_IO_WIN; i++) {
@@ -134,8 +132,8 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
 } /* alloc_io_space */
 
 
-static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
-                            ioaddr_t num)
+static void release_io_space(struct pcmcia_socket *s, unsigned int base,
+                            unsigned int num)
 {
        int i;
 
@@ -209,7 +207,6 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
        if (!(s->state & SOCKET_PRESENT))
                return CS_NO_CARD;
 
-       config->Function = p_dev->func;
 
 #ifdef CONFIG_CARDBUS
        if (s->state & SOCKET_CARDBUS) {
@@ -223,14 +220,22 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
                        config->AssignedIRQ = s->irq.AssignedIRQ;
                        if (config->AssignedIRQ)
                                config->Attributes |= CONF_ENABLE_IRQ;
-                       config->BasePort1 = s->io[0].res->start;
-                       config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
+                       if (s->io[0].res) {
+                               config->BasePort1 = s->io[0].res->start;
+                               config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
+                       }
                }
                return CS_SUCCESS;
        }
 #endif
 
-       c = (p_dev) ? p_dev->function_config : NULL;
+       if (p_dev) {
+               c = p_dev->function_config;
+               config->Function = p_dev->func;
+       } else {
+               c = NULL;
+               config->Function = 0;
+       }
 
        if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
                config->Attributes = 0;
@@ -239,10 +244,17 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
                return CS_SUCCESS;
        }
 
-       /* !!! This is a hack !!! */
-       memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
-       config->Attributes |= CONF_VALID_CLIENT;
-       config->CardValues = c->CardValues;
+       config->Attributes = c->Attributes | CONF_VALID_CLIENT;
+       config->Vcc = s->socket.Vcc;
+       config->Vpp1 = config->Vpp2 = s->socket.Vpp;
+       config->IntType = c->IntType;
+       config->ConfigBase = c->ConfigBase;
+       config->Status = c->Status;
+       config->Pin = c->Pin;
+       config->Copy = c->Copy;
+       config->Option = c->Option;
+       config->ExtStatus = c->ExtStatus;
+       config->Present = config->CardValues = c->CardValues;
        config->IRQAttributes = c->irq.Attributes;
        config->AssignedIRQ = s->irq.AssignedIRQ;
        config->BasePort1 = c->io.BasePort1;
@@ -442,6 +454,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
                   (mod->Attributes & CONF_VPP2_CHANGE_VALID))
                return CS_BAD_VPP;
 
+       if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
+               pccard_io_map io_off = { 0, 0, 0, 0, 1 };
+               pccard_io_map io_on;
+               int i;
+
+               io_on.speed = io_speed;
+               for (i = 0; i < MAX_IO_WIN; i++) {
+                       if (!s->io[i].res)
+                               continue;
+                       io_off.map = i;
+                       io_on.map = i;
+
+                       io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
+                       io_on.start = s->io[i].res->start;
+                       io_on.stop = s->io[i].res->end;
+
+                       s->ops->set_io_map(s, &io_off);
+                       mdelay(40);
+                       s->ops->set_io_map(s, &io_on);
+               }
+       }
+
        return CS_SUCCESS;
 } /* modify_configuration */
 EXPORT_SYMBOL(pcmcia_modify_configuration);
@@ -454,8 +488,8 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
        config_t *c = p_dev->function_config;
        int i;
 
-       if (p_dev->state & CLIENT_CONFIG_LOCKED) {
-               p_dev->state &= ~CLIENT_CONFIG_LOCKED;
+       if (p_dev->_locked) {
+               p_dev->_locked = 0;
                if (--(s->lock_count) == 0) {
                        s->socket.flags = SS_OUTPUT_ENA;   /* Is this correct? */
                        s->socket.Vpp = 0;
@@ -479,7 +513,6 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
 
        return CS_SUCCESS;
 } /* pcmcia_release_configuration */
-EXPORT_SYMBOL(pcmcia_release_configuration);
 
 
 /** pcmcia_release_io
@@ -490,15 +523,15 @@ EXPORT_SYMBOL(pcmcia_release_configuration);
  * don't bother checking the port ranges against the current socket
  * values.
  */
-int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
+static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
 {
        struct pcmcia_socket *s = p_dev->socket;
        config_t *c = p_dev->function_config;
 
-       if (!(p_dev->state & CLIENT_IO_REQ))
+       if (!p_dev->_io )
                return CS_BAD_HANDLE;
 
-       p_dev->state &= ~CLIENT_IO_REQ;
+       p_dev->_io = 0;
 
        if ((c->io.BasePort1 != req->BasePort1) ||
            (c->io.NumPorts1 != req->NumPorts1) ||
@@ -516,14 +549,14 @@ int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
 } /* pcmcia_release_io */
 
 
-int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
+static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
 {
        struct pcmcia_socket *s = p_dev->socket;
        config_t *c= p_dev->function_config;
 
-       if (!(p_dev->state & CLIENT_IRQ_REQ))
+       if (!p_dev->_irq)
                return CS_BAD_HANDLE;
-       p_dev->state &= ~CLIENT_IRQ_REQ;
+       p_dev->_irq = 0;
 
        if (c->state & CONFIG_LOCKED)
                return CS_CONFIGURATION_LOCKED;
@@ -555,7 +588,7 @@ int pcmcia_release_window(window_handle_t win)
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
                return CS_BAD_HANDLE;
        s = win->sock;
-       if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
+       if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
                return CS_BAD_HANDLE;
 
        /* Shut down memory window */
@@ -569,7 +602,7 @@ int pcmcia_release_window(window_handle_t win)
                kfree(win->ctl.res);
                win->ctl.res = NULL;
        }
-       win->handle->state &= ~CLIENT_WIN_REQ(win->index);
+       win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
 
        win->magic = 0;
 
@@ -597,11 +630,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
                return CS_CONFIGURATION_LOCKED;
 
        /* Do power control.  We don't allow changes in Vcc. */
-       if (s->socket.Vcc != req->Vcc)
-               return CS_BAD_VCC;
-       if (req->Vpp1 != req->Vpp2)
-               return CS_BAD_VPP;
-       s->socket.Vpp = req->Vpp1;
+       s->socket.Vpp = req->Vpp;
        if (s->ops->set_socket(s, &s->socket))
                return CS_BAD_VPP;
 
@@ -691,7 +720,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
        }
 
        c->state |= CONFIG_LOCKED;
-       p_dev->state |= CLIENT_CONFIG_LOCKED;
+       p_dev->_locked = 1;
        return CS_SUCCESS;
 } /* pcmcia_request_configuration */
 EXPORT_SYMBOL(pcmcia_request_configuration);
@@ -737,7 +766,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
 
        c->io = *req;
        c->state |= CONFIG_IO_REQ;
-       p_dev->state |= CLIENT_IO_REQ;
+       p_dev->_io = 1;
        return CS_SUCCESS;
 } /* pcmcia_request_io */
 EXPORT_SYMBOL(pcmcia_request_io);
@@ -754,7 +783,7 @@ EXPORT_SYMBOL(pcmcia_request_io);
  */
 
 #ifdef CONFIG_PCMCIA_PROBE
-static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
+static irqreturn_t test_action(int cpl, void *dev_id)
 {
        return IRQ_NONE;
 }
@@ -765,6 +794,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        struct pcmcia_socket *s = p_dev->socket;
        config_t *c;
        int ret = CS_IN_USE, irq = 0;
+       int type;
 
        if (!(s->state & SOCKET_PRESENT))
                return CS_NO_CARD;
@@ -774,6 +804,13 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        if (c->state & CONFIG_IRQ_REQ)
                return CS_IN_USE;
 
+       /* Decide what type of interrupt we are registering */
+       type = 0;
+       if (s->functions > 1)           /* All of this ought to be handled higher up */
+               type = IRQF_SHARED;
+       if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
+               type = IRQF_SHARED;
+
 #ifdef CONFIG_PCMCIA_PROBE
        if (s->irq.AssignedIRQ != 0) {
                /* If the interrupt is already assigned, it must be the same */
@@ -799,9 +836,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
                         * marked as used by the kernel resource management core */
                        ret = request_irq(irq,
                                          (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
-                                         ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
-                                          (s->functions > 1) ||
-                                          (irq == s->pci_irq)) ? SA_SHIRQ : 0,
+                                         type,
                                          p_dev->devname,
                                          (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
                        if (!ret) {
@@ -816,24 +851,27 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        if (ret && !s->irq.AssignedIRQ) {
                if (!s->pci_irq)
                        return ret;
+               type = IRQF_SHARED;
                irq = s->pci_irq;
        }
 
-       if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
-               if (request_irq(irq, req->Handler,
-                               ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
-                                (s->functions > 1) ||
-                                (irq == s->pci_irq)) ? SA_SHIRQ : 0,
-                               p_dev->devname, req->Instance))
+       if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
+               if (request_irq(irq, req->Handler, type,  p_dev->devname, req->Instance))
                        return CS_IN_USE;
        }
 
+       /* Make sure the fact the request type was overridden is passed back */
+       if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
+               req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
+               printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n");
+               printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n");
+       }
        c->irq.Attributes = req->Attributes;
        s->irq.AssignedIRQ = req->AssignedIRQ = irq;
        s->irq.Config++;
 
        c->state |= CONFIG_IRQ_REQ;
-       p_dev->state |= CLIENT_IRQ_REQ;
+       p_dev->_irq = 1;
 
 #ifdef CONFIG_PCMCIA_PROBE
        pcmcia_used_irq[irq]++;
@@ -893,7 +931,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
                if (!win->ctl.res)
                        return CS_IN_USE;
        }
-       (*p_dev)->state |= CLIENT_WIN_REQ(w);
+       (*p_dev)->_win |= CLIENT_WIN_REQ(w);
 
        /* Configure the socket controller */
        win->ctl.map = w+1;
@@ -925,15 +963,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
 EXPORT_SYMBOL(pcmcia_request_window);
 
 void pcmcia_disable_device(struct pcmcia_device *p_dev) {
-       if (!p_dev->instance)
-               return;
-
        pcmcia_release_configuration(p_dev);
-       pcmcia_release_io(p_dev, &p_dev->instance->io);
-       pcmcia_release_irq(p_dev, &p_dev->instance->irq);
-       if (&p_dev->instance->win)
-               pcmcia_release_window(p_dev->instance->win);
-
-       p_dev->instance->dev = NULL;
+       pcmcia_release_io(p_dev, &p_dev->io);
+       pcmcia_release_irq(p_dev, &p_dev->irq);
+       if (&p_dev->win)
+               pcmcia_release_window(p_dev->win);
 }
 EXPORT_SYMBOL(pcmcia_disable_device);