Changeset 12066


Ignore:
Timestamp:
05/08/09 15:47:37 (4 years ago)
Author:
BrainSlayer
Message:

latest sierra driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/linux/sl2312/linux-2.6.23/drivers/usb/serial/sierra.c

    r11897 r12066  
    33 
    44  Copyright (C) 2006, 2007, 2008  Kevin Lloyd <klloyd@sierrawireless.com> 
     5  
     6  Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer 
     7                           <linux@sierrawireless.com> 
    58 
    69  IMPORTANT DISCLAIMER: This driver is not commercially supported by 
     
    1619  Back ported to kernel 2.6.23 
    1720*/ 
    18  
    19 #define DRIVER_VERSION "v.1.3.1b" 
    20 #define DRIVER_AUTHOR "Kevin Lloyd <klloyd@sierrawireless.com>" 
     21/* Uncomment to log function calls */ 
     22/*#define DEBUG*/ 
     23#define DRIVER_VERSION "v.1.7.0" 
     24#define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" 
    2125#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 
    2226 
     
    2933#include <linux/usb.h> 
    3034#include <linux/usb/serial.h> 
    31 #include <linux/usb/ch9.h> 
    3235 
    3336#define SWIMS_USB_REQUEST_SetPower      0x00 
     
    3639#define SWIMS_SET_MODE_Modem            0x0001 
    3740 
    38 /* per port private data */ 
    39 #define N_IN_URB        4 
    40 #define N_OUT_URB       4 
     41#define N_IN_URB        8 
     42#define N_OUT_URB       64 
    4143#define IN_BUFLEN       4096 
     44 
     45#define MAX_TRANSFER            (PAGE_SIZE - 512) 
     46/* MAX_TRANSFER is chosen so that the VM is not stressed by 
     47   allocations > PAGE_SIZE and the number of packets in a page 
     48   is an integer 512 is the largest possible packet on EHCI */ 
    4249 
    4350static int debug; 
    4451static int nmea; 
    4552static int truinstall = 1; 
     53static int suspend_support; 
    4654 
    4755enum devicetype { 
    48         DEVICE_3_PORT =         0, 
    49         DEVICE_1_PORT =         1, 
    50         DEVICE_INSTALLER =      2, 
     56        DEVICE_MODEM =          0, 
     57        DEVICE_INSTALLER =      1, 
    5158}; 
    5259 
     60/* list of interface numbers - used for constructing interface blacklists */ 
     61struct list { 
     62        const u32 listlen; /* number of interface numbers on list */ 
     63        const u8  *list;   /* pointer to the array holding the numbers */ 
     64}; 
     65 
     66/* static device type specific data */ 
     67struct sierra_device_static_info { 
     68        const enum devicetype   dev_type; 
     69        const struct list       iface_blacklist; 
     70}; 
     71 
    5372static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 
    5473{ 
    5574        int result; 
    56         dev_dbg(&udev->dev, "%s", __func__); 
     75        dev_dbg(&udev->dev, "%s\n", __func__); 
    5776        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    5877                        SWIMS_USB_REQUEST_SetPower,     /* __u8 request      */ 
     
    6988{ 
    7089        int result; 
    71         dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); 
     90        dev_dbg(&udev->dev, "%s\n", "DEVICE MODE SWITCH"); 
    7291        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    7392                        SWIMS_USB_REQUEST_SetMode,      /* __u8 request      */ 
     
    84103{ 
    85104        int result; 
    86         dev_dbg(&udev->dev, "%s", __func__); 
     105        dev_dbg(&udev->dev, "%s\n", __func__); 
    87106        result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 
    88107                        SWIMS_USB_REQUEST_SetNmea,      /* __u8 request      */ 
     
    98117static int sierra_calc_num_ports(struct usb_serial *serial) 
    99118{ 
    100         int result; 
    101         int *num_ports = usb_get_serial_data(serial); 
    102         dev_dbg(&serial->dev->dev, "%s", __func__); 
    103  
    104         result = *num_ports; 
    105  
    106         if (result) { 
    107                 kfree(num_ports); 
    108                 usb_set_serial_data(serial, NULL); 
    109         } 
    110  
    111         return result; 
     119        int num_ports = 0; 
     120        u8 ifnum, numendpoints; 
     121         
     122        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     123         
     124        ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 
     125        numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 
     126         
     127        /* Dummy interface present on some SKUs should be ignored */ 
     128        if (ifnum == 0x99) 
     129                num_ports = 0; 
     130        else if (numendpoints <= 3) 
     131                num_ports = 1; 
     132        else 
     133                num_ports = (numendpoints-1)/2; 
     134        return num_ports; 
     135} 
     136 
     137static int is_blacklisted(const u8 ifnum, const struct list *blacklist) 
     138{ 
     139        const u8  *list; 
     140        int i; 
     141         
     142        if (blacklist) { 
     143                list = blacklist->list; 
     144                 
     145                for (i=0; i < blacklist->listlen; i++) { 
     146                        if (list[i] == ifnum) 
     147                                return 1; 
     148                } 
     149        } 
     150        return 0; 
    112151} 
    113152 
     
    117156        struct usb_interface *p_interface; 
    118157        struct usb_host_interface *p_host_interface; 
    119         dev_dbg(&serial->dev->dev, "%s", __func__); 
     158        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    120159 
    121160        /* Get the interface structure pointer from the serial struct */ 
     
    136175                        const struct usb_device_id *id) 
    137176{ 
     177        const struct sierra_device_static_info * info;   
    138178        int result = 0; 
    139179        struct usb_device *udev; 
    140         int *num_ports; 
    141         u8 ifnum, ifclass, numendpoints; 
    142  
    143         dev_dbg(&serial->dev->dev, "%s", __func__); 
    144  
    145         num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); 
    146         if (!num_ports) 
    147                 return -ENOMEM; 
    148  
    149         ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 
     180        u8 ifnum, ifclass;  
     181 
     182        udev = serial->dev; 
     183        dev_dbg(&udev->dev, "%s\n", __func__); 
     184 
     185        /* Check TRU-Install first */ 
     186        info = (const struct sierra_device_static_info *)id->driver_info; 
    150187        ifclass = serial->interface->cur_altsetting->desc.bInterfaceClass; 
    151         numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 
    152         udev = serial->dev; 
    153  
    154         /* Figure out the interface number from the serial structure */ 
     188        if (ifclass == USB_CLASS_MASS_STORAGE) { 
     189                /* If TRU-Install support is enabled, force to modem mode */ 
     190                if (truinstall && info && info->dev_type == DEVICE_INSTALLER) { 
     191                        dev_dbg(&udev->dev, "%s\n", "FOUND TRU-INSTALL DEVICE"); 
     192                        result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 
     193                } 
     194                return -ENODEV; 
     195        } 
     196         
    155197        ifnum = sierra_calc_interface(serial); 
    156  
     198        if (info && is_blacklisted(ifnum, &info->iface_blacklist)) { 
     199                dev_dbg(&serial->dev->dev, 
     200                        "Ignoring blacklisted interface #%d\n", ifnum); 
     201                return -ENODEV; 
     202        } 
     203         
    157204        /* 
    158205         * If this interface supports more than 1 alternate 
     
    165212                usb_set_interface(udev, ifnum, 1); 
    166213        } 
    167  
    168         if (ifclass == USB_CLASS_MASS_STORAGE) { 
    169                 /* If TRU-Install support is enabled, force to modem mode */ 
    170                 if (truinstall && id->driver_info == DEVICE_INSTALLER) { 
    171                         dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE\n"); 
    172                         result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 
    173                 } 
    174                 kfree(num_ports); 
    175                 return -EIO; 
    176         /* Dummy interface present on some SKUs should be ignored */ 
    177         } else if (ifnum == 0x99) 
    178                 *num_ports = 0; 
    179         else if (numendpoints <= 3) 
    180                 *num_ports = 1; 
    181         else 
    182                 *num_ports = (numendpoints-1)/2; 
    183  
    184         /* 
    185          * save off our num_ports info so that we can use it in the 
    186          * calc_num_ports callback 
     214        /* Be careful here, The ifnum, ifclass etc. might be incorrect, because 
     215         * of the usb_set_interface call. (all obtained using  
     216         * serial->interface->cur_altsetting that was changed by that call) 
    187217         */ 
    188         usb_set_serial_data(serial, (void *)num_ports); 
    189  
     218         
    190219        return result; 
    191220} 
     221 
     222static const struct sierra_device_static_info tru_inst_info = { 
     223        .dev_type = DEVICE_INSTALLER, 
     224}; 
     225 
     226static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; 
     227static const struct sierra_device_static_info direct_ip_interface_blacklist = { 
     228        .dev_type = DEVICE_MODEM, 
     229        .iface_blacklist = { 
     230                .listlen = ARRAY_SIZE( direct_ip_non_serial_ifaces ), 
     231                .list = direct_ip_non_serial_ifaces, 
     232        }, 
     233}; 
    192234 
    193235static struct usb_device_id id_table [] = { 
     
    223265        { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ 
    224266        { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ 
    225         { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ 
    226         { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ 
    227         { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ 
     267        /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ 
     268        { USB_DEVICE(0x1199, 0x683C) },  
     269        { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ 
     270        /* Sierra Wireless MC8790, MC8791, MC8792 */ 
     271        { USB_DEVICE(0x1199, 0x683E) }, 
    228272        { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 
    229273        { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ 
     
    246290        { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 
    247291 
    248         { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, 
     292        { USB_DEVICE(0x1199, 0x0FFF), 
     293                .driver_info = (kernel_ulong_t)&tru_inst_info 
     294        }, 
     295         
     296        { USB_DEVICE(0x1199, 0x68A3),   /* Sierra Wireless Direct IP modems */ 
     297                .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist  
     298        }, 
     299         
    249300        { } 
    250301}; 
    251302MODULE_DEVICE_TABLE(usb, id_table); 
    252303 
    253 static struct usb_driver sierra_driver = { 
    254         .name       = "sierra", 
    255         .probe      = usb_serial_probe, 
    256         .disconnect = usb_serial_disconnect, 
    257         .id_table   = id_table, 
    258         .no_dynamic_id =        1, 
    259 }; 
    260  
     304/* per port private data */ 
    261305struct sierra_port_private { 
    262306        spinlock_t lock;        /* lock the structure */ 
     
    265309        /* Input endpoints and buffers for this port */ 
    266310        struct urb *in_urbs[N_IN_URB]; 
    267         char *in_buffer[N_IN_URB]; 
    268311 
    269312        /* Settings for the port */ 
     
    282325        __u16 interface = 0; 
    283326 
    284         dbg("%s", __FUNCTION__); 
     327        dev_dbg(&port->dev, "%s\n", __func__); 
    285328 
    286329        portdata = usb_get_serial_port_data(port); 
    287330 
    288331        if (port->tty) { 
     332 
    289333                int val = 0; 
    290334                if (portdata->dtr_state) 
     
    292336                if (portdata->rts_state) 
    293337                        val |= 0x02; 
    294  
     338                         
    295339                /* If composite device then properly report interface */ 
    296                 if (serial->num_ports == 1) 
     340                if (serial->num_ports == 1) { 
    297341                        interface = sierra_calc_interface(serial); 
     342                        /* Control message is send only to interfaces with  
     343                         * interrupt_in endpoints 
     344                         */ 
     345                        if(port->interrupt_in_urb) { 
     346                                /* send control message */ 
     347                                return usb_control_msg(serial->dev, 
     348                                        usb_rcvctrlpipe(serial->dev, 0), 
     349                                        0x22, 0x21, val, interface, 
     350                                        NULL, 0, USB_CTRL_SET_TIMEOUT); 
     351                        } 
     352                } 
    298353 
    299354                /* Otherwise the need to do non-composite mapping */ 
     
    305360                        else if (port->bulk_out_endpointAddress == 5) 
    306361                                interface = 2; 
    307                 } 
    308  
    309                 return usb_control_msg(serial->dev, 
     362 
     363                        return usb_control_msg(serial->dev, 
    310364                                usb_rcvctrlpipe(serial->dev, 0), 
    311365                                0x22, 0x21, val, interface, 
    312366                                NULL, 0, USB_CTRL_SET_TIMEOUT); 
     367 
     368                } 
    313369        } 
    314370 
     
    319375                        struct ktermios *old_termios) 
    320376{ 
    321         dev_dbg(&port->dev, "%s", __func__); 
     377        dev_dbg(&port->dev, "%s\n", __func__); 
    322378        sierra_send_setup(port); 
    323379} 
     
    328384        struct sierra_port_private *portdata; 
    329385 
     386        dev_dbg(&port->dev, "%s\n", __func__); 
    330387        portdata = usb_get_serial_port_data(port); 
    331388 
     
    358415        return sierra_send_setup(port); 
    359416} 
     417static void sierra_release_urb(struct urb *urb) 
     418{ 
     419        struct usb_serial_port *port; 
     420        if (urb) { 
     421                port =  urb->context; 
     422                dev_dbg(&port->dev, "%s: %p\n", __func__, urb);  
     423                if (urb->transfer_buffer) 
     424                        kfree(urb->transfer_buffer); 
     425                usb_free_urb(urb); 
     426        } 
     427} 
    360428 
    361429static void sierra_outdat_callback(struct urb *urb) 
     
    366434        unsigned long flags; 
    367435 
    368         dev_dbg(&port->dev, "%s - port %d", __func__, port->number); 
     436        dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 
    369437 
    370438        /* free up the transfer buffer, as usb_free_urb() does not do this */ 
     
    373441        if (status) 
    374442                dev_dbg(&port->dev, "%s - nonzero write bulk status " 
    375                     "received: %d", __func__, status); 
     443                    "received: %d\n", __func__, status); 
    376444 
    377445        spin_lock_irqsave(&portdata->lock, flags); 
     
    391459        unsigned char *buffer; 
    392460        struct urb *urb; 
    393         int status; 
     461        size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); 
     462        int retval = 0; 
     463 
     464        /* verify that we actually have some data to write */ 
     465        if (count == 0) 
     466                return 0; 
    394467 
    395468        portdata = usb_get_serial_port_data(port); 
    396469 
    397         dev_dbg(&port->dev, "%s: write (%d chars)", __func__, count); 
     470        dev_dbg(&port->dev, "%s: write (%d bytes)\n", __func__, writesize); 
    398471 
    399472        spin_lock_irqsave(&portdata->lock, flags); 
     
    406479        spin_unlock_irqrestore(&portdata->lock, flags); 
    407480 
    408         buffer = kmalloc(count, GFP_ATOMIC); 
     481        buffer = kmalloc(writesize, GFP_ATOMIC); 
    409482        if (!buffer) { 
    410483                dev_err(&port->dev, "out of memory\n"); 
    411                 count = -ENOMEM; 
     484                retval = -ENOMEM; 
    412485                goto error_no_buffer; 
    413486        } 
     
    416489        if (!urb) { 
    417490                dev_err(&port->dev, "no more free urbs\n"); 
    418                 count = -ENOMEM; 
     491                retval = -ENOMEM; 
    419492                goto error_no_urb; 
    420493        } 
    421494 
    422         memcpy(buffer, buf, count); 
    423  
    424         usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 
     495        memcpy(buffer, buf, writesize);  
     496 
     497        usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); 
    425498 
    426499        usb_fill_bulk_urb(urb, serial->dev, 
    427500                          usb_sndbulkpipe(serial->dev, 
    428501                                          port->bulk_out_endpointAddress), 
    429                           buffer, count, sierra_outdat_callback, port); 
     502                          buffer, writesize, sierra_outdat_callback, port); 
     503 
     504        /* Handle the need to send a zero length packet */ 
     505        urb->transfer_flags |= URB_ZERO_PACKET; 
    430506 
    431507        /* send it down the pipe */ 
    432         status = usb_submit_urb(urb, GFP_ATOMIC); 
    433         if (status) { 
     508        retval = usb_submit_urb(urb, GFP_ATOMIC); 
     509        if (retval) { 
    434510                dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " 
    435                         "with status = %d\n", __func__, status); 
    436                 count = status; 
     511                        "with status = %d\n", __func__, retval); 
    437512                goto error; 
    438513        } 
     
    441516         * really free it when it is finished with it */ 
    442517        usb_free_urb(urb); 
    443  
    444         return count; 
     518         
     519        return writesize; 
    445520error: 
    446521        usb_free_urb(urb); 
     
    451526        --portdata->outstanding_urbs; 
    452527        spin_unlock_irqrestore(&portdata->lock, flags); 
    453         return count; 
     528        return retval; 
    454529} 
    455530 
     
    463538        int status = urb->status; 
    464539 
    465         dbg("%s: %p", __func__, urb); 
    466  
    467540        endpoint = usb_pipeendpoint(urb->pipe); 
    468541        port =  urb->context; 
     542         
     543        dev_dbg(&port->dev, "%s: %p\n", __func__, urb);  
    469544 
    470545        if (status) { 
    471546                dev_dbg(&port->dev, "%s: nonzero status: %d on" 
    472                     " endpoint %02x.", __func__, status, endpoint); 
     547                        " endpoint %02x\n", __func__, status, endpoint); 
    473548        } else { 
    474549                tty = port->tty; 
     
    477552                        tty_insert_flip_string(tty, data, urb->actual_length); 
    478553                        tty_flip_buffer_push(tty); 
     554                        usb_serial_debug_data(debug, &port->dev, __func__,  
     555                                urb->actual_length, data); 
    479556                } else { 
    480557                        dev_dbg(&port->dev, "%s: empty read urb" 
    481                                 " received", __func__); 
    482                 } 
    483  
    484                 /* Resubmit urb so we continue receiving */ 
    485                 if (port->open_count && status != -ESHUTDOWN) { 
    486                         err = usb_submit_urb(urb, GFP_ATOMIC); 
    487                         if (err) 
    488                                 dev_err(&port->dev, "resubmit read urb failed." 
    489                                         "(%d)\n", err); 
    490                 } 
    491         } 
     558                                " received\n", __func__); 
     559                } 
     560        } 
     561 
     562        /* Resubmit urb so we continue receiving */ 
     563        if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 
     564                err = usb_submit_urb(urb, GFP_ATOMIC); 
     565                if (err) 
     566                        dev_err(&port->dev, "resubmit read urb failed." 
     567                                "(%d)\n", err); 
     568        } 
     569         
    492570        return; 
    493571} 
     
    501579        struct usb_serial *serial = port->serial; 
    502580 
    503         dev_dbg(&port->dev, "%s", __func__); 
    504         dev_dbg(&port->dev, "%s: urb %p port %p has data %p", __func__, 
     581        dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, 
    505582                urb, port, portdata); 
    506583 
     
    521598                                        sizeof(struct usb_ctrlrequest)); 
    522599 
    523                         dev_dbg(&port->dev, "%s: signal x%x", __func__, 
     600                        dev_dbg(&port->dev, "%s: signal x%x\n", __func__, 
    524601                                signals); 
    525602 
     
    534611                                tty_hangup(port->tty); 
    535612                } else { 
    536                         dev_dbg(&port->dev, "%s: type %x req %x", 
     613                        dev_dbg(&port->dev, "%s: type %x req %x\n", 
    537614                                __func__, req_pkt->bRequestType, 
    538615                                req_pkt->bRequest); 
    539616                } 
    540617        } else 
    541                 dev_dbg(&port->dev, "%s: error %d", __func__, status); 
     618                dev_dbg(&port->dev, "%s: error %d\n", __func__, status); 
    542619 
    543620        /* Resubmit urb so we continue receiving IRQ data */ 
    544         if (status != -ESHUTDOWN) { 
     621        if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 
    545622                urb->dev = serial->dev; 
    546623                err = usb_submit_urb(urb, GFP_ATOMIC); 
    547624                if (err) 
    548                         dev_dbg(&port->dev, "%s: resubmit intr urb " 
    549                                 "failed. (%d)", __func__, err); 
     625                        dev_err(&port->dev, "%s: resubmit intr urb " 
     626                                "failed. (%d)\n", __func__, err); 
    550627        } 
    551628} 
     
    556633        unsigned long flags; 
    557634 
    558         dev_dbg(&port->dev, "%s - port %d", __func__, port->number); 
     635        dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 
    559636 
    560637        /* try to give a good number back based on if we have any free urbs at 
     
    571648} 
    572649 
     650static void sierra_stop_rx_urbs(struct usb_serial_port *port) 
     651{ 
     652        int i; 
     653        struct sierra_port_private *portdata = usb_get_serial_port_data(port); 
     654         
     655        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     656                usb_kill_urb(portdata->in_urbs[i]); 
     657        } 
     658        usb_kill_urb(port->interrupt_in_urb); 
     659} 
     660 
     661static int sierra_submit_rx_urbs(struct usb_serial_port *port) 
     662{ 
     663        int ok_cnt; 
     664        int err = -EINVAL; 
     665        int i; 
     666        struct urb * urb; 
     667        struct sierra_port_private *portdata = usb_get_serial_port_data(port); 
     668 
     669        ok_cnt = 0; 
     670        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     671                urb = portdata->in_urbs[i]; 
     672                if (!urb) 
     673                        continue; 
     674                err = usb_submit_urb(urb, GFP_KERNEL); 
     675                if (err) { 
     676                        dev_err(&port->dev, "%s: submit urb failed: %d\n", 
     677                                __func__, err ); 
     678                } else { 
     679                        ok_cnt ++; 
     680                } 
     681        } 
     682 
     683        if (ok_cnt && port->interrupt_in_urb) { 
     684                err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 
     685                if (err) { 
     686                        dev_err(&port->dev, "%s: submit intr urb failed: %d\n", 
     687                                __func__, err ); 
     688                } 
     689        } 
     690 
     691        if (ok_cnt > 0) /* at least one rx urb submitted */ 
     692                return 0; 
     693        else 
     694                return err; 
     695} 
     696 
     697static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, 
     698                                        int dir, void *ctx, int len, 
     699                                        usb_complete_t callback) 
     700{ 
     701        struct urb      *urb; 
     702        u8              *buf; 
     703         
     704        if (endpoint == -1) 
     705                return NULL; 
     706 
     707        urb = usb_alloc_urb( 0, GFP_KERNEL ); 
     708        if (urb == NULL) { 
     709                dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n",  
     710                        __func__, endpoint); 
     711                return NULL; 
     712        } 
     713         
     714        buf = kmalloc(len, GFP_KERNEL); 
     715        if (buf) 
     716        { 
     717                /* Fill URB using supplied data */ 
     718                usb_fill_bulk_urb(urb, serial->dev, 
     719                        usb_sndbulkpipe(serial->dev, endpoint) | dir, 
     720                        buf, len, callback, ctx); 
     721 
     722                /* debug */ 
     723                dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__,  
     724                                dir == USB_DIR_IN?'i':'o', urb, buf ); 
     725        } else { 
     726                dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__,  
     727                                dir == USB_DIR_IN?'i':'o', urb, buf ); 
     728 
     729                sierra_release_urb(urb); 
     730                urb = NULL; 
     731        } 
     732         
     733        return urb; 
     734} 
     735 
     736static void sierra_close(struct usb_serial_port *port, struct file *filp) 
     737{ 
     738        int i; 
     739        struct usb_serial *serial = port->serial; 
     740        struct sierra_port_private *portdata; 
     741 
     742        dev_dbg(&port->dev, "%s\n", __func__); 
     743        portdata = usb_get_serial_port_data(port); 
     744 
     745        portdata->rts_state = 0; 
     746        portdata->dtr_state = 0; 
     747 
     748        if (serial->dev) { 
     749                sierra_send_setup(port); 
     750 
     751                /* Stop reading urbs */ 
     752                sierra_stop_rx_urbs(port); 
     753                /* .. and release them */ 
     754                for (i = 0; i < N_IN_URB; i++) { 
     755                        sierra_release_urb(portdata->in_urbs[i]); 
     756                        portdata->in_urbs[i] = NULL; 
     757                } 
     758        } 
     759 
     760        port->tty = NULL; 
     761} 
     762 
    573763static int sierra_open(struct usb_serial_port *port, struct file *filp) 
    574764{ 
     
    576766        struct usb_serial *serial = port->serial; 
    577767        int i; 
     768        int err; 
     769        int endpoint; 
    578770        struct urb *urb; 
    579         int result; 
    580771 
    581772        portdata = usb_get_serial_port_data(port); 
    582773 
    583         dev_dbg(&port->dev, "%s", __func__); 
     774        dev_dbg(&port->dev, "%s\n", __func__); 
    584775 
    585776        /* Set some sane defaults */ 
    586777        portdata->rts_state = 1; 
    587778        portdata->dtr_state = 1; 
    588  
    589         /* Reset low level data toggle and start reading from endpoints */ 
    590         for (i = 0; i < N_IN_URB; i++) { 
    591                 urb = portdata->in_urbs[i]; 
    592                 if (!urb) 
    593                         continue; 
    594                 if (urb->dev != serial->dev) { 
    595                         dev_dbg(&port->dev, "%s: dev %p != %p", 
    596                                  __func__, urb->dev, serial->dev); 
    597                         continue; 
    598                 } 
    599  
    600                 /* 
    601                  * make sure endpoint data toggle is synchronized with the 
    602                  * device 
    603                  */ 
    604                 usb_clear_halt(urb->dev, urb->pipe); 
    605  
    606                 result = usb_submit_urb(urb, GFP_KERNEL); 
    607                 if (result) { 
    608                         dev_err(&port->dev, "submit urb %d failed (%d) %d\n", 
    609                                 i, result, urb->transfer_buffer_length); 
    610                 } 
    611         } 
    612  
    613         port->tty->low_latency = 1; 
    614  
     779         
     780        if (port->tty) { 
     781                port->tty->low_latency = 1; 
     782        } 
     783 
     784        spin_lock_init(&portdata->lock); 
     785         
     786        endpoint = port->bulk_in_endpointAddress; 
     787         
     788        for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 
     789                urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, 
     790                                        IN_BUFLEN, sierra_indat_callback); 
     791                portdata->in_urbs[i] = urb; 
     792        } 
     793        /* clear halt condition */ 
     794        usb_clear_halt(serial->dev,  
     795                        usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); 
     796                 
     797        err = sierra_submit_rx_urbs(port); 
     798        if (err) { 
     799                /* get rid of everything as in close */ 
     800                sierra_close(port, filp); 
     801                return err; 
     802        } 
    615803        sierra_send_setup(port); 
    616804 
    617         /* start up the interrupt endpoint if we have one */ 
    618         if (port->interrupt_in_urb) { 
    619                 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 
    620                 if (result) 
    621                         dev_err(&port->dev, "submit irq_in urb failed %d\n", 
    622                                 result); 
    623         } 
    624805        return 0; 
    625 } 
    626  
    627 static void sierra_close(struct usb_serial_port *port, struct file *filp) 
    628 { 
    629         int i; 
    630         struct usb_serial *serial = port->serial; 
    631         struct sierra_port_private *portdata; 
    632  
    633         dev_dbg(&port->dev, "%s", __func__); 
    634         portdata = usb_get_serial_port_data(port); 
    635  
    636         portdata->rts_state = 0; 
    637         portdata->dtr_state = 0; 
    638  
    639         if (serial->dev) { 
    640                 sierra_send_setup(port); 
    641  
    642                 /* Stop reading/writing urbs */ 
    643                 for (i = 0; i < N_IN_URB; i++) 
    644                         usb_kill_urb(portdata->in_urbs[i]); 
    645         } 
    646  
    647         usb_kill_urb(port->interrupt_in_urb); 
    648  
    649         port->tty = NULL; 
    650806} 
    651807 
     
    654810        struct usb_serial_port *port; 
    655811        struct sierra_port_private *portdata; 
    656         struct urb *urb; 
    657812        int i; 
    658         int j; 
    659  
    660         dev_dbg(&serial->dev->dev, "%s", __func__); 
     813 
     814        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    661815 
    662816        /* Set Device mode to D0 */ 
     
    673827                if (!portdata) { 
    674828                        dev_dbg(&port->dev, "%s: kmalloc for " 
    675                                 "sierra_port_private (%d) failed!.", 
     829                                "sierra_port_private (%d) failed!\n", 
    676830                                __func__, i); 
    677831                        return -ENOMEM; 
    678832                } 
    679                 spin_lock_init(&portdata->lock); 
    680                 for (j = 0; j < N_IN_URB; j++) { 
    681                         portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); 
    682                         if (!portdata->in_buffer[j]) { 
    683                                 for (--j; j >= 0; j--) 
    684                                         kfree(portdata->in_buffer[j]); 
    685                                 kfree(portdata); 
    686                                 return -ENOMEM; 
    687                         } 
    688                 } 
    689  
     833                /* Set the port private data pointer */ 
    690834                usb_set_serial_port_data(port, portdata); 
    691  
    692                 /* initialize the in urbs */ 
    693                 for (j = 0; j < N_IN_URB; ++j) { 
    694                         urb = usb_alloc_urb(0, GFP_KERNEL); 
    695                         if (urb == NULL) { 
    696                                 dev_dbg(&port->dev, "%s: alloc for in " 
    697                                         "port failed.", __func__); 
    698                                 continue; 
    699                         } 
    700                         /* Fill URB using supplied data. */ 
    701                         usb_fill_bulk_urb(urb, serial->dev, 
    702                                           usb_rcvbulkpipe(serial->dev, 
    703                                                 port->bulk_in_endpointAddress), 
    704                                           portdata->in_buffer[j], IN_BUFLEN, 
    705                                           sierra_indat_callback, port); 
    706                         portdata->in_urbs[j] = urb; 
    707                 } 
    708835        } 
    709836 
     
    713840static void sierra_shutdown(struct usb_serial *serial) 
    714841{ 
    715         int i, j; 
     842        int i; 
    716843        struct usb_serial_port *port; 
    717844        struct sierra_port_private *portdata; 
    718845 
    719         dev_dbg(&serial->dev->dev, "%s", __func__); 
     846        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
    720847 
    721848        for (i = 0; i < serial->num_ports; ++i) { 
     
    726853                if (!portdata) 
    727854                        continue; 
    728  
    729                 for (j = 0; j < N_IN_URB; j++) { 
    730                         usb_kill_urb(portdata->in_urbs[j]); 
    731                         usb_free_urb(portdata->in_urbs[j]); 
    732                         kfree(portdata->in_buffer[j]); 
    733                 } 
    734855                kfree(portdata); 
    735856                usb_set_serial_port_data(port, NULL); 
    736857        } 
    737858} 
     859 
     860int sierra_suspend(struct usb_serial *serial, pm_message_t message) 
     861{ 
     862        int i; 
     863 
     864        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     865 
     866        /* The dummy interface doesn't prevent suspended state */ 
     867        if (serial->num_ports == 0) 
     868                return 0; 
     869 
     870        if (!suspend_support) 
     871                return -EOPNOTSUPP; 
     872 
     873        for (i=0; i < serial->num_ports ; i++) { 
     874                sierra_stop_rx_urbs(serial->port[i]); 
     875        } 
     876        return 0; 
     877} 
     878 
     879int sierra_resume(struct usb_serial *serial) 
     880{ 
     881        int i; 
     882 
     883        dev_dbg(&serial->dev->dev, "%s\n", __func__); 
     884 
     885        for (i=0; i < serial->num_ports ; i++) { 
     886                sierra_submit_rx_urbs(serial->port[i]); 
     887        } 
     888 
     889        return 0; 
     890} 
     891 
     892static struct usb_driver sierra_driver = { 
     893        .name       = "sierra", 
     894        .probe      = usb_serial_probe, 
     895        .disconnect = usb_serial_disconnect, 
     896        .suspend    = usb_serial_suspend, 
     897        .resume     = usb_serial_resume, 
     898        .id_table   = id_table, 
     899 
     900        .no_dynamic_id        = 1, 
     901        .supports_autosuspend = 1, 
     902}; 
    738903 
    739904static struct usb_serial_driver sierra_device = { 
     
    760925        .shutdown          = sierra_shutdown, 
    761926        .read_int_callback = sierra_instat_callback, 
     927        .suspend           = sierra_suspend, 
     928        .resume            = sierra_resume, 
    762929}; 
    763930 
     
    807974module_param(debug, bool, S_IRUGO | S_IWUSR); 
    808975MODULE_PARM_DESC(debug, "Debug messages"); 
     976 
     977module_param(suspend_support, bool, S_IRUGO | S_IWUSR); 
     978MODULE_PARM_DESC(suspend_support, "Selective Suspend support"); 
Note: See TracChangeset for help on using the changeset viewer.