cxacru.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. if (likely(value >= 0)) {
  202. return snprintf(buf, PAGE_SIZE, "%u.%02u\n",
  203. value / 100, value % 100);
  204. } else {
  205. value = -value;
  206. return snprintf(buf, PAGE_SIZE, "-%u.%02u\n",
  207. value / 100, value % 100);
  208. }
  209. }
  210. static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
  211. {
  212. static char *str[] = { "no", "yes" };
  213. if (unlikely(value >= ARRAY_SIZE(str)))
  214. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  215. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  216. }
  217. static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
  218. {
  219. static char *str[] = { NULL, "not connected", "connected", "lost" };
  220. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  221. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  222. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  223. }
  224. static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
  225. {
  226. static char *str[] = { "down", "attempting to activate",
  227. "training", "channel analysis", "exchange", "up",
  228. "waiting", "initialising"
  229. };
  230. if (unlikely(value >= ARRAY_SIZE(str)))
  231. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  232. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  233. }
  234. static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
  235. {
  236. static char *str[] = {
  237. NULL,
  238. "ANSI T1.413",
  239. "ITU-T G.992.1 (G.DMT)",
  240. "ITU-T G.992.2 (G.LITE)"
  241. };
  242. if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  243. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  244. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  245. }
  246. /*
  247. * This could use MAC_ADDRESS_HIGH and MAC_ADDRESS_LOW, but since
  248. * this data is already in atm_dev there's no point.
  249. *
  250. * MAC_ADDRESS_HIGH = 0x????5544
  251. * MAC_ADDRESS_LOW = 0x33221100
  252. * Where 00-55 are bytes 0-5 of the MAC.
  253. */
  254. static ssize_t cxacru_sysfs_show_mac_address(struct device *dev,
  255. struct device_attribute *attr, char *buf)
  256. {
  257. struct usb_interface *intf = to_usb_interface(dev);
  258. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  259. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  260. return snprintf(buf, PAGE_SIZE, "%pM\n", atm_dev->esi);
  261. }
  262. static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
  263. struct device_attribute *attr, char *buf)
  264. {
  265. struct usb_interface *intf = to_usb_interface(dev);
  266. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  267. struct cxacru_data *instance = usbatm_instance->driver_data;
  268. u32 value = instance->card_info[CXINF_LINE_STARTABLE];
  269. static char *str[] = { "running", "stopped" };
  270. if (unlikely(value >= ARRAY_SIZE(str)))
  271. return snprintf(buf, PAGE_SIZE, "%u\n", value);
  272. return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
  273. }
  274. static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
  275. struct device_attribute *attr, const char *buf, size_t count)
  276. {
  277. struct usb_interface *intf = to_usb_interface(dev);
  278. struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
  279. struct cxacru_data *instance = usbatm_instance->driver_data;
  280. int ret;
  281. int poll = -1;
  282. char str_cmd[8];
  283. int len = strlen(buf);
  284. if (!capable(CAP_NET_ADMIN))
  285. return -EACCES;
  286. ret = sscanf(buf, "%7s", str_cmd);
  287. if (ret != 1)
  288. return -EINVAL;
  289. ret = 0;
  290. if (mutex_lock_interruptible(&instance->adsl_state_serialize))
  291. return -ERESTARTSYS;
  292. if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) {
  293. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
  294. if (ret < 0) {
  295. atm_err(usbatm_instance, "change adsl state:"
  296. " CHIP_ADSL_LINE_STOP returned %d\n", ret);
  297. ret = -EIO;
  298. } else {
  299. ret = len;
  300. poll = CXPOLL_STOPPED;
  301. }
  302. }
  303. /* Line status is only updated every second
  304. * and the device appears to only react to
  305. * START/STOP every second too. Wait 1.5s to
  306. * be sure that restart will have an effect. */
  307. if (!strcmp(str_cmd, "restart"))
  308. msleep(1500);
  309. if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) {
  310. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  311. if (ret < 0) {
  312. atm_err(usbatm_instance, "change adsl state:"
  313. " CHIP_ADSL_LINE_START returned %d\n", ret);
  314. ret = -EIO;
  315. } else {
  316. ret = len;
  317. poll = CXPOLL_POLLING;
  318. }
  319. }
  320. if (!strcmp(str_cmd, "poll")) {
  321. ret = len;
  322. poll = CXPOLL_POLLING;
  323. }
  324. if (ret == 0) {
  325. ret = -EINVAL;
  326. poll = -1;
  327. }
  328. if (poll == CXPOLL_POLLING) {
  329. mutex_lock(&instance->poll_state_serialize);
  330. switch (instance->poll_state) {
  331. case CXPOLL_STOPPED:
  332. /* start polling */
  333. instance->poll_state = CXPOLL_POLLING;
  334. break;
  335. case CXPOLL_STOPPING:
  336. /* abort stop request */
  337. instance->poll_state = CXPOLL_POLLING;
  338. case CXPOLL_POLLING:
  339. case CXPOLL_SHUTDOWN:
  340. /* don't start polling */
  341. poll = -1;
  342. }
  343. mutex_unlock(&instance->poll_state_serialize);
  344. } else if (poll == CXPOLL_STOPPED) {
  345. mutex_lock(&instance->poll_state_serialize);
  346. /* request stop */
  347. if (instance->poll_state == CXPOLL_POLLING)
  348. instance->poll_state = CXPOLL_STOPPING;
  349. mutex_unlock(&instance->poll_state_serialize);
  350. }
  351. mutex_unlock(&instance->adsl_state_serialize);
  352. if (poll == CXPOLL_POLLING)
  353. cxacru_poll_status(&instance->poll_work.work);
  354. return ret;
  355. }
  356. /*
  357. * All device attributes are included in CXACRU_ALL_FILES
  358. * so that the same list can be used multiple times:
  359. * INIT (define the device attributes)
  360. * CREATE (create all the device files)
  361. * REMOVE (remove all the device files)
  362. *
  363. * With the last two being defined as needed in the functions
  364. * they are used in before calling CXACRU_ALL_FILES()
  365. */
  366. #define CXACRU_ALL_FILES(_action) \
  367. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE, u32, downstream_rate); \
  368. CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE, u32, upstream_rate); \
  369. CXACRU_ATTR_##_action(CXINF_LINK_STATUS, LINK, link_status); \
  370. CXACRU_ATTR_##_action(CXINF_LINE_STATUS, LINE, line_status); \
  371. CXACRU__ATTR_##_action( mac_address); \
  372. CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN, dB, upstream_snr_margin); \
  373. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN, dB, downstream_snr_margin); \
  374. CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION, dB, upstream_attenuation); \
  375. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION, dB, downstream_attenuation); \
  376. CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER, s8, transmitter_power); \
  377. CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME, u32, upstream_bits_per_frame); \
  378. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32, downstream_bits_per_frame); \
  379. CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS, u32, startup_attempts); \
  380. CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS, u32, upstream_crc_errors); \
  381. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS, u32, downstream_crc_errors); \
  382. CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS, u32, upstream_fec_errors); \
  383. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS, u32, downstream_fec_errors); \
  384. CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS, u32, upstream_hec_errors); \
  385. CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS, u32, downstream_hec_errors); \
  386. CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE, bool, line_startable); \
  387. CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \
  388. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \
  389. CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \
  390. CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \
  391. CXACRU_CMD_##_action( adsl_state);
  392. CXACRU_ALL_FILES(INIT);
  393. /* the following three functions are stolen from drivers/usb/core/message.c */
  394. static void cxacru_blocking_completion(struct urb *urb)
  395. {
  396. complete(urb->context);
  397. }
  398. static void cxacru_timeout_kill(unsigned long data)
  399. {
  400. usb_unlink_urb((struct urb *) data);
  401. }
  402. static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
  403. int* actual_length)
  404. {
  405. struct timer_list timer;
  406. init_timer(&timer);
  407. timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
  408. timer.data = (unsigned long) urb;
  409. timer.function = cxacru_timeout_kill;
  410. add_timer(&timer);
  411. wait_for_completion(done);
  412. del_timer_sync(&timer);
  413. if (actual_length)
  414. *actual_length = urb->actual_length;
  415. return urb->status; /* must read status after completion */
  416. }
  417. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  418. u8 *wdata, int wsize, u8 *rdata, int rsize)
  419. {
  420. int ret, actlen;
  421. int offb, offd;
  422. const int stride = CMD_PACKET_SIZE - 4;
  423. u8 *wbuf = instance->snd_buf;
  424. u8 *rbuf = instance->rcv_buf;
  425. int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  426. int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  427. if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
  428. if (printk_ratelimit())
  429. usb_err(instance->usbatm, "requested transfer size too large (%d, %d)\n",
  430. wbuflen, rbuflen);
  431. ret = -ENOMEM;
  432. goto err;
  433. }
  434. mutex_lock(&instance->cm_serialize);
  435. /* submit reading urb before the writing one */
  436. init_completion(&instance->rcv_done);
  437. ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
  438. if (ret < 0) {
  439. if (printk_ratelimit())
  440. usb_err(instance->usbatm, "submit of read urb for cm %#x failed (%d)\n",
  441. cm, ret);
  442. goto fail;
  443. }
  444. memset(wbuf, 0, wbuflen);
  445. /* handle wsize == 0 */
  446. wbuf[0] = cm;
  447. for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
  448. wbuf[offb] = cm;
  449. memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
  450. }
  451. instance->snd_urb->transfer_buffer_length = wbuflen;
  452. init_completion(&instance->snd_done);
  453. ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
  454. if (ret < 0) {
  455. if (printk_ratelimit())
  456. usb_err(instance->usbatm, "submit of write urb for cm %#x failed (%d)\n",
  457. cm, ret);
  458. goto fail;
  459. }
  460. ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
  461. if (ret < 0) {
  462. if (printk_ratelimit())
  463. usb_err(instance->usbatm, "send of cm %#x failed (%d)\n", cm, ret);
  464. goto fail;
  465. }
  466. ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
  467. if (ret < 0) {
  468. if (printk_ratelimit())
  469. usb_err(instance->usbatm, "receive of cm %#x failed (%d)\n", cm, ret);
  470. goto fail;
  471. }
  472. if (actlen % CMD_PACKET_SIZE || !actlen) {
  473. if (printk_ratelimit())
  474. usb_err(instance->usbatm, "invalid response length to cm %#x: %d\n",
  475. cm, actlen);
  476. ret = -EIO;
  477. goto fail;
  478. }
  479. /* check the return status and copy the data to the output buffer, if needed */
  480. for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
  481. if (rbuf[offb] != cm) {
  482. if (printk_ratelimit())
  483. usb_err(instance->usbatm, "wrong cm %#x in response to cm %#x\n",
  484. rbuf[offb], cm);
  485. ret = -EIO;
  486. goto fail;
  487. }
  488. if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
  489. if (printk_ratelimit())
  490. usb_err(instance->usbatm, "response to cm %#x failed: %#x\n",
  491. cm, rbuf[offb + 1]);
  492. ret = -EIO;
  493. goto fail;
  494. }
  495. if (offd >= rsize)
  496. break;
  497. memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
  498. offd += stride;
  499. }
  500. ret = offd;
  501. dbg("cm %#x", cm);
  502. fail:
  503. mutex_unlock(&instance->cm_serialize);
  504. err:
  505. return ret;
  506. }
  507. static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
  508. u32 *data, int size)
  509. {
  510. int ret, len;
  511. __le32 *buf;
  512. int offb, offd;
  513. const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
  514. int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
  515. buf = kmalloc(buflen, GFP_KERNEL);
  516. if (!buf)
  517. return -ENOMEM;
  518. ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
  519. if (ret < 0)
  520. goto cleanup;
  521. /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
  522. len = ret / 4;
  523. for (offb = 0; offb < len; ) {
  524. int l = le32_to_cpu(buf[offb++]);
  525. if (l > stride || l > (len - offb) / 2) {
  526. if (printk_ratelimit())
  527. usb_err(instance->usbatm, "invalid data length from cm %#x: %d\n",
  528. cm, l);
  529. ret = -EIO;
  530. goto cleanup;
  531. }
  532. while (l--) {
  533. offd = le32_to_cpu(buf[offb++]);
  534. if (offd >= size) {
  535. if (printk_ratelimit())
  536. usb_err(instance->usbatm, "wrong index %#x in response to cm %#x\n",
  537. offd, cm);
  538. ret = -EIO;
  539. goto cleanup;
  540. }
  541. data[offd] = le32_to_cpu(buf[offb++]);
  542. }
  543. }
  544. ret = 0;
  545. cleanup:
  546. kfree(buf);
  547. return ret;
  548. }
  549. static int cxacru_card_status(struct cxacru_data *instance)
  550. {
  551. int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  552. if (ret < 0) { /* firmware not loaded */
  553. dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
  554. return ret;
  555. }
  556. return 0;
  557. }
  558. static void cxacru_remove_device_files(struct usbatm_data *usbatm_instance,
  559. struct atm_dev *atm_dev)
  560. {
  561. struct usb_interface *intf = usbatm_instance->usb_intf;
  562. #define CXACRU_DEVICE_REMOVE_FILE(_name) \
  563. device_remove_file(&intf->dev, &dev_attr_##_name);
  564. CXACRU_ALL_FILES(REMOVE);
  565. #undef CXACRU_DEVICE_REMOVE_FILE
  566. }
  567. static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
  568. struct atm_dev *atm_dev)
  569. {
  570. struct cxacru_data *instance = usbatm_instance->driver_data;
  571. struct usb_interface *intf = usbatm_instance->usb_intf;
  572. /*
  573. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  574. */
  575. int ret;
  576. int start_polling = 1;
  577. dbg("cxacru_atm_start");
  578. /* Read MAC address */
  579. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
  580. atm_dev->esi, sizeof(atm_dev->esi));
  581. if (ret < 0) {
  582. atm_err(usbatm_instance, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
  583. return ret;
  584. }
  585. #define CXACRU_DEVICE_CREATE_FILE(_name) \
  586. ret = device_create_file(&intf->dev, &dev_attr_##_name); \
  587. if (unlikely(ret)) \
  588. goto fail_sysfs;
  589. CXACRU_ALL_FILES(CREATE);
  590. #undef CXACRU_DEVICE_CREATE_FILE
  591. /* start ADSL */
  592. mutex_lock(&instance->adsl_state_serialize);
  593. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  594. if (ret < 0)
  595. atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
  596. /* Start status polling */
  597. mutex_lock(&instance->poll_state_serialize);
  598. switch (instance->poll_state) {
  599. case CXPOLL_STOPPED:
  600. /* start polling */
  601. instance->poll_state = CXPOLL_POLLING;
  602. break;
  603. case CXPOLL_STOPPING:
  604. /* abort stop request */
  605. instance->poll_state = CXPOLL_POLLING;
  606. case CXPOLL_POLLING:
  607. case CXPOLL_SHUTDOWN:
  608. /* don't start polling */
  609. start_polling = 0;
  610. }
  611. mutex_unlock(&instance->poll_state_serialize);
  612. mutex_unlock(&instance->adsl_state_serialize);
  613. if (start_polling)
  614. cxacru_poll_status(&instance->poll_work.work);
  615. return 0;
  616. fail_sysfs:
  617. usb_err(usbatm_instance, "cxacru_atm_start: device_create_file failed (%d)\n", ret);
  618. cxacru_remove_device_files(usbatm_instance, atm_dev);
  619. return ret;
  620. }
  621. static void cxacru_poll_status(struct work_struct *work)
  622. {
  623. struct cxacru_data *instance =
  624. container_of(work, struct cxacru_data, poll_work.work);
  625. u32 buf[CXINF_MAX] = {};
  626. struct usbatm_data *usbatm = instance->usbatm;
  627. struct atm_dev *atm_dev = usbatm->atm_dev;
  628. int keep_polling = 1;
  629. int ret;
  630. ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
  631. if (ret < 0) {
  632. if (ret != -ESHUTDOWN)
  633. atm_warn(usbatm, "poll status: error %d\n", ret);
  634. mutex_lock(&instance->poll_state_serialize);
  635. if (instance->poll_state != CXPOLL_SHUTDOWN) {
  636. instance->poll_state = CXPOLL_STOPPED;
  637. if (ret != -ESHUTDOWN)
  638. atm_warn(usbatm, "polling disabled, set adsl_state"
  639. " to 'start' or 'poll' to resume\n");
  640. }
  641. mutex_unlock(&instance->poll_state_serialize);
  642. goto reschedule;
  643. }
  644. memcpy(instance->card_info, buf, sizeof(instance->card_info));
  645. if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) {
  646. instance->adsl_status = buf[CXINF_LINE_STARTABLE];
  647. switch (instance->adsl_status) {
  648. case 0:
  649. atm_printk(KERN_INFO, usbatm, "ADSL state: running\n");
  650. break;
  651. case 1:
  652. atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n");
  653. break;
  654. default:
  655. atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status);
  656. break;
  657. }
  658. }
  659. if (instance->line_status == buf[CXINF_LINE_STATUS])
  660. goto reschedule;
  661. instance->line_status = buf[CXINF_LINE_STATUS];
  662. switch (instance->line_status) {
  663. case 0:
  664. atm_dev->signal = ATM_PHY_SIG_LOST;
  665. atm_info(usbatm, "ADSL line: down\n");
  666. break;
  667. case 1:
  668. atm_dev->signal = ATM_PHY_SIG_LOST;
  669. atm_info(usbatm, "ADSL line: attempting to activate\n");
  670. break;
  671. case 2:
  672. atm_dev->signal = ATM_PHY_SIG_LOST;
  673. atm_info(usbatm, "ADSL line: training\n");
  674. break;
  675. case 3:
  676. atm_dev->signal = ATM_PHY_SIG_LOST;
  677. atm_info(usbatm, "ADSL line: channel analysis\n");
  678. break;
  679. case 4:
  680. atm_dev->signal = ATM_PHY_SIG_LOST;
  681. atm_info(usbatm, "ADSL line: exchange\n");
  682. break;
  683. case 5:
  684. atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
  685. atm_dev->signal = ATM_PHY_SIG_FOUND;
  686. atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
  687. buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
  688. break;
  689. case 6:
  690. atm_dev->signal = ATM_PHY_SIG_LOST;
  691. atm_info(usbatm, "ADSL line: waiting\n");
  692. break;
  693. case 7:
  694. atm_dev->signal = ATM_PHY_SIG_LOST;
  695. atm_info(usbatm, "ADSL line: initializing\n");
  696. break;
  697. default:
  698. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  699. atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
  700. break;
  701. }
  702. reschedule:
  703. mutex_lock(&instance->poll_state_serialize);
  704. if (instance->poll_state == CXPOLL_STOPPING &&
  705. instance->adsl_status == 1 && /* stopped */
  706. instance->line_status == 0) /* down */
  707. instance->poll_state = CXPOLL_STOPPED;
  708. if (instance->poll_state == CXPOLL_STOPPED)
  709. keep_polling = 0;
  710. mutex_unlock(&instance->poll_state_serialize);
  711. if (keep_polling)
  712. schedule_delayed_work(&instance->poll_work,
  713. round_jiffies_relative(POLL_INTERVAL*HZ));
  714. }
  715. static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
  716. u8 code1, u8 code2, u32 addr, const u8 *data, int size)
  717. {
  718. int ret;
  719. u8 *buf;
  720. int offd, offb;
  721. const int stride = CMD_PACKET_SIZE - 8;
  722. buf = (u8 *) __get_free_page(GFP_KERNEL);
  723. if (!buf)
  724. return -ENOMEM;
  725. offb = offd = 0;
  726. do {
  727. int l = min_t(int, stride, size - offd);
  728. buf[offb++] = fw;
  729. buf[offb++] = l;
  730. buf[offb++] = code1;
  731. buf[offb++] = code2;
  732. put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb));
  733. offb += 4;
  734. addr += l;
  735. if(l)
  736. memcpy(buf + offb, data + offd, l);
  737. if (l < stride)
  738. memset(buf + offb + l, 0, stride - l);
  739. offb += stride;
  740. offd += stride;
  741. if ((offb >= PAGE_SIZE) || (offd >= size)) {
  742. ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
  743. buf, offb, NULL, CMD_TIMEOUT);
  744. if (ret < 0) {
  745. dbg("sending fw %#x failed", fw);
  746. goto cleanup;
  747. }
  748. offb = 0;
  749. }
  750. } while(offd < size);
  751. dbg("sent fw %#x", fw);
  752. ret = 0;
  753. cleanup:
  754. free_page((unsigned long) buf);
  755. return ret;
  756. }
  757. static void cxacru_upload_firmware(struct cxacru_data *instance,
  758. const struct firmware *fw,
  759. const struct firmware *bp,
  760. const struct firmware *cf)
  761. {
  762. int ret;
  763. int off;
  764. struct usbatm_data *usbatm = instance->usbatm;
  765. struct usb_device *usb_dev = usbatm->usb_dev;
  766. __le16 signature[] = { usb_dev->descriptor.idVendor,
  767. usb_dev->descriptor.idProduct };
  768. __le32 val;
  769. dbg("cxacru_upload_firmware");
  770. /* FirmwarePllFClkValue */
  771. val = cpu_to_le32(instance->modem_type->pll_f_clk);
  772. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
  773. if (ret) {
  774. usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
  775. return;
  776. }
  777. /* FirmwarePllBClkValue */
  778. val = cpu_to_le32(instance->modem_type->pll_b_clk);
  779. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
  780. if (ret) {
  781. usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
  782. return;
  783. }
  784. /* Enable SDRAM */
  785. val = cpu_to_le32(SDRAM_ENA);
  786. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
  787. if (ret) {
  788. usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
  789. return;
  790. }
  791. /* Firmware */
  792. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
  793. if (ret) {
  794. usb_err(usbatm, "Firmware upload failed: %d\n", ret);
  795. return;
  796. }
  797. /* Boot ROM patch */
  798. if (instance->modem_type->boot_rom_patch) {
  799. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
  800. if (ret) {
  801. usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
  802. return;
  803. }
  804. }
  805. /* Signature */
  806. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
  807. if (ret) {
  808. usb_err(usbatm, "Signature storing failed: %d\n", ret);
  809. return;
  810. }
  811. if (instance->modem_type->boot_rom_patch) {
  812. val = cpu_to_le32(BR_ADDR);
  813. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
  814. }
  815. else {
  816. ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
  817. }
  818. if (ret) {
  819. usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
  820. return;
  821. }
  822. /* Delay to allow firmware to start up. */
  823. msleep_interruptible(1000);
  824. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
  825. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
  826. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
  827. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
  828. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  829. if (ret < 0) {
  830. usb_err(usbatm, "modem failed to initialize: %d\n", ret);
  831. return;
  832. }
  833. /* Load config data (le32), doing one packet at a time */
  834. if (cf)
  835. for (off = 0; off < cf->size / 4; ) {
  836. __le32 buf[CMD_PACKET_SIZE / 4 - 1];
  837. int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
  838. buf[0] = cpu_to_le32(len);
  839. for (i = 0; i < len; i++, off++) {
  840. buf[i * 2 + 1] = cpu_to_le32(off);
  841. memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
  842. }
  843. ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
  844. (u8 *) buf, len, NULL, 0);
  845. if (ret < 0) {
  846. usb_err(usbatm, "load config data failed: %d\n", ret);
  847. return;
  848. }
  849. }
  850. msleep_interruptible(4000);
  851. }
  852. static int cxacru_find_firmware(struct cxacru_data *instance,
  853. char* phase, const struct firmware **fw_p)
  854. {
  855. struct usbatm_data *usbatm = instance->usbatm;
  856. struct device *dev = &usbatm->usb_intf->dev;
  857. char buf[16];
  858. sprintf(buf, "cxacru-%s.bin", phase);
  859. dbg("cxacru_find_firmware: looking for %s", buf);
  860. if (request_firmware(fw_p, buf, dev)) {
  861. usb_dbg(usbatm, "no stage %s firmware found\n", phase);
  862. return -ENOENT;
  863. }
  864. usb_info(usbatm, "found firmware %s\n", buf);
  865. return 0;
  866. }
  867. static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
  868. struct usb_interface *usb_intf)
  869. {
  870. const struct firmware *fw, *bp, *cf;
  871. struct cxacru_data *instance = usbatm_instance->driver_data;
  872. int ret = cxacru_find_firmware(instance, "fw", &fw);
  873. if (ret) {
  874. usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
  875. return ret;
  876. }
  877. if (instance->modem_type->boot_rom_patch) {
  878. ret = cxacru_find_firmware(instance, "bp", &bp);
  879. if (ret) {
  880. usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
  881. release_firmware(fw);
  882. return ret;
  883. }
  884. }
  885. if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
  886. cf = NULL;
  887. cxacru_upload_firmware(instance, fw, bp, cf);
  888. if (cf)
  889. release_firmware(cf);
  890. if (instance->modem_type->boot_rom_patch)
  891. release_firmware(bp);
  892. release_firmware(fw);
  893. ret = cxacru_card_status(instance);
  894. if (ret)
  895. dbg("modem initialisation failed");
  896. else
  897. dbg("done setting up the modem");
  898. return ret;
  899. }
  900. static int cxacru_bind(struct usbatm_data *usbatm_instance,
  901. struct usb_interface *intf, const struct usb_device_id *id)
  902. {
  903. struct cxacru_data *instance;
  904. struct usb_device *usb_dev = interface_to_usbdev(intf);
  905. int ret;
  906. /* instance init */
  907. instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  908. if (!instance) {
  909. dbg("cxacru_bind: no memory for instance data");
  910. return -ENOMEM;
  911. }
  912. instance->usbatm = usbatm_instance;
  913. instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
  914. mutex_init(&instance->poll_state_serialize);
  915. instance->poll_state = CXPOLL_STOPPED;
  916. instance->line_status = -1;
  917. instance->adsl_status = -1;
  918. mutex_init(&instance->adsl_state_serialize);
  919. instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
  920. if (!instance->rcv_buf) {
  921. dbg("cxacru_bind: no memory for rcv_buf");
  922. ret = -ENOMEM;
  923. goto fail;
  924. }
  925. instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
  926. if (!instance->snd_buf) {
  927. dbg("cxacru_bind: no memory for snd_buf");
  928. ret = -ENOMEM;
  929. goto fail;
  930. }
  931. instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
  932. if (!instance->rcv_urb) {
  933. dbg("cxacru_bind: no memory for rcv_urb");
  934. ret = -ENOMEM;
  935. goto fail;
  936. }
  937. instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
  938. if (!instance->snd_urb) {
  939. dbg("cxacru_bind: no memory for snd_urb");
  940. ret = -ENOMEM;
  941. goto fail;
  942. }
  943. usb_fill_int_urb(instance->rcv_urb,
  944. usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
  945. instance->rcv_buf, PAGE_SIZE,
  946. cxacru_blocking_completion, &instance->rcv_done, 1);
  947. usb_fill_int_urb(instance->snd_urb,
  948. usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
  949. instance->snd_buf, PAGE_SIZE,
  950. cxacru_blocking_completion, &instance->snd_done, 4);
  951. mutex_init(&instance->cm_serialize);
  952. INIT_DELAYED_WORK(&instance->poll_work, cxacru_poll_status);
  953. usbatm_instance->driver_data = instance;
  954. usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
  955. return 0;
  956. fail:
  957. free_page((unsigned long) instance->snd_buf);
  958. free_page((unsigned long) instance->rcv_buf);
  959. usb_free_urb(instance->snd_urb);
  960. usb_free_urb(instance->rcv_urb);
  961. kfree(instance);
  962. return ret;
  963. }
  964. static void cxacru_unbind(struct usbatm_data *usbatm_instance,
  965. struct usb_interface *intf)
  966. {
  967. struct cxacru_data *instance = usbatm_instance->driver_data;
  968. int is_polling = 1;
  969. dbg("cxacru_unbind entered");
  970. if (!instance) {
  971. dbg("cxacru_unbind: NULL instance!");
  972. return;
  973. }
  974. mutex_lock(&instance->poll_state_serialize);
  975. BUG_ON(instance->poll_state == CXPOLL_SHUTDOWN);
  976. /* ensure that status polling continues unless
  977. * it has already stopped */
  978. if (instance->poll_state == CXPOLL_STOPPED)
  979. is_polling = 0;
  980. /* stop polling from being stopped or started */
  981. instance->poll_state = CXPOLL_SHUTDOWN;
  982. mutex_unlock(&instance->poll_state_serialize);
  983. if (is_polling)
  984. cancel_rearming_delayed_work(&instance->poll_work);
  985. usb_kill_urb(instance->snd_urb);
  986. usb_kill_urb(instance->rcv_urb);
  987. usb_free_urb(instance->snd_urb);
  988. usb_free_urb(instance->rcv_urb);
  989. free_page((unsigned long) instance->snd_buf);
  990. free_page((unsigned long) instance->rcv_buf);
  991. kfree(instance);
  992. usbatm_instance->driver_data = NULL;
  993. }
  994. static const struct cxacru_modem_type cxacru_cafe = {
  995. .pll_f_clk = 0x02d874df,
  996. .pll_b_clk = 0x0196a51a,
  997. .boot_rom_patch = 1,
  998. };
  999. static const struct cxacru_modem_type cxacru_cb00 = {
  1000. .pll_f_clk = 0x5,
  1001. .pll_b_clk = 0x3,
  1002. .boot_rom_patch = 0,
  1003. };
  1004. static const struct usb_device_id cxacru_usb_ids[] = {
  1005. { /* V = Conexant P = ADSL modem (Euphrates project) */
  1006. USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
  1007. },
  1008. { /* V = Conexant P = ADSL modem (Hasbani project) */
  1009. USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
  1010. },
  1011. { /* V = Conexant P = ADSL modem */
  1012. USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  1013. },
  1014. { /* V = Conexant P = ADSL modem (Well PTI-800) */
  1015. USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
  1016. },
  1017. { /* V = Conexant P = ADSL modem */
  1018. USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
  1019. },
  1020. { /* V = Conexant P = ADSL modem (ZTE ZXDSL 852) */
  1021. USB_DEVICE(0x0572, 0xcb07), .driver_info = (unsigned long) &cxacru_cb00
  1022. },
  1023. { /* V = Olitec P = ADSL modem version 2 */
  1024. USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
  1025. },
  1026. { /* V = Olitec P = ADSL modem version 3 */
  1027. USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
  1028. },
  1029. { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
  1030. USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
  1031. },
  1032. { /* V = Zoom P = 5510 */
  1033. USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
  1034. },
  1035. { /* V = Draytek P = Vigor 318 */
  1036. USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
  1037. },
  1038. { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
  1039. USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
  1040. },
  1041. { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
  1042. USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
  1043. },
  1044. { /* V = Aethra P = Starmodem UM1020 */
  1045. USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
  1046. },
  1047. { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
  1048. USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
  1049. },
  1050. { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
  1051. USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  1052. },
  1053. { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
  1054. USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
  1055. },
  1056. {}
  1057. };
  1058. MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
  1059. static struct usbatm_driver cxacru_driver = {
  1060. .driver_name = cxacru_driver_name,
  1061. .bind = cxacru_bind,
  1062. .heavy_init = cxacru_heavy_init,
  1063. .unbind = cxacru_unbind,
  1064. .atm_start = cxacru_atm_start,
  1065. .atm_stop = cxacru_remove_device_files,
  1066. .bulk_in = CXACRU_EP_DATA,
  1067. .bulk_out = CXACRU_EP_DATA,
  1068. .rx_padding = 3,
  1069. .tx_padding = 11,
  1070. };
  1071. static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1072. {
  1073. return usbatm_usb_probe(intf, id, &cxacru_driver);
  1074. }
  1075. static struct usb_driver cxacru_usb_driver = {
  1076. .name = cxacru_driver_name,
  1077. .probe = cxacru_usb_probe,
  1078. .disconnect = usbatm_usb_disconnect,
  1079. .id_table = cxacru_usb_ids
  1080. };
  1081. static int __init cxacru_init(void)
  1082. {
  1083. return usb_register(&cxacru_usb_driver);
  1084. }
  1085. static void __exit cxacru_cleanup(void)
  1086. {
  1087. usb_deregister(&cxacru_usb_driver);
  1088. }
  1089. module_init(cxacru_init);
  1090. module_exit(cxacru_cleanup);
  1091. MODULE_AUTHOR(DRIVER_AUTHOR);
  1092. MODULE_DESCRIPTION(DRIVER_DESC);
  1093. MODULE_LICENSE("GPL");
  1094. MODULE_VERSION(DRIVER_VERSION);