2 #include <scsi/scsi_host.h>
3 #include <scsi/scsi_cmnd.h>
4 #include <scsi/scsi_device.h>
6 #include <linux/slab.h>
12 #include "sierra_ms.h"
15 #define SWIMS_USB_REQUEST_SetSwocMode 0x0B
16 #define SWIMS_USB_REQUEST_GetSwocInfo 0x0A
17 #define SWIMS_USB_INDEX_SetMode 0x0000
18 #define SWIMS_SET_MODE_Modem 0x0001
20 #define TRU_NORMAL 0x01
21 #define TRU_FORCE_MS 0x02
22 #define TRU_FORCE_MODEM 0x03
24 static unsigned int swi_tru_install
= 1;
25 module_param(swi_tru_install
, uint
, S_IRUGO
| S_IWUSR
);
26 MODULE_PARM_DESC(swi_tru_install
, "TRU-Install mode (1=Full Logic (def),"
27 " 2=Force CD-Rom, 3=Force Modem)");
35 } __attribute__((__packed__
));
37 static bool containsFullLinuxPackage(struct swoc_info
*swocInfo
)
39 if ((swocInfo
->LinuxSKU
>= 0x2100 && swocInfo
->LinuxSKU
<= 0x2FFF) ||
40 (swocInfo
->LinuxSKU
>= 0x7100 && swocInfo
->LinuxSKU
<= 0x7FFF))
46 static int sierra_set_ms_mode(struct usb_device
*udev
, __u16 eSWocMode
)
49 US_DEBUGP("SWIMS: %s", "DEVICE MODE SWITCH\n");
50 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
51 SWIMS_USB_REQUEST_SetSwocMode
, /* __u8 request */
52 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* __u8 request type */
53 eSWocMode
, /* __u16 value */
54 0x0000, /* __u16 index */
55 NULL
, /* void *data */
57 USB_CTRL_SET_TIMEOUT
); /* int timeout */
62 static int sierra_get_swoc_info(struct usb_device
*udev
,
63 struct swoc_info
*swocInfo
)
67 US_DEBUGP("SWIMS: Attempting to get TRU-Install info.\n");
69 result
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
70 SWIMS_USB_REQUEST_GetSwocInfo
, /* __u8 request */
71 USB_TYPE_VENDOR
| USB_DIR_IN
, /* __u8 request type */
74 (void *) swocInfo
, /* void *data */
75 sizeof(struct swoc_info
), /* __u16 size */
76 USB_CTRL_SET_TIMEOUT
); /* int timeout */
78 swocInfo
->LinuxSKU
= le16_to_cpu(swocInfo
->LinuxSKU
);
79 swocInfo
->LinuxVer
= le16_to_cpu(swocInfo
->LinuxVer
);
83 static void debug_swoc(struct swoc_info
*swocInfo
)
85 US_DEBUGP("SWIMS: SWoC Rev: %02d \n", swocInfo
->rev
);
86 US_DEBUGP("SWIMS: Linux SKU: %04X \n", swocInfo
->LinuxSKU
);
87 US_DEBUGP("SWIMS: Linux Version: %04X \n", swocInfo
->LinuxVer
);
91 static ssize_t
show_truinst(struct device
*dev
, struct device_attribute
*attr
,
94 struct swoc_info
*swocInfo
;
95 struct usb_interface
*intf
= to_usb_interface(dev
);
96 struct usb_device
*udev
= interface_to_usbdev(intf
);
98 if (swi_tru_install
== TRU_FORCE_MS
) {
99 result
= snprintf(buf
, PAGE_SIZE
, "Forced Mass Storage\n");
101 swocInfo
= kmalloc(sizeof(struct swoc_info
), GFP_KERNEL
);
103 US_DEBUGP("SWIMS: Allocation failure\n");
104 snprintf(buf
, PAGE_SIZE
, "Error\n");
107 result
= sierra_get_swoc_info(udev
, swocInfo
);
109 US_DEBUGP("SWIMS: failed SWoC query\n");
111 snprintf(buf
, PAGE_SIZE
, "Error\n");
114 debug_swoc(swocInfo
);
115 result
= snprintf(buf
, PAGE_SIZE
,
116 "REV=%02d SKU=%04X VER=%04X\n",
124 static DEVICE_ATTR(truinst
, S_IRUGO
, show_truinst
, NULL
);
126 int sierra_ms_init(struct us_data
*us
)
130 struct swoc_info
*swocInfo
;
131 struct usb_device
*udev
;
132 struct Scsi_Host
*sh
;
133 struct scsi_device
*sd
;
141 sd
= scsi_get_host_dev(sh
);
143 US_DEBUGP("SWIMS: sierra_ms_init called\n");
145 /* Force Modem mode */
146 if (swi_tru_install
== TRU_FORCE_MODEM
) {
147 US_DEBUGP("SWIMS: %s", "Forcing Modem Mode\n");
148 result
= sierra_set_ms_mode(udev
, SWIMS_SET_MODE_Modem
);
150 US_DEBUGP("SWIMS: Failed to switch to modem mode.\n");
153 /* Force Mass Storage mode (keep CD-Rom) */
154 else if (swi_tru_install
== TRU_FORCE_MS
) {
155 US_DEBUGP("SWIMS: %s", "Forcing Mass Storage Mode\n");
158 /* Normal TRU-Install Logic */
160 US_DEBUGP("SWIMS: %s", "Normal SWoC Logic\n");
162 swocInfo
= kmalloc(sizeof(struct swoc_info
),
165 US_DEBUGP("SWIMS: %s", "Allocation failure\n");
172 result
= sierra_get_swoc_info(udev
, swocInfo
);
174 US_DEBUGP("SWIMS: %s", "Failed SWoC query\n");
175 schedule_timeout_uninterruptible(2*HZ
);
177 } while (retries
&& result
< 0);
180 US_DEBUGP("SWIMS: %s",
181 "Completely failed SWoC query\n");
186 debug_swoc(swocInfo
);
188 /* If there is not Linux software on the TRU-Install device
189 * then switch to modem mode
191 if (!containsFullLinuxPackage(swocInfo
)) {
192 US_DEBUGP("SWIMS: %s",
193 "Switching to Modem Mode\n");
194 result
= sierra_set_ms_mode(udev
,
195 SWIMS_SET_MODE_Modem
);
197 US_DEBUGP("SWIMS: Failed to switch modem\n");
204 result
= device_create_file(&us
->pusb_intf
->dev
, &dev_attr_truinst
);