nfsd4: setclientid_confirm callback-change fixes
[safe/jmp/linux-2.6] / drivers / pcmcia / pcmcia_resource.c
index 3e01385..f5d0ba8 100644 (file)
@@ -29,7 +29,6 @@
 #include <pcmcia/ds.h>
 
 #include "cs_internal.h"
-#include "ds_internal.h"
 
 
 /* Access speed for IO windows */
@@ -175,7 +174,7 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
        c = p_dev->function_config;
 
        if (!(c->state & CONFIG_LOCKED))
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        addr = (c->ConfigBase + reg->Offset) >> 1;
 
@@ -189,7 +188,7 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
                pcmcia_write_cis_mem(s, 1, addr, 1, &val);
                break;
        default:
-               return CS_BAD_ARGS;
+               return -EINVAL;
                break;
        }
        return 0;
@@ -211,7 +210,7 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
                if (s->state & SOCKET_WIN_REQ(w))
                        break;
        if (w == MAX_WIN)
-               return CS_NO_MORE_ITEMS;
+               return -EINVAL;
        win = &s->win[w];
        req->Base = win->ctl.res->start;
        req->Size = win->ctl.res->end - win->ctl.res->start + 1;
@@ -238,7 +237,7 @@ EXPORT_SYMBOL(pcmcia_get_window);
 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
 {
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        req->Page = 0;
        req->CardOffset = win->ctl.card_start;
        return 0;
@@ -250,13 +249,17 @@ int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
 {
        struct pcmcia_socket *s;
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
-       if (req->Page != 0)
-               return CS_BAD_PAGE;
+               return -EINVAL;
        s = win->sock;
+       if (req->Page != 0) {
+               ds_dbg(s, 0, "failure: requested page is zero\n");
+               return -EINVAL;
+       }
        win->ctl.card_start = req->CardOffset;
-       if (s->ops->set_mem_map(s, &win->ctl) != 0)
-               return CS_BAD_OFFSET;
+       if (s->ops->set_mem_map(s, &win->ctl) != 0) {
+               ds_dbg(s, 0, "failed to set_mem_map\n");
+               return -EIO;
+       }
        return 0;
 } /* pcmcia_map_mem_page */
 EXPORT_SYMBOL(pcmcia_map_mem_page);
@@ -278,7 +281,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
        if (!(s->state & SOCKET_PRESENT))
                return -ENODEV;
        if (!(c->state & CONFIG_LOCKED))
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
                if (mod->Attributes & CONF_ENABLE_IRQ) {
@@ -299,9 +302,10 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
        /* We only allow changing Vpp1 and Vpp2 to the same value */
        if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
            (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
-               if (mod->Vpp1 != mod->Vpp2)
+               if (mod->Vpp1 != mod->Vpp2) {
                        ds_dbg(s, 0, "Vpp1 and Vpp2 must be the same\n");
                        return -EINVAL;
+               }
                s->socket.Vpp = mod->Vpp1;
                if (s->ops->set_socket(s, &s->socket)) {
                        dev_printk(KERN_WARNING, &s->dev,
@@ -389,7 +393,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
        config_t *c = p_dev->function_config;
 
        if (!p_dev->_io )
-               return CS_BAD_HANDLE;
+               return -EINVAL;
 
        p_dev->_io = 0;
 
@@ -397,7 +401,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
            (c->io.NumPorts1 != req->NumPorts1) ||
            (c->io.BasePort2 != req->BasePort2) ||
            (c->io.NumPorts2 != req->NumPorts2))
-               return CS_BAD_ARGS;
+               return -EINVAL;
 
        c->state &= ~CONFIG_IO_REQ;
 
@@ -415,15 +419,19 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        config_t *c= p_dev->function_config;
 
        if (!p_dev->_irq)
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        p_dev->_irq = 0;
 
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->irq.Attributes != req->Attributes)
-               return CS_BAD_ATTRIBUTE;
-       if (s->irq.AssignedIRQ != req->AssignedIRQ)
-               return CS_BAD_IRQ;
+               return -EACCES;
+       if (c->irq.Attributes != req->Attributes) {
+               ds_dbg(s, 0, "IRQ attributes must match assigned ones\n");
+               return -EINVAL;
+       }
+       if (s->irq.AssignedIRQ != req->AssignedIRQ) {
+               ds_dbg(s, 0, "IRQ must match assigned one\n");
+               return -EINVAL;
+       }
        if (--s->irq.Config == 0) {
                c->state &= ~CONFIG_IRQ_REQ;
                s->irq.AssignedIRQ = 0;
@@ -446,10 +454,10 @@ int pcmcia_release_window(window_handle_t win)
        struct pcmcia_socket *s;
 
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        s = win->sock;
        if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
 
        /* Shut down memory window */
        win->ctl.flags &= ~MAP_ACTIVE;
@@ -489,7 +497,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
        }
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        /* Do power control.  We don't allow changes in Vcc. */
        s->socket.Vpp = req->Vpp;
@@ -608,24 +616,35 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
                return -EINVAL;
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->state & CONFIG_IO_REQ)
-               return CS_IN_USE;
-       if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
-               return CS_BAD_ATTRIBUTE;
+               return -EACCES;
+       if (c->state & CONFIG_IO_REQ) {
+               ds_dbg(s, 0, "IO already configured\n");
+               return -EBUSY;
+       }
+       if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
+               ds_dbg(s, 0, "bad attribute setting for IO region 1\n");
+               return -EINVAL;
+       }
        if ((req->NumPorts2 > 0) &&
-           (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
-               return CS_BAD_ATTRIBUTE;
+           (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
+               ds_dbg(s, 0, "bad attribute setting for IO region 2\n");
+               return -EINVAL;
+       }
 
+       ds_dbg(s, 1, "trying to allocate resource 1\n");
        if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
-                          req->NumPorts1, req->IOAddrLines))
-               return CS_IN_USE;
+                          req->NumPorts1, req->IOAddrLines)) {
+               ds_dbg(s, 0, "allocation of resource 1 failed\n");
+               return -EBUSY;
+       }
 
        if (req->NumPorts2) {
+               ds_dbg(s, 1, "trying to allocate resource 2\n");
                if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
                                   req->NumPorts2, req->IOAddrLines)) {
+                       ds_dbg(s, 0, "allocation of resource 2 failed\n");
                        release_io_space(s, req->BasePort1, req->NumPorts1);
-                       return CS_IN_USE;
+                       return -EBUSY;
                }
        }
 
