aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/pcmcia/ipwireless/hardware.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/pcmcia/ipwireless/hardware.c')
-rw-r--r--drivers/char/pcmcia/ipwireless/hardware.c275
1 files changed, 136 insertions, 139 deletions
diff --git a/drivers/char/pcmcia/ipwireless/hardware.c b/drivers/char/pcmcia/ipwireless/hardware.c
index 929101ecbae2..7d500f82195a 100644
--- a/drivers/char/pcmcia/ipwireless/hardware.c
+++ b/drivers/char/pcmcia/ipwireless/hardware.c
@@ -30,11 +30,11 @@
30static void ipw_send_setup_packet(struct ipw_hardware *hw); 30static void ipw_send_setup_packet(struct ipw_hardware *hw);
31static void handle_received_SETUP_packet(struct ipw_hardware *ipw, 31static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
32 unsigned int address, 32 unsigned int address,
33 unsigned char *data, int len, 33 const unsigned char *data, int len,
34 int is_last); 34 int is_last);
35static void ipwireless_setup_timer(unsigned long data); 35static void ipwireless_setup_timer(unsigned long data);
36static void handle_received_CTRL_packet(struct ipw_hardware *hw, 36static void handle_received_CTRL_packet(struct ipw_hardware *hw,
37 unsigned int channel_idx, unsigned char *data, int len); 37 unsigned int channel_idx, const unsigned char *data, int len);
38 38
39/*#define TIMING_DIAGNOSTICS*/ 39/*#define TIMING_DIAGNOSTICS*/
40 40
@@ -79,8 +79,7 @@ static void report_timing(void)
79 timing_stats.last_report_time = jiffies; 79 timing_stats.last_report_time = jiffies;
80 if (!first) 80 if (!first)
81 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 81 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
82 ": %u us elapsed - read %lu bytes in %u us, " 82 ": %u us elapsed - read %lu bytes in %u us, wrote %lu bytes in %u us\n",
83 "wrote %lu bytes in %u us\n",
84 jiffies_to_usecs(since), 83 jiffies_to_usecs(since),
85 timing_stats.read_bytes, 84 timing_stats.read_bytes,
86 jiffies_to_usecs(timing_stats.read_time), 85 jiffies_to_usecs(timing_stats.read_time),
@@ -133,29 +132,17 @@ enum {
133#define NL_FOLLOWING_PACKET_HEADER_SIZE 1 132#define NL_FOLLOWING_PACKET_HEADER_SIZE 1
134 133
135struct nl_first_packet_header { 134struct 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;
140#else
141 unsigned char protocol:3; 135 unsigned char protocol:3;
142 unsigned char address:3; 136 unsigned char address:3;
143 unsigned char packet_rank:2; 137 unsigned char packet_rank:2;
144#endif
145 unsigned char length_lsb; 138 unsigned char length_lsb;
146 unsigned char length_msb; 139 unsigned char length_msb;
147}; 140};
148 141
149struct nl_packet_header { 142struct 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;
154#else
155 unsigned char protocol:3; 143 unsigned char protocol:3;
156 unsigned char address:3; 144 unsigned char address:3;
157 unsigned char packet_rank:2; 145 unsigned char packet_rank:2;
158#endif
159}; 146};
160 147
161/* Value of 'packet_rank' above */ 148/* Value of 'packet_rank' above */
@@ -227,15 +214,12 @@ struct MEMINFREG {
227 unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */ 214 unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
228}; 215};
229 216
230#define IODMADPR 0x00 /* DMA Data Port Register (R/W) */
231
232#define CARD_PRESENT_VALUE (0xBEEFCAFEUL) 217#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
233 218
234#define MEMTX_TX 0x0001 219#define MEMTX_TX 0x0001
235#define MEMRX_RX 0x0001 220#define MEMRX_RX 0x0001
236#define MEMRX_RX_DONE 0x0001 221#define MEMRX_RX_DONE 0x0001
237#define MEMRX_PCINTACKK 0x0001 222#define MEMRX_PCINTACKK 0x0001
238#define MEMRX_MEMSPURIOUSINT 0x0001
239 223
240#define NL_NUM_OF_PRIORITIES 3 224#define NL_NUM_OF_PRIORITIES 3
241#define NL_NUM_OF_PROTOCOLS 3 225#define NL_NUM_OF_PROTOCOLS 3
@@ -245,7 +229,7 @@ struct ipw_hardware {
245 unsigned int base_port; 229 unsigned int base_port;
246 short hw_version; 230 short hw_version;
247 unsigned short ll_mtu; 231 unsigned short ll_mtu;
248 spinlock_t spinlock; 232 spinlock_t lock;
249 233
250 int initializing; 234 int initializing;
251 int init_loops; 235 int init_loops;
@@ -386,26 +370,52 @@ static void dump_data_bytes(const char *type, const unsigned char *data,
386 length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES); 370 length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
387} 371}
388 372
389static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data, 373static void swap_packet_bitfield_to_le(unsigned char *data)
374{
375#ifdef __BIG_ENDIAN_BITFIELD
376 unsigned char tmp = *data, ret = 0;
377
378 /*
379 * transform bits from aa.bbb.ccc to ccc.bbb.aa
380 */
381 ret |= tmp & 0xc0 >> 6;
382 ret |= tmp & 0x38 >> 1;
383 ret |= tmp & 0x07 << 5;
384 *data = ret & 0xff;
385#endif
386}
387
388static void swap_packet_bitfield_from_le(unsigned char *data)
389{
390#ifdef __BIG_ENDIAN_BITFIELD
391 unsigned char tmp = *data, ret = 0;
392
393 /*
394 * transform bits from ccc.bbb.aa to aa.bbb.ccc
395 */
396 ret |= tmp & 0xe0 >> 5;
397 ret |= tmp & 0x1c << 1;
398 ret |= tmp & 0x03 << 6;
399 *data = ret & 0xff;
400#endif
401}
402
403static void do_send_fragment(struct ipw_hardware *hw, unsigned char *data,
390 unsigned length) 404 unsigned length)
391{ 405{
392 int i; 406 unsigned i;
393 unsigned long flags; 407 unsigned long flags;
394 408
395 start_timing(); 409 start_timing();
396 410 BUG_ON(length > hw->ll_mtu);
397 if (length == 0)
398 return 0;
399
400 if (length > hw->ll_mtu)
401 return -1;
402 411
403 if (ipwireless_debug) 412 if (ipwireless_debug)
404 dump_data_bytes("send", data, length); 413 dump_data_bytes("send", data, length);
405 414
406 spin_lock_irqsave(&hw->spinlock, flags); 415 spin_lock_irqsave(&hw->lock, flags);
407 416
408 hw->tx_ready = 0; 417 hw->tx_ready = 0;
418 swap_packet_bitfield_to_le(data);
409 419
410 if (hw->hw_version == HW_VERSION_1) { 420 if (hw->hw_version == HW_VERSION_1) {
411 outw((unsigned short) length, hw->base_port + IODWR); 421 outw((unsigned short) length, hw->base_port + IODWR);
@@ -414,7 +424,7 @@ static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
414 unsigned short d = data[i]; 424 unsigned short d = data[i];
415 __le16 raw_data; 425 __le16 raw_data;
416 426
417 if (likely(i + 1 < length)) 427 if (i + 1 < length)
418 d |= data[i + 1] << 8; 428 d |= data[i + 1] << 8;
419 raw_data = cpu_to_le16(d); 429 raw_data = cpu_to_le16(d);
420 outw(raw_data, hw->base_port + IODWR); 430 outw(raw_data, hw->base_port + IODWR);
@@ -422,32 +432,30 @@ static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
422 432
423 outw(DCR_TXDONE, hw->base_port + IODCR); 433 outw(DCR_TXDONE, hw->base_port + IODCR);
424 } else if (hw->hw_version == HW_VERSION_2) { 434 } else if (hw->hw_version == HW_VERSION_2) {
425 outw((unsigned short) length, hw->base_port + IODMADPR); 435 outw((unsigned short) length, hw->base_port);
426 436
427 for (i = 0; i < length; i += 2) { 437 for (i = 0; i < length; i += 2) {
428 unsigned short d = data[i]; 438 unsigned short d = data[i];
429 __le16 raw_data; 439 __le16 raw_data;
430 440
431 if ((i + 1 < length)) 441 if (i + 1 < length)
432 d |= data[i + 1] << 8; 442 d |= data[i + 1] << 8;
433 raw_data = cpu_to_le16(d); 443 raw_data = cpu_to_le16(d);
434 outw(raw_data, hw->base_port + IODMADPR); 444 outw(raw_data, hw->base_port);
435 } 445 }
436 while ((i & 3) != 2) { 446 while ((i & 3) != 2) {
437 outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR); 447 outw((unsigned short) 0xDEAD, hw->base_port);
438 i += 2; 448 i += 2;
439 } 449 }
440 writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx); 450 writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
441 } 451 }
442 452
443 spin_unlock_irqrestore(&hw->spinlock, flags); 453 spin_unlock_irqrestore(&hw->lock, flags);
444 454
445 end_write_timing(length); 455 end_write_timing(length);
446
447 return 0;
448} 456}
449 457
450static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet) 458static void do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
451{ 459{
452 unsigned short fragment_data_len; 460 unsigned short fragment_data_len;
453 unsigned short data_left = packet->length - packet->offset; 461 unsigned short data_left = packet->length - packet->offset;
@@ -462,6 +470,10 @@ static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
462 if (data_left < fragment_data_len) 470 if (data_left < fragment_data_len)
463 fragment_data_len = data_left; 471 fragment_data_len = data_left;
464 472
473 /*
474 * hdr_first is now in machine bitfield order, which will be swapped
475 * to le just before it goes to hw
476 */
465 pkt.hdr_first.protocol = packet->protocol; 477 pkt.hdr_first.protocol = packet->protocol;
466 pkt.hdr_first.address = packet->dest_addr; 478 pkt.hdr_first.address = packet->dest_addr;
467 pkt.hdr_first.packet_rank = 0; 479 pkt.hdr_first.packet_rank = 0;
@@ -493,25 +505,23 @@ static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
493 */ 505 */
494 unsigned long flags; 506 unsigned long flags;
495 507
496 spin_lock_irqsave(&hw->spinlock, flags); 508 spin_lock_irqsave(&hw->lock, flags);
497 list_add(&packet->queue, &hw->tx_queue[0]); 509 list_add(&packet->queue, &hw->tx_queue[0]);
498 hw->tx_queued++; 510 hw->tx_queued++;
499 spin_unlock_irqrestore(&hw->spinlock, flags); 511 spin_unlock_irqrestore(&hw->lock, flags);
500 } else { 512 } else {
501 if (packet->packet_callback) 513 if (packet->packet_callback)
502 packet->packet_callback(packet->callback_data, 514 packet->packet_callback(packet->callback_data,
503 packet->length); 515 packet->length);
504 kfree(packet); 516 kfree(packet);
505 } 517 }
506
507 return 0;
508} 518}
509 519
510static void ipw_setup_hardware(struct ipw_hardware *hw) 520static void ipw_setup_hardware(struct ipw_hardware *hw)
511{ 521{
512 unsigned long flags; 522 unsigned long flags;
513 523
514 spin_lock_irqsave(&hw->spinlock, flags); 524 spin_lock_irqsave(&hw->lock, flags);
515 if (hw->hw_version == HW_VERSION_1) { 525 if (hw->hw_version == HW_VERSION_1) {
516 /* Reset RX FIFO */ 526 /* Reset RX FIFO */
517 outw(DCR_RXRESET, hw->base_port + IODCR); 527 outw(DCR_RXRESET, hw->base_port + IODCR);
@@ -530,7 +540,7 @@ static void ipw_setup_hardware(struct ipw_hardware *hw)
530 csr |= 1; 540 csr |= 1;
531 writew(csr, &hw->memregs_CCR->reg_config_and_status); 541 writew(csr, &hw->memregs_CCR->reg_config_and_status);
532 } 542 }
533 spin_unlock_irqrestore(&hw->spinlock, flags); 543 spin_unlock_irqrestore(&hw->lock, flags);
534} 544}
535 545
536/* 546/*
@@ -549,28 +559,23 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
549 if (!packet) { 559 if (!packet) {
550 unsigned long flags; 560 unsigned long flags;
551 561
552 /* 562 spin_lock_irqsave(&hw->lock, flags);
553 * If this is the first fragment, then we will need to fetch a
554 * packet to put it in.
555 */
556 spin_lock_irqsave(&hw->spinlock, flags);
557 /* If we have one in our pool, then pull it out. */
558 if (!list_empty(&hw->rx_pool)) { 563 if (!list_empty(&hw->rx_pool)) {
559 packet = list_first_entry(&hw->rx_pool, 564 packet = list_first_entry(&hw->rx_pool,
560 struct ipw_rx_packet, queue); 565 struct ipw_rx_packet, queue);
561 list_del(&packet->queue);
562 hw->rx_pool_size--; 566 hw->rx_pool_size--;
563 spin_unlock_irqrestore(&hw->spinlock, flags); 567 spin_unlock_irqrestore(&hw->lock, flags);
568 list_del(&packet->queue);
564 } else { 569 } else {
565 /* Otherwise allocate a new one. */ 570 const int min_capacity =
566 static int min_capacity = 256; 571 ipwireless_ppp_mru(hw->network + 2);
567 int new_capacity; 572 int new_capacity;
568 573
569 spin_unlock_irqrestore(&hw->spinlock, flags); 574 spin_unlock_irqrestore(&hw->lock, flags);
570 new_capacity = 575 new_capacity =
571 minimum_free_space > min_capacity 576 (minimum_free_space > min_capacity
572 ? minimum_free_space 577 ? minimum_free_space
573 : min_capacity; 578 : min_capacity);
574 packet = kmalloc(sizeof(struct ipw_rx_packet) 579 packet = kmalloc(sizeof(struct ipw_rx_packet)
575 + new_capacity, GFP_ATOMIC); 580 + new_capacity, GFP_ATOMIC);
576 if (!packet) 581 if (!packet)
@@ -580,10 +585,6 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
580 packet->length = 0; 585 packet->length = 0;
581 } 586 }
582 587
583 /*
584 * If this packet does not have sufficient capacity for the data we
585 * want to add, then make it bigger.
586 */
587 if (packet->length + minimum_free_space > packet->capacity) { 588 if (packet->length + minimum_free_space > packet->capacity) {
588 struct ipw_rx_packet *old_packet = packet; 589 struct ipw_rx_packet *old_packet = packet;
589 590
@@ -610,13 +611,15 @@ static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
610 kfree(packet); 611 kfree(packet);
611 else { 612 else {
612 hw->rx_pool_size++; 613 hw->rx_pool_size++;
613 list_add_tail(&packet->queue, &hw->rx_pool); 614 list_add(&packet->queue, &hw->rx_pool);
614 } 615 }
615} 616}
616 617
617static void queue_received_packet(struct ipw_hardware *hw, 618static void queue_received_packet(struct ipw_hardware *hw,
618 unsigned int protocol, unsigned int address, 619 unsigned int protocol,
619 unsigned char *data, int length, int is_last) 620 unsigned int address,
621 const unsigned char *data, int length,
622 int is_last)
620{ 623{
621 unsigned int channel_idx = address - 1; 624 unsigned int channel_idx = address - 1;
622 struct ipw_rx_packet *packet = NULL; 625 struct ipw_rx_packet *packet = NULL;
@@ -658,9 +661,9 @@ static void queue_received_packet(struct ipw_hardware *hw,
658 packet = *assem; 661 packet = *assem;
659 *assem = NULL; 662 *assem = NULL;
660 /* Count queued DATA bytes only */ 663 /* Count queued DATA bytes only */
661 spin_lock_irqsave(&hw->spinlock, flags); 664 spin_lock_irqsave(&hw->lock, flags);
662 hw->rx_bytes_queued += packet->length; 665 hw->rx_bytes_queued += packet->length;
663 spin_unlock_irqrestore(&hw->spinlock, flags); 666 spin_unlock_irqrestore(&hw->lock, flags);
664 } 667 }
665 } else { 668 } else {
666 /* If it's a CTRL packet, don't assemble, just queue it. */ 669 /* If it's a CTRL packet, don't assemble, just queue it. */
@@ -682,13 +685,13 @@ static void queue_received_packet(struct ipw_hardware *hw,
682 * network layer. 685 * network layer.
683 */ 686 */
684 if (packet) { 687 if (packet) {
685 spin_lock_irqsave(&hw->spinlock, flags); 688 spin_lock_irqsave(&hw->lock, flags);
686 list_add_tail(&packet->queue, &hw->rx_queue); 689 list_add_tail(&packet->queue, &hw->rx_queue);
687 /* Block reception of incoming packets if queue is full. */ 690 /* Block reception of incoming packets if queue is full. */
688 hw->blocking_rx = 691 hw->blocking_rx =
689 hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE; 692 (hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE);
690 693
691 spin_unlock_irqrestore(&hw->spinlock, flags); 694 spin_unlock_irqrestore(&hw->lock, flags);
692 schedule_work(&hw->work_rx); 695 schedule_work(&hw->work_rx);
693 } 696 }
694} 697}
@@ -702,7 +705,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
702 container_of(work_rx, struct ipw_hardware, work_rx); 705 container_of(work_rx, struct ipw_hardware, work_rx);
703 unsigned long flags; 706 unsigned long flags;
704 707
705 spin_lock_irqsave(&hw->spinlock, flags); 708 spin_lock_irqsave(&hw->lock, flags);
706 while (!list_empty(&hw->rx_queue)) { 709 while (!list_empty(&hw->rx_queue)) {
707 struct ipw_rx_packet *packet = 710 struct ipw_rx_packet *packet =
708 list_first_entry(&hw->rx_queue, 711 list_first_entry(&hw->rx_queue,
@@ -720,7 +723,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
720 if (packet->protocol == TL_PROTOCOLID_COM_DATA) { 723 if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
721 if (hw->network != NULL) { 724 if (hw->network != NULL) {
722 /* If the network hasn't been disconnected. */ 725 /* If the network hasn't been disconnected. */
723 spin_unlock_irqrestore(&hw->spinlock, flags); 726 spin_unlock_irqrestore(&hw->lock, flags);
724 /* 727 /*
725 * This must run unlocked due to tty processing 728 * This must run unlocked due to tty processing
726 * and mutex locking 729 * and mutex locking
@@ -731,7 +734,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
731 (unsigned char *)packet 734 (unsigned char *)packet
732 + sizeof(struct ipw_rx_packet), 735 + sizeof(struct ipw_rx_packet),
733 packet->length); 736 packet->length);
734 spin_lock_irqsave(&hw->spinlock, flags); 737 spin_lock_irqsave(&hw->lock, flags);
735 } 738 }
736 /* Count queued DATA bytes only */ 739 /* Count queued DATA bytes only */
737 hw->rx_bytes_queued -= packet->length; 740 hw->rx_bytes_queued -= packet->length;
@@ -755,15 +758,15 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
755 if (hw->shutting_down) 758 if (hw->shutting_down)
756 break; 759 break;
757 } 760 }
758 spin_unlock_irqrestore(&hw->spinlock, flags); 761 spin_unlock_irqrestore(&hw->lock, flags);
759} 762}
760 763
761static void handle_received_CTRL_packet(struct ipw_hardware *hw, 764static void handle_received_CTRL_packet(struct ipw_hardware *hw,
762 unsigned int channel_idx, 765 unsigned int channel_idx,
763 unsigned char *data, int len) 766 const unsigned char *data, int len)
764{ 767{
765 struct ipw_control_packet_body *body = 768 const struct ipw_control_packet_body *body =
766 (struct ipw_control_packet_body *) data; 769 (const struct ipw_control_packet_body *) data;
767 unsigned int changed_mask; 770 unsigned int changed_mask;
768 771
769 if (len != sizeof(struct ipw_control_packet_body)) { 772 if (len != sizeof(struct ipw_control_packet_body)) {
@@ -805,13 +808,13 @@ static void handle_received_CTRL_packet(struct ipw_hardware *hw,
805} 808}
806 809
807static void handle_received_packet(struct ipw_hardware *hw, 810static void handle_received_packet(struct ipw_hardware *hw,
808 union nl_packet *packet, 811 const union nl_packet *packet,
809 unsigned short len) 812 unsigned short len)
810{ 813{
811 unsigned int protocol = packet->hdr.protocol; 814 unsigned int protocol = packet->hdr.protocol;
812 unsigned int address = packet->hdr.address; 815 unsigned int address = packet->hdr.address;
813 unsigned int header_length; 816 unsigned int header_length;
814 unsigned char *data; 817 const unsigned char *data;
815 unsigned int data_len; 818 unsigned int data_len;
816 int is_last = packet->hdr.packet_rank & NL_LAST_PACKET; 819 int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
817 820
@@ -850,7 +853,7 @@ static void acknowledge_data_read(struct ipw_hardware *hw)
850static void do_receive_packet(struct ipw_hardware *hw) 853static void do_receive_packet(struct ipw_hardware *hw)
851{ 854{
852 unsigned len; 855 unsigned len;
853 unsigned int i; 856 unsigned i;
854 unsigned char pkt[LL_MTU_MAX]; 857 unsigned char pkt[LL_MTU_MAX];
855 858
856 start_timing(); 859 start_timing();
@@ -859,8 +862,7 @@ static void do_receive_packet(struct ipw_hardware *hw)
859 len = inw(hw->base_port + IODRR); 862 len = inw(hw->base_port + IODRR);
860 if (len > hw->ll_mtu) { 863 if (len > hw->ll_mtu) {
861 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 864 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
862 ": received a packet of %u bytes - " 865 ": received a packet of %u bytes - longer than the MTU!\n", len);
863 "longer than the MTU!\n", len);
864 outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR); 866 outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
865 return; 867 return;
866 } 868 }
@@ -873,18 +875,17 @@ static void do_receive_packet(struct ipw_hardware *hw)
873 pkt[i + 1] = (unsigned char) (data >> 8); 875 pkt[i + 1] = (unsigned char) (data >> 8);
874 } 876 }
875 } else { 877 } else {
876 len = inw(hw->base_port + IODMADPR); 878 len = inw(hw->base_port);
877 if (len > hw->ll_mtu) { 879 if (len > hw->ll_mtu) {
878 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 880 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
879 ": received a packet of %u bytes - " 881 ": received a packet of %u bytes - longer than the MTU!\n", len);
880 "longer than the MTU!\n", len);
881 writew(MEMRX_PCINTACKK, 882 writew(MEMRX_PCINTACKK,
882 &hw->memory_info_regs->memreg_pc_interrupt_ack); 883 &hw->memory_info_regs->memreg_pc_interrupt_ack);
883 return; 884 return;
884 } 885 }
885 886
886 for (i = 0; i < len; i += 2) { 887 for (i = 0; i < len; i += 2) {
887 __le16 raw_data = inw(hw->base_port + IODMADPR); 888 __le16 raw_data = inw(hw->base_port);
888 unsigned short data = le16_to_cpu(raw_data); 889 unsigned short data = le16_to_cpu(raw_data);
889 890
890 pkt[i] = (unsigned char) data; 891 pkt[i] = (unsigned char) data;
@@ -892,13 +893,15 @@ static void do_receive_packet(struct ipw_hardware *hw)
892 } 893 }
893 894
894 while ((i & 3) != 2) { 895 while ((i & 3) != 2) {
895 inw(hw->base_port + IODMADPR); 896 inw(hw->base_port);
896 i += 2; 897 i += 2;
897 } 898 }
898 } 899 }
899 900
900 acknowledge_data_read(hw); 901 acknowledge_data_read(hw);
901 902
903 swap_packet_bitfield_from_le(pkt);
904
902 if (ipwireless_debug) 905 if (ipwireless_debug)
903 dump_data_bytes("recv", pkt, len); 906 dump_data_bytes("recv", pkt, len);
904 907
@@ -916,8 +919,7 @@ static int get_current_packet_priority(struct ipw_hardware *hw)
916 * until setup is complete. 919 * until setup is complete.
917 */ 920 */
918 return (hw->to_setup || hw->initializing 921 return (hw->to_setup || hw->initializing
919 ? PRIO_SETUP + 1 : 922 ? PRIO_SETUP + 1 : NL_NUM_OF_PRIORITIES);
920 NL_NUM_OF_PRIORITIES);
921} 923}
922 924
923/* 925/*
@@ -928,17 +930,17 @@ static int get_packets_from_hw(struct ipw_hardware *hw)
928 int received = 0; 930 int received = 0;
929 unsigned long flags; 931 unsigned long flags;
930 932
931 spin_lock_irqsave(&hw->spinlock, flags); 933 spin_lock_irqsave(&hw->lock, flags);
932 while (hw->rx_ready && !hw->blocking_rx) { 934 while (hw->rx_ready && !hw->blocking_rx) {
933 received = 1; 935 received = 1;
934 hw->rx_ready--; 936 hw->rx_ready--;
935 spin_unlock_irqrestore(&hw->spinlock, flags); 937 spin_unlock_irqrestore(&hw->lock, flags);
936 938
937 do_receive_packet(hw); 939 do_receive_packet(hw);
938 940
939 spin_lock_irqsave(&hw->spinlock, flags); 941 spin_lock_irqsave(&hw->lock, flags);
940 } 942 }
941 spin_unlock_irqrestore(&hw->spinlock, flags); 943 spin_unlock_irqrestore(&hw->lock, flags);
942 944
943 return received; 945 return received;
944} 946}
@@ -954,7 +956,7 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
954 int more_to_send = 0; 956 int more_to_send = 0;
955 unsigned long flags; 957 unsigned long flags;
956 958
957 spin_lock_irqsave(&hw->spinlock, flags); 959 spin_lock_irqsave(&hw->lock, flags);
958 if (hw->tx_queued && hw->tx_ready) { 960 if (hw->tx_queued && hw->tx_ready) {
959 int priority; 961 int priority;
960 struct ipw_tx_packet *packet = NULL; 962 struct ipw_tx_packet *packet = NULL;
@@ -975,17 +977,17 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
975 } 977 }
976 if (!packet) { 978 if (!packet) {
977 hw->tx_queued = 0; 979 hw->tx_queued = 0;
978 spin_unlock_irqrestore(&hw->spinlock, flags); 980 spin_unlock_irqrestore(&hw->lock, flags);
979 return 0; 981 return 0;
980 } 982 }
981 983
982 spin_unlock_irqrestore(&hw->spinlock, flags); 984 spin_unlock_irqrestore(&hw->lock, flags);
983 985
984 /* Send */ 986 /* Send */
985 do_send_packet(hw, packet); 987 do_send_packet(hw, packet);
986 988
987 /* Check if more to send */ 989 /* Check if more to send */
988 spin_lock_irqsave(&hw->spinlock, flags); 990 spin_lock_irqsave(&hw->lock, flags);
989 for (priority = 0; priority < priority_limit; priority++) 991 for (priority = 0; priority < priority_limit; priority++)
990 if (!list_empty(&hw->tx_queue[priority])) { 992 if (!list_empty(&hw->tx_queue[priority])) {
991 more_to_send = 1; 993 more_to_send = 1;
@@ -995,7 +997,7 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
995 if (!more_to_send) 997 if (!more_to_send)
996 hw->tx_queued = 0; 998 hw->tx_queued = 0;
997 } 999 }
998 spin_unlock_irqrestore(&hw->spinlock, flags); 1000 spin_unlock_irqrestore(&hw->lock, flags);
999 1001
1000 return more_to_send; 1002 return more_to_send;
1001} 1003}
@@ -1008,9 +1010,9 @@ static void ipwireless_do_tasklet(unsigned long hw_)
1008 struct ipw_hardware *hw = (struct ipw_hardware *) hw_; 1010 struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
1009 unsigned long flags; 1011 unsigned long flags;
1010 1012
1011 spin_lock_irqsave(&hw->spinlock, flags); 1013 spin_lock_irqsave(&hw->lock, flags);
1012 if (hw->shutting_down) { 1014 if (hw->shutting_down) {
1013 spin_unlock_irqrestore(&hw->spinlock, flags); 1015 spin_unlock_irqrestore(&hw->lock, flags);
1014 return; 1016 return;
1015 } 1017 }
1016 1018
@@ -1019,7 +1021,7 @@ static void ipwireless_do_tasklet(unsigned long hw_)
1019 * Initial setup data sent to hardware 1021 * Initial setup data sent to hardware
1020 */ 1022 */
1021 hw->to_setup = 2; 1023 hw->to_setup = 2;
1022 spin_unlock_irqrestore(&hw->spinlock, flags); 1024 spin_unlock_irqrestore(&hw->lock, flags);
1023 1025
1024 ipw_setup_hardware(hw); 1026 ipw_setup_hardware(hw);
1025 ipw_send_setup_packet(hw); 1027 ipw_send_setup_packet(hw);
@@ -1030,7 +1032,7 @@ static void ipwireless_do_tasklet(unsigned long hw_)
1030 int priority_limit = get_current_packet_priority(hw); 1032 int priority_limit = get_current_packet_priority(hw);
1031 int again; 1033 int again;
1032 1034
1033 spin_unlock_irqrestore(&hw->spinlock, flags); 1035 spin_unlock_irqrestore(&hw->lock, flags);
1034 1036
1035 do { 1037 do {
1036 again = send_pending_packet(hw, priority_limit); 1038 again = send_pending_packet(hw, priority_limit);
@@ -1068,16 +1070,16 @@ static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
1068 /* Transmit complete. */ 1070 /* Transmit complete. */
1069 if (irqn & IR_TXINTR) { 1071 if (irqn & IR_TXINTR) {
1070 ack |= IR_TXINTR; 1072 ack |= IR_TXINTR;
1071 spin_lock_irqsave(&hw->spinlock, flags); 1073 spin_lock_irqsave(&hw->lock, flags);
1072 hw->tx_ready = 1; 1074 hw->tx_ready = 1;
1073 spin_unlock_irqrestore(&hw->spinlock, flags); 1075 spin_unlock_irqrestore(&hw->lock, flags);
1074 } 1076 }
1075 /* Received data */ 1077 /* Received data */
1076 if (irqn & IR_RXINTR) { 1078 if (irqn & IR_RXINTR) {
1077 ack |= IR_RXINTR; 1079 ack |= IR_RXINTR;
1078 spin_lock_irqsave(&hw->spinlock, flags); 1080 spin_lock_irqsave(&hw->lock, flags);
1079 hw->rx_ready++; 1081 hw->rx_ready++;
1080 spin_unlock_irqrestore(&hw->spinlock, flags); 1082 spin_unlock_irqrestore(&hw->lock, flags);
1081 } 1083 }
1082 if (ack != 0) { 1084 if (ack != 0) {
1083 outw(ack, hw->base_port + IOIR); 1085 outw(ack, hw->base_port + IOIR);
@@ -1128,9 +1130,8 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1128 } else { 1130 } else {
1129 return IRQ_NONE; 1131 return IRQ_NONE;
1130 } 1132 }
1131 } else { 1133 } else
1132 return IRQ_NONE; 1134 return IRQ_NONE;
1133 }
1134 } 1135 }
1135 1136
1136 /* 1137 /*
@@ -1149,9 +1150,9 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1149 if (hw->serial_number_detected) { 1150 if (hw->serial_number_detected) {
1150 if (memtx_serial != hw->last_memtx_serial) { 1151 if (memtx_serial != hw->last_memtx_serial) {
1151 hw->last_memtx_serial = memtx_serial; 1152 hw->last_memtx_serial = memtx_serial;
1152 spin_lock_irqsave(&hw->spinlock, flags); 1153 spin_lock_irqsave(&hw->lock, flags);
1153 hw->rx_ready++; 1154 hw->rx_ready++;
1154 spin_unlock_irqrestore(&hw->spinlock, flags); 1155 spin_unlock_irqrestore(&hw->lock, flags);
1155 rx = 1; 1156 rx = 1;
1156 } else 1157 } else
1157 /* Ignore 'Timer Recovery' duplicates. */ 1158 /* Ignore 'Timer Recovery' duplicates. */
@@ -1166,18 +1167,18 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1166 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME 1167 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1167 ": memreg_tx serial num detected\n"); 1168 ": memreg_tx serial num detected\n");
1168 1169
1169 spin_lock_irqsave(&hw->spinlock, flags); 1170 spin_lock_irqsave(&hw->lock, flags);
1170 hw->rx_ready++; 1171 hw->rx_ready++;
1171 spin_unlock_irqrestore(&hw->spinlock, flags); 1172 spin_unlock_irqrestore(&hw->lock, flags);
1172 } 1173 }
1173 rx = 1; 1174 rx = 1;
1174 } 1175 }
1175 } 1176 }
1176 if (memrxdone & MEMRX_RX_DONE) { 1177 if (memrxdone & MEMRX_RX_DONE) {
1177 writew(0, &hw->memory_info_regs->memreg_rx_done); 1178 writew(0, &hw->memory_info_regs->memreg_rx_done);
1178 spin_lock_irqsave(&hw->spinlock, flags); 1179 spin_lock_irqsave(&hw->lock, flags);
1179 hw->tx_ready = 1; 1180 hw->tx_ready = 1;
1180 spin_unlock_irqrestore(&hw->spinlock, flags); 1181 spin_unlock_irqrestore(&hw->lock, flags);
1181 tx = 1; 1182 tx = 1;
1182 } 1183 }
1183 if (tx) 1184 if (tx)
@@ -1195,8 +1196,7 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1195 ": spurious interrupt - new_tx mode\n"); 1196 ": spurious interrupt - new_tx mode\n");
1196 else { 1197 else {
1197 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME 1198 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1198 ": no valid memreg_tx value - " 1199 ": no valid memreg_tx value - switching to the old memreg_tx\n");
1199 "switching to the old memreg_tx\n");
1200 hw->memreg_tx = 1200 hw->memreg_tx =
1201 &hw->memory_info_regs->memreg_tx_old; 1201 &hw->memory_info_regs->memreg_tx_old;
1202 try_mem_tx_old = 1; 1202 try_mem_tx_old = 1;
@@ -1211,7 +1211,7 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1211 return IRQ_HANDLED; 1211 return IRQ_HANDLED;
1212} 1212}
1213 1213
1214irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1214irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
1215{ 1215{
1216 struct ipw_hardware *hw = dev_id; 1216 struct ipw_hardware *hw = dev_id;
1217 1217
@@ -1226,9 +1226,9 @@ static void flush_packets_to_hw(struct ipw_hardware *hw)
1226 int priority_limit; 1226 int priority_limit;
1227 unsigned long flags; 1227 unsigned long flags;
1228 1228
1229 spin_lock_irqsave(&hw->spinlock, flags); 1229 spin_lock_irqsave(&hw->lock, flags);
1230 priority_limit = get_current_packet_priority(hw); 1230 priority_limit = get_current_packet_priority(hw);
1231 spin_unlock_irqrestore(&hw->spinlock, flags); 1231 spin_unlock_irqrestore(&hw->lock, flags);
1232 1232
1233 while (send_pending_packet(hw, priority_limit)); 1233 while (send_pending_packet(hw, priority_limit));
1234} 1234}
@@ -1238,10 +1238,10 @@ static void send_packet(struct ipw_hardware *hw, int priority,
1238{ 1238{
1239 unsigned long flags; 1239 unsigned long flags;
1240 1240
1241 spin_lock_irqsave(&hw->spinlock, flags); 1241 spin_lock_irqsave(&hw->lock, flags);
1242 list_add_tail(&packet->queue, &hw->tx_queue[priority]); 1242 list_add_tail(&packet->queue, &hw->tx_queue[priority]);
1243 hw->tx_queued++; 1243 hw->tx_queued++;
1244 spin_unlock_irqrestore(&hw->spinlock, flags); 1244 spin_unlock_irqrestore(&hw->lock, flags);
1245 1245
1246 flush_packets_to_hw(hw); 1246 flush_packets_to_hw(hw);
1247} 1247}
@@ -1291,21 +1291,20 @@ static void *alloc_ctrl_packet(int header_size,
1291} 1291}
1292 1292
1293int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx, 1293int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
1294 unsigned char *data, unsigned int length, 1294 const unsigned char *data, unsigned int length,
1295 void (*callback) (void *cb, unsigned int length), 1295 void (*callback) (void *cb, unsigned int length),
1296 void *callback_data) 1296 void *callback_data)
1297{ 1297{
1298 struct ipw_tx_packet *packet; 1298 struct ipw_tx_packet *packet;
1299 1299
1300 packet = alloc_data_packet(length, 1300 packet = alloc_data_packet(length, (channel_idx + 1),
1301 (unsigned char) (channel_idx + 1), 1301 TL_PROTOCOLID_COM_DATA);
1302 TL_PROTOCOLID_COM_DATA);
1303 if (!packet) 1302 if (!packet)
1304 return -ENOMEM; 1303 return -ENOMEM;
1305 packet->packet_callback = callback; 1304 packet->packet_callback = callback;
1306 packet->callback_data = callback_data; 1305 packet->callback_data = callback_data;
1307 memcpy((unsigned char *) packet + 1306 memcpy((unsigned char *) packet + sizeof(struct ipw_tx_packet), data,
1308 sizeof(struct ipw_tx_packet), data, length); 1307 length);
1309 1308
1310 send_packet(hw, PRIO_DATA, packet); 1309 send_packet(hw, PRIO_DATA, packet);
1311 return 0; 1310 return 0;
@@ -1321,12 +1320,11 @@ static int set_control_line(struct ipw_hardware *hw, int prio,
1321 protocolid = TL_PROTOCOLID_SETUP; 1320 protocolid = TL_PROTOCOLID_SETUP;
1322 1321
1323 packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet), 1322 packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
1324 (unsigned char) (channel_idx + 1), 1323 (channel_idx + 1), protocolid, line);
1325 protocolid, line);
1326 if (!packet) 1324 if (!packet)
1327 return -ENOMEM; 1325 return -ENOMEM;
1328 packet->header.length = sizeof(struct ipw_control_packet_body); 1326 packet->header.length = sizeof(struct ipw_control_packet_body);
1329 packet->body.value = (unsigned char) (state == 0 ? 0 : 1); 1327 packet->body.value = (state == 0 ? 0 : 1);
1330 send_packet(hw, prio, &packet->header); 1328 send_packet(hw, prio, &packet->header);
1331 return 0; 1329 return 0;
1332} 1330}
@@ -1504,8 +1502,7 @@ static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
1504 if (vers_no == TL_SETUP_VERSION) 1502 if (vers_no == TL_SETUP_VERSION)
1505 __handle_setup_get_version_rsp(hw); 1503 __handle_setup_get_version_rsp(hw);
1506 else 1504 else
1507 printk(KERN_ERR 1505 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1508 IPWIRELESS_PCCARD_NAME
1509 ": invalid hardware version no %u\n", 1506 ": invalid hardware version no %u\n",
1510 (unsigned int) vers_no); 1507 (unsigned int) vers_no);
1511} 1508}
@@ -1528,10 +1525,10 @@ static void ipw_send_setup_packet(struct ipw_hardware *hw)
1528 1525
1529static void handle_received_SETUP_packet(struct ipw_hardware *hw, 1526static void handle_received_SETUP_packet(struct ipw_hardware *hw,
1530 unsigned int address, 1527 unsigned int address,
1531 unsigned char *data, int len, 1528 const unsigned char *data, int len,
1532 int is_last) 1529 int is_last)
1533{ 1530{
1534 union ipw_setup_rx_msg *rx_msg = (union ipw_setup_rx_msg *) data; 1531 const union ipw_setup_rx_msg *rx_msg = (const union ipw_setup_rx_msg *) data;
1535 1532
1536 if (address != ADDR_SETUP_PROT) { 1533 if (address != ADDR_SETUP_PROT) {
1537 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 1534 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
@@ -1629,7 +1626,7 @@ struct ipw_hardware *ipwireless_hardware_create(void)
1629 1626
1630 INIT_LIST_HEAD(&hw->rx_queue); 1627 INIT_LIST_HEAD(&hw->rx_queue);
1631 INIT_LIST_HEAD(&hw->rx_pool); 1628 INIT_LIST_HEAD(&hw->rx_pool);
1632 spin_lock_init(&hw->spinlock); 1629 spin_lock_init(&hw->lock);
1633 tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw); 1630 tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
1634 INIT_WORK(&hw->work_rx, ipw_receive_data_work); 1631 INIT_WORK(&hw->work_rx, ipw_receive_data_work);
1635 setup_timer(&hw->setup_timer, ipwireless_setup_timer, 1632 setup_timer(&hw->setup_timer, ipwireless_setup_timer,
@@ -1651,8 +1648,8 @@ void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
1651 enable_irq(hw->irq); 1648 enable_irq(hw->irq);
1652 } 1649 }
1653 hw->base_port = base_port; 1650 hw->base_port = base_port;
1654 hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1; 1651 hw->hw_version = (is_v2_card ? HW_VERSION_2 : HW_VERSION_1);
1655 hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2; 1652 hw->ll_mtu = (hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2);
1656 hw->memregs_CCR = (struct MEMCCR __iomem *) 1653 hw->memregs_CCR = (struct MEMCCR __iomem *)
1657 ((unsigned short __iomem *) attr_memory + 0x200); 1654 ((unsigned short __iomem *) attr_memory + 0x200);
1658 hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory; 1655 hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
@@ -1695,10 +1692,10 @@ static void ipwireless_setup_timer(unsigned long data)
1695 if (is_card_present(hw)) { 1692 if (is_card_present(hw)) {
1696 unsigned long flags; 1693 unsigned long flags;
1697 1694
1698 spin_lock_irqsave(&hw->spinlock, flags); 1695 spin_lock_irqsave(&hw->lock, flags);
1699 hw->to_setup = 1; 1696 hw->to_setup = 1;
1700 hw->tx_ready = 1; 1697 hw->tx_ready = 1;
1701 spin_unlock_irqrestore(&hw->spinlock, flags); 1698 spin_unlock_irqrestore(&hw->lock, flags);
1702 tasklet_schedule(&hw->tasklet); 1699 tasklet_schedule(&hw->tasklet);
1703 } 1700 }
1704 1701