2 * IPWireless 3G PCMCIA Network Driver
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
18 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/kernel.h>
22 #include <linux/list.h>
23 #include <linux/slab.h>
26 #include "setup_protocol.h"
30 static void ipw_send_setup_packet(struct ipw_hardware *hw);
31 static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
33 unsigned char *data, int len,
35 static void ipwireless_setup_timer(unsigned long data);
36 static void handle_received_CTRL_packet(struct ipw_hardware *hw,
37 unsigned int channel_idx, unsigned char *data, int len);
39 /*#define TIMING_DIAGNOSTICS*/
41 #ifdef TIMING_DIAGNOSTICS
43 static struct timing_stats {
44 unsigned long last_report_time;
45 unsigned long read_time;
46 unsigned long write_time;
47 unsigned long read_bytes;
48 unsigned long write_bytes;
49 unsigned long start_time;
52 static void start_timing(void)
54 timing_stats.start_time = jiffies;
57 static void end_read_timing(unsigned length)
59 timing_stats.read_time += (jiffies - start_time);
60 timing_stats.read_bytes += length + 2;
64 static void end_write_timing(unsigned length)
66 timing_stats.write_time += (jiffies - start_time);
67 timing_stats.write_bytes += length + 2;
71 static void report_timing(void)
73 unsigned long since = jiffies - timing_stats.last_report_time;
75 /* If it's been more than one second... */
77 int first = (timing_stats.last_report_time == 0);
79 timing_stats.last_report_time = jiffies;
81 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
82 ": %u us elapsed - read %lu bytes in %u us, "
83 "wrote %lu bytes in %u us\n",
84 jiffies_to_usecs(since),
85 timing_stats.read_bytes,
86 jiffies_to_usecs(timing_stats.read_time),
87 timing_stats.write_bytes,
88 jiffies_to_usecs(timing_stats.write_time));
90 timing_stats.read_time = 0;
91 timing_stats.write_time = 0;
92 timing_stats.read_bytes = 0;
93 timing_stats.write_bytes = 0;
97 static void start_timing(void) { }
98 static void end_read_timing(unsigned length) { }
99 static void end_write_timing(unsigned length) { }
102 /* Imported IPW definitions */
104 #define LL_MTU_V1 318
105 #define LL_MTU_V2 250
106 #define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
113 #define ADDR_SETUP_PROT 0
117 /* Identifier for the Com Data protocol */
118 TL_PROTOCOLID_COM_DATA = 0,
120 /* Identifier for the Com Control protocol */
121 TL_PROTOCOLID_COM_CTRL = 1,
123 /* Identifier for the Setup protocol */
124 TL_PROTOCOLID_SETUP = 2
127 /* Number of bytes in NL packet header (cannot do
128 * sizeof(nl_packet_header) since it's a bitfield) */
129 #define NL_FIRST_PACKET_HEADER_SIZE 3
131 /* Number of bytes in NL packet header (cannot do
132 * sizeof(nl_packet_header) since it's a bitfield) */
133 #define NL_FOLLOWING_PACKET_HEADER_SIZE 1
135 struct nl_first_packet_header {
136 #if defined(__BIG_ENDIAN_BITFIELD)
137 unsigned char packet_rank:2;
138 unsigned char address:3;
139 unsigned char protocol:3;
141 unsigned char protocol:3;
142 unsigned char address:3;
143 unsigned char packet_rank:2;
145 unsigned char length_lsb;
146 unsigned char length_msb;
149 struct nl_packet_header {
150 #if defined(__BIG_ENDIAN_BITFIELD)
151 unsigned char packet_rank:2;
152 unsigned char address:3;
153 unsigned char protocol:3;
155 unsigned char protocol:3;
156 unsigned char address:3;
157 unsigned char packet_rank:2;
161 /* Value of 'packet_rank' above */
162 #define NL_INTERMEDIATE_PACKET 0x0
163 #define NL_LAST_PACKET 0x1
164 #define NL_FIRST_PACKET 0x2
167 /* Network packet header of the first packet (a special case) */
168 struct nl_first_packet_header hdr_first;
169 /* Network packet header of the following packets (if any) */
170 struct nl_packet_header hdr;
171 /* Complete network packet (header + data) */
172 unsigned char rawpkt[LL_MTU_MAX];
173 } __attribute__ ((__packed__));
175 #define HW_VERSION_UNKNOWN -1
176 #define HW_VERSION_1 1
177 #define HW_VERSION_2 2
180 #define IOIER 0x00 /* Interrupt Enable Register */
181 #define IOIR 0x02 /* Interrupt Source/ACK register */
182 #define IODCR 0x04 /* Data Control Register */
183 #define IODRR 0x06 /* Data Read Register */
184 #define IODWR 0x08 /* Data Write Register */
185 #define IOESR 0x0A /* Embedded Driver Status Register */
186 #define IORXR 0x0C /* Rx Fifo Register (Host to Embedded) */
187 #define IOTXR 0x0E /* Tx Fifo Register (Embedded to Host) */
189 /* I/O ports and bit definitions for version 1 of the hardware */
192 #define IER_RXENABLED 0x1
193 #define IER_TXENABLED 0x2
196 #define IR_RXINTR 0x1
197 #define IR_TXINTR 0x2
200 #define DCR_RXDONE 0x1
201 #define DCR_TXDONE 0x2
202 #define DCR_RXRESET 0x4
203 #define DCR_TXRESET 0x8
205 /* I/O ports and bit definitions for version 2 of the hardware */
208 unsigned short reg_config_option; /* PCCOR: Configuration Option Register */
209 unsigned short reg_config_and_status; /* PCCSR: Configuration and Status Register */
210 unsigned short reg_pin_replacement; /* PCPRR: Pin Replacemant Register */
211 unsigned short reg_socket_and_copy; /* PCSCR: Socket and Copy Register */
212 unsigned short reg_ext_status; /* PCESR: Extendend Status Register */
213 unsigned short reg_io_base; /* PCIOB: I/O Base Register */
217 unsigned short memreg_tx_old; /* TX Register (R/W) */
219 unsigned short memreg_rx_done; /* RXDone Register (R/W) */
221 unsigned short memreg_rx; /* RX Register (R/W) */
223 unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
225 unsigned long memreg_card_present;/* Mask for Host to check (R) for
226 * CARD_PRESENT_VALUE */
227 unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
230 #define IODMADPR 0x00 /* DMA Data Port Register (R/W) */
232 #define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
234 #define MEMTX_TX 0x0001
235 #define MEMRX_RX 0x0001
236 #define MEMRX_RX_DONE 0x0001
237 #define MEMRX_PCINTACKK 0x0001
238 #define MEMRX_MEMSPURIOUSINT 0x0001
240 #define NL_NUM_OF_PRIORITIES 3
241 #define NL_NUM_OF_PROTOCOLS 3
242 #define NL_NUM_OF_ADDRESSES NO_OF_IPW_CHANNELS
244 struct ipw_hardware {
245 unsigned int base_port;
247 unsigned short ll_mtu;
252 struct timer_list setup_timer;
255 struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
256 /* True if any packets are queued for transmission */
260 struct list_head rx_queue;
261 /* Pool of rx_packet structures that are not currently used. */
262 struct list_head rx_pool;
264 /* True if reception of data is blocked while userspace processes it. */
266 /* True if there is RX data ready on the hardware. */
268 unsigned short last_memtx_serial;
270 * Newer versions of the V2 card firmware send serial numbers in the
271 * MemTX register. 'serial_number_detected' is set true when we detect
272 * a non-zero serial number (indicating the new firmware). Thereafter,
273 * the driver can safely ignore the Timer Recovery re-sends to avoid
274 * out-of-sync problems.
276 int serial_number_detected;
277 struct work_struct work_rx;
279 /* True if we are to send the set-up data to the hardware. */
282 /* Card has been removed */
284 /* Saved irq value when we disable the interrupt. */
286 /* True if this driver is shutting down. */
288 /* Modem control lines */
289 unsigned int control_lines[NL_NUM_OF_ADDRESSES];
290 struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
292 struct tasklet_struct tasklet;
294 /* The handle for the network layer, for the sending of events to it. */
295 struct ipw_network *network;
296 struct MEMINFREG __iomem *memory_info_regs;
297 struct MEMCCR __iomem *memregs_CCR;
298 void (*reboot_callback) (void *data);
299 void *reboot_callback_data;
301 unsigned short __iomem *memreg_tx;
305 * Packet info structure for tx packets.
306 * Note: not all the fields defined here are required for all protocols
308 struct ipw_tx_packet {
309 struct list_head queue;
310 /* channel idx + 1 */
311 unsigned char dest_addr;
312 /* SETUP, CTRL or DATA */
313 unsigned char protocol;
314 /* Length of data block, which starts at the end of this structure */
315 unsigned short length;
317 /* Offset of where we've sent up to so far */
318 unsigned long offset;
319 /* Count of packet fragments, starting at 0 */
322 /* Called after packet is sent and before is freed */
323 void (*packet_callback) (void *cb_data, unsigned int packet_length);
327 /* Signals from DTE */
328 #define COMCTRL_RTS 0
329 #define COMCTRL_DTR 1
331 /* Signals from DCE */
332 #define COMCTRL_CTS 2
333 #define COMCTRL_DCD 3
334 #define COMCTRL_DSR 4
337 struct ipw_control_packet_body {
338 /* DTE signal or DCE signal */
339 unsigned char sig_no;
340 /* 0: set signal, 1: clear signal */
342 } __attribute__ ((__packed__));
344 struct ipw_control_packet {
345 struct ipw_tx_packet header;
346 struct ipw_control_packet_body body;
349 struct ipw_rx_packet {
350 struct list_head queue;
351 unsigned int capacity;
353 unsigned int protocol;
354 unsigned int channel_idx;
357 static char *data_type(const unsigned char *buf, unsigned length)
359 struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
364 if (hdr->packet_rank & NL_FIRST_PACKET) {
365 switch (hdr->protocol) {
366 case TL_PROTOCOLID_COM_DATA: return "DATA ";
367 case TL_PROTOCOLID_COM_CTRL: return "CTRL ";
368 case TL_PROTOCOLID_SETUP: return "SETUP";
369 default: return "???? ";
375 #define DUMP_MAX_BYTES 64
377 static void dump_data_bytes(const char *type, const unsigned char *data,
382 sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
383 type, data_type(data, length));
384 print_hex_dump_bytes(prefix, 0, (void *)data,
385 length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
388 static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
399 if (length > hw->ll_mtu)
402 if (ipwireless_debug)
403 dump_data_bytes("send", data, length);
405 spin_lock_irqsave(&hw->spinlock, flags);
407 if (hw->hw_version == HW_VERSION_1) {
408 outw((unsigned short) length, hw->base_port + IODWR);
410 for (i = 0; i < length; i += 2) {
411 unsigned short d = data[i];
414 if (likely(i + 1 < length))
415 d |= data[i + 1] << 8;
416 raw_data = cpu_to_le16(d);
417 outw(raw_data, hw->base_port + IODWR);
420 outw(DCR_TXDONE, hw->base_port + IODCR);
421 } else if (hw->hw_version == HW_VERSION_2) {
422 outw((unsigned short) length, hw->base_port + IODMADPR);
424 for (i = 0; i < length; i += 2) {
425 unsigned short d = data[i];
428 if ((i + 1 < length))
429 d |= data[i + 1] << 8;
430 raw_data = cpu_to_le16(d);
431 outw(raw_data, hw->base_port + IODMADPR);
433 while ((i & 3) != 2) {
434 outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR);
437 writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
440 spin_unlock_irqrestore(&hw->spinlock, flags);
442 end_write_timing(length);
447 static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
449 unsigned short fragment_data_len;
450 unsigned short data_left = packet->length - packet->offset;
451 unsigned short header_size;
455 (packet->fragment_count == 0)
456 ? NL_FIRST_PACKET_HEADER_SIZE
457 : NL_FOLLOWING_PACKET_HEADER_SIZE;
458 fragment_data_len = hw->ll_mtu - header_size;
459 if (data_left < fragment_data_len)
460 fragment_data_len = data_left;
462 pkt.hdr_first.protocol = packet->protocol;
463 pkt.hdr_first.address = packet->dest_addr;
464 pkt.hdr_first.packet_rank = 0;
467 if (packet->fragment_count == 0) {
468 pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
469 pkt.hdr_first.length_lsb = (unsigned char) packet->length;
470 pkt.hdr_first.length_msb =
471 (unsigned char) (packet->length >> 8);
474 memcpy(pkt.rawpkt + header_size,
475 ((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
476 packet->offset, fragment_data_len);
477 packet->offset += fragment_data_len;
478 packet->fragment_count++;
480 /* Last packet? (May also be first packet.) */
481 if (packet->offset == packet->length)
482 pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
483 do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
485 /* If this packet has unsent data, then re-queue it. */
486 if (packet->offset < packet->length) {
488 * Re-queue it at the head of the highest priority queue so
489 * it goes before all other packets
493 spin_lock_irqsave(&hw->spinlock, flags);
494 list_add(&packet->queue, &hw->tx_queue[0]);
495 spin_unlock_irqrestore(&hw->spinlock, flags);
497 if (packet->packet_callback)
498 packet->packet_callback(packet->callback_data,
506 static void ipw_setup_hardware(struct ipw_hardware *hw)
510 spin_lock_irqsave(&hw->spinlock, flags);
511 if (hw->hw_version == HW_VERSION_1) {
513 outw(DCR_RXRESET, hw->base_port + IODCR);
514 /* SB: Reset TX FIFO */
515 outw(DCR_TXRESET, hw->base_port + IODCR);
517 /* Enable TX and RX interrupts. */
518 outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
521 * Set INTRACK bit (bit 0), which means we must explicitly
522 * acknowledge interrupts by clearing bit 2 of reg_config_and_status.
524 unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
527 writew(csr, &hw->memregs_CCR->reg_config_and_status);
529 spin_unlock_irqrestore(&hw->spinlock, flags);
533 * If 'packet' is NULL, then this function allocates a new packet, setting its
534 * length to 0 and ensuring it has the specified minimum amount of free space.
536 * If 'packet' is not NULL, then this function enlarges it if it doesn't
537 * have the specified minimum amount of free space.
540 static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
541 struct ipw_rx_packet *packet,
542 int minimum_free_space)
549 * If this is the first fragment, then we will need to fetch a
550 * packet to put it in.
552 spin_lock_irqsave(&hw->spinlock, flags);
553 /* If we have one in our pool, then pull it out. */
554 if (!list_empty(&hw->rx_pool)) {
555 packet = list_first_entry(&hw->rx_pool,
556 struct ipw_rx_packet, queue);
557 list_del(&packet->queue);
559 spin_unlock_irqrestore(&hw->spinlock, flags);
561 /* Otherwise allocate a new one. */
562 static int min_capacity = 256;
565 spin_unlock_irqrestore(&hw->spinlock, flags);
567 minimum_free_space > min_capacity
570 packet = kmalloc(sizeof(struct ipw_rx_packet)
571 + new_capacity, GFP_ATOMIC);
574 packet->capacity = new_capacity;
580 * If this packet does not have sufficient capacity for the data we
581 * want to add, then make it bigger.
583 if (packet->length + minimum_free_space > packet->capacity) {
584 struct ipw_rx_packet *old_packet = packet;
586 packet = kmalloc(sizeof(struct ipw_rx_packet) +
587 old_packet->length + minimum_free_space,
591 memcpy(packet, old_packet,
592 sizeof(struct ipw_rx_packet)
593 + old_packet->length);
594 packet->capacity = old_packet->length + minimum_free_space;
601 static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
603 if (hw->rx_pool_size > 6)
607 list_add_tail(&packet->queue, &hw->rx_pool);
611 static void queue_received_packet(struct ipw_hardware *hw,
612 unsigned int protocol, unsigned int address,
613 unsigned char *data, int length, int is_last)
615 unsigned int channel_idx = address - 1;
616 struct ipw_rx_packet *packet = NULL;
619 /* Discard packet if channel index is out of range. */
620 if (channel_idx >= NL_NUM_OF_ADDRESSES) {
621 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
622 ": data packet has bad address %u\n", address);
627 * ->packet_assembler is safe to touch unlocked, this is the only place
629 if (protocol == TL_PROTOCOLID_COM_DATA) {
630 struct ipw_rx_packet **assem =
631 &hw->packet_assembler[channel_idx];
634 * Create a new packet, or assembler already contains one
635 * enlarge it by 'length' bytes.
637 (*assem) = pool_allocate(hw, *assem, length);
639 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
640 ": no memory for incomming data packet, dropped!\n");
643 (*assem)->protocol = protocol;
644 (*assem)->channel_idx = channel_idx;
646 /* Append this packet data onto existing data. */
647 memcpy((unsigned char *)(*assem) +
648 sizeof(struct ipw_rx_packet)
649 + (*assem)->length, data, length);
650 (*assem)->length += length;
654 /* Count queued DATA bytes only */
655 spin_lock_irqsave(&hw->spinlock, flags);
656 hw->rx_bytes_queued += packet->length;
657 spin_unlock_irqrestore(&hw->spinlock, flags);
660 /* If it's a CTRL packet, don't assemble, just queue it. */
661 packet = pool_allocate(hw, NULL, length);
663 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
664 ": no memory for incomming ctrl packet, dropped!\n");
667 packet->protocol = protocol;
668 packet->channel_idx = channel_idx;
669 memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
671 packet->length = length;
675 * If this is the last packet, then send the assembled packet on to the
679 spin_lock_irqsave(&hw->spinlock, flags);
680 list_add_tail(&packet->queue, &hw->rx_queue);
681 /* Block reception of incoming packets if queue is full. */
683 hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
685 spin_unlock_irqrestore(&hw->spinlock, flags);
686 schedule_work(&hw->work_rx);
693 static void ipw_receive_data_work(struct work_struct *work_rx)
695 struct ipw_hardware *hw =
696 container_of(work_rx, struct ipw_hardware, work_rx);
699 spin_lock_irqsave(&hw->spinlock, flags);
700 while (!list_empty(&hw->rx_queue)) {
701 struct ipw_rx_packet *packet =
702 list_first_entry(&hw->rx_queue,
703 struct ipw_rx_packet, queue);
705 if (hw->shutting_down)
707 list_del(&packet->queue);
710 * Note: ipwireless_network_packet_received must be called in a
711 * process context (i.e. via schedule_work) because the tty
712 * output code can sleep in the tty_flip_buffer_push call.
714 if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
715 if (hw->network != NULL) {
716 /* If the network hasn't been disconnected. */
717 spin_unlock_irqrestore(&hw->spinlock, flags);
719 * This must run unlocked due to tty processing
722 ipwireless_network_packet_received(
725 (unsigned char *)packet
726 + sizeof(struct ipw_rx_packet),
728 spin_lock_irqsave(&hw->spinlock, flags);
730 /* Count queued DATA bytes only */
731 hw->rx_bytes_queued -= packet->length;
734 * This is safe to be called locked, callchain does
737 handle_received_CTRL_packet(hw, packet->channel_idx,
738 (unsigned char *)packet
739 + sizeof(struct ipw_rx_packet),
742 pool_free(hw, packet);
744 * Unblock reception of incoming packets if queue is no longer
748 hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
749 if (hw->shutting_down)
752 spin_unlock_irqrestore(&hw->spinlock, flags);
755 static void handle_received_CTRL_packet(struct ipw_hardware *hw,
756 unsigned int channel_idx,
757 unsigned char *data, int len)
759 struct ipw_control_packet_body *body =
760 (struct ipw_control_packet_body *) data;
761 unsigned int changed_mask;
763 if (len != sizeof(struct ipw_control_packet_body)) {
764 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
765 ": control packet was %d bytes - wrong size!\n",
770 switch (body->sig_no) {
772 changed_mask = IPW_CONTROL_LINE_CTS;
775 changed_mask = IPW_CONTROL_LINE_DCD;
778 changed_mask = IPW_CONTROL_LINE_DSR;
781 changed_mask = IPW_CONTROL_LINE_RI;
787 if (changed_mask != 0) {
789 hw->control_lines[channel_idx] |= changed_mask;
791 hw->control_lines[channel_idx] &= ~changed_mask;
793 ipwireless_network_notify_control_line_change(
796 hw->control_lines[channel_idx],
801 static void handle_received_packet(struct ipw_hardware *hw,
802 union nl_packet *packet,
805 unsigned int protocol = packet->hdr.protocol;
806 unsigned int address = packet->hdr.address;
807 unsigned int header_length;
809 unsigned int data_len;
810 int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
812 if (packet->hdr.packet_rank & NL_FIRST_PACKET)
813 header_length = NL_FIRST_PACKET_HEADER_SIZE;
815 header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
817 data = packet->rawpkt + header_length;
818 data_len = len - header_length;
820 case TL_PROTOCOLID_COM_DATA:
821 case TL_PROTOCOLID_COM_CTRL:
822 queue_received_packet(hw, protocol, address, data, data_len,
825 case TL_PROTOCOLID_SETUP:
826 handle_received_SETUP_packet(hw, address, data, data_len,
832 static void acknowledge_data_read(struct ipw_hardware *hw)
834 if (hw->hw_version == HW_VERSION_1)
835 outw(DCR_RXDONE, hw->base_port + IODCR);
837 writew(MEMRX_PCINTACKK,
838 &hw->memory_info_regs->memreg_pc_interrupt_ack);
842 * Retrieve a packet from the IPW hardware.
844 static void do_receive_packet(struct ipw_hardware *hw)
848 unsigned char pkt[LL_MTU_MAX];
852 if (hw->hw_version == HW_VERSION_1) {
853 len = inw(hw->base_port + IODRR);
854 if (len > hw->ll_mtu) {
855 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
856 ": received a packet of %u bytes - "
857 "longer than the MTU!\n", len);
858 outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
862 for (i = 0; i < len; i += 2) {
863 __le16 raw_data = inw(hw->base_port + IODRR);
864 unsigned short data = le16_to_cpu(raw_data);
866 pkt[i] = (unsigned char) data;
867 pkt[i + 1] = (unsigned char) (data >> 8);
870 len = inw(hw->base_port + IODMADPR);
871 if (len > hw->ll_mtu) {
872 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
873 ": received a packet of %u bytes - "
874 "longer than the MTU!\n", len);
875 writew(MEMRX_PCINTACKK,
876 &hw->memory_info_regs->memreg_pc_interrupt_ack);
880 for (i = 0; i < len; i += 2) {
881 __le16 raw_data = inw(hw->base_port + IODMADPR);
882 unsigned short data = le16_to_cpu(raw_data);
884 pkt[i] = (unsigned char) data;
885 pkt[i + 1] = (unsigned char) (data >> 8);
888 while ((i & 3) != 2) {
889 inw(hw->base_port + IODMADPR);
894 acknowledge_data_read(hw);
896 if (ipwireless_debug)
897 dump_data_bytes("recv", pkt, len);
899 handle_received_packet(hw, (union nl_packet *) pkt, len);
901 end_read_timing(len);
904 static int get_current_packet_priority(struct ipw_hardware *hw)
907 * If we're initializing, don't send anything of higher priority than
908 * PRIO_SETUP. The network layer therefore need not care about
909 * hardware initialization - any of its stuff will simply be queued
910 * until setup is complete.
912 return (hw->to_setup || hw->initializing
914 NL_NUM_OF_PRIORITIES);
918 * return 1 if something has been received from hw
920 static int get_packets_from_hw(struct ipw_hardware *hw)
925 spin_lock_irqsave(&hw->spinlock, flags);
926 while (hw->rx_ready && !hw->blocking_rx) {
929 spin_unlock_irqrestore(&hw->spinlock, flags);
931 do_receive_packet(hw);
933 spin_lock_irqsave(&hw->spinlock, flags);
935 spin_unlock_irqrestore(&hw->spinlock, flags);
941 * Send pending packet up to given priority, prioritize SETUP data until
942 * hardware is fully setup.
944 * return 1 if more packets can be sent
946 static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
948 int more_to_send = 0;
951 spin_lock_irqsave(&hw->spinlock, flags);
952 if (hw->tx_queued && hw->tx_ready != 0) {
954 struct ipw_tx_packet *packet = NULL;
959 for (priority = 0; priority < priority_limit; priority++) {
960 if (!list_empty(&hw->tx_queue[priority])) {
961 packet = list_first_entry(
962 &hw->tx_queue[priority],
963 struct ipw_tx_packet,
966 list_del(&packet->queue);
973 spin_unlock_irqrestore(&hw->spinlock, flags);
976 spin_unlock_irqrestore(&hw->spinlock, flags);
979 do_send_packet(hw, packet);
981 /* Check if more to send */
982 spin_lock_irqsave(&hw->spinlock, flags);
983 for (priority = 0; priority < priority_limit; priority++)
984 if (!list_empty(&hw->tx_queue[priority])) {
992 spin_unlock_irqrestore(&hw->spinlock, flags);
998 * Send and receive all queued packets.
1000 static void ipwireless_do_tasklet(unsigned long hw_)
1002 struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
1003 unsigned long flags;
1005 spin_lock_irqsave(&hw->spinlock, flags);
1006 if (hw->shutting_down) {
1007 spin_unlock_irqrestore(&hw->spinlock, flags);
1011 if (hw->to_setup == 1) {
1013 * Initial setup data sent to hardware
1016 spin_unlock_irqrestore(&hw->spinlock, flags);
1018 ipw_setup_hardware(hw);
1019 ipw_send_setup_packet(hw);
1021 send_pending_packet(hw, PRIO_SETUP + 1);
1022 get_packets_from_hw(hw);
1024 int priority_limit = get_current_packet_priority(hw);
1027 spin_unlock_irqrestore(&hw->spinlock, flags);
1030 again = send_pending_packet(hw, priority_limit);
1031 again |= get_packets_from_hw(hw);
1037 * return true if the card is physically present.
1039 static int is_card_present(struct ipw_hardware *hw)
1041 if (hw->hw_version == HW_VERSION_1)
1042 return inw(hw->base_port + IOIR) != 0xFFFF;
1044 return readl(&hw->memory_info_regs->memreg_card_present) ==
1048 static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
1049 struct ipw_hardware *hw)
1051 unsigned short irqn;
1053 irqn = inw(hw->base_port + IOIR);
1055 /* Check if card is present */
1058 else if (irqn != 0) {
1059 unsigned short ack = 0;
1060 unsigned long flags;
1062 /* Transmit complete. */
1063 if (irqn & IR_TXINTR) {
1065 spin_lock_irqsave(&hw->spinlock, flags);
1067 spin_unlock_irqrestore(&hw->spinlock, flags);
1070 if (irqn & IR_RXINTR) {
1072 spin_lock_irqsave(&hw->spinlock, flags);
1074 spin_unlock_irqrestore(&hw->spinlock, flags);
1077 outw(ack, hw->base_port + IOIR);
1078 tasklet_schedule(&hw->tasklet);
1085 static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
1087 unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
1090 writew(csr, &hw->memregs_CCR->reg_config_and_status);
1093 static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1094 struct ipw_hardware *hw)
1100 unsigned long flags;
1104 unsigned short memtx = readw(hw->memreg_tx);
1105 unsigned short memtx_serial;
1106 unsigned short memrxdone =
1107 readw(&hw->memory_info_regs->memreg_rx_done);
1111 /* check whether the interrupt was generated by ipwireless card */
1112 if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
1114 /* check if the card uses memreg_tx_old register */
1115 if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1116 memtx = readw(&hw->memory_info_regs->memreg_tx_old);
1117 if (memtx & MEMTX_TX) {
1118 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1119 ": Using memreg_tx_old\n");
1121 &hw->memory_info_regs->memreg_tx_old;
1131 * See if the card is physically present. Note that while it is
1132 * powering up, it appears not to be present.
1134 if (!is_card_present(hw)) {
1135 acknowledge_pcmcia_interrupt(hw);
1139 memtx_serial = memtx & (unsigned short) 0xff00;
1140 if (memtx & MEMTX_TX) {
1141 writew(memtx_serial, hw->memreg_tx);
1143 if (hw->serial_number_detected) {
1144 if (memtx_serial != hw->last_memtx_serial) {
1145 hw->last_memtx_serial = memtx_serial;
1146 spin_lock_irqsave(&hw->spinlock, flags);
1148 spin_unlock_irqrestore(&hw->spinlock, flags);
1151 /* Ignore 'Timer Recovery' duplicates. */
1155 * If a non-zero serial number is seen, then enable
1156 * serial number checking.
1158 if (memtx_serial != 0) {
1159 hw->serial_number_detected = 1;
1160 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1161 ": memreg_tx serial num detected\n");
1163 spin_lock_irqsave(&hw->spinlock, flags);
1165 spin_unlock_irqrestore(&hw->spinlock, flags);
1170 if (memrxdone & MEMRX_RX_DONE) {
1171 writew(0, &hw->memory_info_regs->memreg_rx_done);
1172 spin_lock_irqsave(&hw->spinlock, flags);
1174 spin_unlock_irqrestore(&hw->spinlock, flags);
1178 writew(MEMRX_PCINTACKK,
1179 &hw->memory_info_regs->memreg_pc_interrupt_ack);
1181 acknowledge_pcmcia_interrupt(hw);
1184 tasklet_schedule(&hw->tasklet);
1185 else if (!rx_repeat) {
1186 if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1187 if (hw->serial_number_detected)
1188 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1189 ": spurious interrupt - new_tx mode\n");
1191 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1192 ": no valid memreg_tx value - "
1193 "switching to the old memreg_tx\n");
1195 &hw->memory_info_regs->memreg_tx_old;
1199 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1200 ": spurious interrupt - old_tx mode\n");
1203 } while (try_mem_tx_old == 1);
1208 irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1210 struct ipw_hardware *hw = dev_id;
1212 if (hw->hw_version == HW_VERSION_1)
1213 return ipwireless_handle_v1_interrupt(irq, hw);
1215 return ipwireless_handle_v2_v3_interrupt(irq, hw);
1218 static void flush_packets_to_hw(struct ipw_hardware *hw)
1221 unsigned long flags;
1223 spin_lock_irqsave(&hw->spinlock, flags);
1224 priority_limit = get_current_packet_priority(hw);
1225 spin_unlock_irqrestore(&hw->spinlock, flags);
1227 while (send_pending_packet(hw, priority_limit));
1230 static void send_packet(struct ipw_hardware *hw, int priority,
1231 struct ipw_tx_packet *packet)
1233 unsigned long flags;
1235 spin_lock_irqsave(&hw->spinlock, flags);
1236 list_add_tail(&packet->queue, &hw->tx_queue[priority]);
1238 spin_unlock_irqrestore(&hw->spinlock, flags);
1240 flush_packets_to_hw(hw);
1243 /* Create data packet, non-atomic allocation */
1244 static void *alloc_data_packet(int data_size,
1245 unsigned char dest_addr,
1246 unsigned char protocol)
1248 struct ipw_tx_packet *packet = kzalloc(
1249 sizeof(struct ipw_tx_packet) + data_size,
1255 INIT_LIST_HEAD(&packet->queue);
1256 packet->dest_addr = dest_addr;
1257 packet->protocol = protocol;
1258 packet->length = data_size;
1263 static void *alloc_ctrl_packet(int header_size,
1264 unsigned char dest_addr,
1265 unsigned char protocol,
1266 unsigned char sig_no)
1269 * sig_no is located right after ipw_tx_packet struct in every
1270 * CTRL or SETUP packets, we can use ipw_control_packet as a
1273 struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
1278 INIT_LIST_HEAD(&packet->header.queue);
1279 packet->header.dest_addr = dest_addr;
1280 packet->header.protocol = protocol;
1281 packet->header.length = header_size - sizeof(struct ipw_tx_packet);
1282 packet->body.sig_no = sig_no;
1287 int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
1288 unsigned char *data, unsigned int length,
1289 void (*callback) (void *cb, unsigned int length),
1290 void *callback_data)
1292 struct ipw_tx_packet *packet;
1294 packet = alloc_data_packet(length,
1295 (unsigned char) (channel_idx + 1),
1296 TL_PROTOCOLID_COM_DATA);
1299 packet->packet_callback = callback;
1300 packet->callback_data = callback_data;
1301 memcpy((unsigned char *) packet +
1302 sizeof(struct ipw_tx_packet), data, length);
1304 send_packet(hw, PRIO_DATA, packet);
1308 static int set_control_line(struct ipw_hardware *hw, int prio,
1309 unsigned int channel_idx, int line, int state)
1311 struct ipw_control_packet *packet;
1312 int protocolid = TL_PROTOCOLID_COM_CTRL;
1314 if (prio == PRIO_SETUP)
1315 protocolid = TL_PROTOCOLID_SETUP;
1317 packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
1318 (unsigned char) (channel_idx + 1),
1322 packet->header.length = sizeof(struct ipw_control_packet_body);
1323 packet->body.value = (unsigned char) (state == 0 ? 0 : 1);
1324 send_packet(hw, prio, &packet->header);
1329 static int set_DTR(struct ipw_hardware *hw, int priority,
1330 unsigned int channel_idx, int state)
1333 hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
1335 hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
1337 return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
1340 static int set_RTS(struct ipw_hardware *hw, int priority,
1341 unsigned int channel_idx, int state)
1344 hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
1346 hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
1348 return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
1351 int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
1354 return set_DTR(hw, PRIO_CTRL, channel_idx, state);
1357 int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
1360 return set_RTS(hw, PRIO_CTRL, channel_idx, state);
1363 struct ipw_setup_get_version_query_packet {
1364 struct ipw_tx_packet header;
1365 struct tl_setup_get_version_qry body;
1368 struct ipw_setup_config_packet {
1369 struct ipw_tx_packet header;
1370 struct tl_setup_config_msg body;
1373 struct ipw_setup_config_done_packet {
1374 struct ipw_tx_packet header;
1375 struct tl_setup_config_done_msg body;
1378 struct ipw_setup_open_packet {
1379 struct ipw_tx_packet header;
1380 struct tl_setup_open_msg body;
1383 struct ipw_setup_info_packet {
1384 struct ipw_tx_packet header;
1385 struct tl_setup_info_msg body;
1388 struct ipw_setup_reboot_msg_ack {
1389 struct ipw_tx_packet header;
1390 struct TlSetupRebootMsgAck body;
1393 /* This handles the actual initialization of the card */
1394 static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
1396 struct ipw_setup_config_packet *config_packet;
1397 struct ipw_setup_config_done_packet *config_done_packet;
1398 struct ipw_setup_open_packet *open_packet;
1399 struct ipw_setup_info_packet *info_packet;
1401 unsigned int channel_idx;
1403 /* generate config packet */
1404 for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
1405 config_packet = alloc_ctrl_packet(
1406 sizeof(struct ipw_setup_config_packet),
1408 TL_PROTOCOLID_SETUP,
1409 TL_SETUP_SIGNO_CONFIG_MSG);
1412 config_packet->header.length = sizeof(struct tl_setup_config_msg);
1413 config_packet->body.port_no = port;
1414 config_packet->body.prio_data = PRIO_DATA;
1415 config_packet->body.prio_ctrl = PRIO_CTRL;
1416 send_packet(hw, PRIO_SETUP, &config_packet->header);
1418 config_done_packet = alloc_ctrl_packet(
1419 sizeof(struct ipw_setup_config_done_packet),
1421 TL_PROTOCOLID_SETUP,
1422 TL_SETUP_SIGNO_CONFIG_DONE_MSG);
1423 if (!config_done_packet)
1425 config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
1426 send_packet(hw, PRIO_SETUP, &config_done_packet->header);
1428 /* generate open packet */
1429 for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
1430 open_packet = alloc_ctrl_packet(
1431 sizeof(struct ipw_setup_open_packet),
1433 TL_PROTOCOLID_SETUP,
1434 TL_SETUP_SIGNO_OPEN_MSG);
1437 open_packet->header.length = sizeof(struct tl_setup_open_msg);
1438 open_packet->body.port_no = port;
1439 send_packet(hw, PRIO_SETUP, &open_packet->header);
1441 for (channel_idx = 0;
1442 channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
1445 ret = set_DTR(hw, PRIO_SETUP, channel_idx,
1446 (hw->control_lines[channel_idx] &
1447 IPW_CONTROL_LINE_DTR) != 0);
1449 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1450 ": error setting DTR (%d)\n", ret);
1454 set_RTS(hw, PRIO_SETUP, channel_idx,
1455 (hw->control_lines [channel_idx] &
1456 IPW_CONTROL_LINE_RTS) != 0);
1458 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1459 ": error setting RTS (%d)\n", ret);
1464 * For NDIS we assume that we are using sync PPP frames, for COM async.
1465 * This driver uses NDIS mode too. We don't bother with translation
1466 * from async -> sync PPP.
1468 info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
1470 TL_PROTOCOLID_SETUP,
1471 TL_SETUP_SIGNO_INFO_MSG);
1474 info_packet->header.length = sizeof(struct tl_setup_info_msg);
1475 info_packet->body.driver_type = NDISWAN_DRIVER;
1476 info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
1477 info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
1478 send_packet(hw, PRIO_SETUP, &info_packet->header);
1480 /* Initialization is now complete, so we clear the 'to_setup' flag */
1486 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1487 ": not enough memory to alloc control packet\n");
1491 static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
1492 unsigned char vers_no)
1494 del_timer(&hw->setup_timer);
1495 hw->initializing = 0;
1496 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
1498 if (vers_no == TL_SETUP_VERSION)
1499 __handle_setup_get_version_rsp(hw);
1502 IPWIRELESS_PCCARD_NAME
1503 ": invalid hardware version no %u\n",
1504 (unsigned int) vers_no);
1507 static void ipw_send_setup_packet(struct ipw_hardware *hw)
1509 struct ipw_setup_get_version_query_packet *ver_packet;
1511 ver_packet = alloc_ctrl_packet(
1512 sizeof(struct ipw_setup_get_version_query_packet),
1513 ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
1514 TL_SETUP_SIGNO_GET_VERSION_QRY);
1515 ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
1518 * Response is handled in handle_received_SETUP_packet
1520 send_packet(hw, PRIO_SETUP, &ver_packet->header);
1523 static void handle_received_SETUP_packet(struct ipw_hardware *hw,
1524 unsigned int address,
1525 unsigned char *data, int len,
1528 union ipw_setup_rx_msg *rx_msg = (union ipw_setup_rx_msg *) data;
1530 if (address != ADDR_SETUP_PROT) {
1531 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1532 ": setup packet has bad address %d\n", address);
1536 switch (rx_msg->sig_no) {
1537 case TL_SETUP_SIGNO_GET_VERSION_RSP:
1539 handle_setup_get_version_rsp(hw,
1540 rx_msg->version_rsp_msg.version);
1543 case TL_SETUP_SIGNO_OPEN_MSG:
1544 if (ipwireless_debug) {
1545 unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
1547 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1548 ": OPEN_MSG [channel %u] reply received\n",
1553 case TL_SETUP_SIGNO_INFO_MSG_ACK:
1554 if (ipwireless_debug)
1555 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1556 ": card successfully configured as NDISWAN\n");
1559 case TL_SETUP_SIGNO_REBOOT_MSG:
1561 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1562 ": Setup not completed - ignoring reboot msg\n");
1564 struct ipw_setup_reboot_msg_ack *packet;
1566 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1567 ": Acknowledging REBOOT message\n");
1568 packet = alloc_ctrl_packet(
1569 sizeof(struct ipw_setup_reboot_msg_ack),
1570 ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
1571 TL_SETUP_SIGNO_REBOOT_MSG_ACK);
1572 packet->header.length =
1573 sizeof(struct TlSetupRebootMsgAck);
1574 send_packet(hw, PRIO_SETUP, &packet->header);
1575 if (hw->reboot_callback)
1576 hw->reboot_callback(hw->reboot_callback_data);
1581 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1582 ": unknown setup message %u received\n",
1583 (unsigned int) rx_msg->sig_no);
1587 static void do_close_hardware(struct ipw_hardware *hw)
1591 if (hw->hw_version == HW_VERSION_1) {
1592 /* Disable TX and RX interrupts. */
1593 outw(0, hw->base_port + IOIER);
1595 /* Acknowledge any outstanding interrupt requests */
1596 irqn = inw(hw->base_port + IOIR);
1597 if (irqn & IR_TXINTR)
1598 outw(IR_TXINTR, hw->base_port + IOIR);
1599 if (irqn & IR_RXINTR)
1600 outw(IR_RXINTR, hw->base_port + IOIR);
1602 synchronize_irq(hw->irq);
1606 struct ipw_hardware *ipwireless_hardware_create(void)
1609 struct ipw_hardware *hw =
1610 kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
1616 hw->initializing = 1;
1618 hw->rx_bytes_queued = 0;
1619 hw->rx_pool_size = 0;
1620 hw->last_memtx_serial = (unsigned short) 0xffff;
1621 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
1622 INIT_LIST_HEAD(&hw->tx_queue[i]);
1624 INIT_LIST_HEAD(&hw->rx_queue);
1625 INIT_LIST_HEAD(&hw->rx_pool);
1626 spin_lock_init(&hw->spinlock);
1627 tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
1628 INIT_WORK(&hw->work_rx, ipw_receive_data_work);
1629 setup_timer(&hw->setup_timer, ipwireless_setup_timer,
1630 (unsigned long) hw);
1635 void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
1636 unsigned int base_port,
1637 void __iomem *attr_memory,
1638 void __iomem *common_memory,
1640 void (*reboot_callback) (void *data),
1641 void *reboot_callback_data)
1645 enable_irq(hw->irq);
1647 hw->base_port = base_port;
1648 hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1;
1649 hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2;
1650 hw->memregs_CCR = (struct MEMCCR __iomem *)
1651 ((unsigned short __iomem *) attr_memory + 0x200);
1652 hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
1653 hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
1654 hw->reboot_callback = reboot_callback;
1655 hw->reboot_callback_data = reboot_callback_data;
1658 void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
1660 hw->initializing = 1;
1662 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1663 ": waiting for card to start up...\n");
1664 ipwireless_setup_timer((unsigned long) hw);
1667 static void ipwireless_setup_timer(unsigned long data)
1669 struct ipw_hardware *hw = (struct ipw_hardware *) data;
1673 if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
1674 hw->hw_version == HW_VERSION_2 &&
1675 hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1676 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1677 ": failed to startup using TX2, trying TX\n");
1679 hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
1682 /* Give up after a certain number of retries */
1683 if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
1684 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1685 ": card failed to start up!\n");
1686 hw->initializing = 0;
1688 /* Do not attempt to write to the board if it is not present. */
1689 if (is_card_present(hw)) {
1690 unsigned long flags;
1692 spin_lock_irqsave(&hw->spinlock, flags);
1695 spin_unlock_irqrestore(&hw->spinlock, flags);
1696 tasklet_schedule(&hw->tasklet);
1699 mod_timer(&hw->setup_timer,
1700 jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
1705 * Stop any interrupts from executing so that, once this function returns,
1706 * other layers of the driver can be sure they won't get any more callbacks.
1707 * Thus must be called on a proper process context.
1709 void ipwireless_stop_interrupts(struct ipw_hardware *hw)
1711 if (!hw->shutting_down) {
1712 /* Tell everyone we are going down. */
1713 hw->shutting_down = 1;
1714 del_timer(&hw->setup_timer);
1716 /* Prevent the hardware from sending any more interrupts */
1717 do_close_hardware(hw);
1721 void ipwireless_hardware_free(struct ipw_hardware *hw)
1724 struct ipw_rx_packet *rp, *rq;
1725 struct ipw_tx_packet *tp, *tq;
1727 ipwireless_stop_interrupts(hw);
1729 flush_scheduled_work();
1731 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
1732 if (hw->packet_assembler[i] != NULL)
1733 kfree(hw->packet_assembler[i]);
1735 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
1736 list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
1737 list_del(&tp->queue);
1741 list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
1742 list_del(&rp->queue);
1746 list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
1747 list_del(&rp->queue);
1754 * Associate the specified network with this hardware, so it will receive events
1757 void ipwireless_associate_network(struct ipw_hardware *hw,
1758 struct ipw_network *network)
1760 hw->network = network;