2 #include <scsi/scsi_host.h>
3 #include <scsi/scsi_cmnd.h>
4 #include <scsi/scsi_device.h>
6 #include <linux/module.h>
7 #include <linux/slab.h>
10 #include "transport.h"
13 #include "sierra_ms.h"
16 #define SWIMS_USB_REQUEST_SetSwocMode 0x0B
17 #define SWIMS_USB_REQUEST_GetSwocInfo 0x0A
18 #define SWIMS_USB_INDEX_SetMode 0x0000
19 #define SWIMS_SET_MODE_Modem 0x0001
21 #define TRU_NORMAL 0x01
22 #define TRU_FORCE_MS 0x02
23 #define TRU_FORCE_MODEM 0x03
25 static unsigned int swi_tru_install
= 1;
26 module_param(swi_tru_install
, uint
, S_IRUGO
| S_IWUSR
);
27 MODULE_PARM_DESC(swi_tru_install
, "TRU-Install mode (1=Full Logic (def),"
28 " 2=Force CD-Rom, 3=Force Modem)");
36 } __attribute__((__packed__
));
38 static bool containsFullLinuxPackage(struct swoc_info
*swocInfo
)
40 if ((swocInfo
->LinuxSKU
>= 0x2100 && swocInfo
->LinuxSKU
<= 0x2FFF) ||
41 (swocInfo
->LinuxSKU
>= 0x7100 && swocInfo
->LinuxSKU
<= 0x7FFF))
47 static int sierra_set_ms_mode(struct usb_device
*udev
, __u16 eSWocMode
)
50 dev_dbg(&udev
->dev
, "SWIMS: %s", "DEVICE MODE SWITCH\n");
51 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
52 SWIMS_USB_REQUEST_SetSwocMode
, /* __u8 request */
53 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* __u8 request type */
54 eSWocMode
, /* __u16 value */
55 0x0000, /* __u16 index */
56 NULL
, /* void *data */
58 USB_CTRL_SET_TIMEOUT
); /* int timeout */
63 static int sierra_get_swoc_info(struct usb_device
*udev
,
64 struct swoc_info
*swocInfo
)
68 dev_dbg(&udev
->dev
, "SWIMS: Attempting to get TRU-Install info\n");
70 result
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
71 SWIMS_USB_REQUEST_GetSwocInfo
, /* __u8 request */
72 USB_TYPE_VENDOR
| USB_DIR_IN
, /* __u8 request type */
75 (void *) swocInfo
, /* void *data */
76 sizeof(struct swoc_info
), /* __u16 size */
77 USB_CTRL_SET_TIMEOUT
); /* int timeout */
79 swocInfo
->LinuxSKU
= le16_to_cpu(swocInfo
->LinuxSKU
);
80 swocInfo
->LinuxVer
= le16_to_cpu(swocInfo
->LinuxVer
);
84 static void debug_swoc(const struct device
*dev
, struct swoc_info
*swocInfo
)
86 dev_dbg(dev
, "SWIMS: SWoC Rev: %02d\n", swocInfo
->rev
);
87 dev_dbg(dev
, "SWIMS: Linux SKU: %04X\n", swocInfo
->LinuxSKU
);
88 dev_dbg(dev
, "SWIMS: Linux Version: %04X\n", swocInfo
->LinuxVer
);
92 static ssize_t
show_truinst(struct device
*dev
, struct device_attribute
*attr
,
95 struct swoc_info
*swocInfo
;
96 struct usb_interface
*intf
= to_usb_interface(dev
);
97 struct usb_device
*udev
= interface_to_usbdev(intf
);
99 if (swi_tru_install
== TRU_FORCE_MS
) {
100 result
= snprintf(buf
, PAGE_SIZE
, "Forced Mass Storage\n");
102 swocInfo
= kmalloc(sizeof(struct swoc_info
), GFP_KERNEL
);
104 snprintf(buf
, PAGE_SIZE
, "Error\n");
107 result
= sierra_get_swoc_info(udev
, swocInfo
);
109 dev_dbg(dev
, "SWIMS: failed SWoC query\n");
111 snprintf(buf
, PAGE_SIZE
, "Error\n");
114 debug_swoc(dev
, 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
)
129 struct swoc_info
*swocInfo
;
130 struct usb_device
*udev
;
131 struct Scsi_Host
*sh
;
138 scsi_get_host_dev(sh
);
140 /* Force Modem mode */
141 if (swi_tru_install
== TRU_FORCE_MODEM
) {
142 usb_stor_dbg(us
, "SWIMS: Forcing Modem Mode\n");
143 result
= sierra_set_ms_mode(udev
, SWIMS_SET_MODE_Modem
);
145 usb_stor_dbg(us
, "SWIMS: Failed to switch to modem mode\n");
148 /* Force Mass Storage mode (keep CD-Rom) */
149 else if (swi_tru_install
== TRU_FORCE_MS
) {
150 usb_stor_dbg(us
, "SWIMS: Forcing Mass Storage Mode\n");
153 /* Normal TRU-Install Logic */
155 usb_stor_dbg(us
, "SWIMS: Normal SWoC Logic\n");
157 swocInfo
= kmalloc(sizeof(struct swoc_info
),
165 result
= sierra_get_swoc_info(udev
, swocInfo
);
167 usb_stor_dbg(us
, "SWIMS: Failed SWoC query\n");
168 schedule_timeout_uninterruptible(2*HZ
);
170 } while (retries
&& result
< 0);
173 usb_stor_dbg(us
, "SWIMS: Completely failed SWoC query\n");
178 debug_swoc(&us
->pusb_dev
->dev
, swocInfo
);
180 /* If there is not Linux software on the TRU-Install device
181 * then switch to modem mode
183 if (!containsFullLinuxPackage(swocInfo
)) {
184 usb_stor_dbg(us
, "SWIMS: Switching to Modem Mode\n");
185 result
= sierra_set_ms_mode(udev
,
186 SWIMS_SET_MODE_Modem
);
188 usb_stor_dbg(us
, "SWIMS: Failed to switch modem\n");
195 result
= device_create_file(&us
->pusb_intf
->dev
, &dev_attr_truinst
);