OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
13 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../linux26/adaptec-usbxchange.patch
  5. # Copyright (C) 2007 The OpenSDE Project
  6. # Copyright (C) 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This patch file is dual-licensed. It is available under the license the
  11. # patched project is licensed under, as long as it is an OpenSource license
  12. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  13. # of the GNU General Public License as published by the Free Software
  14. # Foundation; either version 2 of the License, or (at your option) any later
  15. # version.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. Support for the Adaptec USB*Xchange family of USB<->SCSI cables.
  18. - Rene Rebe <rene@exactcode.de>
  19. --- linux-2.6.15-mm4/drivers/usb/storage/Kconfig 2006-01-30 12:16:10.838447250 +0100
  20. +++ linux-2.6.15-usb2x/drivers/usb/storage/Kconfig 2006-01-30 12:09:28.857325000 +0100
  21. @@ -134,6 +134,13 @@
  22. this input in any keybinding software. (e.g. gnome's keyboard short-
  23. cuts)
  24. +config USB_USBXCHANGE
  25. + tristate "Adaptec USBXchange and USB2Xchange firmware loader"
  26. + depends on USB_STORAGE
  27. + help
  28. + Say Y here to include additional code to load the firmware into the
  29. + Adaptec USBXchange and USB2Xchange USB --> SCSI converter dongle.
  30. +
  31. config USB_LIBUSUAL
  32. bool "The shared table of common (or usual) storage devices"
  33. depends on USB
  34. --- linux-2.6.15-mm4/drivers/usb/storage/Makefile 2006-01-30 12:16:10.838447250 +0100
  35. +++ linux-2.6.15-usb2x/drivers/usb/storage/Makefile 2006-01-30 12:08:29.781633000 +0100
  36. @@ -24,6 +24,8 @@
  37. usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
  38. initializers.o $(usb-storage-obj-y)
  39. +obj-$(CONFIG_USB_USBXCHANGE) += usbxchange_fw.o
  40. +
  41. ifneq ($(CONFIG_USB_LIBUSUAL),)
  42. obj-$(CONFIG_USB) += libusual.o
  43. endif
  44. --- linux-2.6.19/drivers/usb/storage/initializers.c.vanilla 2006-11-30 09:14:20.000000000 +0100
  45. +++ linux-2.6.19/drivers/usb/storage/initializers.c 2006-11-30 09:14:55.000000000 +0100
  46. @@ -91,3 +91,28 @@
  47. return (res ? -1 : 0);
  48. }
  49. +
  50. +/* Firmware Initialisation for the Adaptec USB2Xchange, needed for
  51. + * to recognize devices properly. Ren� Rebe <rene@exactcode.de> */
  52. +int usb2xchange_init(struct us_data *us)
  53. +{
  54. + int result;
  55. +
  56. + US_DEBUGP ("usb2xchange_init: initialising after reenumeration.\n");
  57. +
  58. + result = usb_control_msg(us->pusb_dev, us->send_ctrl_pipe,
  59. + 0x5a, 0x40, 0x01,
  60. + 0, 0, // buffer,
  61. + 0, // length,
  62. + 300);
  63. + US_DEBUGP ("usb2xchange_init: reset #1 (%d)\n", result);
  64. +
  65. + result = usb_control_msg(us->pusb_dev, us->send_ctrl_pipe,
  66. + 0x5a, 0x40, 0x02,
  67. + 0, 0, // buffer,
  68. + 0, // length,
  69. + 300);
  70. + US_DEBUGP ("usb2xchange_init: reset #2 (%d)\n", result);
  71. +
  72. + return result;
  73. +}
  74. --- linux-2.6.15-mm4/drivers/usb/storage/initializers.h 2006-01-30 12:16:10.826446500 +0100
  75. +++ linux-2.6.15-usb2x/drivers/usb/storage/initializers.h 2006-01-30 12:04:35.110967000 +0100
  76. @@ -48,2 +48,5 @@
  77. * flash reader */
  78. int usb_stor_ucr61s2b_init(struct us_data *us);
  79. +
  80. +/* Firmware Initialization for the Adaptec USB2Xchange */
  81. +int usb2xchange_init(struct us_data *us);
  82. --- linux-2.6.15-mm4/drivers/usb/storage/unusual_devs.h 2006-01-30 12:16:10.870449250 +0100
  83. +++ linux-2.6.15-usb2x/drivers/usb/storage/unusual_devs.h 2006-01-27 21:49:46.570867000 +0100
  84. @@ -1180,6 +1180,21 @@
  85. US_FL_SINGLE_LUN),
  86. #endif
  87. +/* Adaptec USBXchange and USB2Xchange, after firmware download.
  88. + * Requires Ez-USB Style firmware loader. Ren� Rebe <rene@exactcode.de> */
  89. +
  90. +UNUSUAL_DEV( 0x03f3, 0x2001, 0x0000, 0xffff,
  91. + "Adaptec",
  92. + "USBXchange",
  93. + US_SC_SCSI, US_PR_BULK, NULL,
  94. + 0 ),
  95. +
  96. +UNUSUAL_DEV( 0x03f3, 0x2003, 0x0000, 0xffff,
  97. + "Adaptec",
  98. + "USB2Xchange",
  99. + US_SC_SCSI, US_PR_BULK, usb2xchange_init,
  100. + US_FL_SCM_MULT_TARG ),
  101. +
  102. /* Control/Bulk transport for all SubClass values */
  103. USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
  104. USUAL_DEV(US_SC_8020, US_PR_CB, USB_US_TYPE_STOR),
  105. --- linux-2.6.15-mm4/drivers/usb/storage/usbxchange_fw.c 1970-01-01 01:00:00.000000000 +0100
  106. +++ linux-2.6.15-usb2x/drivers/usb/storage/usbxchange_fw.c 2006-01-28 09:45:14.308438000 +0100
  107. @@ -0,0 +1,215 @@
  108. +/*
  109. + * Firmware loader for Adaptec USBXchange / USB2Xchange.
  110. + *
  111. + * Uploads device firmware into the Adaptec USBXchange and USB2Xchange
  112. + * USB --> SCSI dongle.
  113. + *
  114. + * Current development and maintenance by:
  115. + * (c) 2005 Ren� Rebe <rene@exactcode.de>
  116. + *
  117. + * Initial work by:
  118. + * (c) 2004 Beier & Dauskardt IT <sda@bdit.de>
  119. + *
  120. + * Based on emi26.c:
  121. + * (c) 2002 Tapio Laxstr�m <tapio.laxstrom@iptime.fi>
  122. + *
  123. + * To use this driver, you need to get the devices firmware from some
  124. + * windows driver:
  125. + * usbxchg_win_v120.exe - for USBXchange
  126. + * usb2xchg_win_drv_v200.exe - for USB2Xchange
  127. + *
  128. + * Hotplug firmware loader compatible files can be found at:
  129. + * http://dl.exactcode.de/adaptec-usbxchange/
  130. + *
  131. + * Note:
  132. + * The USB2Xchange seems to have some internal buffer < 64K.
  133. + * Sending 64K requests crashes the device. Possibly it needs a
  134. + * "max_sectors: 8" setting.
  135. + *
  136. + * This program is distributed in the hope that it will be useful, but
  137. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  138. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  139. + * General Public License for more details.
  140. + *
  141. + * This program is free software; you can redistribute it and/or modify
  142. + * it under the terms of the GNU General Public License, as published by
  143. + * the Free Software Foundation, version 2.
  144. + */
  145. +
  146. +#include <linux/kernel.h>
  147. +#include <linux/errno.h>
  148. +#include <linux/slab.h>
  149. +#include <linux/module.h>
  150. +#include <linux/init.h>
  151. +#include <linux/usb.h>
  152. +#include <linux/firmware.h>
  153. +
  154. +#include "usbxchange_fw.h"
  155. +
  156. +static int usbxchange_writememory(struct usb_device *dev, int address,
  157. + unsigned char *data, int length,
  158. + __u8 bRequest);
  159. +static int usbxchange_set_reset(struct usb_device *dev, int cpureg,
  160. + unsigned char reset_bit);
  161. +static int usbxchange_load_firmware(struct usb_device *dev);
  162. +
  163. +static int usbxchange_probe(struct usb_interface *iface,
  164. + const struct usb_device_id *id);
  165. +static void usbxchange_disconnect(struct usb_interface *iface);
  166. +static int __init usbxchange_init(void);
  167. +static void __exit usbxchange_exit(void);
  168. +
  169. +#define usbxchange_VENDOR_ID 0x03f3
  170. +#define usbxchange_PRODUCT_ID 0x2000
  171. +#define usb2xchange_PRODUCT_ID 0x2002
  172. +
  173. +static struct usb_device_id usbxchange_usb_ids[] = {
  174. + {USB_DEVICE(usbxchange_VENDOR_ID, usbxchange_PRODUCT_ID)},
  175. + {USB_DEVICE(usbxchange_VENDOR_ID, usb2xchange_PRODUCT_ID)},
  176. + {} /* terminating entry */
  177. +};
  178. +
  179. +MODULE_DEVICE_TABLE(usb, usbxchange_usb_ids);
  180. +
  181. +/* thanks to drivers/usb/serial/keyspan_pda.c code */
  182. +static int usbxchange_writememory(struct usb_device *dev, int address,
  183. + unsigned char *data, int length, __u8 request)
  184. +{
  185. + int result;
  186. + unsigned char *buffer = kmalloc(length, GFP_KERNEL);
  187. +
  188. + if (!buffer) {
  189. + printk(KERN_ERR "usbxchange: kmalloc(%d) failed.\n", length);
  190. + return -ENOMEM;
  191. + }
  192. + memcpy(buffer, data, length);
  193. + result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request, 0x40,
  194. + address, 0, buffer, length, 300);
  195. + kfree(buffer);
  196. + return result;
  197. +}
  198. +
  199. +/* thanks to drivers/usb/serial/keyspan_pda.c code */
  200. +static int usbxchange_set_reset(struct usb_device *dev, int cpureg,
  201. + unsigned char reset_bit)
  202. +{
  203. + int response;
  204. + printk(KERN_INFO "%s - %d\n", __FUNCTION__, reset_bit);
  205. + response =
  206. + usbxchange_writememory(dev, cpureg, &reset_bit, 1,
  207. + ANCHOR_LOAD_INTERNAL);
  208. + if (response < 0) {
  209. + printk(KERN_ERR "usbxchange: set_reset (%d) failed\n",
  210. + reset_bit);
  211. + }
  212. + return response;
  213. +}
  214. +
  215. +static int usbxchange_load_firmware(struct usb_device *dev)
  216. +{
  217. + INTEL_HEX_RECORD *record;
  218. + int err, cpureg;
  219. +
  220. + const struct firmware *firmware;
  221. +
  222. + switch (le16_to_cpu(dev->descriptor.idProduct)) {
  223. + case usbxchange_PRODUCT_ID:
  224. + err = request_firmware(&firmware, "usbxchange.fw", &dev->dev);
  225. + cpureg = CPUCS_REG;
  226. + break;
  227. + case usb2xchange_PRODUCT_ID:
  228. + err = request_firmware(&firmware, "usb2xchange.fw", &dev->dev);
  229. + cpureg = CPUCS_REG_FX2;
  230. + break;
  231. + default:
  232. + printk(KERN_ERR "%s - device not recognized %x\n", __FUNCTION__,
  233. + le16_to_cpu(dev->descriptor.idProduct));
  234. + return 1;
  235. + }
  236. +
  237. + if (err != 0) {
  238. + printk(KERN_ERR "Hotplug firmware request failed.\n");
  239. + return err;
  240. + }
  241. +
  242. + /* Stop CPU */
  243. + err = usbxchange_set_reset(dev, cpureg, 1);
  244. + err = usbxchange_set_reset(dev, cpureg, 1);
  245. + if (err < 0) {
  246. + printk(KERN_ERR "%s - error stopping dongle CPU: error = %d\n",
  247. + __FUNCTION__, err);
  248. + return err;
  249. + }
  250. +
  251. + /* Upload firmware */
  252. + for (record = (INTEL_HEX_RECORD *)firmware->data;
  253. + record->type == 0; record++) {
  254. +
  255. + err = usbxchange_writememory(dev, le32_to_cpu(record->address),
  256. + record->data,
  257. + le32_to_cpu(record->length),
  258. + ANCHOR_LOAD_INTERNAL);
  259. + if (err < 0) {
  260. + printk(KERN_ERR
  261. + "%s - error loading firmware: error = %d\n",
  262. + __FUNCTION__, err);
  263. + return err;
  264. + }
  265. + }
  266. +
  267. + /* De-assert reset (let the CPU run) */
  268. + err = usbxchange_set_reset(dev, cpureg, 1);
  269. + err = usbxchange_set_reset(dev, cpureg, 0);
  270. + if (err < 0) {
  271. + printk(KERN_ERR "%s - error resetting dongle CPU: error = %d\n",
  272. + __FUNCTION__, err);
  273. + return err;
  274. + }
  275. +
  276. + return 0;
  277. +}
  278. +
  279. +static int usbxchange_probe(struct usb_interface *iface,
  280. + const struct usb_device_id *id)
  281. +{
  282. + struct usb_device *dev = interface_to_usbdev(iface);
  283. +
  284. + printk(KERN_INFO "%s start\n", __FUNCTION__);
  285. +
  286. + usbxchange_load_firmware(dev);
  287. +
  288. + /* forcing an unload would save some kB of kernel memory ... */
  289. + return 0;
  290. +}
  291. +
  292. +static void usbxchange_disconnect(struct usb_interface *iface)
  293. +{
  294. +}
  295. +
  296. +static struct usb_driver usbxchange_driver = {
  297. + .name = "usbxchange_fw",
  298. + .probe = usbxchange_probe,
  299. + .disconnect = usbxchange_disconnect,
  300. + .id_table = usbxchange_usb_ids,
  301. +};
  302. +
  303. +static int __init usbxchange_init(void)
  304. +{
  305. + usb_register(&usbxchange_driver);
  306. + return 0;
  307. +}
  308. +
  309. +static void __exit usbxchange_exit(void)
  310. +{
  311. + usb_deregister(&usbxchange_driver);
  312. +}
  313. +
  314. +module_init(usbxchange_init);
  315. +module_exit(usbxchange_exit);
  316. +
  317. +MODULE_AUTHOR("Ren� Rebe <rene@exactcode.de>, Sancho Dauskardt <sda@bdit.de>");
  318. +MODULE_DESCRIPTION("Adaptec USBXchange firmware loader.");
  319. +MODULE_LICENSE("GPL");
  320. +
  321. +/* vi:ai:syntax=c:sw=8:ts=8:tw=80
  322. + */
  323. --- linux-2.6.15-mm4/drivers/usb/storage/usbxchange_fw.h 1970-01-01 01:00:00.000000000 +0100
  324. +++ linux-2.6.15-usb2x/drivers/usb/storage/usbxchange_fw.h 2006-01-27 17:18:18.246377000 +0100
  325. @@ -0,0 +1,45 @@
  326. +/*
  327. + * Firmware loader for Adaptec USBXchange / USB2Xchange.
  328. + *
  329. + * Uploads device firmware into the Adaptec USBXchange and USB2Xchange
  330. + * USB --> SCSI dongle.
  331. + *
  332. + * Current development and maintenance by:
  333. + * (c) 2005 Ren� Rebe <rene@exactcode.de>
  334. + *
  335. + * Initial work by:
  336. + * (c) 2004 Beier & Dauskardt IT <sda@bdit.de>
  337. + *
  338. + * Based on emi26.c:
  339. + * (c) 2002 Tapio Laxstr�m <tapio.laxstrom@iptime.fi>
  340. + *
  341. + * This program is distributed in the hope that it will be useful, but
  342. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  343. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  344. + * General Public License for more details.
  345. + *
  346. + * This program is free software; you can redistribute it and/or modify
  347. + * it under the terms of the GNU General Public License, as published by
  348. + * the Free Software Foundation, version 2.
  349. + */
  350. +
  351. +#ifndef _USB_USBXCHANGE_FW_H_INCLUDED
  352. +#define _USB_USBXCHANGE_FW_H_INCLUDED
  353. +
  354. +#define MAX_INTEL_HEX_RECORD_LENGTH 16
  355. +typedef struct _INTEL_HEX_RECORD {
  356. + __u32 length;
  357. + __u32 address;
  358. + __u32 type;
  359. + __u8 data[MAX_INTEL_HEX_RECORD_LENGTH];
  360. +} INTEL_HEX_RECORD, *PINTEL_HEX_RECORD;
  361. +
  362. +/* Vendor specific request code for Anchor Upload/Download
  363. + (This one is implemented in the core). */
  364. +#define ANCHOR_LOAD_INTERNAL 0xA0
  365. +
  366. +/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
  367. +#define CPUCS_REG 0x7F92 /* original / FX */
  368. +#define CPUCS_REG_FX2 0xE600 /* FX2 */
  369. +
  370. +#endif
  371. --- linux-2.6.15/drivers/usb/storage/transport.c 2006-01-03 04:21:10.000000000 +0100
  372. +++ ./drivers/usb/storage/transport.c 2006-01-30 19:41:26.727402000 +0100
  373. @@ -984,6 +984,11 @@
  374. bcb->Lun = srb->device->lun;
  375. if (us->flags & US_FL_SCM_MULT_TARG)
  376. bcb->Lun |= srb->device->id << 4;
  377. + /* Adaptec USB2Xchange */
  378. + if (us->pusb_dev->descriptor.idVendor == 0x03f3 &&
  379. + us->pusb_dev->descriptor.idProduct == 0x2003)
  380. + bcb->Lun = srb->device->id;
  381. +
  382. bcb->Length = srb->cmd_len;
  383. /* copy the command payload */
  384. @@ -1069,6 +1074,20 @@
  385. US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
  386. le32_to_cpu(bcs->Signature), bcs->Tag,
  387. residue, bcs->Status);
  388. + if (bcs->Status > US_BULK_STAT_FAIL) {
  389. + /* Adaptec USB2XCHANGE ? */
  390. + if (us->pusb_dev->descriptor.idVendor == 0x03f3 &&
  391. + us->pusb_dev->descriptor.idProduct == 0x2003) {
  392. +
  393. + /* This device will send
  394. + * bcs->Status == 0x8a for unused LUN's
  395. + * bcs->Status == 0x02 for SRB's that require SENSE.
  396. + */
  397. + bcs->Status = US_BULK_STAT_OK;
  398. + fake_sense = 1;
  399. + US_DEBUGP("Patched Bulk status to %d.\n", bcs->Status);
  400. + }
  401. + }
  402. if (bcs->Tag != us->tag || bcs->Status > US_BULK_STAT_PHASE) {
  403. US_DEBUGP("Bulk logical error\n");
  404. return USB_STOR_TRANSPORT_ERROR;