cxacru.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /******************************************************************************
  2. * cxacru.c - driver for USB ADSL modems based on
  3. * Conexant AccessRunner chipset
  4. *
  5. * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
  6. * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
  7. * Copyright (C) 2007 Simon Arlott
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. ******************************************************************************/
  24. /*
  25. * Credit is due for Josep Comas, who created the original patch to speedtch.c
  26. * to support the different padding used by the AccessRunner (now generalized
  27. * into usbatm), and the userspace firmware loading utility.
  28. */
  29. #include <linux/module.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/kernel.h>
  32. #include <linux/timer.h>
  33. #include <linux/errno.h>
  34. #include <linux/slab.h>
  35. #include <linux/init.h>
  36. #include <linux/device.h>
  37. #include <linux/firmware.h>
  38. #include <linux/mutex.h>
  39. #include <asm/unaligned.h>
  40. #include "usbatm.h"
  41. #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
  42. #define DRIVER_VERSION "0.3"
  43. #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
  44. static const char cxacru_driver_name[] = "cxacru";
  45. #define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
  46. #define CXACRU_EP_DATA 0x02 /* Bulk in/out */
  47. #define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
  48. /* Addresses */
  49. #define PLLFCLK_ADDR 0x00350068
  50. #define PLLBCLK_ADDR 0x0035006c
  51. #define SDRAMEN_ADDR 0x00350010
  52. #define FW_ADDR 0x00801000
  53. #define BR_ADDR 0x00180600
  54. #define SIG_ADDR 0x00180500
  55. #define BR_STACK_ADDR 0x00187f10
  56. /* Values */
  57. #define SDRAM_ENA 0x1
  58. #define CMD_TIMEOUT 2000 /* msecs */
  59. #define POLL_INTERVAL 1 /* secs */
  60. /* commands for interaction with the modem through the control channel before
  61. * firmware is loaded */
  62. enum cxacru_fw_request {
  63. FW_CMD_ERR,
  64. FW_GET_VER,
  65. FW_READ_MEM,
  66. FW_WRITE_MEM,
  67. FW_RMW_MEM,
  68. FW_CHECKSUM_MEM,
  69. FW_GOTO_MEM,
  70. };
  71. /* commands for interaction with the modem through the control channel once
  72. * firmware is loaded */
  73. enum cxacru_cm_request {
  74. CM_REQUEST_UNDEFINED = 0x80,
  75. CM_REQUEST_TEST,
  76. CM_REQUEST_CHIP_GET_MAC_ADDRESS,
  77. CM_REQUEST_CHIP_GET_DP_VERSIONS,
  78. CM_REQUEST_CHIP_ADSL_LINE_START,
  79. CM_REQUEST_CHIP_ADSL_LINE_STOP,
  80. CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
  81. CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
  82. CM_REQUEST_CARD_INFO_GET,
  83. CM_REQUEST_CARD_DATA_GET,
  84. CM_REQUEST_CARD_DATA_SET,
  85. CM_REQUEST_COMMAND_HW_IO,
  86. CM_REQUEST_INTERFACE_HW_IO,
  87. CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
  88. CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
  89. CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
  90. CM_REQUEST_CARD_GET_STATUS,
  91. CM_REQUEST_CARD_GET_MAC_ADDRESS,
  92. CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
  93. CM_REQUEST_MAX,
  94. };
  95. /* reply codes to the commands above */
  96. enum cxacru_cm_status {
  97. CM_STATUS_UNDEFINED,
  98. CM_STATUS_SUCCESS,
  99. CM_STATUS_ERROR,
  100. CM_STATUS_UNSUPPORTED,
  101. CM_STATUS_UNIMPLEMENTED,
  102. CM_STATUS_PARAMETER_ERROR,
  103. CM_STATUS_DBG_LOOPBACK,
  104. CM_STATUS_MAX,
  105. };
  106. /* indices into CARD_INFO_GET return array */
  107. enum cxacru_info_idx {
  108. CXINF_DOWNSTREAM_RATE,
  109. CXINF_UPSTREAM_RATE,
  110. CXINF_LINK_STATUS,
  111. CXINF_LINE_STATUS,
  112. CXINF_MAC_ADDRESS_HIGH,
  113. CXINF_MAC_ADDRESS_LOW,
  114. CXINF_UPSTREAM_SNR_MARGIN,
  115. CXINF_DOWNSTREAM_SNR_MARGIN,
  116. CXINF_UPSTREAM_ATTENUATION,
  117. CXINF_DOWNSTREAM_ATTENUATION,
  118. CXINF_TRANSMITTER_POWER,
  119. CXINF_UPSTREAM_BITS_PER_FRAME,
  120. CXINF_DOWNSTREAM_BITS_PER_FRAME,
  121. CXINF_STARTUP_ATTEMPTS,
  122. CXINF_UPSTREAM_CRC_ERRORS,
  123. CXINF_DOWNSTREAM_CRC_ERRORS,
  124. CXINF_UPSTREAM_FEC_ERRORS,
  125. CXINF_DOWNSTREAM_FEC_ERRORS,
  126. CXINF_UPSTREAM_HEC_ERRORS,
  127. CXINF_DOWNSTREAM_HEC_ERRORS,
  128. CXINF_LINE_STARTABLE,
  129. CXINF_MODULATION,
  130. CXINF_ADSL_HEADEND,
  131. CXINF_ADSL_HEADEND_ENVIRONMENT,
  132. CXINF_CONTROLLER_VERSION,
  133. /* dunno what the missing two mean */
  134. CXINF_MAX = 0x1c,
  135. };
  136. enum cxacru_poll_state {
  137. CXPOLL_STOPPING,
  138. CXPOLL_STOPPED,
  139. CXPOLL_POLLING,
  140. CXPOLL_SHUTDOWN
  141. };
  142. struct cxacru_modem_type {
  143. u32 pll_f_clk;
  144. u32 pll_b_clk;
  145. int boot_rom_patch;
  146. };
  147. struct cxacru_data {
  148. struct usbatm_data *usbatm;
  149. const struct cxacru_modem_type *modem_type;
  150. int line_status;
  151. struct mutex adsl_state_serialize;
  152. int adsl_status;
  153. struct delayed_work poll_work;
  154. u32 card_info[CXINF_MAX];
  155. struct mutex poll_state_serialize;
  156. enum cxacru_poll_state poll_state;
  157. /* contol handles */
  158. struct mutex cm_serialize;
  159. u8 *rcv_buf;
  160. u8 *snd_buf;
  161. struct urb *rcv_urb;
  162. struct urb *snd_urb;
  163. struct completion rcv_done;
  164. struct completion snd_done;
  165. };
  166. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  167. u8 *wdata, int wsize, u8 *rdata, int rsize);
  168. static void cxacru_poll_status(struct work_struct *work);
  169. /* Card info exported through sysfs */
  170. #define CXACRU__ATTR_INIT(_name) \
  171. static DEVICE_ATTR(_name, S_IRUGO, cxacru_sysfs_show_##_name, NULL)
  172. #define CXACRU_CMD_INIT(_name) \
  173. static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \
  174. cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name)
  175. #define CXACRU_ATTR_INIT(_value, _type, _name) \
  176. static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \
  177. struct device_attribute *attr, char *buf) \
  178. { \
  179. struct usb_interface *intf = to_usb_interface(dev); \
  180. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); \
  181. struct cxacru_data *instance = usbatm_instance->driver_data; \
  182. return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \
  183. } \
  184. CXACRU__ATTR_INIT(_name)
  185. #define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name)
  186. #define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
  187. #define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
  188. #define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name)
  189. #define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
  190. #define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
  191. static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
  192. {
  193. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  194. }
  195. static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
  196. {
  197. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  198. }
  199. static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
  200. {
  201. return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
  202. value / 100, abs(value) % 100);
  203. }
  204. static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
  205. {
  206. static char *str[] = { "no", "yes" };
  207. if (unlikely(value >= ARRAY_SIZE(str)))
  208. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  209. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  210. }
  211. static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
  212. {
  213. static char *str[] = { NULL, "not connected", "connected", "lost" };
  214. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  215. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  216. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  217. }
  218. static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
  219. {
  220. static char *str[] = { "down", "attempting to activate",
  221. "training", "channel analysis", "exchange", "up",
  222. "waiting", "initialising"
  223. };
  224. if (unlikely(value >= ARRAY_SIZE(str)))
  225. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  226. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  227. }
  228. static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
  229. {
  230. static char *str[] = {
  231. NULL,
  232. "ANSI T1.413",
  233. "ITU-T G.992.1 (G.DMT)",
  234. "ITU-T G.992.2 (G.LITE)"
  235. };
  236. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  237. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  238. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  239. }
  240. /*
  241. * This could use MAC_ADDRESS_HIGH and MAC_ADDRESS_LOW, but since
  242. * this data is already in atm_dev there's no point.
  243. *
  244. * MAC_ADDRESS_HIGH = 0x????5544
  245. * MAC_ADDRESS_LOW = 0x33221100
  246. * Where 00-55 are bytes 0-5 of the MAC.
  247. */
  248. static ssize_t cxacru_sysfs_show_mac_address(struct device *dev,
  249. struct device_attribute *attr, char *buf)
  250. {
  251. struct usb_interface *intf = to_usb_interface(dev);
  252. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  253. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  254. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  255. atm_dev->esi[0], atm_dev->esi[1], atm_dev->esi[2],
  256. atm_dev->esi[3], atm_dev->esi[4], atm_dev->esi[5]);
  257. }
  258. static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
  259. struct device_attribute *attr, char *buf)
  260. {
  261. struct usb_interface *intf = to_usb_interface(dev);
  262. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  263. struct cxacru_data *instance = usbatm_instance->driver_data;
  264. u32 value = instance->card_info[CXINF_LINE_STARTABLE];
  265. static char *str[] = { "running", "stopped" };
  266. if (unlikely(value >= ARRAY_SIZE(str)))
  267. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  268. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  269. }
  270. static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
  271. struct device_attribute *attr, const char *buf, size_t count)
  272. {
  273. struct usb_interface *intf = to_usb_interface(dev);
  274. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  275. struct cxacru_data *instance = usbatm_instance->driver_data;
  276. int ret;
  277. int poll = -1;
  278. char str_cmd[8];
  279. int len = strlen(buf);
  280. if (!capable(CAP_NET_ADMIN))
  281. return -EACCES;
  282. ret = sscanf(buf, "%7s", str_cmd);
  283. if (ret != 1)
  284. return -EINVAL;
  285. ret = 0;
  286. if (mutex_lock_interruptible(&instance->adsl_state_serialize))
  287. return -ERESTARTSYS;
  288. if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) {
  289. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
  290. if (ret < 0) {
  291. atm_err(usbatm_instance, "change adsl state:"
  292. " CHIP_ADSL_LINE_STOP returned %d\n", ret);
  293. ret = -EIO;
  294. } else {
  295. ret = len;
  296. poll = CXPOLL_STOPPED;
  297. }
  298. }
  299. /* Line status is only updated every second
  300. * and the device appears to only react to
  301. * START/STOP every second too. Wait 1.5s to
  302. * be sure that restart will have an effect. */
  303. if (!strcmp(str_cmd, "restart"))
  304. msleep(1500);
  305. if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) {
  306. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  307. if (ret < 0) {
  308. atm_err(usbatm_instance, "change adsl state:"
  309. " CHIP_ADSL_LINE_START returned %d\n", ret);
  310. ret = -EIO;
  311. } else {
  312. ret = len;
  313. poll = CXPOLL_POLLING;
  314. }
  315. }
  316. if (!strcmp(str_cmd, "poll")) {
  317. ret = len;
  318. poll = CXPOLL_POLLING;
  319. }
  320. if (ret == 0) {
  321. ret = -EINVAL;
  322. poll = -1;
  323. }
  324. if (poll == CXPOLL_POLLING) {
  325. mutex_lock(&instance->poll_state_serialize);
  326. switch (instance->poll_state) {
  327. case CXPOLL_STOPPED:
  328. /* start polling */
  329. instance->poll_state = CXPOLL_POLLING;
  330. break;
  331. case CXPOLL_STOPPING:
  332. /* abort stop request */
  333. instance->poll_state = CXPOLL_POLLING;
  334. case CXPOLL_POLLING:
  335. case CXPOLL_SHUTDOWN:
  336. /* don't start polling */
  337. poll = -1;
  338. }
  339. mutex_unlock(&instance->poll_state_serialize);
  340. } else if (poll == CXPOLL_STOPPED) {
  341. mutex_lock(&instance->poll_state_serialize);
  342. /* request stop */
  343. if (instance->poll_state == CXPOLL_POLLING)
  344. instance->poll_state = CXPOLL_STOPPING;
  345. mutex_unlock(&instance->poll_state_serialize);
  346. }
  347. mutex_unlock(&instance->adsl_state_serialize);
  348. if (poll == CXPOLL_POLLING)
  349. cxacru_poll_status(&instance->poll_work.work);
  350. return ret;
  351. }
  352. /*
  353. * All device attributes are included in CXACRU_ALL_FILES
  354. * so that the same list can be used multiple times:
  355. * INIT (define the device attributes)
  356. * CREATE (create all the device files)
  357. * REMOVE (remove all the device files)
  358. *
  359. * With the last two being defined as needed in the functions
  360. * they are used in before calling CXACRU_ALL_FILES()
  361. */
  362. #define CXACRU_ALL_FILES(_action) \
  363. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE, u32, downstream_rate); \
  364. CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE, u32, upstream_rate); \
  365. CXACRU_ATTR_##_action(CXINF_LINK_STATUS, LINK, link_status); \
  366. CXACRU_ATTR_##_action(CXINF_LINE_STATUS, LINE, line_status); \
  367. CXACRU__ATTR_##_action( mac_address); \
  368. CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN, dB, upstream_snr_margin); \
  369. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN, dB, downstream_snr_margin); \
  370. CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION, dB, upstream_attenuation); \
  371. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION, dB, downstream_attenuation); \
  372. CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER, s8, transmitter_power); \
  373. CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME, u32, upstream_bits_per_frame); \
  374. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32, downstream_bits_per_frame); \
  375. CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS, u32, startup_attempts); \
  376. CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS, u32, upstream_crc_errors); \
  377. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS, u32, downstream_crc_errors); \
  378. CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS, u32, upstream_fec_errors); \
  379. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS, u32, downstream_fec_errors); \
  380. CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS, u32, upstream_hec_errors); \
  381. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS, u32, downstream_hec_errors); \
  382. CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE, bool, line_startable); \
  383. CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \
  384. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \
  385. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \
  386. CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \
  387. CXACRU_CMD_##_action( adsl_state);
  388. CXACRU_ALL_FILES(INIT);
  389. /* the following three functions are stolen from drivers/usb/core/message.c */
  390. static void cxacru_blocking_completion(struct urb *urb)
  391. {
  392. complete(urb->context);
  393. }
  394. static void cxacru_timeout_kill(unsigned long data)
  395. {
  396. usb_unlink_urb((struct urb *) data);
  397. }
  398. static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
  399. int* actual_length)
  400. {
  401. struct timer_list timer;
  402. init_timer(&timer);
  403. timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
  404. timer.data = (unsigned long) urb;
  405. timer.function = cxacru_timeout_kill;
  406. add_timer(&timer);
  407. wait_for_completion(done);
  408. del_timer_sync(&timer);
  409. if (actual_length)
  410. *actual_length = urb->actual_length;
  411. return urb->status; /* must read status after completion */
  412. }
  413. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  414. u8 *wdata, int wsize, u8 *rdata, int rsize)
  415. {
  416. int ret, actlen;
  417. int offb, offd;
  418. const int stride = CMD_PACKET_SIZE - 4;
  419. u8 *wbuf = instance->snd_buf;
  420. u8 *rbuf = instance->rcv_buf;
  421. int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  422. int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  423. if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
  424. if (printk_ratelimit())
  425. usb_err(instance->usbatm, "requested transfer size too large (%d, %d)\n",
  426. wbuflen, rbuflen);
  427. ret = -ENOMEM;
  428. goto fail;
  429. }
  430. mutex_lock(&instance->cm_serialize);
  431. /* submit reading urb before the writing one */
  432. init_completion(&instance->rcv_done);
  433. ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
  434. if (ret < 0) {
  435. if (printk_ratelimit())
  436. usb_err(instance->usbatm, "submit of read urb for cm %#x failed (%d)\n",
  437. cm, ret);
  438. goto fail;
  439. }
  440. memset(wbuf, 0, wbuflen);
  441. /* handle wsize == 0 */
  442. wbuf[0] = cm;
  443. for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
  444. wbuf[offb] = cm;
  445. memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
  446. }
  447. instance->snd_urb->transfer_buffer_length = wbuflen;
  448. init_completion(&instance->snd_done);
  449. ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
  450. if (ret < 0) {
  451. if (printk_ratelimit())
  452. usb_err(instance->usbatm, "submit of write urb for cm %#x failed (%d)\n",
  453. cm, ret);
  454. goto fail;
  455. }
  456. ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
  457. if (ret < 0) {
  458. if (printk_ratelimit())
  459. usb_err(instance->usbatm, "send of cm %#x failed (%d)\n", cm, ret);
  460. goto fail;
  461. }
  462. ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
  463. if (ret < 0) {
  464. if (printk_ratelimit())
  465. usb_err(instance->usbatm, "receive of cm %#x failed (%d)\n", cm, ret);
  466. goto fail;
  467. }
  468. if (actlen % CMD_PACKET_SIZE || !actlen) {
  469. if (printk_ratelimit())
  470. usb_err(instance->usbatm, "invalid response length to cm %#x: %d\n",
  471. cm, actlen);
  472. ret = -EIO;
  473. goto fail;
  474. }
  475. /* check the return status and copy the data to the output buffer, if needed */
  476. for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
  477. if (rbuf[offb] != cm) {
  478. if (printk_ratelimit())
  479. usb_err(instance->usbatm, "wrong cm %#x in response to cm %#x\n",
  480. rbuf[offb], cm);
  481. ret = -EIO;
  482. goto fail;
  483. }
  484. if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
  485. if (printk_ratelimit())
  486. usb_err(instance->usbatm, "response to cm %#x failed: %#x\n",
  487. cm, rbuf[offb + 1]);
  488. ret = -EIO;
  489. goto fail;
  490. }
  491. if (offd >= rsize)
  492. break;
  493. memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
  494. offd += stride;
  495. }
  496. ret = offd;
  497. dbg("cm %#x", cm);
  498. fail:
  499. mutex_unlock(&instance->cm_serialize);
  500. return ret;
  501. }
  502. static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
  503. u32 *data, int size)
  504. {
  505. int ret, len;
  506. __le32 *buf;
  507. int offb, offd;
  508. const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
  509. int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
  510. buf = kmalloc(buflen, GFP_KERNEL);
  511. if (!buf)
  512. return -ENOMEM;
  513. ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
  514. if (ret < 0)
  515. goto cleanup;
  516. /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
  517. len = ret / 4;
  518. for (offb = 0; offb < len; ) {
  519. int l = le32_to_cpu(buf[offb++]);
  520. if (l > stride || l > (len - offb) / 2) {
  521. if (printk_ratelimit())
  522. usb_err(instance->usbatm, "invalid data length from cm %#x: %d\n",
  523. cm, l);
  524. ret = -EIO;
  525. goto cleanup;
  526. }
  527. while (l--) {
  528. offd = le32_to_cpu(buf[offb++]);
  529. if (offd >= size) {
  530. if (printk_ratelimit())
  531. usb_err(instance->usbatm, "wrong index %#x in response to cm %#x\n",
  532. offd, cm);
  533. ret = -EIO;
  534. goto cleanup;
  535. }
  536. data[offd] = le32_to_cpu(buf[offb++]);
  537. }
  538. }
  539. ret = 0;
  540. cleanup:
  541. kfree(buf);
  542. return ret;
  543. }
  544. static int cxacru_card_status(struct cxacru_data *instance)
  545. {
  546. int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  547. if (ret < 0) { /* firmware not loaded */
  548. dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
  549. return ret;
  550. }
  551. return 0;
  552. }
  553. static void cxacru_remove_device_files(struct usbatm_data *usbatm_instance,
  554. struct atm_dev *atm_dev)
  555. {
  556. struct usb_interface *intf = usbatm_instance->usb_intf;
  557. #define CXACRU_DEVICE_REMOVE_FILE(_name) \
  558. device_remove_file(&intf->dev, &dev_attr_##_name);
  559. CXACRU_ALL_FILES(REMOVE);
  560. #undef CXACRU_DEVICE_REMOVE_FILE
  561. }
  562. static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
  563. struct atm_dev *atm_dev)
  564. {
  565. struct cxacru_data *instance = usbatm_instance->driver_data;
  566. struct usb_interface *intf = usbatm_instance->usb_intf;
  567. /*
  568. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  569. */
  570. int ret;
  571. int start_polling = 1;
  572. dbg("cxacru_atm_start");
  573. /* Read MAC address */
  574. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
  575. atm_dev->esi, sizeof(atm_dev->esi));
  576. if (ret < 0) {
  577. atm_err(usbatm_instance, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
  578. return ret;
  579. }
  580. #define CXACRU_DEVICE_CREATE_FILE(_name) \
  581. ret = device_create_file(&intf->dev, &dev_attr_##_name); \
  582. if (unlikely(ret)) \
  583. goto fail_sysfs;
  584. CXACRU_ALL_FILES(CREATE);
  585. #undef CXACRU_DEVICE_CREATE_FILE
  586. /* start ADSL */
  587. mutex_lock(&instance->adsl_state_serialize);
  588. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  589. if (ret < 0)
  590. atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
  591. /* Start status polling */
  592. mutex_lock(&instance->poll_state_serialize);
  593. switch (instance->poll_state) {
  594. case CXPOLL_STOPPED:
  595. /* start polling */
  596. instance->poll_state = CXPOLL_POLLING;
  597. break;
  598. case CXPOLL_STOPPING:
  599. /* abort stop request */
  600. instance->poll_state = CXPOLL_POLLING;
  601. case CXPOLL_POLLING:
  602. case CXPOLL_SHUTDOWN:
  603. /* don't start polling */
  604. start_polling = 0;
  605. }
  606. mutex_unlock(&instance->poll_state_serialize);
  607. mutex_unlock(&instance->adsl_state_serialize);
  608. if (start_polling)
  609. cxacru_poll_status(&instance->poll_work.work);
  610. return 0;
  611. fail_sysfs:
  612. usb_err(usbatm_instance, "cxacru_atm_start: device_create_file failed (%d)\n", ret);
  613. cxacru_remove_device_files(usbatm_instance, atm_dev);
  614. return ret;
  615. }
  616. static void cxacru_poll_status(struct work_struct *work)
  617. {
  618. struct cxacru_data *instance =
  619. container_of(work, struct cxacru_data, poll_work.work);
  620. u32 buf[CXINF_MAX] = {};
  621. struct usbatm_data *usbatm = instance->usbatm;
  622. struct atm_dev *atm_dev = usbatm->atm_dev;
  623. int keep_polling = 1;
  624. int ret;
  625. ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
  626. if (ret < 0) {
  627. if (ret != -ESHUTDOWN)
  628. atm_warn(usbatm, "poll status: error %d\n", ret);
  629. mutex_lock(&instance->poll_state_serialize);
  630. if (instance->poll_state != CXPOLL_SHUTDOWN) {
  631. instance->poll_state = CXPOLL_STOPPED;
  632. if (ret != -ESHUTDOWN)
  633. atm_warn(usbatm, "polling disabled, set adsl_state"
  634. " to 'start' or 'poll' to resume\n");
  635. }
  636. mutex_unlock(&instance->poll_state_serialize);
  637. goto reschedule;
  638. }
  639. memcpy(instance->card_info, buf, sizeof(instance->card_info));
  640. if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) {
  641. instance->adsl_status = buf[CXINF_LINE_STARTABLE];
  642. switch (instance->adsl_status) {
  643. case 0:
  644. atm_printk(KERN_INFO, usbatm, "ADSL state: running\n");
  645. break;
  646. case 1:
  647. atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n");
  648. break;
  649. default:
  650. atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status);
  651. break;
  652. }
  653. }
  654. if (instance->line_status == buf[CXINF_LINE_STATUS])
  655. goto reschedule;
  656. instance->line_status = buf[CXINF_LINE_STATUS];
  657. switch (instance->line_status) {
  658. case 0:
  659. atm_dev->signal = ATM_PHY_SIG_LOST;
  660. atm_info(usbatm, "ADSL line: down\n");
  661. break;
  662. case 1:
  663. atm_dev->signal = ATM_PHY_SIG_LOST;
  664. atm_info(usbatm, "ADSL line: attempting to activate\n");
  665. break;
  666. case 2:
  667. atm_dev->signal = ATM_PHY_SIG_LOST;
  668. atm_info(usbatm, "ADSL line: training\n");
  669. break;
  670. case 3:
  671. atm_dev->signal = ATM_PHY_SIG_LOST;
  672. atm_info(usbatm, "ADSL line: channel analysis\n");
  673. break;
  674. case 4:
  675. atm_dev->signal = ATM_PHY_SIG_LOST;
  676. atm_info(usbatm, "ADSL line: exchange\n");
  677. break;
  678. case 5:
  679. atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
  680. atm_dev->signal = ATM_PHY_SIG_FOUND;
  681. atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
  682. buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
  683. break;
  684. case 6:
  685. atm_dev->signal = ATM_PHY_SIG_LOST;
  686. atm_info(usbatm, "ADSL line: waiting\n");
  687. break;
  688. case 7:
  689. atm_dev->signal = ATM_PHY_SIG_LOST;
  690. atm_info(usbatm, "ADSL line: initializing\n");
  691. break;
  692. default:
  693. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  694. atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
  695. break;
  696. }
  697. reschedule:
  698. mutex_lock(&instance->poll_state_serialize);
  699. if (instance->poll_state == CXPOLL_STOPPING &&
  700. instance->adsl_status == 1 && /* stopped */
  701. instance->line_status == 0) /* down */
  702. instance->poll_state = CXPOLL_STOPPED;
  703. if (instance->poll_state == CXPOLL_STOPPED)
  704. keep_polling = 0;
  705. mutex_unlock(&instance->poll_state_serialize);
  706. if (keep_polling)
  707. schedule_delayed_work(&instance->poll_work,
  708. round_jiffies_relative(POLL_INTERVAL*HZ));
  709. }
  710. static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
  711. u8 code1, u8 code2, u32 addr, const u8 *data, int size)
  712. {
  713. int ret;
  714. u8 *buf;
  715. int offd, offb;
  716. const int stride = CMD_PACKET_SIZE - 8;
  717. buf = (u8 *) __get_free_page(GFP_KERNEL);
  718. if (!buf)
  719. return -ENOMEM;
  720. offb = offd = 0;
  721. do {
  722. int l = min_t(int, stride, size - offd);
  723. buf[offb++] = fw;
  724. buf[offb++] = l;
  725. buf[offb++] = code1;
  726. buf[offb++] = code2;
  727. put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb));
  728. offb += 4;
  729. addr += l;
  730. if(l)
  731. memcpy(buf + offb, data + offd, l);
  732. if (l < stride)
  733. memset(buf + offb + l, 0, stride - l);
  734. offb += stride;
  735. offd += stride;
  736. if ((offb >= PAGE_SIZE) || (offd >= size)) {
  737. ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
  738. buf, offb, NULL, CMD_TIMEOUT);
  739. if (ret < 0) {
  740. dbg("sending fw %#x failed", fw);
  741. goto cleanup;
  742. }
  743. offb = 0;
  744. }
  745. } while(offd < size);
  746. dbg("sent fw %#x", fw);
  747. ret = 0;
  748. cleanup:
  749. free_page((unsigned long) buf);
  750. return ret;
  751. }
  752. static void cxacru_upload_firmware(struct cxacru_data *instance,
  753. const struct firmware *fw,
  754. const struct firmware *bp,
  755. const struct firmware *cf)
  756. {
  757. int ret;
  758. int off;
  759. struct usbatm_data *usbatm = instance->usbatm;
  760. struct usb_device *usb_dev = usbatm->usb_dev;
  761. __le16 signature[] = { usb_dev->descriptor.idVendor,
  762. usb_dev->descriptor.idProduct };
  763. __le32 val;
  764. dbg("cxacru_upload_firmware");
  765. /* FirmwarePllFClkValue */
  766. val = cpu_to_le32(instance->modem_type->pll_f_clk);
  767. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
  768. if (ret) {
  769. usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
  770. return;
  771. }
  772. /* FirmwarePllBClkValue */
  773. val = cpu_to_le32(instance->modem_type->pll_b_clk);
  774. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
  775. if (ret) {
  776. usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
  777. return;
  778. }
  779. /* Enable SDRAM */
  780. val = cpu_to_le32(SDRAM_ENA);
  781. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
  782. if (ret) {
  783. usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
  784. return;
  785. }
  786. /* Firmware */
  787. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
  788. if (ret) {
  789. usb_err(usbatm, "Firmware upload failed: %d\n", ret);
  790. return;
  791. }
  792. /* Boot ROM patch */
  793. if (instance->modem_type->boot_rom_patch) {
  794. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
  795. if (ret) {
  796. usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
  797. return;
  798. }
  799. }
  800. /* Signature */
  801. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
  802. if (ret) {
  803. usb_err(usbatm, "Signature storing failed: %d\n", ret);
  804. return;
  805. }
  806. if (instance->modem_type->boot_rom_patch) {
  807. val = cpu_to_le32(BR_ADDR);
  808. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
  809. }
  810. else {
  811. ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
  812. }
  813. if (ret) {
  814. usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
  815. return;
  816. }
  817. /* Delay to allow firmware to start up. */
  818. msleep_interruptible(1000);
  819. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
  820. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
  821. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
  822. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
  823. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  824. if (ret < 0) {
  825. usb_err(usbatm, "modem failed to initialize: %d\n", ret);
  826. return;
  827. }
  828. /* Load config data (le32), doing one packet at a time */
  829. if (cf)
  830. for (off = 0; off < cf->size / 4; ) {
  831. __le32 buf[CMD_PACKET_SIZE / 4 - 1];
  832. int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
  833. buf[0] = cpu_to_le32(len);
  834. for (i = 0; i < len; i++, off++) {
  835. buf[i * 2 + 1] = cpu_to_le32(off);
  836. memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
  837. }
  838. ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
  839. (u8 *) buf, len, NULL, 0);
  840. if (ret < 0) {
  841. usb_err(usbatm, "load config data failed: %d\n", ret);
  842. return;
  843. }
  844. }
  845. msleep_interruptible(4000);
  846. }
  847. static int cxacru_find_firmware(struct cxacru_data *instance,
  848. char* phase, const struct firmware **fw_p)
  849. {
  850. struct usbatm_data *usbatm = instance->usbatm;
  851. struct device *dev = &usbatm->usb_intf->dev;
  852. char buf[16];
  853. sprintf(buf, "cxacru-%s.bin", phase);
  854. dbg("cxacru_find_firmware: looking for %s", buf);
  855. if (request_firmware(fw_p, buf, dev)) {
  856. usb_dbg(usbatm, "no stage %s firmware found\n", phase);
  857. return -ENOENT;
  858. }
  859. usb_info(usbatm, "found firmware %s\n", buf);
  860. return 0;
  861. }
  862. static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
  863. struct usb_interface *usb_intf)
  864. {
  865. const struct firmware *fw, *bp, *cf;
  866. struct cxacru_data *instance = usbatm_instance->driver_data;
  867. int ret = cxacru_find_firmware(instance, "fw", &fw);
  868. if (ret) {
  869. usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
  870. return ret;
  871. }
  872. if (instance->modem_type->boot_rom_patch) {
  873. ret = cxacru_find_firmware(instance, "bp", &bp);
  874. if (ret) {
  875. usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
  876. release_firmware(fw);
  877. return ret;
  878. }
  879. }
  880. if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
  881. cf = NULL;
  882. cxacru_upload_firmware(instance, fw, bp, cf);
  883. if (cf)
  884. release_firmware(cf);
  885. if (instance->modem_type->boot_rom_patch)
  886. release_firmware(bp);
  887. release_firmware(fw);
  888. ret = cxacru_card_status(instance);
  889. if (ret)
  890. dbg("modem initialisation failed");
  891. else
  892. dbg("done setting up the modem");
  893. return ret;
  894. }
  895. static int cxacru_bind(struct usbatm_data *usbatm_instance,
  896. struct usb_interface *intf, const struct usb_device_id *id)
  897. {
  898. struct cxacru_data *instance;
  899. struct usb_device *usb_dev = interface_to_usbdev(intf);
  900. int ret;
  901. /* instance init */
  902. instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  903. if (!instance) {
  904. dbg("cxacru_bind: no memory for instance data");
  905. return -ENOMEM;
  906. }
  907. instance->usbatm = usbatm_instance;
  908. instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
  909. mutex_init(&instance->poll_state_serialize);
  910. instance->poll_state = CXPOLL_STOPPED;
  911. instance->line_status = -1;
  912. instance->adsl_status = -1;
  913. mutex_init(&instance->adsl_state_serialize);
  914. instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
  915. if (!instance->rcv_buf) {
  916. dbg("cxacru_bind: no memory for rcv_buf");
  917. ret = -ENOMEM;
  918. goto fail;
  919. }
  920. instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
  921. if (!instance->snd_buf) {
  922. dbg("cxacru_bind: no memory for snd_buf");
  923. ret = -ENOMEM;
  924. goto fail;
  925. }
  926. instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
  927. if (!instance->rcv_urb) {
  928. dbg("cxacru_bind: no memory for rcv_urb");
  929. ret = -ENOMEM;
  930. goto fail;
  931. }
  932. instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
  933. if (!instance->snd_urb) {
  934. dbg("cxacru_bind: no memory for snd_urb");
  935. ret = -ENOMEM;
  936. goto fail;
  937. }
  938. usb_fill_int_urb(instance->rcv_urb,
  939. usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
  940. instance->rcv_buf, PAGE_SIZE,
  941. cxacru_blocking_completion, &instance->rcv_done, 1);
  942. usb_fill_int_urb(instance->snd_urb,
  943. usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
  944. instance->snd_buf, PAGE_SIZE,
  945. cxacru_blocking_completion, &instance->snd_done, 4);
  946. mutex_init(&instance->cm_serialize);
  947. INIT_DELAYED_WORK(&instance->poll_work, cxacru_poll_status);
  948. usbatm_instance->driver_data = instance;
  949. usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
  950. return 0;
  951. fail:
  952. free_page((unsigned long) instance->snd_buf);
  953. free_page((unsigned long) instance->rcv_buf);
  954. usb_free_urb(instance->snd_urb);
  955. usb_free_urb(instance->rcv_urb);
  956. kfree(instance);
  957. return ret;
  958. }
  959. static void cxacru_unbind(struct usbatm_data *usbatm_instance,
  960. struct usb_interface *intf)
  961. {
  962. struct cxacru_data *instance = usbatm_instance->driver_data;
  963. int is_polling = 1;
  964. dbg("cxacru_unbind entered");
  965. if (!instance) {
  966. dbg("cxacru_unbind: NULL instance!");
  967. return;
  968. }
  969. mutex_lock(&instance->poll_state_serialize);
  970. BUG_ON(instance->poll_state == CXPOLL_SHUTDOWN);
  971. /* ensure that status polling continues unless
  972. * it has already stopped */
  973. if (instance->poll_state == CXPOLL_STOPPED)
  974. is_polling = 0;
  975. /* stop polling from being stopped or started */
  976. instance->poll_state = CXPOLL_SHUTDOWN;
  977. mutex_unlock(&instance->poll_state_serialize);
  978. if (is_polling)
  979. cancel_rearming_delayed_work(&instance->poll_work);
  980. usb_kill_urb(instance->snd_urb);
  981. usb_kill_urb(instance->rcv_urb);
  982. usb_free_urb(instance->snd_urb);
  983. usb_free_urb(instance->rcv_urb);
  984. free_page((unsigned long) instance->snd_buf);
  985. free_page((unsigned long) instance->rcv_buf);
  986. kfree(instance);
  987. usbatm_instance->driver_data = NULL;
  988. }
  989. static const struct cxacru_modem_type cxacru_cafe = {
  990. .pll_f_clk = 0x02d874df,
  991. .pll_b_clk = 0x0196a51a,
  992. .boot_rom_patch = 1,
  993. };
  994. static const struct cxacru_modem_type cxacru_cb00 = {
  995. .pll_f_clk = 0x5,
  996. .pll_b_clk = 0x3,
  997. .boot_rom_patch = 0,
  998. };
  999. static const struct usb_device_id cxacru_usb_ids[] = {
  1000. { /* V = Conexant P = ADSL modem (Euphrates project) */
  1001. USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
  1002. },
  1003. { /* V = Conexant P = ADSL modem (Hasbani project) */
  1004. USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
  1005. },
  1006. { /* V = Conexant P = ADSL modem */
  1007. USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  1008. },
  1009. { /* V = Conexant P = ADSL modem (Well PTI-800) */
  1010. USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
  1011. },
  1012. { /* V = Conexant P = ADSL modem */
  1013. USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
  1014. },
  1015. { /* V = Conexant P = ADSL modem (ZTE ZXDSL 852) */
  1016. USB_DEVICE(0x0572, 0xcb07), .driver_info = (unsigned long) &cxacru_cb00
  1017. },
  1018. { /* V = Olitec P = ADSL modem version 2 */
  1019. USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
  1020. },
  1021. { /* V = Olitec P = ADSL modem version 3 */
  1022. USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
  1023. },
  1024. { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
  1025. USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
  1026. },
  1027. { /* V = Zoom P = 5510 */
  1028. USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
  1029. },
  1030. { /* V = Draytek P = Vigor 318 */
  1031. USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
  1032. },
  1033. { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
  1034. USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
  1035. },
  1036. { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
  1037. USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
  1038. },
  1039. { /* V = Aethra P = Starmodem UM1020 */
  1040. USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
  1041. },
  1042. { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
  1043. USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
  1044. },
  1045. { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
  1046. USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  1047. },
  1048. { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
  1049. USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
  1050. },
  1051. {}
  1052. };
  1053. MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
  1054. static struct usbatm_driver cxacru_driver = {
  1055. .driver_name = cxacru_driver_name,
  1056. .bind = cxacru_bind,
  1057. .heavy_init = cxacru_heavy_init,
  1058. .unbind = cxacru_unbind,
  1059. .atm_start = cxacru_atm_start,
  1060. .atm_stop = cxacru_remove_device_files,
  1061. .bulk_in = CXACRU_EP_DATA,
  1062. .bulk_out = CXACRU_EP_DATA,
  1063. .rx_padding = 3,
  1064. .tx_padding = 11,
  1065. };
  1066. static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1067. {
  1068. return usbatm_usb_probe(intf, id, &cxacru_driver);
  1069. }
  1070. static struct usb_driver cxacru_usb_driver = {
  1071. .name = cxacru_driver_name,
  1072. .probe = cxacru_usb_probe,
  1073. .disconnect = usbatm_usb_disconnect,
  1074. .id_table = cxacru_usb_ids
  1075. };
  1076. static int __init cxacru_init(void)
  1077. {
  1078. return usb_register(&cxacru_usb_driver);
  1079. }
  1080. static void __exit cxacru_cleanup(void)
  1081. {
  1082. usb_deregister(&cxacru_usb_driver);
  1083. }
  1084. module_init(cxacru_init);
  1085. module_exit(cxacru_cleanup);
  1086. MODULE_AUTHOR(DRIVER_AUTHOR);
  1087. MODULE_DESCRIPTION(DRIVER_DESC);
  1088. MODULE_LICENSE("GPL");
  1089. MODULE_VERSION(DRIVER_VERSION);