sb1000.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /* sb1000.c: A General Instruments SB1000 driver for linux. */
  2. /*
  3. Written 1998 by Franco Venturi.
  4. Copyright 1998 by Franco Venturi.
  5. Copyright 1994,1995 by Donald Becker.
  6. Copyright 1993 United States Government as represented by the
  7. Director, National Security Agency.
  8. This driver is for the General Instruments SB1000 (internal SURFboard)
  9. The author may be reached as fventuri@mediaone.net
  10. This program is free software; you can redistribute it
  11. and/or modify it under the terms of the GNU General
  12. Public License as published by the Free Software
  13. Foundation; either version 2 of the License, or (at
  14. your option) any later version.
  15. Changes:
  16. 981115 Steven Hirsch <shirsch@adelphia.net>
  17. Linus changed the timer interface. Should work on all recent
  18. development kernels.
  19. 980608 Steven Hirsch <shirsch@adelphia.net>
  20. Small changes to make it work with 2.1.x kernels. Hopefully,
  21. nothing major will change before official release of Linux 2.2.
  22. Merged with 2.2 - Alan Cox
  23. */
  24. static char version[] = "sb1000.c:v1.1.2 6/01/98 (fventuri@mediaone.net)\n";
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/string.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/errno.h>
  31. #include <linux/if_cablemodem.h> /* for SIOGCM/SIOSCM stuff */
  32. #include <linux/in.h>
  33. #include <linux/ioport.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/if_arp.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/delay.h> /* for udelay() */
  38. #include <linux/etherdevice.h>
  39. #include <linux/pnp.h>
  40. #include <linux/init.h>
  41. #include <linux/bitops.h>
  42. #include <linux/gfp.h>
  43. #include <asm/io.h>
  44. #include <asm/processor.h>
  45. #include <asm/uaccess.h>
  46. #ifdef SB1000_DEBUG
  47. static int sb1000_debug = SB1000_DEBUG;
  48. #else
  49. static const int sb1000_debug = 1;
  50. #endif
  51. static const int SB1000_IO_EXTENT = 8;
  52. /* SB1000 Maximum Receive Unit */
  53. static const int SB1000_MRU = 1500; /* octects */
  54. #define NPIDS 4
  55. struct sb1000_private {
  56. struct sk_buff *rx_skb[NPIDS];
  57. short rx_dlen[NPIDS];
  58. unsigned int rx_frames;
  59. short rx_error_count;
  60. short rx_error_dpc_count;
  61. unsigned char rx_session_id[NPIDS];
  62. unsigned char rx_frame_id[NPIDS];
  63. unsigned char rx_pkt_type[NPIDS];
  64. };
  65. /* prototypes for Linux interface */
  66. extern int sb1000_probe(struct net_device *dev);
  67. static int sb1000_open(struct net_device *dev);
  68. static int sb1000_dev_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd);
  69. static netdev_tx_t sb1000_start_xmit(struct sk_buff *skb,
  70. struct net_device *dev);
  71. static irqreturn_t sb1000_interrupt(int irq, void *dev_id);
  72. static int sb1000_close(struct net_device *dev);
  73. /* SB1000 hardware routines to be used during open/configuration phases */
  74. static int card_wait_for_busy_clear(const int ioaddr[],
  75. const char* name);
  76. static int card_wait_for_ready(const int ioaddr[], const char* name,
  77. unsigned char in[]);
  78. static int card_send_command(const int ioaddr[], const char* name,
  79. const unsigned char out[], unsigned char in[]);
  80. /* SB1000 hardware routines to be used during frame rx interrupt */
  81. static int sb1000_wait_for_ready(const int ioaddr[], const char* name);
  82. static int sb1000_wait_for_ready_clear(const int ioaddr[],
  83. const char* name);
  84. static void sb1000_send_command(const int ioaddr[], const char* name,
  85. const unsigned char out[]);
  86. static void sb1000_read_status(const int ioaddr[], unsigned char in[]);
  87. static void sb1000_issue_read_command(const int ioaddr[],
  88. const char* name);
  89. /* SB1000 commands for open/configuration */
  90. static int sb1000_reset(const int ioaddr[], const char* name);
  91. static int sb1000_check_CRC(const int ioaddr[], const char* name);
  92. static inline int sb1000_start_get_set_command(const int ioaddr[],
  93. const char* name);
  94. static int sb1000_end_get_set_command(const int ioaddr[],
  95. const char* name);
  96. static int sb1000_activate(const int ioaddr[], const char* name);
  97. static int sb1000_get_firmware_version(const int ioaddr[],
  98. const char* name, unsigned char version[], int do_end);
  99. static int sb1000_get_frequency(const int ioaddr[], const char* name,
  100. int* frequency);
  101. static int sb1000_set_frequency(const int ioaddr[], const char* name,
  102. int frequency);
  103. static int sb1000_get_PIDs(const int ioaddr[], const char* name,
  104. short PID[]);
  105. static int sb1000_set_PIDs(const int ioaddr[], const char* name,
  106. const short PID[]);
  107. /* SB1000 commands for frame rx interrupt */
  108. static int sb1000_rx(struct net_device *dev);
  109. static void sb1000_error_dpc(struct net_device *dev);
  110. static const struct pnp_device_id sb1000_pnp_ids[] = {
  111. { "GIC1000", 0 },
  112. { "", 0 }
  113. };
  114. MODULE_DEVICE_TABLE(pnp, sb1000_pnp_ids);
  115. static const struct net_device_ops sb1000_netdev_ops = {
  116. .ndo_open = sb1000_open,
  117. .ndo_start_xmit = sb1000_start_xmit,
  118. .ndo_do_ioctl = sb1000_dev_ioctl,
  119. .ndo_stop = sb1000_close,
  120. .ndo_change_mtu = eth_change_mtu,
  121. .ndo_set_mac_address = eth_mac_addr,
  122. .ndo_validate_addr = eth_validate_addr,
  123. };
  124. static int
  125. sb1000_probe_one(struct pnp_dev *pdev, const struct pnp_device_id *id)
  126. {
  127. struct net_device *dev;
  128. unsigned short ioaddr[2], irq;
  129. unsigned int serial_number;
  130. int error = -ENODEV;
  131. if (pnp_device_attach(pdev) < 0)
  132. return -ENODEV;
  133. if (pnp_activate_dev(pdev) < 0)
  134. goto out_detach;
  135. if (!pnp_port_valid(pdev, 0) || !pnp_port_valid(pdev, 1))
  136. goto out_disable;
  137. if (!pnp_irq_valid(pdev, 0))
  138. goto out_disable;
  139. serial_number = pdev->card->serial;
  140. ioaddr[0] = pnp_port_start(pdev, 0);
  141. ioaddr[1] = pnp_port_start(pdev, 0);
  142. irq = pnp_irq(pdev, 0);
  143. if (!request_region(ioaddr[0], 16, "sb1000"))
  144. goto out_disable;
  145. if (!request_region(ioaddr[1], 16, "sb1000"))
  146. goto out_release_region0;
  147. dev = alloc_etherdev(sizeof(struct sb1000_private));
  148. if (!dev) {
  149. error = -ENOMEM;
  150. goto out_release_regions;
  151. }
  152. dev->base_addr = ioaddr[0];
  153. /* mem_start holds the second I/O address */
  154. dev->mem_start = ioaddr[1];
  155. dev->irq = irq;
  156. if (sb1000_debug > 0)
  157. printk(KERN_NOTICE "%s: sb1000 at (%#3.3lx,%#3.3lx), "
  158. "S/N %#8.8x, IRQ %d.\n", dev->name, dev->base_addr,
  159. dev->mem_start, serial_number, dev->irq);
  160. /*
  161. * The SB1000 is an rx-only cable modem device. The uplink is a modem
  162. * and we do not want to arp on it.
  163. */
  164. dev->flags = IFF_POINTOPOINT|IFF_NOARP;
  165. SET_NETDEV_DEV(dev, &pdev->dev);
  166. if (sb1000_debug > 0)
  167. printk(KERN_NOTICE "%s", version);
  168. dev->netdev_ops = &sb1000_netdev_ops;
  169. /* hardware address is 0:0:serial_number */
  170. dev->dev_addr[2] = serial_number >> 24 & 0xff;
  171. dev->dev_addr[3] = serial_number >> 16 & 0xff;
  172. dev->dev_addr[4] = serial_number >> 8 & 0xff;
  173. dev->dev_addr[5] = serial_number >> 0 & 0xff;
  174. pnp_set_drvdata(pdev, dev);
  175. error = register_netdev(dev);
  176. if (error)
  177. goto out_free_netdev;
  178. return 0;
  179. out_free_netdev:
  180. free_netdev(dev);
  181. out_release_regions:
  182. release_region(ioaddr[1], 16);
  183. out_release_region0:
  184. release_region(ioaddr[0], 16);
  185. out_disable:
  186. pnp_disable_dev(pdev);
  187. out_detach:
  188. pnp_device_detach(pdev);
  189. return error;
  190. }
  191. static void
  192. sb1000_remove_one(struct pnp_dev *pdev)
  193. {
  194. struct net_device *dev = pnp_get_drvdata(pdev);
  195. unregister_netdev(dev);
  196. release_region(dev->base_addr, 16);
  197. release_region(dev->mem_start, 16);
  198. free_netdev(dev);
  199. }
  200. static struct pnp_driver sb1000_driver = {
  201. .name = "sb1000",
  202. .id_table = sb1000_pnp_ids,
  203. .probe = sb1000_probe_one,
  204. .remove = sb1000_remove_one,
  205. };
  206. /*
  207. * SB1000 hardware routines to be used during open/configuration phases
  208. */
  209. static const int TimeOutJiffies = (875 * HZ) / 100;
  210. /* Card Wait For Busy Clear (cannot be used during an interrupt) */
  211. static int
  212. card_wait_for_busy_clear(const int ioaddr[], const char* name)
  213. {
  214. unsigned char a;
  215. unsigned long timeout;
  216. a = inb(ioaddr[0] + 7);
  217. timeout = jiffies + TimeOutJiffies;
  218. while (a & 0x80 || a & 0x40) {
  219. /* a little sleep */
  220. yield();
  221. a = inb(ioaddr[0] + 7);
  222. if (time_after_eq(jiffies, timeout)) {
  223. printk(KERN_WARNING "%s: card_wait_for_busy_clear timeout\n",
  224. name);
  225. return -ETIME;
  226. }
  227. }
  228. return 0;
  229. }
  230. /* Card Wait For Ready (cannot be used during an interrupt) */
  231. static int
  232. card_wait_for_ready(const int ioaddr[], const char* name, unsigned char in[])
  233. {
  234. unsigned char a;
  235. unsigned long timeout;
  236. a = inb(ioaddr[1] + 6);
  237. timeout = jiffies + TimeOutJiffies;
  238. while (a & 0x80 || !(a & 0x40)) {
  239. /* a little sleep */
  240. yield();
  241. a = inb(ioaddr[1] + 6);
  242. if (time_after_eq(jiffies, timeout)) {
  243. printk(KERN_WARNING "%s: card_wait_for_ready timeout\n",
  244. name);
  245. return -ETIME;
  246. }
  247. }
  248. in[1] = inb(ioaddr[0] + 1);
  249. in[2] = inb(ioaddr[0] + 2);
  250. in[3] = inb(ioaddr[0] + 3);
  251. in[4] = inb(ioaddr[0] + 4);
  252. in[0] = inb(ioaddr[0] + 5);
  253. in[6] = inb(ioaddr[0] + 6);
  254. in[5] = inb(ioaddr[1] + 6);
  255. return 0;
  256. }
  257. /* Card Send Command (cannot be used during an interrupt) */
  258. static int
  259. card_send_command(const int ioaddr[], const char* name,
  260. const unsigned char out[], unsigned char in[])
  261. {
  262. int status, x;
  263. if ((status = card_wait_for_busy_clear(ioaddr, name)))
  264. return status;
  265. outb(0xa0, ioaddr[0] + 6);
  266. outb(out[2], ioaddr[0] + 1);
  267. outb(out[3], ioaddr[0] + 2);
  268. outb(out[4], ioaddr[0] + 3);
  269. outb(out[5], ioaddr[0] + 4);
  270. outb(out[1], ioaddr[0] + 5);
  271. outb(0xa0, ioaddr[0] + 6);
  272. outb(out[0], ioaddr[0] + 7);
  273. if (out[0] != 0x20 && out[0] != 0x30) {
  274. if ((status = card_wait_for_ready(ioaddr, name, in)))
  275. return status;
  276. inb(ioaddr[0] + 7);
  277. if (sb1000_debug > 3)
  278. printk(KERN_DEBUG "%s: card_send_command "
  279. "out: %02x%02x%02x%02x%02x%02x "
  280. "in: %02x%02x%02x%02x%02x%02x%02x\n", name,
  281. out[0], out[1], out[2], out[3], out[4], out[5],
  282. in[0], in[1], in[2], in[3], in[4], in[5], in[6]);
  283. } else {
  284. if (sb1000_debug > 3)
  285. printk(KERN_DEBUG "%s: card_send_command "
  286. "out: %02x%02x%02x%02x%02x%02x\n", name,
  287. out[0], out[1], out[2], out[3], out[4], out[5]);
  288. }
  289. if (out[1] == 0x1b) {
  290. x = (out[2] == 0x02);
  291. } else {
  292. if (out[0] >= 0x80 && in[0] != (out[1] | 0x80))
  293. return -EIO;
  294. }
  295. return 0;
  296. }
  297. /*
  298. * SB1000 hardware routines to be used during frame rx interrupt
  299. */
  300. static const int Sb1000TimeOutJiffies = 7 * HZ;
  301. /* Card Wait For Ready (to be used during frame rx) */
  302. static int
  303. sb1000_wait_for_ready(const int ioaddr[], const char* name)
  304. {
  305. unsigned long timeout;
  306. timeout = jiffies + Sb1000TimeOutJiffies;
  307. while (inb(ioaddr[1] + 6) & 0x80) {
  308. if (time_after_eq(jiffies, timeout)) {
  309. printk(KERN_WARNING "%s: sb1000_wait_for_ready timeout\n",
  310. name);
  311. return -ETIME;
  312. }
  313. }
  314. timeout = jiffies + Sb1000TimeOutJiffies;
  315. while (!(inb(ioaddr[1] + 6) & 0x40)) {
  316. if (time_after_eq(jiffies, timeout)) {
  317. printk(KERN_WARNING "%s: sb1000_wait_for_ready timeout\n",
  318. name);
  319. return -ETIME;
  320. }
  321. }
  322. inb(ioaddr[0] + 7);
  323. return 0;
  324. }
  325. /* Card Wait For Ready Clear (to be used during frame rx) */
  326. static int
  327. sb1000_wait_for_ready_clear(const int ioaddr[], const char* name)
  328. {
  329. unsigned long timeout;
  330. timeout = jiffies + Sb1000TimeOutJiffies;
  331. while (inb(ioaddr[1] + 6) & 0x80) {
  332. if (time_after_eq(jiffies, timeout)) {
  333. printk(KERN_WARNING "%s: sb1000_wait_for_ready_clear timeout\n",
  334. name);
  335. return -ETIME;
  336. }
  337. }
  338. timeout = jiffies + Sb1000TimeOutJiffies;
  339. while (inb(ioaddr[1] + 6) & 0x40) {
  340. if (time_after_eq(jiffies, timeout)) {
  341. printk(KERN_WARNING "%s: sb1000_wait_for_ready_clear timeout\n",
  342. name);
  343. return -ETIME;
  344. }
  345. }
  346. return 0;
  347. }
  348. /* Card Send Command (to be used during frame rx) */
  349. static void
  350. sb1000_send_command(const int ioaddr[], const char* name,
  351. const unsigned char out[])
  352. {
  353. outb(out[2], ioaddr[0] + 1);
  354. outb(out[3], ioaddr[0] + 2);
  355. outb(out[4], ioaddr[0] + 3);
  356. outb(out[5], ioaddr[0] + 4);
  357. outb(out[1], ioaddr[0] + 5);
  358. outb(out[0], ioaddr[0] + 7);
  359. if (sb1000_debug > 3)
  360. printk(KERN_DEBUG "%s: sb1000_send_command out: %02x%02x%02x%02x"
  361. "%02x%02x\n", name, out[0], out[1], out[2], out[3], out[4], out[5]);
  362. }
  363. /* Card Read Status (to be used during frame rx) */
  364. static void
  365. sb1000_read_status(const int ioaddr[], unsigned char in[])
  366. {
  367. in[1] = inb(ioaddr[0] + 1);
  368. in[2] = inb(ioaddr[0] + 2);
  369. in[3] = inb(ioaddr[0] + 3);
  370. in[4] = inb(ioaddr[0] + 4);
  371. in[0] = inb(ioaddr[0] + 5);
  372. }
  373. /* Issue Read Command (to be used during frame rx) */
  374. static void
  375. sb1000_issue_read_command(const int ioaddr[], const char* name)
  376. {
  377. static const unsigned char Command0[6] = {0x20, 0x00, 0x00, 0x01, 0x00, 0x00};
  378. sb1000_wait_for_ready_clear(ioaddr, name);
  379. outb(0xa0, ioaddr[0] + 6);
  380. sb1000_send_command(ioaddr, name, Command0);
  381. }
  382. /*
  383. * SB1000 commands for open/configuration
  384. */
  385. /* reset SB1000 card */
  386. static int
  387. sb1000_reset(const int ioaddr[], const char* name)
  388. {
  389. static const unsigned char Command0[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
  390. unsigned char st[7];
  391. int port, status;
  392. port = ioaddr[1] + 6;
  393. outb(0x4, port);
  394. inb(port);
  395. udelay(1000);
  396. outb(0x0, port);
  397. inb(port);
  398. ssleep(1);
  399. outb(0x4, port);
  400. inb(port);
  401. udelay(1000);
  402. outb(0x0, port);
  403. inb(port);
  404. udelay(0);
  405. if ((status = card_send_command(ioaddr, name, Command0, st)))
  406. return status;
  407. if (st[3] != 0xf0)
  408. return -EIO;
  409. return 0;
  410. }
  411. /* check SB1000 firmware CRC */
  412. static int
  413. sb1000_check_CRC(const int ioaddr[], const char* name)
  414. {
  415. static const unsigned char Command0[6] = {0x80, 0x1f, 0x00, 0x00, 0x00, 0x00};
  416. unsigned char st[7];
  417. int crc, status;
  418. /* check CRC */
  419. if ((status = card_send_command(ioaddr, name, Command0, st)))
  420. return status;
  421. if (st[1] != st[3] || st[2] != st[4])
  422. return -EIO;
  423. crc = st[1] << 8 | st[2];
  424. return 0;
  425. }
  426. static inline int
  427. sb1000_start_get_set_command(const int ioaddr[], const char* name)
  428. {
  429. static const unsigned char Command0[6] = {0x80, 0x1b, 0x00, 0x00, 0x00, 0x00};
  430. unsigned char st[7];
  431. return card_send_command(ioaddr, name, Command0, st);
  432. }
  433. static int
  434. sb1000_end_get_set_command(const int ioaddr[], const char* name)
  435. {
  436. static const unsigned char Command0[6] = {0x80, 0x1b, 0x02, 0x00, 0x00, 0x00};
  437. static const unsigned char Command1[6] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
  438. unsigned char st[7];
  439. int status;
  440. if ((status = card_send_command(ioaddr, name, Command0, st)))
  441. return status;
  442. return card_send_command(ioaddr, name, Command1, st);
  443. }
  444. static int
  445. sb1000_activate(const int ioaddr[], const char* name)
  446. {
  447. static const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
  448. static const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
  449. unsigned char st[7];
  450. int status;
  451. ssleep(1);
  452. if ((status = card_send_command(ioaddr, name, Command0, st)))
  453. return status;
  454. if ((status = card_send_command(ioaddr, name, Command1, st)))
  455. return status;
  456. if (st[3] != 0xf1) {
  457. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  458. return status;
  459. return -EIO;
  460. }
  461. udelay(1000);
  462. return sb1000_start_get_set_command(ioaddr, name);
  463. }
  464. /* get SB1000 firmware version */
  465. static int
  466. sb1000_get_firmware_version(const int ioaddr[], const char* name,
  467. unsigned char version[], int do_end)
  468. {
  469. static const unsigned char Command0[6] = {0x80, 0x23, 0x00, 0x00, 0x00, 0x00};
  470. unsigned char st[7];
  471. int status;
  472. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  473. return status;
  474. if ((status = card_send_command(ioaddr, name, Command0, st)))
  475. return status;
  476. if (st[0] != 0xa3)
  477. return -EIO;
  478. version[0] = st[1];
  479. version[1] = st[2];
  480. if (do_end)
  481. return sb1000_end_get_set_command(ioaddr, name);
  482. else
  483. return 0;
  484. }
  485. /* get SB1000 frequency */
  486. static int
  487. sb1000_get_frequency(const int ioaddr[], const char* name, int* frequency)
  488. {
  489. static const unsigned char Command0[6] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00};
  490. unsigned char st[7];
  491. int status;
  492. udelay(1000);
  493. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  494. return status;
  495. if ((status = card_send_command(ioaddr, name, Command0, st)))
  496. return status;
  497. *frequency = ((st[1] << 8 | st[2]) << 8 | st[3]) << 8 | st[4];
  498. return sb1000_end_get_set_command(ioaddr, name);
  499. }
  500. /* set SB1000 frequency */
  501. static int
  502. sb1000_set_frequency(const int ioaddr[], const char* name, int frequency)
  503. {
  504. unsigned char st[7];
  505. int status;
  506. unsigned char Command0[6] = {0x80, 0x29, 0x00, 0x00, 0x00, 0x00};
  507. const int FrequencyLowerLimit = 57000;
  508. const int FrequencyUpperLimit = 804000;
  509. if (frequency < FrequencyLowerLimit || frequency > FrequencyUpperLimit) {
  510. printk(KERN_ERR "%s: frequency chosen (%d kHz) is not in the range "
  511. "[%d,%d] kHz\n", name, frequency, FrequencyLowerLimit,
  512. FrequencyUpperLimit);
  513. return -EINVAL;
  514. }
  515. udelay(1000);
  516. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  517. return status;
  518. Command0[5] = frequency & 0xff;
  519. frequency >>= 8;
  520. Command0[4] = frequency & 0xff;
  521. frequency >>= 8;
  522. Command0[3] = frequency & 0xff;
  523. frequency >>= 8;
  524. Command0[2] = frequency & 0xff;
  525. return card_send_command(ioaddr, name, Command0, st);
  526. }
  527. /* get SB1000 PIDs */
  528. static int
  529. sb1000_get_PIDs(const int ioaddr[], const char* name, short PID[])
  530. {
  531. static const unsigned char Command0[6] = {0x80, 0x40, 0x00, 0x00, 0x00, 0x00};
  532. static const unsigned char Command1[6] = {0x80, 0x41, 0x00, 0x00, 0x00, 0x00};
  533. static const unsigned char Command2[6] = {0x80, 0x42, 0x00, 0x00, 0x00, 0x00};
  534. static const unsigned char Command3[6] = {0x80, 0x43, 0x00, 0x00, 0x00, 0x00};
  535. unsigned char st[7];
  536. int status;
  537. udelay(1000);
  538. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  539. return status;
  540. if ((status = card_send_command(ioaddr, name, Command0, st)))
  541. return status;
  542. PID[0] = st[1] << 8 | st[2];
  543. if ((status = card_send_command(ioaddr, name, Command1, st)))
  544. return status;
  545. PID[1] = st[1] << 8 | st[2];
  546. if ((status = card_send_command(ioaddr, name, Command2, st)))
  547. return status;
  548. PID[2] = st[1] << 8 | st[2];
  549. if ((status = card_send_command(ioaddr, name, Command3, st)))
  550. return status;
  551. PID[3] = st[1] << 8 | st[2];
  552. return sb1000_end_get_set_command(ioaddr, name);
  553. }
  554. /* set SB1000 PIDs */
  555. static int
  556. sb1000_set_PIDs(const int ioaddr[], const char* name, const short PID[])
  557. {
  558. static const unsigned char Command4[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
  559. unsigned char st[7];
  560. short p;
  561. int status;
  562. unsigned char Command0[6] = {0x80, 0x31, 0x00, 0x00, 0x00, 0x00};
  563. unsigned char Command1[6] = {0x80, 0x32, 0x00, 0x00, 0x00, 0x00};
  564. unsigned char Command2[6] = {0x80, 0x33, 0x00, 0x00, 0x00, 0x00};
  565. unsigned char Command3[6] = {0x80, 0x34, 0x00, 0x00, 0x00, 0x00};
  566. udelay(1000);
  567. if ((status = sb1000_start_get_set_command(ioaddr, name)))
  568. return status;
  569. p = PID[0];
  570. Command0[3] = p & 0xff;
  571. p >>= 8;
  572. Command0[2] = p & 0xff;
  573. if ((status = card_send_command(ioaddr, name, Command0, st)))
  574. return status;
  575. p = PID[1];
  576. Command1[3] = p & 0xff;
  577. p >>= 8;
  578. Command1[2] = p & 0xff;
  579. if ((status = card_send_command(ioaddr, name, Command1, st)))
  580. return status;
  581. p = PID[2];
  582. Command2[3] = p & 0xff;
  583. p >>= 8;
  584. Command2[2] = p & 0xff;
  585. if ((status = card_send_command(ioaddr, name, Command2, st)))
  586. return status;
  587. p = PID[3];
  588. Command3[3] = p & 0xff;
  589. p >>= 8;
  590. Command3[2] = p & 0xff;
  591. if ((status = card_send_command(ioaddr, name, Command3, st)))
  592. return status;
  593. if ((status = card_send_command(ioaddr, name, Command4, st)))
  594. return status;
  595. return sb1000_end_get_set_command(ioaddr, name);
  596. }
  597. static void
  598. sb1000_print_status_buffer(const char* name, unsigned char st[],
  599. unsigned char buffer[], int size)
  600. {
  601. int i, j, k;
  602. printk(KERN_DEBUG "%s: status: %02x %02x\n", name, st[0], st[1]);
  603. if (buffer[24] == 0x08 && buffer[25] == 0x00 && buffer[26] == 0x45) {
  604. printk(KERN_DEBUG "%s: length: %d protocol: %d from: %d.%d.%d.%d:%d "
  605. "to %d.%d.%d.%d:%d\n", name, buffer[28] << 8 | buffer[29],
  606. buffer[35], buffer[38], buffer[39], buffer[40], buffer[41],
  607. buffer[46] << 8 | buffer[47],
  608. buffer[42], buffer[43], buffer[44], buffer[45],
  609. buffer[48] << 8 | buffer[49]);
  610. } else {
  611. for (i = 0, k = 0; i < (size + 7) / 8; i++) {
  612. printk(KERN_DEBUG "%s: %s", name, i ? " " : "buffer:");
  613. for (j = 0; j < 8 && k < size; j++, k++)
  614. printk(" %02x", buffer[k]);
  615. printk("\n");
  616. }
  617. }
  618. }
  619. /*
  620. * SB1000 commands for frame rx interrupt
  621. */
  622. /* receive a single frame and assemble datagram
  623. * (this is the heart of the interrupt routine)
  624. */
  625. static int
  626. sb1000_rx(struct net_device *dev)
  627. {
  628. #define FRAMESIZE 184
  629. unsigned char st[2], buffer[FRAMESIZE], session_id, frame_id;
  630. short dlen;
  631. int ioaddr, ns;
  632. unsigned int skbsize;
  633. struct sk_buff *skb;
  634. struct sb1000_private *lp = netdev_priv(dev);
  635. struct net_device_stats *stats = &dev->stats;
  636. /* SB1000 frame constants */
  637. const int FrameSize = FRAMESIZE;
  638. const int NewDatagramHeaderSkip = 8;
  639. const int NewDatagramHeaderSize = NewDatagramHeaderSkip + 18;
  640. const int NewDatagramDataSize = FrameSize - NewDatagramHeaderSize;
  641. const int ContDatagramHeaderSkip = 7;
  642. const int ContDatagramHeaderSize = ContDatagramHeaderSkip + 1;
  643. const int ContDatagramDataSize = FrameSize - ContDatagramHeaderSize;
  644. const int TrailerSize = 4;
  645. ioaddr = dev->base_addr;
  646. insw(ioaddr, (unsigned short*) st, 1);
  647. #ifdef XXXDEBUG
  648. printk("cm0: received: %02x %02x\n", st[0], st[1]);
  649. #endif /* XXXDEBUG */
  650. lp->rx_frames++;
  651. /* decide if it is a good or bad frame */
  652. for (ns = 0; ns < NPIDS; ns++) {
  653. session_id = lp->rx_session_id[ns];
  654. frame_id = lp->rx_frame_id[ns];
  655. if (st[0] == session_id) {
  656. if (st[1] == frame_id || (!frame_id && (st[1] & 0xf0) == 0x30)) {
  657. goto good_frame;
  658. } else if ((st[1] & 0xf0) == 0x30 && (st[0] & 0x40)) {
  659. goto skipped_frame;
  660. } else {
  661. goto bad_frame;
  662. }
  663. } else if (st[0] == (session_id | 0x40)) {
  664. if ((st[1] & 0xf0) == 0x30) {
  665. goto skipped_frame;
  666. } else {
  667. goto bad_frame;
  668. }
  669. }
  670. }
  671. goto bad_frame;
  672. skipped_frame:
  673. stats->rx_frame_errors++;
  674. skb = lp->rx_skb[ns];
  675. if (sb1000_debug > 1)
  676. printk(KERN_WARNING "%s: missing frame(s): got %02x %02x "
  677. "expecting %02x %02x\n", dev->name, st[0], st[1],
  678. skb ? session_id : session_id | 0x40, frame_id);
  679. if (skb) {
  680. dev_kfree_skb(skb);
  681. skb = NULL;
  682. }
  683. good_frame:
  684. lp->rx_frame_id[ns] = 0x30 | ((st[1] + 1) & 0x0f);
  685. /* new datagram */
  686. if (st[0] & 0x40) {
  687. /* get data length */
  688. insw(ioaddr, buffer, NewDatagramHeaderSize / 2);
  689. #ifdef XXXDEBUG
  690. printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer[30], buffer[31], buffer[32], buffer[33]);
  691. #endif /* XXXDEBUG */
  692. if (buffer[0] != NewDatagramHeaderSkip) {
  693. if (sb1000_debug > 1)
  694. printk(KERN_WARNING "%s: new datagram header skip error: "
  695. "got %02x expecting %02x\n", dev->name, buffer[0],
  696. NewDatagramHeaderSkip);
  697. stats->rx_length_errors++;
  698. insw(ioaddr, buffer, NewDatagramDataSize / 2);
  699. goto bad_frame_next;
  700. }
  701. dlen = ((buffer[NewDatagramHeaderSkip + 3] & 0x0f) << 8 |
  702. buffer[NewDatagramHeaderSkip + 4]) - 17;
  703. if (dlen > SB1000_MRU) {
  704. if (sb1000_debug > 1)
  705. printk(KERN_WARNING "%s: datagram length (%d) greater "
  706. "than MRU (%d)\n", dev->name, dlen, SB1000_MRU);
  707. stats->rx_length_errors++;
  708. insw(ioaddr, buffer, NewDatagramDataSize / 2);
  709. goto bad_frame_next;
  710. }
  711. lp->rx_dlen[ns] = dlen;
  712. /* compute size to allocate for datagram */
  713. skbsize = dlen + FrameSize;
  714. if ((skb = alloc_skb(skbsize, GFP_ATOMIC)) == NULL) {
  715. if (sb1000_debug > 1)
  716. printk(KERN_WARNING "%s: can't allocate %d bytes long "
  717. "skbuff\n", dev->name, skbsize);
  718. stats->rx_dropped++;
  719. insw(ioaddr, buffer, NewDatagramDataSize / 2);
  720. goto dropped_frame;
  721. }
  722. skb->dev = dev;
  723. skb_reset_mac_header(skb);
  724. skb->protocol = (unsigned short) buffer[NewDatagramHeaderSkip + 16];
  725. insw(ioaddr, skb_put(skb, NewDatagramDataSize),
  726. NewDatagramDataSize / 2);
  727. lp->rx_skb[ns] = skb;
  728. } else {
  729. /* continuation of previous datagram */
  730. insw(ioaddr, buffer, ContDatagramHeaderSize / 2);
  731. if (buffer[0] != ContDatagramHeaderSkip) {
  732. if (sb1000_debug > 1)
  733. printk(KERN_WARNING "%s: cont datagram header skip error: "
  734. "got %02x expecting %02x\n", dev->name, buffer[0],
  735. ContDatagramHeaderSkip);
  736. stats->rx_length_errors++;
  737. insw(ioaddr, buffer, ContDatagramDataSize / 2);
  738. goto bad_frame_next;
  739. }
  740. skb = lp->rx_skb[ns];
  741. insw(ioaddr, skb_put(skb, ContDatagramDataSize),
  742. ContDatagramDataSize / 2);
  743. dlen = lp->rx_dlen[ns];
  744. }
  745. if (skb->len < dlen + TrailerSize) {
  746. lp->rx_session_id[ns] &= ~0x40;
  747. return 0;
  748. }
  749. /* datagram completed: send to upper level */
  750. skb_trim(skb, dlen);
  751. netif_rx(skb);
  752. stats->rx_bytes+=dlen;
  753. stats->rx_packets++;
  754. lp->rx_skb[ns] = NULL;
  755. lp->rx_session_id[ns] |= 0x40;
  756. return 0;
  757. bad_frame:
  758. insw(ioaddr, buffer, FrameSize / 2);
  759. if (sb1000_debug > 1)
  760. printk(KERN_WARNING "%s: frame error: got %02x %02x\n",
  761. dev->name, st[0], st[1]);
  762. stats->rx_frame_errors++;
  763. bad_frame_next:
  764. if (sb1000_debug > 2)
  765. sb1000_print_status_buffer(dev->name, st, buffer, FrameSize);
  766. dropped_frame:
  767. stats->rx_errors++;
  768. if (ns < NPIDS) {
  769. if ((skb = lp->rx_skb[ns])) {
  770. dev_kfree_skb(skb);
  771. lp->rx_skb[ns] = NULL;
  772. }
  773. lp->rx_session_id[ns] |= 0x40;
  774. }
  775. return -1;
  776. }
  777. static void
  778. sb1000_error_dpc(struct net_device *dev)
  779. {
  780. static const unsigned char Command0[6] = {0x80, 0x26, 0x00, 0x00, 0x00, 0x00};
  781. char *name;
  782. unsigned char st[5];
  783. int ioaddr[2];
  784. struct sb1000_private *lp = netdev_priv(dev);
  785. const int ErrorDpcCounterInitialize = 200;
  786. ioaddr[0] = dev->base_addr;
  787. /* mem_start holds the second I/O address */
  788. ioaddr[1] = dev->mem_start;
  789. name = dev->name;
  790. sb1000_wait_for_ready_clear(ioaddr, name);
  791. sb1000_send_command(ioaddr, name, Command0);
  792. sb1000_wait_for_ready(ioaddr, name);
  793. sb1000_read_status(ioaddr, st);
  794. if (st[1] & 0x10)
  795. lp->rx_error_dpc_count = ErrorDpcCounterInitialize;
  796. }
  797. /*
  798. * Linux interface functions
  799. */
  800. static int
  801. sb1000_open(struct net_device *dev)
  802. {
  803. char *name;
  804. int ioaddr[2], status;
  805. struct sb1000_private *lp = netdev_priv(dev);
  806. const unsigned short FirmwareVersion[] = {0x01, 0x01};
  807. ioaddr[0] = dev->base_addr;
  808. /* mem_start holds the second I/O address */
  809. ioaddr[1] = dev->mem_start;
  810. name = dev->name;
  811. /* initialize sb1000 */
  812. if ((status = sb1000_reset(ioaddr, name)))
  813. return status;
  814. ssleep(1);
  815. if ((status = sb1000_check_CRC(ioaddr, name)))
  816. return status;
  817. /* initialize private data before board can catch interrupts */
  818. lp->rx_skb[0] = NULL;
  819. lp->rx_skb[1] = NULL;
  820. lp->rx_skb[2] = NULL;
  821. lp->rx_skb[3] = NULL;
  822. lp->rx_dlen[0] = 0;
  823. lp->rx_dlen[1] = 0;
  824. lp->rx_dlen[2] = 0;
  825. lp->rx_dlen[3] = 0;
  826. lp->rx_frames = 0;
  827. lp->rx_error_count = 0;
  828. lp->rx_error_dpc_count = 0;
  829. lp->rx_session_id[0] = 0x50;
  830. lp->rx_session_id[1] = 0x48;
  831. lp->rx_session_id[2] = 0x44;
  832. lp->rx_session_id[3] = 0x42;
  833. lp->rx_frame_id[0] = 0;
  834. lp->rx_frame_id[1] = 0;
  835. lp->rx_frame_id[2] = 0;
  836. lp->rx_frame_id[3] = 0;
  837. if (request_irq(dev->irq, sb1000_interrupt, 0, "sb1000", dev)) {
  838. return -EAGAIN;
  839. }
  840. if (sb1000_debug > 2)
  841. printk(KERN_DEBUG "%s: Opening, IRQ %d\n", name, dev->irq);
  842. /* Activate board and check firmware version */
  843. udelay(1000);
  844. if ((status = sb1000_activate(ioaddr, name)))
  845. return status;
  846. udelay(0);
  847. if ((status = sb1000_get_firmware_version(ioaddr, name, version, 0)))
  848. return status;
  849. if (version[0] != FirmwareVersion[0] || version[1] != FirmwareVersion[1])
  850. printk(KERN_WARNING "%s: found firmware version %x.%02x "
  851. "(should be %x.%02x)\n", name, version[0], version[1],
  852. FirmwareVersion[0], FirmwareVersion[1]);
  853. netif_start_queue(dev);
  854. return 0; /* Always succeed */
  855. }
  856. static int sb1000_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  857. {
  858. char* name;
  859. unsigned char version[2];
  860. short PID[4];
  861. int ioaddr[2], status, frequency;
  862. unsigned int stats[5];
  863. struct sb1000_private *lp = netdev_priv(dev);
  864. if (!(dev && dev->flags & IFF_UP))
  865. return -ENODEV;
  866. ioaddr[0] = dev->base_addr;
  867. /* mem_start holds the second I/O address */
  868. ioaddr[1] = dev->mem_start;
  869. name = dev->name;
  870. switch (cmd) {
  871. case SIOCGCMSTATS: /* get statistics */
  872. stats[0] = dev->stats.rx_bytes;
  873. stats[1] = lp->rx_frames;
  874. stats[2] = dev->stats.rx_packets;
  875. stats[3] = dev->stats.rx_errors;
  876. stats[4] = dev->stats.rx_dropped;
  877. if(copy_to_user(ifr->ifr_data, stats, sizeof(stats)))
  878. return -EFAULT;
  879. status = 0;
  880. break;
  881. case SIOCGCMFIRMWARE: /* get firmware version */
  882. if ((status = sb1000_get_firmware_version(ioaddr, name, version, 1)))
  883. return status;
  884. if(copy_to_user(ifr->ifr_data, version, sizeof(version)))
  885. return -EFAULT;
  886. break;
  887. case SIOCGCMFREQUENCY: /* get frequency */
  888. if ((status = sb1000_get_frequency(ioaddr, name, &frequency)))
  889. return status;
  890. if(put_user(frequency, (int __user *) ifr->ifr_data))
  891. return -EFAULT;
  892. break;
  893. case SIOCSCMFREQUENCY: /* set frequency */
  894. if (!capable(CAP_NET_ADMIN))
  895. return -EPERM;
  896. if(get_user(frequency, (int __user *) ifr->ifr_data))
  897. return -EFAULT;
  898. if ((status = sb1000_set_frequency(ioaddr, name, frequency)))
  899. return status;
  900. break;
  901. case SIOCGCMPIDS: /* get PIDs */
  902. if ((status = sb1000_get_PIDs(ioaddr, name, PID)))
  903. return status;
  904. if(copy_to_user(ifr->ifr_data, PID, sizeof(PID)))
  905. return -EFAULT;
  906. break;
  907. case SIOCSCMPIDS: /* set PIDs */
  908. if (!capable(CAP_NET_ADMIN))
  909. return -EPERM;
  910. if(copy_from_user(PID, ifr->ifr_data, sizeof(PID)))
  911. return -EFAULT;
  912. if ((status = sb1000_set_PIDs(ioaddr, name, PID)))
  913. return status;
  914. /* set session_id, frame_id and pkt_type too */
  915. lp->rx_session_id[0] = 0x50 | (PID[0] & 0x0f);
  916. lp->rx_session_id[1] = 0x48;
  917. lp->rx_session_id[2] = 0x44;
  918. lp->rx_session_id[3] = 0x42;
  919. lp->rx_frame_id[0] = 0;
  920. lp->rx_frame_id[1] = 0;
  921. lp->rx_frame_id[2] = 0;
  922. lp->rx_frame_id[3] = 0;
  923. break;
  924. default:
  925. status = -EINVAL;
  926. break;
  927. }
  928. return status;
  929. }
  930. /* transmit function: do nothing since SB1000 can't send anything out */
  931. static netdev_tx_t
  932. sb1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
  933. {
  934. printk(KERN_WARNING "%s: trying to transmit!!!\n", dev->name);
  935. /* sb1000 can't xmit datagrams */
  936. dev_kfree_skb(skb);
  937. return NETDEV_TX_OK;
  938. }
  939. /* SB1000 interrupt handler. */
  940. static irqreturn_t sb1000_interrupt(int irq, void *dev_id)
  941. {
  942. static const unsigned char Command0[6] = {0x80, 0x2c, 0x00, 0x00, 0x00, 0x00};
  943. static const unsigned char Command1[6] = {0x80, 0x2e, 0x00, 0x00, 0x00, 0x00};
  944. char *name;
  945. unsigned char st;
  946. int ioaddr[2];
  947. struct net_device *dev = dev_id;
  948. struct sb1000_private *lp = netdev_priv(dev);
  949. const int MaxRxErrorCount = 6;
  950. ioaddr[0] = dev->base_addr;
  951. /* mem_start holds the second I/O address */
  952. ioaddr[1] = dev->mem_start;
  953. name = dev->name;
  954. /* is it a good interrupt? */
  955. st = inb(ioaddr[1] + 6);
  956. if (!(st & 0x08 && st & 0x20)) {
  957. return IRQ_NONE;
  958. }
  959. if (sb1000_debug > 3)
  960. printk(KERN_DEBUG "%s: entering interrupt\n", dev->name);
  961. st = inb(ioaddr[0] + 7);
  962. if (sb1000_rx(dev))
  963. lp->rx_error_count++;
  964. #ifdef SB1000_DELAY
  965. udelay(SB1000_DELAY);
  966. #endif /* SB1000_DELAY */
  967. sb1000_issue_read_command(ioaddr, name);
  968. if (st & 0x01) {
  969. sb1000_error_dpc(dev);
  970. sb1000_issue_read_command(ioaddr, name);
  971. }
  972. if (lp->rx_error_dpc_count && !(--lp->rx_error_dpc_count)) {
  973. sb1000_wait_for_ready_clear(ioaddr, name);
  974. sb1000_send_command(ioaddr, name, Command0);
  975. sb1000_wait_for_ready(ioaddr, name);
  976. sb1000_issue_read_command(ioaddr, name);
  977. }
  978. if (lp->rx_error_count >= MaxRxErrorCount) {
  979. sb1000_wait_for_ready_clear(ioaddr, name);
  980. sb1000_send_command(ioaddr, name, Command1);
  981. sb1000_wait_for_ready(ioaddr, name);
  982. sb1000_issue_read_command(ioaddr, name);
  983. lp->rx_error_count = 0;
  984. }
  985. return IRQ_HANDLED;
  986. }
  987. static int sb1000_close(struct net_device *dev)
  988. {
  989. int i;
  990. int ioaddr[2];
  991. struct sb1000_private *lp = netdev_priv(dev);
  992. if (sb1000_debug > 2)
  993. printk(KERN_DEBUG "%s: Shutting down sb1000.\n", dev->name);
  994. netif_stop_queue(dev);
  995. ioaddr[0] = dev->base_addr;
  996. /* mem_start holds the second I/O address */
  997. ioaddr[1] = dev->mem_start;
  998. free_irq(dev->irq, dev);
  999. /* If we don't do this, we can't re-insmod it later. */
  1000. release_region(ioaddr[1], SB1000_IO_EXTENT);
  1001. release_region(ioaddr[0], SB1000_IO_EXTENT);
  1002. /* free rx_skb's if needed */
  1003. for (i=0; i<4; i++) {
  1004. if (lp->rx_skb[i]) {
  1005. dev_kfree_skb(lp->rx_skb[i]);
  1006. }
  1007. }
  1008. return 0;
  1009. }
  1010. MODULE_AUTHOR("Franco Venturi <fventuri@mediaone.net>");
  1011. MODULE_DESCRIPTION("General Instruments SB1000 driver");
  1012. MODULE_LICENSE("GPL");
  1013. static int __init
  1014. sb1000_init(void)
  1015. {
  1016. return pnp_register_driver(&sb1000_driver);
  1017. }
  1018. static void __exit
  1019. sb1000_exit(void)
  1020. {
  1021. pnp_unregister_driver(&sb1000_driver);
  1022. }
  1023. module_init(sb1000_init);
  1024. module_exit(sb1000_exit);