2 #include <scsi/scsi_host.h>
3 #include <scsi/scsi_cmnd.h>
4 #include <scsi/scsi_device.h>
11 #include "sierra_ms.h"
14 #define SWIMS_USB_REQUEST_SetSwocMode 0x0B
15 #define SWIMS_USB_REQUEST_GetSwocInfo 0x0A
16 #define SWIMS_USB_INDEX_SetMode 0x0000
17 #define SWIMS_SET_MODE_Modem 0x0001
19 #define TRU_NORMAL 0x01
20 #define TRU_FORCE_MS 0x02
21 #define TRU_FORCE_MODEM 0x03
23 static unsigned int swi_tru_install
= 1;
24 module_param(swi_tru_install
, uint
, S_IRUGO
| S_IWUSR
);
25 MODULE_PARM_DESC(swi_tru_install
, "TRU-Install mode (1=Full Logic (def),"
26 " 2=Force CD-Rom, 3=Force Modem)");
34 } __attribute__((__packed__
));
36 static bool containsFullLinuxPackage(struct swoc_info
*swocInfo
)
38 if ((swocInfo
->LinuxSKU
>= 0x2100 && swocInfo
->LinuxSKU
<= 0x2FFF) ||
39 (swocInfo
->LinuxSKU
>= 0x7100 && swocInfo
->LinuxSKU
<= 0x7FFF))
45 static int sierra_set_ms_mode(struct usb_device
*udev
, __u16 eSWocMode
)
48 US_DEBUGP("SWIMS: %s", "DEVICE MODE SWITCH\n");
49 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
50 SWIMS_USB_REQUEST_SetSwocMode
, /* __u8 request */
51 USB_TYPE_VENDOR
| USB_DIR_OUT
, /* __u8 request type */
52 eSWocMode
, /* __u16 value */
53 0x0000, /* __u16 index */
54 NULL
, /* void *data */
56 USB_CTRL_SET_TIMEOUT
); /* int timeout */
61 static int sierra_get_swoc_info(struct usb_device
*udev
,
62 struct swoc_info
*swocInfo
)
66 US_DEBUGP("SWIMS: Attempting to get TRU-Install info.\n");
68 result
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
69 SWIMS_USB_REQUEST_GetSwocInfo
, /* __u8 request */
70 USB_TYPE_VENDOR
| USB_DIR_IN
, /* __u8 request type */
73 (void *) swocInfo
, /* void *data */
74 sizeof(struct swoc_info
), /* __u16 size */
75 USB_CTRL_SET_TIMEOUT
); /* int timeout */
77 swocInfo
->LinuxSKU
= le16_to_cpu(swocInfo
->LinuxSKU
);
78 swocInfo
->LinuxVer
= le16_to_cpu(swocInfo
->LinuxVer
);
82 static void debug_swoc(struct swoc_info
*swocInfo
)
84 US_DEBUGP("SWIMS: SWoC Rev: %02d \n", swocInfo
->rev
);
85 US_DEBUGP("SWIMS: Linux SKU: %04X \n", swocInfo
->LinuxSKU
);
86 US_DEBUGP("SWIMS: Linux Version: %04X \n", swocInfo
->LinuxVer
);
90 static ssize_t
show_truinst(struct device
*dev
, struct device_attribute
*attr
,
93 struct swoc_info
*swocInfo
;
94 struct usb_interface
*intf
= to_usb_interface(dev
);
95 struct usb_device
*udev
= interface_to_usbdev(intf
);
97 if (swi_tru_install
== TRU_FORCE_MS
) {
98 result
= snprintf(buf
, PAGE_SIZE
, "Forced Mass Storage\n");
100 swocInfo
= kmalloc(sizeof(struct swoc_info
), GFP_KERNEL
);
102 US_DEBUGP("SWIMS: Allocation failure\n");
103 snprintf(buf
, PAGE_SIZE
, "Error\n");
106 result
= sierra_get_swoc_info(udev
, swocInfo
);
108 US_DEBUGP("SWIMS: failed SWoC query\n");
110 snprintf(buf
, PAGE_SIZE
, "Error\n");
113 debug_swoc(swocInfo
);
114 result
= snprintf(buf
, PAGE_SIZE
,
115 "REV=%02d SKU=%04X VER=%04X\n",
123 static DEVICE_ATTR(truinst
, S_IWUGO
| S_IRUGO
, show_truinst
, NULL
);
125 int sierra_ms_init(struct us_data
*us
)
129 struct swoc_info
*swocInfo
;
130 struct usb_device
*udev
;
131 struct Scsi_Host
*sh
;
132 struct scsi_device
*sd
;
140 sd
= scsi_get_host_dev(sh
);
142 US_DEBUGP("SWIMS: sierra_ms_init called\n");
144 /* Force Modem mode */
145 if (swi_tru_install
== TRU_FORCE_MODEM
) {
146 US_DEBUGP("SWIMS: %s", "Forcing Modem Mode\n");
147 result
= sierra_set_ms_mode(udev
, SWIMS_SET_MODE_Modem
);
149 US_DEBUGP("SWIMS: Failed to switch to modem mode.\n");
152 /* Force Mass Storage mode (keep CD-Rom) */
153 else if (swi_tru_install
== TRU_FORCE_MS
) {
154 US_DEBUGP("SWIMS: %s", "Forcing Mass Storage Mode\n");
157 /* Normal TRU-Install Logic */
159 US_DEBUGP("SWIMS: %s", "Normal SWoC Logic\n");
161 swocInfo
= kmalloc(sizeof(struct swoc_info
),
164 US_DEBUGP("SWIMS: %s", "Allocation failure\n");
171 result
= sierra_get_swoc_info(udev
, swocInfo
);
173 US_DEBUGP("SWIMS: %s", "Failed SWoC query\n");
174 schedule_timeout_uninterruptible(2*HZ
);
176 } while (retries
&& result
< 0);
179 US_DEBUGP("SWIMS: %s",
180 "Completely failed SWoC query\n");
185 debug_swoc(swocInfo
);
187 /* If there is not Linux software on the TRU-Install device
188 * then switch to modem mode
190 if (!containsFullLinuxPackage(swocInfo
)) {
191 US_DEBUGP("SWIMS: %s",
192 "Switching to Modem Mode\n");
193 result
= sierra_set_ms_mode(udev
,
194 SWIMS_SET_MODE_Modem
);
196 US_DEBUGP("SWIMS: Failed to switch modem\n");
203 result
= device_create_file(&us
->pusb_intf
->dev
, &dev_attr_truinst
);