diff options
author | Tomoya <tomoya-linux@dsn.okisemi.com> | 2010-11-29 13:15:02 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-12-02 16:04:51 -0500 |
commit | 15ffc8fddf72712cc45d51c64bd500760ec63c80 (patch) | |
tree | 6b26123026d65d0752ed0e7c64d3fe1782958f23 /drivers/net/can | |
parent | 8339a7ed562719e040ca783bf59fa2d614d10ac9 (diff) |
can: EG20T PCH: Change Message Object Index
For easy to readable, add Message Object index like below.
PCH_RX_OBJ_START
PCH_RX_OBJ_END
PCH_TX_OBJ_START
PCH_TX_OBJ_END
Signed-off-by: Tomoya MORINAGA <tomoya-linux@dsn.okisemi.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/pch_can.c | 263 |
1 files changed, 116 insertions, 147 deletions
diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c index dae8ed19630e..982ff2d757a8 100644 --- a/drivers/net/can/pch_can.c +++ b/drivers/net/can/pch_can.c | |||
@@ -32,10 +32,6 @@ | |||
32 | #include <linux/can/dev.h> | 32 | #include <linux/can/dev.h> |
33 | #include <linux/can/error.h> | 33 | #include <linux/can/error.h> |
34 | 34 | ||
35 | #define PCH_MAX_MSG_OBJ 32 | ||
36 | #define PCH_MSG_OBJ_RX 0 /* The receive message object flag. */ | ||
37 | #define PCH_MSG_OBJ_TX 1 /* The transmit message object flag. */ | ||
38 | |||
39 | #define PCH_ENABLE 1 /* The enable flag */ | 35 | #define PCH_ENABLE 1 /* The enable flag */ |
40 | #define PCH_DISABLE 0 /* The disable flag */ | 36 | #define PCH_DISABLE 0 /* The disable flag */ |
41 | #define PCH_CTRL_INIT BIT(0) /* The INIT bit of CANCONT register. */ | 37 | #define PCH_CTRL_INIT BIT(0) /* The INIT bit of CANCONT register. */ |
@@ -107,9 +103,12 @@ | |||
107 | /* Define the number of message object. | 103 | /* Define the number of message object. |
108 | * PCH CAN communications are done via Message RAM. | 104 | * PCH CAN communications are done via Message RAM. |
109 | * The Message RAM consists of 32 message objects. */ | 105 | * The Message RAM consists of 32 message objects. */ |
110 | #define PCH_RX_OBJ_NUM 26 /* 1~ PCH_RX_OBJ_NUM is Rx*/ | 106 | #define PCH_RX_OBJ_NUM 26 |
111 | #define PCH_TX_OBJ_NUM 6 /* PCH_RX_OBJ_NUM is RX ~ Tx*/ | 107 | #define PCH_TX_OBJ_NUM 6 |
112 | #define PCH_OBJ_NUM (PCH_TX_OBJ_NUM + PCH_RX_OBJ_NUM) | 108 | #define PCH_RX_OBJ_START 1 |
109 | #define PCH_RX_OBJ_END PCH_RX_OBJ_NUM | ||
110 | #define PCH_TX_OBJ_START (PCH_RX_OBJ_END + 1) | ||
111 | #define PCH_TX_OBJ_END (PCH_RX_OBJ_NUM + PCH_TX_OBJ_NUM) | ||
113 | 112 | ||
114 | #define PCH_FIFO_THRESH 16 | 113 | #define PCH_FIFO_THRESH 16 |
115 | 114 | ||
@@ -172,14 +171,14 @@ struct pch_can_priv { | |||
172 | struct can_priv can; | 171 | struct can_priv can; |
173 | unsigned int can_num; | 172 | unsigned int can_num; |
174 | struct pci_dev *dev; | 173 | struct pci_dev *dev; |
175 | unsigned int tx_enable[PCH_MAX_MSG_OBJ]; | 174 | int tx_enable[PCH_TX_OBJ_END]; |
176 | unsigned int rx_enable[PCH_MAX_MSG_OBJ]; | 175 | int rx_enable[PCH_TX_OBJ_END]; |
177 | unsigned int rx_link[PCH_MAX_MSG_OBJ]; | 176 | int rx_link[PCH_TX_OBJ_END]; |
178 | unsigned int int_enables; | 177 | unsigned int int_enables; |
179 | unsigned int int_stat; | 178 | unsigned int int_stat; |
180 | struct net_device *ndev; | 179 | struct net_device *ndev; |
181 | spinlock_t msgif_reg_lock; /* Message Interface Registers Access Lock*/ | 180 | spinlock_t msgif_reg_lock; /* Message Interface Registers Access Lock*/ |
182 | unsigned int msg_obj[PCH_MAX_MSG_OBJ]; | 181 | unsigned int msg_obj[PCH_TX_OBJ_END]; |
183 | struct pch_can_regs __iomem *regs; | 182 | struct pch_can_regs __iomem *regs; |
184 | struct napi_struct napi; | 183 | struct napi_struct napi; |
185 | unsigned int tx_obj; /* Point next Tx Obj index */ | 184 | unsigned int tx_obj; /* Point next Tx Obj index */ |
@@ -347,10 +346,8 @@ static void pch_can_set_rx_all(struct pch_can_priv *priv, u32 set) | |||
347 | int i; | 346 | int i; |
348 | 347 | ||
349 | /* Traversing to obtain the object configured as receivers. */ | 348 | /* Traversing to obtain the object configured as receivers. */ |
350 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 349 | for (i = PCH_RX_OBJ_START; i <= PCH_RX_OBJ_END; i++) |
351 | if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) | 350 | pch_can_set_rxtx(priv, i, set, PCH_RX_IFREG); |
352 | pch_can_set_rxtx(priv, i + 1, set, PCH_RX_IFREG); | ||
353 | } | ||
354 | } | 351 | } |
355 | 352 | ||
356 | static void pch_can_set_tx_all(struct pch_can_priv *priv, u32 set) | 353 | static void pch_can_set_tx_all(struct pch_can_priv *priv, u32 set) |
@@ -358,10 +355,8 @@ static void pch_can_set_tx_all(struct pch_can_priv *priv, u32 set) | |||
358 | int i; | 355 | int i; |
359 | 356 | ||
360 | /* Traversing to obtain the object configured as transmit object. */ | 357 | /* Traversing to obtain the object configured as transmit object. */ |
361 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 358 | for (i = PCH_TX_OBJ_START; i <= PCH_TX_OBJ_END; i++) |
362 | if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) | 359 | pch_can_set_rxtx(priv, i, set, PCH_TX_IFREG); |
363 | pch_can_set_rxtx(priv, i + 1, set, PCH_TX_IFREG); | ||
364 | } | ||
365 | } | 360 | } |
366 | 361 | ||
367 | static u32 pch_can_get_rxtx_ir(struct pch_can_priv *priv, u32 buff_num, | 362 | static u32 pch_can_get_rxtx_ir(struct pch_can_priv *priv, u32 buff_num, |
@@ -381,9 +376,9 @@ static u32 pch_can_get_rxtx_ir(struct pch_can_priv *priv, u32 buff_num, | |||
381 | 376 | ||
382 | if (((ioread32(&priv->regs->ifregs[dir].id2)) & PCH_ID_MSGVAL) && | 377 | if (((ioread32(&priv->regs->ifregs[dir].id2)) & PCH_ID_MSGVAL) && |
383 | ((ioread32(&priv->regs->ifregs[dir].mcont)) & ie)) { | 378 | ((ioread32(&priv->regs->ifregs[dir].mcont)) & ie)) { |
384 | enable = PCH_ENABLE; | 379 | enable = 1; |
385 | } else { | 380 | } else { |
386 | enable = PCH_DISABLE; | 381 | enable = 0; |
387 | } | 382 | } |
388 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); | 383 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); |
389 | return enable; | 384 | return enable; |
@@ -434,7 +429,7 @@ static void pch_can_clear_buffers(struct pch_can_priv *priv) | |||
434 | { | 429 | { |
435 | int i; | 430 | int i; |
436 | 431 | ||
437 | for (i = 0; i < PCH_RX_OBJ_NUM; i++) { | 432 | for (i = PCH_RX_OBJ_START; i <= PCH_RX_OBJ_END; i++) { |
438 | iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->ifregs[0].cmask); | 433 | iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->ifregs[0].cmask); |
439 | iowrite32(0xffff, &priv->regs->ifregs[0].mask1); | 434 | iowrite32(0xffff, &priv->regs->ifregs[0].mask1); |
440 | iowrite32(0xffff, &priv->regs->ifregs[0].mask2); | 435 | iowrite32(0xffff, &priv->regs->ifregs[0].mask2); |
@@ -448,10 +443,10 @@ static void pch_can_clear_buffers(struct pch_can_priv *priv) | |||
448 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | | 443 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | |
449 | PCH_CMASK_ARB | PCH_CMASK_CTRL, | 444 | PCH_CMASK_ARB | PCH_CMASK_CTRL, |
450 | &priv->regs->ifregs[0].cmask); | 445 | &priv->regs->ifregs[0].cmask); |
451 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i+1); | 446 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i); |
452 | } | 447 | } |
453 | 448 | ||
454 | for (i = i; i < PCH_OBJ_NUM; i++) { | 449 | for (i = PCH_TX_OBJ_START; i <= PCH_TX_OBJ_END; i++) { |
455 | iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->ifregs[1].cmask); | 450 | iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->ifregs[1].cmask); |
456 | iowrite32(0xffff, &priv->regs->ifregs[1].mask1); | 451 | iowrite32(0xffff, &priv->regs->ifregs[1].mask1); |
457 | iowrite32(0xffff, &priv->regs->ifregs[1].mask2); | 452 | iowrite32(0xffff, &priv->regs->ifregs[1].mask2); |
@@ -465,7 +460,7 @@ static void pch_can_clear_buffers(struct pch_can_priv *priv) | |||
465 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | | 460 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | |
466 | PCH_CMASK_ARB | PCH_CMASK_CTRL, | 461 | PCH_CMASK_ARB | PCH_CMASK_CTRL, |
467 | &priv->regs->ifregs[1].cmask); | 462 | &priv->regs->ifregs[1].cmask); |
468 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i+1); | 463 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i); |
469 | } | 464 | } |
470 | } | 465 | } |
471 | 466 | ||
@@ -476,64 +471,62 @@ static void pch_can_config_rx_tx_buffers(struct pch_can_priv *priv) | |||
476 | 471 | ||
477 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); | 472 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); |
478 | 473 | ||
479 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 474 | for (i = PCH_RX_OBJ_START; i <= PCH_RX_OBJ_END; i++) { |
480 | if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) { | 475 | iowrite32(PCH_CMASK_RX_TX_GET, |
481 | iowrite32(PCH_CMASK_RX_TX_GET, | 476 | &priv->regs->ifregs[0].cmask); |
482 | &priv->regs->ifregs[0].cmask); | 477 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i); |
483 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i+1); | ||
484 | 478 | ||
485 | iowrite32(0x0, &priv->regs->ifregs[0].id1); | 479 | iowrite32(0x0, &priv->regs->ifregs[0].id1); |
486 | iowrite32(0x0, &priv->regs->ifregs[0].id2); | 480 | iowrite32(0x0, &priv->regs->ifregs[0].id2); |
487 | 481 | ||
488 | pch_can_bit_set(&priv->regs->ifregs[0].mcont, | 482 | pch_can_bit_set(&priv->regs->ifregs[0].mcont, |
489 | PCH_IF_MCONT_UMASK); | 483 | PCH_IF_MCONT_UMASK); |
490 | 484 | ||
491 | /* Set FIFO mode set to 0 except last Rx Obj*/ | 485 | /* Set FIFO mode set to 0 except last Rx Obj*/ |
492 | pch_can_bit_clear(&priv->regs->ifregs[0].mcont, | 486 | pch_can_bit_clear(&priv->regs->ifregs[0].mcont, |
487 | PCH_IF_MCONT_EOB); | ||
488 | /* In case FIFO mode, Last EoB of Rx Obj must be 1 */ | ||
489 | if (i == PCH_RX_OBJ_END) | ||
490 | pch_can_bit_set(&priv->regs->ifregs[0].mcont, | ||
493 | PCH_IF_MCONT_EOB); | 491 | PCH_IF_MCONT_EOB); |
494 | /* In case FIFO mode, Last EoB of Rx Obj must be 1 */ | ||
495 | if (i == (PCH_RX_OBJ_NUM - 1)) | ||
496 | pch_can_bit_set(&priv->regs->ifregs[0].mcont, | ||
497 | PCH_IF_MCONT_EOB); | ||
498 | |||
499 | iowrite32(0, &priv->regs->ifregs[0].mask1); | ||
500 | pch_can_bit_clear(&priv->regs->ifregs[0].mask2, | ||
501 | 0x1fff | PCH_MASK2_MDIR_MXTD); | ||
502 | |||
503 | /* Setting CMASK for writing */ | ||
504 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | | ||
505 | PCH_CMASK_ARB | PCH_CMASK_CTRL, | ||
506 | &priv->regs->ifregs[0].cmask); | ||
507 | 492 | ||
508 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i+1); | 493 | iowrite32(0, &priv->regs->ifregs[0].mask1); |
509 | } else if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) { | 494 | pch_can_bit_clear(&priv->regs->ifregs[0].mask2, |
510 | iowrite32(PCH_CMASK_RX_TX_GET, | 495 | 0x1fff | PCH_MASK2_MDIR_MXTD); |
511 | &priv->regs->ifregs[1].cmask); | ||
512 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i+1); | ||
513 | 496 | ||
514 | /* Resetting DIR bit for reception */ | 497 | /* Setting CMASK for writing */ |
515 | iowrite32(0x0, &priv->regs->ifregs[1].id1); | 498 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | |
516 | iowrite32(0x0, &priv->regs->ifregs[1].id2); | 499 | PCH_CMASK_ARB | PCH_CMASK_CTRL, |
517 | pch_can_bit_set(&priv->regs->ifregs[1].id2, | 500 | &priv->regs->ifregs[0].cmask); |
518 | PCH_ID2_DIR); | ||
519 | 501 | ||
520 | /* Setting EOB bit for transmitter */ | 502 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, i); |
521 | iowrite32(PCH_IF_MCONT_EOB, | 503 | } |
522 | &priv->regs->ifregs[1].mcont); | ||
523 | 504 | ||
524 | pch_can_bit_set(&priv->regs->ifregs[1].mcont, | 505 | for (i = PCH_TX_OBJ_START; i <= PCH_TX_OBJ_END; i++) { |
525 | PCH_IF_MCONT_UMASK); | 506 | iowrite32(PCH_CMASK_RX_TX_GET, |
507 | &priv->regs->ifregs[1].cmask); | ||
508 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i); | ||
526 | 509 | ||
527 | iowrite32(0, &priv->regs->ifregs[1].mask1); | 510 | /* Resetting DIR bit for reception */ |
528 | pch_can_bit_clear(&priv->regs->ifregs[1].mask2, 0x1fff); | 511 | iowrite32(0x0, &priv->regs->ifregs[1].id1); |
512 | iowrite32(0x0, &priv->regs->ifregs[1].id2); | ||
513 | pch_can_bit_set(&priv->regs->ifregs[1].id2, PCH_ID2_DIR); | ||
529 | 514 | ||
530 | /* Setting CMASK for writing */ | 515 | /* Setting EOB bit for transmitter */ |
531 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | | 516 | iowrite32(PCH_IF_MCONT_EOB, &priv->regs->ifregs[1].mcont); |
532 | PCH_CMASK_ARB | PCH_CMASK_CTRL, | ||
533 | &priv->regs->ifregs[1].cmask); | ||
534 | 517 | ||
535 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i+1); | 518 | pch_can_bit_set(&priv->regs->ifregs[1].mcont, |
536 | } | 519 | PCH_IF_MCONT_UMASK); |
520 | |||
521 | iowrite32(0, &priv->regs->ifregs[1].mask1); | ||
522 | pch_can_bit_clear(&priv->regs->ifregs[1].mask2, 0x1fff); | ||
523 | |||
524 | /* Setting CMASK for writing */ | ||
525 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK | | ||
526 | PCH_CMASK_ARB | PCH_CMASK_CTRL, | ||
527 | &priv->regs->ifregs[1].cmask); | ||
528 | |||
529 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, i); | ||
537 | } | 530 | } |
538 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); | 531 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); |
539 | } | 532 | } |
@@ -577,7 +570,20 @@ static void pch_can_int_clr(struct pch_can_priv *priv, u32 mask) | |||
577 | } | 570 | } |
578 | 571 | ||
579 | /* Clear interrupt for transmit object */ | 572 | /* Clear interrupt for transmit object */ |
580 | if (priv->msg_obj[mask - 1] == PCH_MSG_OBJ_TX) { | 573 | if ((mask >= PCH_RX_OBJ_START) && (mask <= PCH_RX_OBJ_END)) { |
574 | /* Setting CMASK for clearing the reception interrupts. */ | ||
575 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB, | ||
576 | &priv->regs->ifregs[0].cmask); | ||
577 | |||
578 | /* Clearing the Dir bit. */ | ||
579 | pch_can_bit_clear(&priv->regs->ifregs[0].id2, PCH_ID2_DIR); | ||
580 | |||
581 | /* Clearing NewDat & IntPnd */ | ||
582 | pch_can_bit_clear(&priv->regs->ifregs[0].mcont, | ||
583 | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND); | ||
584 | |||
585 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, mask); | ||
586 | } else if ((mask >= PCH_TX_OBJ_START) && (mask <= PCH_TX_OBJ_END)) { | ||
581 | /* Setting CMASK for clearing interrupts for | 587 | /* Setting CMASK for clearing interrupts for |
582 | frame transmission. */ | 588 | frame transmission. */ |
583 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB, | 589 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB, |
@@ -593,19 +599,6 @@ static void pch_can_int_clr(struct pch_can_priv *priv, u32 mask) | |||
593 | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND | | 599 | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND | |
594 | PCH_IF_MCONT_TXRQXT); | 600 | PCH_IF_MCONT_TXRQXT); |
595 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, mask); | 601 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, mask); |
596 | } else if (priv->msg_obj[mask - 1] == PCH_MSG_OBJ_RX) { | ||
597 | /* Setting CMASK for clearing the reception interrupts. */ | ||
598 | iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB, | ||
599 | &priv->regs->ifregs[0].cmask); | ||
600 | |||
601 | /* Clearing the Dir bit. */ | ||
602 | pch_can_bit_clear(&priv->regs->ifregs[0].id2, PCH_ID2_DIR); | ||
603 | |||
604 | /* Clearing NewDat & IntPnd */ | ||
605 | pch_can_bit_clear(&priv->regs->ifregs[0].mcont, | ||
606 | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND); | ||
607 | |||
608 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, mask); | ||
609 | } | 602 | } |
610 | } | 603 | } |
611 | 604 | ||
@@ -793,8 +786,8 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 int_stat) | |||
793 | cf->can_dlc = 0; | 786 | cf->can_dlc = 0; |
794 | cf->can_id |= CAN_RTR_FLAG; | 787 | cf->can_id |= CAN_RTR_FLAG; |
795 | } else { | 788 | } else { |
796 | cf->can_dlc = ((ioread32(&priv->regs->ifregs[0].mcont)) | 789 | cf->can_dlc = |
797 | & 0x0f); | 790 | ((ioread32(&priv->regs->ifregs[0].mcont)) & 0x0f); |
798 | } | 791 | } |
799 | 792 | ||
800 | for (i = 0, j = 0; i < cf->can_dlc; j++) { | 793 | for (i = 0, j = 0; i < cf->can_dlc; j++) { |
@@ -832,7 +825,7 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 int_stat) | |||
832 | RX_NEXT: | 825 | RX_NEXT: |
833 | /* Reading the messsage object from the Message RAM */ | 826 | /* Reading the messsage object from the Message RAM */ |
834 | iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->ifregs[0].cmask); | 827 | iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->ifregs[0].cmask); |
835 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, k + 1); | 828 | pch_can_check_if_busy(&priv->regs->ifregs[0].creq, k); |
836 | reg = ioread32(&priv->regs->ifregs[0].mcont); | 829 | reg = ioread32(&priv->regs->ifregs[0].mcont); |
837 | } | 830 | } |
838 | 831 | ||
@@ -880,29 +873,27 @@ INT_STAT: | |||
880 | } | 873 | } |
881 | 874 | ||
882 | MSG_OBJ: | 875 | MSG_OBJ: |
883 | if ((int_stat >= 1) && (int_stat <= PCH_RX_OBJ_NUM)) { | 876 | if ((int_stat >= PCH_RX_OBJ_START) && (int_stat <= PCH_RX_OBJ_END)) { |
884 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); | 877 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); |
885 | rcv_pkts = pch_can_rx_normal(ndev, int_stat); | 878 | rcv_pkts = pch_can_rx_normal(ndev, int_stat); |
886 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); | 879 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); |
887 | if (rcv_pkts < 0) | 880 | if (rcv_pkts < 0) |
888 | return 0; | 881 | return 0; |
889 | } else if ((int_stat > PCH_RX_OBJ_NUM) && (int_stat <= PCH_OBJ_NUM)) { | 882 | } else if ((int_stat >= PCH_TX_OBJ_START) && |
890 | if (priv->msg_obj[int_stat - 1] == PCH_MSG_OBJ_TX) { | 883 | (int_stat <= PCH_TX_OBJ_END)) { |
891 | /* Handle transmission interrupt */ | 884 | /* Handle transmission interrupt */ |
892 | can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_NUM - 1); | 885 | can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_END - 1); |
893 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); | 886 | spin_lock_irqsave(&priv->msgif_reg_lock, flags); |
894 | iowrite32(PCH_CMASK_RX_TX_GET | PCH_CMASK_CLRINTPND, | 887 | iowrite32(PCH_CMASK_RX_TX_GET | PCH_CMASK_CLRINTPND, |
895 | &priv->regs->ifregs[1].cmask); | 888 | &priv->regs->ifregs[1].cmask); |
896 | dlc = ioread32(&priv->regs->ifregs[1].mcont) & | 889 | dlc = ioread32(&priv->regs->ifregs[1].mcont) & |
897 | PCH_IF_MCONT_DLC; | 890 | PCH_IF_MCONT_DLC; |
898 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, | 891 | pch_can_check_if_busy(&priv->regs->ifregs[1].creq, int_stat); |
899 | int_stat); | 892 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); |
900 | spin_unlock_irqrestore(&priv->msgif_reg_lock, flags); | 893 | if (dlc > 8) |
901 | if (dlc > 8) | 894 | dlc = 8; |
902 | dlc = 8; | 895 | stats->tx_bytes += dlc; |
903 | stats->tx_bytes += dlc; | 896 | stats->tx_packets++; |
904 | stats->tx_packets++; | ||
905 | } | ||
906 | } | 897 | } |
907 | 898 | ||
908 | int_stat = pch_can_int_pending(priv); | 899 | int_stat = pch_can_int_pending(priv); |
@@ -1064,12 +1055,12 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
1064 | if (can_dropped_invalid_skb(ndev, skb)) | 1055 | if (can_dropped_invalid_skb(ndev, skb)) |
1065 | return NETDEV_TX_OK; | 1056 | return NETDEV_TX_OK; |
1066 | 1057 | ||
1067 | if (priv->tx_obj == (PCH_OBJ_NUM + 1)) { /* Point tail Obj */ | 1058 | if (priv->tx_obj == PCH_TX_OBJ_END) { /* Point tail Obj */ |
1068 | while (pch_get_msg_obj_sts(ndev, (((1 << PCH_TX_OBJ_NUM)-1) << | 1059 | while (pch_get_msg_obj_sts(ndev, (((1 << PCH_TX_OBJ_NUM)-1) << |
1069 | PCH_RX_OBJ_NUM))) | 1060 | PCH_RX_OBJ_NUM))) |
1070 | udelay(500); | 1061 | udelay(500); |
1071 | 1062 | ||
1072 | priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj ID */ | 1063 | priv->tx_obj = PCH_TX_OBJ_START; /* Point head of Tx Obj ID */ |
1073 | tx_buffer_avail = priv->tx_obj; /* Point Tail of Tx Obj */ | 1064 | tx_buffer_avail = priv->tx_obj; /* Point Tail of Tx Obj */ |
1074 | } else { | 1065 | } else { |
1075 | tx_buffer_avail = priv->tx_obj; | 1066 | tx_buffer_avail = priv->tx_obj; |
@@ -1113,7 +1104,7 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev) | |||
1113 | (&priv->regs->ifregs[1].dataa1) + j*4); | 1104 | (&priv->regs->ifregs[1].dataa1) + j*4); |
1114 | } | 1105 | } |
1115 | 1106 | ||
1116 | can_put_echo_skb(skb, ndev, tx_buffer_avail - PCH_RX_OBJ_NUM - 1); | 1107 | can_put_echo_skb(skb, ndev, tx_buffer_avail - PCH_RX_OBJ_END - 1); |
1117 | 1108 | ||
1118 | /* Updating the size of the data. */ | 1109 | /* Updating the size of the data. */ |
1119 | pch_can_bit_clear(&priv->regs->ifregs[1].mcont, 0x0f); | 1110 | pch_can_bit_clear(&priv->regs->ifregs[1].mcont, 0x0f); |
@@ -1188,23 +1179,16 @@ static int pch_can_suspend(struct pci_dev *pdev, pm_message_t state) | |||
1188 | pch_can_set_int_enables(priv, PCH_CAN_DISABLE); | 1179 | pch_can_set_int_enables(priv, PCH_CAN_DISABLE); |
1189 | 1180 | ||
1190 | /* Save Tx buffer enable state */ | 1181 | /* Save Tx buffer enable state */ |
1191 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 1182 | for (i = PCH_TX_OBJ_START; i <= PCH_TX_OBJ_END; i++) |
1192 | if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) | 1183 | priv->tx_enable[i] = pch_can_get_rxtx_ir(priv, i, PCH_TX_IFREG); |
1193 | priv->tx_enable[i] = pch_can_get_rxtx_ir(priv, i + 1, | ||
1194 | PCH_TX_IFREG); | ||
1195 | } | ||
1196 | 1184 | ||
1197 | /* Disable all Transmit buffers */ | 1185 | /* Disable all Transmit buffers */ |
1198 | pch_can_set_tx_all(priv, 0); | 1186 | pch_can_set_tx_all(priv, 0); |
1199 | 1187 | ||
1200 | /* Save Rx buffer enable state */ | 1188 | /* Save Rx buffer enable state */ |
1201 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 1189 | for (i = PCH_RX_OBJ_START; i <= PCH_RX_OBJ_END; i++) { |
1202 | if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) { | 1190 | priv->rx_enable[i] = pch_can_get_rxtx_ir(priv, i, PCH_RX_IFREG); |
1203 | priv->rx_enable[i] = pch_can_get_rxtx_ir(priv, i + 1, | 1191 | pch_can_get_rx_buffer_link(priv, i, &priv->rx_link[i]); |
1204 | PCH_RX_IFREG); | ||
1205 | pch_can_get_rx_buffer_link(priv, i + 1, | ||
1206 | &(priv->rx_link[i])); | ||
1207 | } | ||
1208 | } | 1192 | } |
1209 | 1193 | ||
1210 | /* Disable all Receive buffers */ | 1194 | /* Disable all Receive buffers */ |
@@ -1256,24 +1240,16 @@ static int pch_can_resume(struct pci_dev *pdev) | |||
1256 | pch_can_set_optmode(priv); | 1240 | pch_can_set_optmode(priv); |
1257 | 1241 | ||
1258 | /* Enabling the transmit buffer. */ | 1242 | /* Enabling the transmit buffer. */ |
1259 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 1243 | for (i = PCH_TX_OBJ_START; i <= PCH_TX_OBJ_END; i++) |
1260 | if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) | 1244 | pch_can_set_rxtx(priv, i, priv->tx_enable[i], PCH_TX_IFREG); |
1261 | pch_can_set_rxtx(priv, i, priv->tx_enable[i], | ||
1262 | PCH_TX_IFREG); | ||
1263 | } | ||
1264 | 1245 | ||
1265 | /* Configuring the receive buffer and enabling them. */ | 1246 | /* Configuring the receive buffer and enabling them. */ |
1266 | for (i = 0; i < PCH_OBJ_NUM; i++) { | 1247 | for (i = PCH_RX_OBJ_START; i <= PCH_RX_OBJ_END; i++) { |
1267 | if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) { | 1248 | /* Restore buffer link */ |
1268 | /* Restore buffer link */ | 1249 | pch_can_set_rx_buffer_link(priv, i, priv->rx_link[i]); |
1269 | pch_can_set_rx_buffer_link(priv, i + 1, | ||
1270 | priv->rx_link[i]); | ||
1271 | 1250 | ||
1272 | /* Restore buffer enables */ | 1251 | /* Restore buffer enables */ |
1273 | pch_can_set_rxtx(priv, i, priv->rx_enable[i], | 1252 | pch_can_set_rxtx(priv, i, priv->rx_enable[i], PCH_RX_IFREG); |
1274 | PCH_RX_IFREG); | ||
1275 | |||
1276 | } | ||
1277 | } | 1253 | } |
1278 | 1254 | ||
1279 | /* Enable CAN Interrupts */ | 1255 | /* Enable CAN Interrupts */ |
@@ -1306,7 +1282,6 @@ static int __devinit pch_can_probe(struct pci_dev *pdev, | |||
1306 | struct net_device *ndev; | 1282 | struct net_device *ndev; |
1307 | struct pch_can_priv *priv; | 1283 | struct pch_can_priv *priv; |
1308 | int rc; | 1284 | int rc; |
1309 | int index; | ||
1310 | void __iomem *addr; | 1285 | void __iomem *addr; |
1311 | 1286 | ||
1312 | rc = pci_enable_device(pdev); | 1287 | rc = pci_enable_device(pdev); |
@@ -1328,7 +1303,7 @@ static int __devinit pch_can_probe(struct pci_dev *pdev, | |||
1328 | goto probe_exit_ipmap; | 1303 | goto probe_exit_ipmap; |
1329 | } | 1304 | } |
1330 | 1305 | ||
1331 | ndev = alloc_candev(sizeof(struct pch_can_priv), PCH_TX_OBJ_NUM); | 1306 | ndev = alloc_candev(sizeof(struct pch_can_priv), PCH_TX_OBJ_END); |
1332 | if (!ndev) { | 1307 | if (!ndev) { |
1333 | rc = -ENOMEM; | 1308 | rc = -ENOMEM; |
1334 | dev_err(&pdev->dev, "Failed alloc_candev\n"); | 1309 | dev_err(&pdev->dev, "Failed alloc_candev\n"); |
@@ -1344,7 +1319,7 @@ static int __devinit pch_can_probe(struct pci_dev *pdev, | |||
1344 | priv->can.do_get_berr_counter = pch_can_get_berr_counter; | 1319 | priv->can.do_get_berr_counter = pch_can_get_berr_counter; |
1345 | priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | | 1320 | priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | |
1346 | CAN_CTRLMODE_LOOPBACK; | 1321 | CAN_CTRLMODE_LOOPBACK; |
1347 | priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj */ | 1322 | priv->tx_obj = PCH_TX_OBJ_START; /* Point head of Tx Obj */ |
1348 | 1323 | ||
1349 | ndev->irq = pdev->irq; | 1324 | ndev->irq = pdev->irq; |
1350 | ndev->flags |= IFF_ECHO; | 1325 | ndev->flags |= IFF_ECHO; |
@@ -1352,15 +1327,9 @@ static int __devinit pch_can_probe(struct pci_dev *pdev, | |||
1352 | pci_set_drvdata(pdev, ndev); | 1327 | pci_set_drvdata(pdev, ndev); |
1353 | SET_NETDEV_DEV(ndev, &pdev->dev); | 1328 | SET_NETDEV_DEV(ndev, &pdev->dev); |
1354 | ndev->netdev_ops = &pch_can_netdev_ops; | 1329 | ndev->netdev_ops = &pch_can_netdev_ops; |
1355 | |||
1356 | priv->can.clock.freq = PCH_CAN_CLK; /* Hz */ | 1330 | priv->can.clock.freq = PCH_CAN_CLK; /* Hz */ |
1357 | for (index = 0; index < PCH_RX_OBJ_NUM;) | ||
1358 | priv->msg_obj[index++] = PCH_MSG_OBJ_RX; | ||
1359 | |||
1360 | for (index = index; index < PCH_OBJ_NUM;) | ||
1361 | priv->msg_obj[index++] = PCH_MSG_OBJ_TX; | ||
1362 | 1331 | ||
1363 | netif_napi_add(ndev, &priv->napi, pch_can_rx_poll, PCH_RX_OBJ_NUM); | 1332 | netif_napi_add(ndev, &priv->napi, pch_can_rx_poll, PCH_RX_OBJ_END); |
1364 | 1333 | ||
1365 | rc = register_candev(ndev); | 1334 | rc = register_candev(ndev); |
1366 | if (rc) { | 1335 | if (rc) { |