5 #include <linux/config.h>
6 #include <linux/kernel.h>
7 #include <linux/errno.h>
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <linux/smp_lock.h>
12 #include <linux/completion.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/usb.h>
16 #include <linux/pci.h>
17 #include <linux/firmware.h>
18 #include <asm/uaccess.h>
19 #include "prism54_usb.h"
21 #include "sent_data_ok.h"
25 #ifdef CONFIG_USB_DEBUG
32 static const char driver_name
[] = "prism54_usb";
34 static const struct usb_device_id p54u_table
[] = {
35 {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */
36 {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */
37 {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */
38 {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */
39 {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */
40 {USB_DEVICE(0x2001, 0x3701)}, /* DLink G120 */
41 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900 */
42 {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */
43 {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */
44 {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */
45 {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */
46 {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15 (Airvast WM168g) */
50 static const struct p54u_pipe_desc p54u_pipes
[] = {
51 { P54U_PIPE_DATA
, USB_ENDPOINT_XFER_BULK
},
52 { P54U_PIPE_MGMT
, USB_ENDPOINT_XFER_BULK
},
53 { P54U_PIPE_BRG
, USB_ENDPOINT_XFER_BULK
},
54 { P54U_PIPE_DEV
, USB_ENDPOINT_XFER_BULK
},
55 { P54U_PIPE_DATA
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
56 { P54U_PIPE_MGMT
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
57 { P54U_PIPE_3
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
58 { P54U_PIPE_4
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
59 { P54U_PIPE_BRG
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
60 { P54U_PIPE_DEV
| USB_DIR_IN
, USB_ENDPOINT_XFER_BULK
},
61 { P54U_PIPE_INT
| USB_DIR_IN
, USB_ENDPOINT_XFER_INT
},
65 MODULE_DESCRIPTION("Prism54 USB Driver");
66 MODULE_AUTHOR("Feyd <feyd@seznam.cz>");
67 MODULE_LICENSE("GPL");
68 MODULE_DEVICE_TABLE(usb
, p54u_table
);
69 MODULE_PARM(debug
, "i");
70 MODULE_PARM(load_fw
, "i");
71 MODULE_PARM_DESC(debug
, "Debug enabled or not");
72 MODULE_PARM_DESC(load_fw
, "Load firmware on probe (1) or open (0)");
74 static int p54u_reset_usb(struct net_device
*netdev
)
76 struct p54u
*p54u
= netdev_priv(netdev
);
77 struct usb_device
*usbdev
= p54u
->usbdev
;
83 p54u_info("%s: Reset USB device.\n", netdev
->name
);
84 err
= usb_reset_device(usbdev
);
86 p54u_err("%s: Reset USB device failed.\n", netdev
->name
);
90 p54u_info("%s: Reset USB device done.\n", netdev
->name
);
95 p54u_err("%s: Reset USB device failed.\n", netdev
->name
);
99 static void p54u_free_pipe(struct net_device
*netdev
, struct p54u_pipe
*pipe
)
101 struct p54u
*p54u
= netdev_priv(netdev
);
102 struct usb_device
*usbdev
= p54u
->usbdev
;
105 p54u_info("Freeing pipe.\n");
107 /* first unlink all submitted urbs
108 We have to do this before freeing
109 resources that are accessed by the
110 completion callbacks, such as completion
113 if(atomic_read(&pipe
->busy
)) {
114 p54u_info("pipe->busy is set to %i",atomic_read(&pipe
->busy
));
115 // this will do for the current situation
116 usb_unlink_urb(pipe
->urb
[0]);
120 p54u_info("pipe->buf == NULL\n");
125 p54u_info("pipe->urb == NULL\n");
130 p54u_info("pipe->size == NULL\n");
134 for(i
= 0; i
< pipe
->len
; i
++) {
137 usb_buffer_free(usbdev
, pipe
->size
[i
], pipe
->buf
[i
], pipe
->urb
[i
]->transfer_dma
);
139 p54u_info("pipe->buf[%i] == NULL\n", i
);
142 usb_free_urb(pipe
->urb
[i
]);
144 p54u_info("pipe->urb[%i] == NULL\n", i
);
154 p54u_info("pipe->urb == NULL\n");
161 p54u_info("pipe->size == NULL\n");
165 p54u_info("Clear the memory.\n");
167 memset(pipe
, 0, sizeof(*pipe
));
169 p54u_info("Freeing pipe done.\n");
174 static void p54u_free_buffers(struct net_device
*netdev
)
176 struct p54u
*p54u
= netdev_priv(netdev
);
177 struct usb_device
*usbdev
= p54u
->usbdev
;
179 p54u_free_pipe(netdev
, &p54u
->data_tx
);
180 p54u_free_pipe(netdev
, &p54u
->data_rx
);
181 p54u_free_pipe(netdev
, &p54u
->mgmt_tx
);
182 p54u_free_pipe(netdev
, &p54u
->mgmt_rx
);
183 p54u_free_pipe(netdev
, &p54u
->int_rx
);
188 static int p54u_reset_pipe(struct usb_device
*usbdev
, int addr
)
192 p54u_dbg("resetting pipe %02x", addr
);
197 err
= usb_clear_halt(usbdev
, usb_sndbulkpipe(usbdev
,addr
) );
199 case P54U_PIPE_BRG
| USB_DIR_IN
:
200 case P54U_PIPE_DATA
| USB_DIR_IN
:
201 case P54U_PIPE_MGMT
| USB_DIR_IN
:
202 err
= usb_clear_halt(usbdev
, usb_rcvbulkpipe(usbdev
,addr
) );
204 case P54U_PIPE_INT
| USB_DIR_IN
:
205 err
= usb_clear_halt(usbdev
, usb_rcvintpipe(usbdev
,addr
) );
213 static int p54u_reset_pipes(struct net_device
*netdev
)
215 struct p54u
*p54u
= netdev_priv(netdev
);
216 struct usb_device
*usbdev
= p54u
->usbdev
;
218 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_DEV
| USB_DIR_IN
);
219 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_DEV
);
220 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_BRG
| USB_DIR_IN
);
221 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_BRG
);
223 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_INT
| USB_DIR_IN
);
225 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_DATA
| USB_DIR_IN
);
226 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_DATA
);
227 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_MGMT
| USB_DIR_IN
);
228 (void) p54u_reset_pipe(usbdev
, P54U_PIPE_MGMT
);
233 static int p54u_alloc_pipe(struct net_device
*netdev
, struct usb_endpoint_descriptor
*desc
, struct p54u_pipe
*pipe
, usb_complete_t callback
)
235 struct p54u
*p54u
= netdev_priv(netdev
);
236 struct usb_device
*usbdev
= p54u
->usbdev
;
242 p54u_info("%s: Allocate pipe %02x, max pkt size is %02x\n", netdev
->name
, desc
->bEndpointAddress
, desc
->wMaxPacketSize
);
244 pipe
->pkt_size
= desc
->wMaxPacketSize
;
245 pipe
->type
= desc
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
;
246 pipe
->addr
= desc
->bEndpointAddress
;
247 pipe
->len
= P54U_QUEUE_LEN
;
249 pipe
->size
= kmalloc(sizeof(*pipe
->size
) * pipe
->len
, GFP_KERNEL
);
251 p54u_info("Failed to allocate pipe->size\n");
254 p54u_info("pipe->size == %p\n", pipe
->size
);
256 memset(pipe
->size
, 0, sizeof(*pipe
->size
) * pipe
->len
);
259 pipe
->urb
= kmalloc(sizeof(*pipe
->urb
) * pipe
->len
, GFP_KERNEL
);
261 p54u_info("Failed to allocate pipe->urb\n");
264 p54u_info("pipe->urb == %p\n", pipe
->urb
);
266 memset(pipe
->urb
, 0, sizeof(*pipe
->urb
) * pipe
->len
);
268 pipe
->buf
= kmalloc(sizeof(*pipe
->buf
) * pipe
->len
, GFP_KERNEL
);
270 p54u_info("Failed to allocate pipe->buf\n");
273 p54u_info("pipe->buf == %p\n", pipe
->buf
);
275 memset(pipe
->buf
, 0, sizeof(*pipe
->buf
) * pipe
->len
);
277 init_completion(&pipe
->comp
);
278 atomic_set(&pipe
->busy
, 0);
280 p54u_info("%s: Allocate buffers.\n", netdev
->name
);
282 for(i
= 0; i
< pipe
->len
; i
++) {
283 pipe
->size
[i
] = P54U_MAX_FRAME_SIZE
;
284 if(pipe
->type
== USB_ENDPOINT_XFER_INT
) {
288 p54u_info("pipe->size [%i] = %i\n", i
, pipe
->size
[i
]);
290 pipe
->urb
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
292 p54u_info("Failed to allocate pipe->urb[%i]\n", i
);
295 p54u_info("pipe->urb[%i] == %p\n", i
, pipe
->urb
[i
]);
297 pipe
->urb
[i
]->transfer_flags
= (URB_NO_TRANSFER_DMA_MAP
| URB_ASYNC_UNLINK
);
299 pipe
->buf
[i
] = usb_buffer_alloc(usbdev
, pipe
->size
[i
], GFP_KERNEL
, &pipe
->urb
[i
]->transfer_dma
);
301 p54u_info("Failed to allocate pipe->buf[%i]\n", i
);
304 p54u_info("pipe->buf[%i] == %p\n", i
, pipe
->buf
[i
]);
307 e
= pipe
->addr
& USB_ENDPOINT_NUMBER_MASK
;
308 p54u_info("pipe->addr = %i\n", e
);
311 case USB_ENDPOINT_XFER_BULK
:
312 p
= pipe
->addr
& USB_DIR_IN
? usb_rcvbulkpipe(usbdev
, e
) : usb_sndbulkpipe(usbdev
, e
);
313 usb_fill_bulk_urb(pipe
->urb
[i
], usbdev
, p
, pipe
->buf
[i
], pipe
->size
[i
], callback
, netdev
);
314 case USB_ENDPOINT_XFER_INT
:
315 p
= usb_rcvintpipe(usbdev
, e
);
316 usb_fill_int_urb(pipe
->urb
[i
], usbdev
, p
, pipe
->buf
[i
], pipe
->size
[i
], callback
, netdev
, 6);
317 // usb_fill_int_urb(pipe->urb[i], usbdev, p, pipe->buf[i], pipe->size[i], callback, netdev, HZ / 4);
318 // p = pipe->addr & USB_DIR_IN ? usb_rcvbulkpipe(usbdev, e) : usb_sndbulkpipe(usbdev, e);
319 // usb_fill_bulk_urb(pipe->urb[i], usbdev, p, pipe->buf[i], pipe->size[i], callback, netdev);
323 p54u_info("%s: Allocate pipe done.\n", netdev
->name
);
327 p54u_info("%s: Not enough memory.\n", netdev
->name
);
330 p54u_info("%s: Allocate pipe failed.\n", netdev
->name
);
334 static int p54u_alloc_buffers(struct net_device
*netdev
)
336 struct p54u
*p54u
= netdev_priv(netdev
);
337 struct usb_device
*usbdev
= p54u
->usbdev
;
338 struct usb_interface
*interface
= p54u
->interface
;
339 struct usb_host_interface
*iface_desc
= &interface
->altsetting
[0];
340 struct usb_endpoint_descriptor
*desc
;
341 struct p54u_pipe
*pipe
;
344 p54u_info("%s: Setup USB structures.\n", netdev
->name
);
346 for(i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
347 desc
= &iface_desc
->endpoint
[i
].desc
;
348 switch(desc
->bEndpointAddress
) {
350 err
= p54u_alloc_pipe(netdev
, desc
, &p54u
->data_tx
, NULL
);
353 err
= p54u_alloc_pipe(netdev
, desc
, &p54u
->mgmt_tx
, NULL
);
355 case P54U_PIPE_DATA
| USB_DIR_IN
:
356 err
= p54u_alloc_pipe(netdev
, desc
, &p54u
->data_rx
, p54u_data_rx_cb
);
358 case P54U_PIPE_MGMT
| USB_DIR_IN
:
359 err
= p54u_alloc_pipe(netdev
, desc
, &p54u
->mgmt_rx
, p54u_mgmt_rx_cb
);
361 case P54U_PIPE_INT
| USB_DIR_IN
:
362 err
= p54u_alloc_pipe(netdev
, desc
, &p54u
->int_rx
, p54u_int_rx_cb
);
370 p54u_info("%s: Setup USB structures successful.\n", netdev
->name
);
375 p54u_info("%s: Setup USB structures failed: %i\n", netdev
->name
, err
);
376 p54u_free_buffers(netdev
);
381 static int p54u_reset_dev(struct net_device
*netdev
)
383 struct p54u
*p54u
= netdev_priv(netdev
);
384 struct usb_device
*usbdev
= p54u
->usbdev
;
388 p54u_info("%s: Reset device.\n", netdev
->name
);
391 /* Reset the usb<->pci bridge */
392 p54u_dbg("%s: Reset bridge\n", netdev
->name
);
393 reg
= p54u_brg_readl(netdev
, NET2280_GPIOCTL
);
396 p54u_brg_writel(netdev
, NET2280_GPIOCTL
, (reg
| P54U_BRG_POWER_DOWN
) & ~P54U_BRG_POWER_UP
);
400 p54u_brg_writel(netdev
, NET2280_GPIOCTL
, (reg
| P54U_BRG_POWER_UP
) & ~P54U_BRG_POWER_DOWN
);
403 p54u_dbg("%s: Reset bridge done\n", netdev
->name
);
406 /* See 11.5.1 on net2280 doc */
407 p54u_dbg("%s: Magic 1\n", netdev
->name
);
408 p54u_brg_writel(netdev
, NET2280_DEVINIT
, NET2280_CLK_30Mhz
| NET2280_PCI_ENABLE
| NET2280_PCI_SOFT_RESET
);
411 p54u_dbg("%s: Magic 1 done\n", netdev
->name
);
414 /* Enable mmio and busmaster on the bridge */
415 p54u_dbg("%s: Setup bridge pci resources\n", netdev
->name
);
416 p54u_pcicfg_brg_writew(netdev
, PCI_COMMAND
, (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
));
418 /* Set base address 0 */
419 p54u_pcicfg_brg_writel(netdev
, PCI_BASE_ADDRESS_0
, NET2280_BASE
);
421 /* Set PCI_STATUS_REC_MASTER_ABORT (why?) */
422 reg
= p54u_pcicfg_brg_readw(netdev
, PCI_STATUS
);
423 p54u_pcicfg_brg_writew(netdev
, PCI_STATUS
, (reg
| PCI_STATUS_REC_MASTER_ABORT
));
426 revision
= p54u_brg_readl(netdev
, NET2280_RELNUM
);
427 p54u_dbg("%s: Setup bridge pci resources done\n", netdev
->name
);
430 p54u_dbg("%s: Magic 2\n", netdev
->name
);
431 p54u_brg_writel(netdev
, NET2280_EPA_RSP
, NET2280_CLEAR_NAK_OUT_PACKETS_MODE
);
432 p54u_brg_writel(netdev
, NET2280_EPC_RSP
, NET2280_CLEAR_NAK_OUT_PACKETS_MODE
);
433 p54u_dbg("%s: Magic 2 done\n", netdev
->name
);
435 /* Set base address 2 for bridge : where the endpoint fifos are */
436 p54u_dbg("%s: Setup bridge base addr 2\n", netdev
->name
);
437 p54u_pcicfg_brg_writel(netdev
, PCI_BASE_ADDRESS_2
, NET2280_BASE2
);
438 p54u_dbg("%s: Setup bridge base addr 2 done\n", netdev
->name
);
441 /* Enable mmio and busmaster on the device */
442 p54u_dbg("%s: Setup device pci resources\n", netdev
->name
);
443 p54u_pcicfg_dev_writew(netdev
, PCI_COMMAND
| 0x10000, (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
));
444 // p54u_pcicfg_dev_writew(netdev, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
446 /* Set TRDY_TIMEOUT and RETRY_TIMEOUT to 0 */
447 p54u_pcicfg_dev_writew(netdev
, P54U_TRDY_TIMEOUT
| 0x10000, 0);
448 // p54u_pcicfg_dev_writew(netdev, P54U_TRDY_TIMEOUT, 0);
450 /* Set base address 0 */
451 p54u_pcicfg_dev_writel(netdev
, PCI_BASE_ADDRESS_0
| 0x10000, P54U_DEV_BASE
);
452 // p54u_pcicfg_dev_writel(netdev, PCI_BASE_ADDRESS_0, P54U_DEV_BASE);
453 p54u_dbg("%s: Setup device pci resources done\n", netdev
->name
);
455 /* See 7.6.5.5 and chapter 9 of net2280 doc */
456 p54u_dbg("%s: Magic 3\n", netdev
->name
);
457 p54u_brg_writel(netdev
, NET2280_USBIRQENB1
, 0);
458 // p54u_brg_writel(netdev, NET2280_USBIRQENB1, NET2280_PCI_INTA_INTERRUPT_ENABLE | NET2280_USB_INTERRUPT_ENABLE);
459 p54u_brg_writel(netdev
, NET2280_IRQSTAT1
, NET2280_PCI_INTA_INTERRUPT
);
460 p54u_dbg("%s: Magic 3 done\n", netdev
->name
);
463 p54u_dbg("%s: Assert device\n", netdev
->name
);
464 p54u_dev_writel(netdev
, ISL38XX_DEV_INT_REG
, ISL38XX_DEV_INT_WAKEUP
);
469 /* (see old driver for INT_ABORT definition) */
470 p54u_dev_writel(netdev
, ISL38XX_DEV_INT_REG
, ISL38XX_DEV_INT_ABORT
);
473 p54u_dbg("%s: Assert device done\n", netdev
->name
);
476 /* Reset the device */
477 p54u_dbg("%s: Reset device\n", netdev
->name
);
479 /* clear the RAMBoot, the CLKRUN and the Reset bit */
480 reg
= p54u_dev_readl(netdev
, ISL38XX_CTRL_STAT_REG
);
481 // reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
482 reg
&= ~(ISL38XX_CTRL_STAT_RESET
| ISL38XX_CTRL_STAT_RAMBOOT
| ISL38XX_CTRL_STAT_CLKRUN
);
483 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
);
484 p54u_mdelay(20); /* WRITEIO_DELAY */
486 /* set the Reset bit without reading the register */
487 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
| ISL38XX_CTRL_STAT_RESET
);
488 p54u_mdelay(20); /* WRITEIO_DELAY */
489 /* clear the Reset bit */
490 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
);
494 p54u_dbg("%s: Reset device done\n", netdev
->name
);
495 /* wait for the device to reboot */
497 p54u_dbg("%s: Disable irq\n", netdev
->name
);
498 p54u_dev_writel(netdev
, ISL38XX_INT_EN_REG
, 0);
499 // p54u_dev_writel(netdev, ISL38XX_INT_EN_REG, 0x00004004);
500 p54u_dbg("%s: Disable irq done\n", netdev
->name
);
505 p54u_dbg("%s: Ack irq\n", netdev
->name
);
506 reg
= p54u_dev_readl(netdev
, ISL38XX_INT_IDENT_REG
);
507 p54u_dev_writel(netdev
, ISL38XX_INT_ACK_REG
, reg
);
510 p54u_dbg("%s: Ack done\n", netdev
->name
);
513 p54u_dbg("%s: Magic 4\n", netdev
->name
);
514 p54u_brg_writel(netdev
, NET2280_EPA_STAT
, NET2280_FIFO_FLUSH
);
515 p54u_brg_writel(netdev
, NET2280_EPB_STAT
, NET2280_FIFO_FLUSH
);
516 p54u_brg_writel(netdev
, NET2280_EPC_STAT
, NET2280_FIFO_FLUSH
);
517 p54u_brg_writel(netdev
, NET2280_EPD_STAT
, NET2280_FIFO_FLUSH
);
518 /* why this again ? */
519 p54u_brg_writel(netdev
, NET2280_EPA_STAT
, NET2280_FIFO_FLUSH
);
520 p54u_dbg("%s: Magic 4 done\n", netdev
->name
);
522 p54u_info("%s: Reset device done.\n", netdev
->name
);
527 p54u_err("%s: Reset error: %i\n", netdev
->name
, p54u
->err
);
533 static int p54u_load_firmware(struct net_device
*netdev
)
535 struct p54u
*p54u
= netdev_priv(netdev
);
536 struct usb_device
*usbdev
= p54u
->usbdev
;
547 p54u_info("%s: Load firmware.\n", netdev
->name
);
551 pipe
= usb_sndbulkpipe(usbdev
, P54U_PIPE_DATA
);
552 data
= p54u
->fw_entry
->data
;
553 i
= p54u
->fw_entry
->size
;
555 kmptr
= kmalloc(P54U_FW_BLOCK
, GFP_KERNEL
);
562 len
= i
> P54U_FW_BLOCK
? P54U_FW_BLOCK
: i
;
563 memcpy(kmptr
, data
, len
);
565 p54u
->err
= usb_bulk_msg(usbdev
, pipe
, kmptr
, len
, &retlen
, 10*HZ
);
569 p54u_dbg("Actually written %i of %i", retlen
, len
);
570 p54u_data_debug(netdev
, P54U_PIPE_DATA
, data
, len
);
573 p54u_dbg("%s: Error writing firmware block: writen %i of %i.\n", netdev
->name
, j
, p54u
->fw_entry
->size
);
577 data
+= P54U_FW_BLOCK
;
581 p54u_dev_writel(netdev
, ISL38XX_DIR_MEM_BASE_REG
, 0xc0000f00);
582 p54u_dev_writel(netdev
, 0x1020, 0);
583 p54u_dev_writel(netdev
, 0x1020, 1);
584 p54u_dev_writel(netdev
, 0x1024, len
);
585 p54u_dev_writel(netdev
, 0x1028, j
| 0x00020000);
586 p54u_dev_writel(netdev
, 0x0060, 0x20000000);
587 p54u_dev_writel(netdev
, 0x0064, len
/4);
588 p54u_dev_writel(netdev
, 0x0068, 4);
589 reg
= p54u_dev_readl(netdev
, 0x102c);
591 p54u_brg_writel(netdev
, NET2280_EPA_STAT
, NET2280_FIFO_FLUSH
);
593 p54u_dbg("%s: Error updating registers: writen %i of %i.\n", netdev
->name
, j
, p54u
->fw_entry
->size
);
600 reg
= p54u_dev_readl(netdev
, ISL38XX_CTRL_STAT_REG
);
601 // reg |= ISL38XX_CTRL_STAT_RAMBOOT | ISL38XX_CTRL_STAT_CLKRUN;
602 reg
|= ISL38XX_CTRL_STAT_RAMBOOT
;
603 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
);
604 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
| ISL38XX_CTRL_STAT_RESET
);
605 p54u_dev_writel(netdev
, ISL38XX_CTRL_STAT_REG
, reg
);
608 p54u_dbg("%s: Error latching reset: %i\n", netdev
->name
, p54u
->err
);
614 p54u_info("%s: Load firmware done.\n", netdev
->name
);
622 p54u_err("%s: Load error: %i\n", netdev
->name
, p54u
->err
);
628 int p54u_setup_dev(struct net_device
*netdev
)
630 struct p54u
*p54u
= netdev_priv(netdev
);
631 struct usb_device
*usbdev
= p54u
->usbdev
;
633 int i
, j
, k
, pending
, err
;
635 p54u
->err
= usb_submit_urb(p54u
->int_rx
.urb
[0], GFP_KERNEL
);
637 p54u_dbg("%s: Error submit int 0: %i\n", netdev
->name
, p54u
->err
);
639 p54u_dbg("%s: Submit int 0 ok.\n", netdev
->name
);
642 p54u
->err
= p54u_data_rx_submit(netdev
);
643 p54u
->err
= p54u_mgmt_rx_submit(netdev
);
646 //p54u_dev_writel(netdev, ISL38XX_INT_EN_REG, 0x80004004);
647 p54u_dev_writel(netdev
, ISL38XX_INT_EN_REG
, 0x00004004);
648 p54u_brg_writel(netdev
, NET2280_IRQSTAT1
, NET2280_PCI_INTA_INTERRUPT
);
649 p54u_brg_writel(netdev
, NET2280_USBIRQENB1
, NET2280_PCI_INTA_INTERRUPT_ENABLE
| NET2280_USB_INTERRUPT_ENABLE
);
650 p54u_dev_writel(netdev
, ISL38XX_DEV_INT_REG
, ISL38XX_DEV_INT_RESET
);
652 p54u_wait_int(netdev
);
656 int p54u_mgmt_readback(struct net_device
*netdev
)
658 struct p54u
*p54u
= netdev_priv(netdev
);
659 struct usb_device
*usbdev
= p54u
->usbdev
;
660 struct p54u_mgmt_tx1
*tx1
;
661 struct p54u_mgmt_tx2
*tx2
;
665 memset(p54u
->mgmt_tx
.buf
[0], 0, p54u
->mgmt_tx
.size
[0]);
666 memset(p54u
->mgmt_tx
.buf
[1], 0, p54u
->mgmt_tx
.size
[1]);
668 tx1
= p54u
->mgmt_tx
.buf
[0];
669 tx2
= p54u
->mgmt_tx
.buf
[1];
671 tx1
->magic1
= cpu_to_le32(0x02066c);
672 tx1
->magic2
= cpu_to_le16(0x2);
676 tx2
->magic1
= cpu_to_le16(0x8000);
677 /* The low bits of magic2 varies, i dont really know where the
679 // tx2->magic3 = cpu_to_le32(0xc);
680 tx2
->magic3
= cpu_to_le32(0xc);
682 i
= P54U_MGMT_MEM_SIZE
;
685 /* Each iteration will trigger a 0x82 pipe response */
687 /* those alternate between addresses of buffers... used by the windows driver, only. with ndiswrapper, this alternates between three values.
688 We can put here a value that will not be overwritten... and given bakc in the response packet */
689 tx2
->magic2
= cpu_to_le32(0);
692 len
= i
> P54U_INIT_BLOCK
? P54U_INIT_BLOCK
: i
;
694 /* announces to the device what the full length
695 of the next mgmt frame will be */
696 tx1
->len
= cpu_to_le16(len
+ sizeof(*tx2
) - sizeof(void*));
697 p54u_bulk_msg(netdev
, P54U_PIPE_MGMT
, tx1
, 16);
699 /* The +4 is for the length + pos field in p54u_mgmt_tx struct */
700 tx2
->len
= cpu_to_le16(len
+ 4);
701 tx2
->sub_len
= cpu_to_le16(len
);
702 tx2
->sub_pos
= cpu_to_le16(P54U_MGMT_MEM_SIZE
- i
);
704 /* The following two writes can be done concurrently */
705 p54u_mgmt_msg(netdev
, tx2
, len
+ sizeof(*tx2
) -sizeof(void*));
707 p54u_wait_mgmt_response(netdev
);
713 /* maybe check size ? Hum ? */
714 struct p54u_rx
* rxd
= p54u
->mgmt_rx
.urb
[0]->transfer_buffer
;
715 struct p54u_mgmt_tx2
*txd
= (struct p54u_mgmt_tx2
*) &rxd
->data
;
716 struct p54u_mgmt_rx_header
*mgmt_h
= (struct p54u_mgmt_rx_header
*) &txd
->data
;
717 struct p54u_mgmt_rx_frame
*mgmt
;
720 p54u_info("Storing mgm frame");
722 frame_offset
= le16_to_cpu(mgmt_h
->preamble_length
);
723 mgmt
= (struct p54u_mgmt_rx_frame
*) &(((u8
*)&(mgmt_h
->data
))[frame_offset
]);
724 memcpy(&p54u
->mgmt_frame
, (char*) mgmt
, sizeof(p54u
->mgmt_frame
));
725 memcpy(netdev
->dev_addr
, &mgmt
->mac_addr
, ETH_ALEN
);
728 p54u_mgmt_rx_submit(netdev
);
730 i
-= P54U_INIT_BLOCK
;
736 int p54u_readback_conf(struct net_device
*netdev
)
738 struct p54u
*p54u
= netdev_priv(netdev
);
741 a
= p54u_brg_readl(netdev
,NET2280_FIFOCTL
);
742 p54u_info("FIFOCTL : %08x",a
);
744 a
= p54u_brg_readl(netdev
,NET2280_EPA_CFG
);
745 p54u_info("EPA : %08x",a
);
747 a
= p54u_brg_readl(netdev
,NET2280_EPB_CFG
);
748 p54u_info("EPB : %08x",a
);
750 a
= p54u_brg_readl(netdev
,NET2280_EPC_CFG
);
751 p54u_info("EPC : %08x",a
);
753 a
= p54u_brg_readl(netdev
,NET2280_EPD_CFG
);
754 p54u_info("EPD : %08x",a
);
759 inline void make_rx_filter_packet(struct net_device
*netdev
, char* data
)
761 struct p54u_tx
*tx
= (struct p54u_tx
*) data
;
762 struct p54u_tx_control
*txc
= (struct p54u_tx_control
*) &tx
->data
;
763 struct p54u_tx_control_filter
*txcf
= (struct p54u_tx_control_filter
*) &txc
->data
;
766 memcpy(data
,p54u_data_filter
,FULL_TX_CONTROL_FILTER
);
767 printk("origin %p, int0 %p, int1 %p, int2 %p, destination %p", data
, tx
, txc
, txcf
, &txcf
->destination
[0]);
769 /* fill with ff:ff:ff:ff:ff:ff address */
770 for( i
= 0 ; i
< ETH_ALEN
; i
++)
771 txcf
->source
[i
] = 0xff;
773 memcpy(&txcf
->destination
[0],netdev
->dev_addr
,ETH_ALEN
);
778 static int p54u_set_filter(struct net_device
*netdev
)
780 struct p54u
*p54u
= netdev_priv(netdev
);
783 filter_packet
= kmalloc(FULL_TX_CONTROL_FILTER
, GFP_KERNEL
);
787 make_rx_filter_packet(netdev
, filter_packet
);
789 p54u_control_msg(netdev
, p54u_mode_send
, sizeof(p54u_mode_send
));
790 p54u_control_msg(netdev
, filter_packet
, FULL_TX_CONTROL_FILTER
);
791 p54u_control_msg(netdev
, p54u_mode_monitor
, sizeof(p54u_mode_monitor
));
796 int p54u_data_send(struct net_device
*netdev
)
798 struct p54u
*p54u
= netdev_priv(netdev
);
799 struct usb_device
*usbdev
= p54u
->usbdev
;
800 char *channel_packet
= 0;
803 channel_packet
=kmalloc(FULL_TX_CONTROL_CHANNEL
,GFP_KERNEL
);
807 /* submit initial data on data pipe */
808 p54u_control_msg(netdev
, p54u_data_packet1
, sizeof(p54u_data_packet1
));
809 /* p54u_control_msg(netdev, p54u_mode_send, sizeof(p54u_mode_send)); */
810 /* //p54u_control_msg(netdev, p54u_data_pkt_crc, sizeof(p54u_data_pkt_crc)); */
811 /* p54u_control_msg(netdev, p54u_data_filter, sizeof(p54u_data_filter)); */
812 /* p54u_control_msg(netdev, p54u_mode_monitor, sizeof(p54u_mode_monitor)); */
813 p54u_set_filter(netdev
);
815 /* cycle through the channels */
816 /* for ( i = 1 ; i <= P54U_NR_CHANNELS ; i++) */
818 /* make_tx_control_channel(p54u, channel_packet, i); */
819 /* p54u_control_msg(netdev, p54u_freqs[i-1], FULL_TX_CONTROL_CHANNEL); */
820 /* p54u_wait_data(netdev); */
826 int p54u_boot(struct net_device
*netdev
)
828 struct p54u
*p54u
= netdev_priv(netdev
);
831 p54u
->state
= P54U_BOOT
;
833 p54u_info("%s: Boot the device.\n", netdev
->name
);
835 p54u_dbg("%s: Request firmware.\n", netdev
->name
);
837 err
= request_firmware(&p54u
->fw_entry
, P54U_IMAGE_FILE
, netdev
->class_dev
.dev
);
839 p54u_err("%s: Request firmware failed: %i\n", netdev
->name
, err
);
843 p54u_dbg("%s: Request firmware done: len = %i.\n", netdev
->name
, p54u
->fw_entry
->size
);
845 p54u
->time
= get_jiffies_64();
847 INIT_WORK(&p54u
->int_ack
, p54u_int_ack
, netdev
);
848 INIT_WORK(&p54u
->data_bh
, p54u_data_rx
, netdev
);
850 /* will be overwritten in mgmt_readback */
851 memcpy(netdev
->dev_addr
, dummy_mac
, ETH_ALEN
);
853 err
= p54u_reset_usb(netdev
);
856 err
= p54u_alloc_buffers(netdev
);
858 err
= p54u_reset_dev(netdev
);
860 err
= p54u_load_firmware(netdev
);
862 err
= p54u_setup_dev(netdev
);
864 err
= p54u_mgmt_readback(netdev
);
866 // err = p54u_readback_conf(netdev);
867 /* dont do this yet, first generate properly channel freq change paquets */
870 err
= p54u_data_send(netdev
);
873 // err = p54u_reset_pipes(netdev);
875 /* err = p54u_reset_usb(netdev); */
878 // err = p54u_reset_dev(netdev);
880 /* err = p54u_load_firmware(netdev); */
882 /* err = p54u_setup_dev(netdev); */
884 /* err = p54u_mgmt_readback(netdev); */
887 /* err = p54u_data_send(netdev); */
890 release_firmware(p54u
->fw_entry
);
893 p54u
->state
= P54U_RUN
;
896 p54u_err("%s: Boot the device failed: %i\n", netdev
->name
, err
);
900 p54u_info("%s: Boot the device done.\n", netdev
->name
);
904 int p54u_shutdown(struct net_device
*netdev
)
906 struct p54u
*p54u
= netdev_priv(netdev
);
907 struct usb_device
*usbdev
= p54u
->usbdev
;
910 p54u_dbg("%s: Shutting down the device.\n", netdev
->name
);
912 /* so that the bottom halves wont resubmit urbs */
913 p54u
->state
= P54U_SHUTDOWN
;
915 p54u_free_buffers(netdev
);
916 /* now there's no way work will be scheduled again, so we can wait on the bh's. Wait is sufficient for now*/
921 // reg = p54u_brg_readl(netdev, P54U_BRG_CTRL_REG);
922 // p54u_brg_writel(netdev, P54U_BRG_CTRL_REG, (reg | P54U_BRG_POWER_DOWN) & ~P54U_BRG_POWER_UP);
923 // p54u_brg_writel(netdev, P54U_BRG_CTRL_REG, 0x3e);
926 p54u_dbg("%s: Shutdown complete.\n", netdev
->name
);
931 static int p54u_validate_device(struct usb_interface
*interface
, const struct usb_device_id
*id
)
933 /* See if the device offered us matches what we can accept */
938 static int p54u_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
940 struct usb_device
*usbdev
= interface_to_usbdev(interface
);
941 struct net_device
*netdev
;
945 p54u_dbg("Prism54 USB Device Probe (Device number:%d): 0x%4.4x:0x%4.4x:0x%4.4x", usbdev
->devnum
, (int) usbdev
->descriptor
.idVendor
, (int) usbdev
->descriptor
.idProduct
, (int) usbdev
->descriptor
.bcdDevice
);
946 p54u_dbg("Device at %p", usbdev
);
947 p54u_dbg("Descriptor length: %x type: %x", (int) usbdev
->descriptor
.bLength
, (int) usbdev
->descriptor
.bDescriptorType
);
949 if(p54u_validate_device(interface
, id
))
952 netdev
= alloc_etherdev(sizeof(*p54u
));
954 p54u_err("Failed to allocate netdevice.");
958 SET_MODULE_OWNER(netdev
);
959 SET_NETDEV_DEV(netdev
, &interface
->dev
);
961 usb_set_intfdata(interface
, netdev
);
963 p54u
= netdev_priv(netdev
);
964 p54u
->interface
= interface
;
965 p54u
->usbdev
= usbdev
;
966 p54u
->netdev
= netdev
;
968 init_MUTEX (&p54u
->disconnect_sem
);
969 memcpy(netdev
->dev_addr
, dummy_mac
, ETH_ALEN
);
972 /* Dont error if it fails, give it chance on open. */
975 if(p54u_setup_net(netdev
)) {
976 p54u_err("Failed to setup netdevice.");
980 if(register_netdev(netdev
)) {
981 p54u_err("Failed to register netdevice.");
985 p54u_info("Prism54 USB device now attached to %s", netdev
->name
);
989 p54u_free_buffers(netdev
);
990 usb_set_intfdata(interface
, NULL
);
996 static void p54u_disconnect(struct usb_interface
*interface
)
998 struct net_device
*netdev
= usb_get_intfdata(interface
);
999 struct p54u
*p54u
= netdev_priv(netdev
);
1000 struct usb_device
*usbdev
= p54u
->usbdev
;
1002 p54u_info("Prism54 USB device %s disconnecing\n", netdev
->name
);
1004 p54u_dbg("sem down\n");
1005 down(&p54u
->disconnect_sem
);
1006 p54u_dbg("sem down done\n");
1010 p54u_dbg("Running = 0.\n");
1012 usb_set_intfdata(interface
, NULL
);
1014 p54u_dbg("Cleared interface data.\n");
1016 unregister_netdev(netdev
);
1018 p54u_dbg("Unregistered netdevice.\n");
1020 p54u_free_buffers(netdev
);
1022 p54u_dbg("Freed buffers.\n");
1024 free_netdev(netdev
);
1026 p54u_dbg("Freed netdevice.\n");
1028 p54u_info("Disconnect complete.\n");
1030 p54u_dbg("sem up\n");
1031 up(&p54u
->disconnect_sem
);
1032 p54u_dbg("sem up done\n");
1035 static struct usb_driver p54u_driver
= {
1036 .owner
= THIS_MODULE
,
1037 .name
= driver_name
,
1038 .probe
= p54u_probe
,
1039 .disconnect
= p54u_disconnect
,
1040 .id_table
= p54u_table
,
1043 static int __init
p54u_init(void)
1047 /* register this driver with the USB subsystem */
1048 result
= usb_register(&p54u_driver
);
1050 p54u_err("usb_register failed. Error number %d", result
);
1057 static void __exit
p54u_exit(void)
1059 /* deregister this driver with the USB subsystem */
1060 usb_deregister(&p54u_driver
);
1063 module_init(p54u_init
);
1064 module_exit(p54u_exit
);