@@ -658,23 +677,26 @@ 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 ret = -EINVAL, irq = 0;
        int type;
 
        if (!(s->state & SOCKET_PRESENT))
                return -ENODEV;
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->state & CONFIG_IRQ_REQ)
-               return CS_IN_USE;
+               return -EACCES;
+       if (c->state & CONFIG_IRQ_REQ) {
+               ds_dbg(s, 0, "IRQ already configured\n");
+               return -EBUSY;
+       }
 
        /* 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)
+       else if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
                type = IRQF_SHARED;
+       else printk(KERN_WARNING "pcmcia: Driver needs updating to support IRQ sharing.\n");
 
 #ifdef CONFIG_PCMCIA_PROBE
 
@@ -730,8 +752,10 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        }
 
        if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
-               if (request_irq(irq, req->Handler, type,  p_dev->devname, req->Instance))
-                       return CS_IN_USE;
+               ret = request_irq(irq, req->Handler, type,
+                                 p_dev->devname, req->Instance);
+               if (ret)
+                       return ret;
        }
 
        /* Make sure the fact the request type was overridden is passed back */
@@ -772,8 +796,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
 
        if (!(s->state & SOCKET_PRESENT))
                return -ENODEV;
-       if (req->Attributes & (WIN_PAGED | WIN_SHARED))
-               return CS_BAD_ATTRIBUTE;
+       if (req->Attributes & (WIN_PAGED | WIN_SHARED)) {
+               ds_dbg(s, 0, "bad attribute setting for iomem region\n");
+               return -EINVAL;
+       }
 
        /* Window size defaults to smallest available */
        if (req->Size == 0)
@@ -781,19 +807,25 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        align = (((s->features & SS_CAP_MEM_ALIGN) ||
                  (req->Attributes & WIN_STRICT_ALIGN)) ?
                 req->Size : s->map_size);
-       if (req->Size & (s->map_size-1))
-               return CS_BAD_SIZE;
+       if (req->Size & (s->map_size-1)) {
+               ds_dbg(s, 0, "invalid map size\n");
+               return -EINVAL;
+       }
        if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
-           (req->Base & (align-1)))
-               return CS_BAD_BASE;
+           (req->Base & (align-1))) {
+               ds_dbg(s, 0, "invalid base address\n");
+               return -EINVAL;
+       }
        if (req->Base)
                align = 0;
 
        /* Allocate system memory window */
        for (w = 0; w < MAX_WIN; w++)
                if (!(s->state & SOCKET_WIN_REQ(w))) break;
-       if (w == MAX_WIN)
-               return CS_IN_USE;
+       if (w == MAX_WIN) {
+               ds_dbg(s, 0, "all windows are used already\n");
+               return -EINVAL;
+       }
 
        win = &s->win[w];
        win->magic = WINDOW_MAGIC;
@@ -804,8 +836,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        if (!(s->features & SS_CAP_STATIC_MAP)) {
                win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
                                                      (req->Attributes & WIN_MAP_BELOW_1MB), s);
-               if (!win->ctl.res)
-                       return CS_IN_USE;
+               if (!win->ctl.res) {
+                       ds_dbg(s, 0, "allocating mem region failed\n");
+                       return -EINVAL;
+               }
        }
        (*p_dev)->_win |= CLIENT_WIN_REQ(w);
 
@@ -822,8 +856,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        if (req->Attributes & WIN_USE_WAIT)
                win->ctl.flags |= MAP_USE_WAIT;
        win->ctl.card_start = 0;
-       if (s->ops->set_mem_map(s, &win->ctl) != 0)
-               return CS_BAD_ARGS;
+       if (s->ops->set_mem_map(s, &win->ctl) != 0) {
+               ds_dbg(s, 0, "failed to set memory mapping\n");
+               return -EIO;
+       }
        s->state |= SOCKET_WIN_REQ(w);
 
        /* Return window handle */
@@ -903,7 +939,7 @@ int pcmcia_loop_config(struct pcmcia_device *p_dev,
                if (pcmcia_get_tuple_data(p_dev, tuple))
                        goto next_entry;
 
-               if (pcmcia_parse_tuple(p_dev, tuple, &cfg_mem->parse))
+               if (pcmcia_parse_tuple(tuple, &cfg_mem->parse))
                        goto next_entry;
 
                /* default values */