cxacru.c 36 KB

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