Skip to content

Commit 2c6ce53

Browse files
ParthibanI17164kuba-moo
authored andcommitted
net: ethernet: oa_tc6: implement mac-phy interrupt
The MAC-PHY interrupt is asserted when the following conditions are met. Receive chunks available - This interrupt is asserted when the previous data footer had no receive data chunks available and once the receive data chunks become available for reading. On reception of the first data header this interrupt will be deasserted. Transmit chunk credits available - This interrupt is asserted when the previous data footer indicated no transmit credits available and once the transmit credits become available for transmitting transmit data chunks. On reception of the first data header this interrupt will be deasserted. Extended status event - This interrupt is asserted when the previous data footer indicated no extended status and once the extended event become available. In this case the host should read status #0 register to know the corresponding error/event. On reception of the first data header this interrupt will be deasserted. Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Parthiban Veerasooran <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d70a0d8 commit 2c6ce53

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

drivers/net/ethernet/oa_tc6.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct oa_tc6 {
126126
u16 tx_credits;
127127
u8 rx_chunks_available;
128128
bool rx_buf_overflow;
129+
bool int_flag;
129130
};
130131

131132
enum oa_tc6_header_type {
@@ -1064,6 +1065,14 @@ static int oa_tc6_try_spi_transfer(struct oa_tc6 *tc6)
10641065

10651066
spi_len = oa_tc6_prepare_spi_tx_buf_for_rx_chunks(tc6, spi_len);
10661067

1068+
if (tc6->int_flag) {
1069+
tc6->int_flag = false;
1070+
if (spi_len == 0) {
1071+
oa_tc6_add_empty_chunks_to_spi_buf(tc6, 1);
1072+
spi_len = OA_TC6_CHUNK_SIZE;
1073+
}
1074+
}
1075+
10671076
if (spi_len == 0)
10681077
break;
10691078

@@ -1098,8 +1107,11 @@ static int oa_tc6_spi_thread_handler(void *data)
10981107
int ret;
10991108

11001109
while (likely(!kthread_should_stop())) {
1101-
/* This kthread will be waken up if there is a tx skb */
1110+
/* This kthread will be waken up if there is a tx skb or mac-phy
1111+
* interrupt to perform spi transfer with tx chunks.
1112+
*/
11021113
wait_event_interruptible(tc6->spi_wq, tc6->waiting_tx_skb ||
1114+
tc6->int_flag ||
11031115
kthread_should_stop());
11041116

11051117
if (kthread_should_stop())
@@ -1133,6 +1145,24 @@ static int oa_tc6_update_buffer_status_from_register(struct oa_tc6 *tc6)
11331145
return 0;
11341146
}
11351147

1148+
static irqreturn_t oa_tc6_macphy_isr(int irq, void *data)
1149+
{
1150+
struct oa_tc6 *tc6 = data;
1151+
1152+
/* MAC-PHY interrupt can occur for the following reasons.
1153+
* - availability of tx credits if it was 0 before and not reported in
1154+
* the previous rx footer.
1155+
* - availability of rx chunks if it was 0 before and not reported in
1156+
* the previous rx footer.
1157+
* - extended status event not reported in the previous rx footer.
1158+
*/
1159+
tc6->int_flag = true;
1160+
/* Wake spi kthread to perform spi transfer */
1161+
wake_up_interruptible(&tc6->spi_wq);
1162+
1163+
return IRQ_HANDLED;
1164+
}
1165+
11361166
/**
11371167
* oa_tc6_start_xmit - function for sending the tx skb which consists ethernet
11381168
* frame.
@@ -1260,8 +1290,28 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev)
12601290

12611291
sched_set_fifo(tc6->spi_thread);
12621292

1293+
ret = devm_request_irq(&tc6->spi->dev, tc6->spi->irq, oa_tc6_macphy_isr,
1294+
IRQF_TRIGGER_FALLING, dev_name(&tc6->spi->dev),
1295+
tc6);
1296+
if (ret) {
1297+
dev_err(&tc6->spi->dev, "Failed to request macphy isr %d\n",
1298+
ret);
1299+
goto kthread_stop;
1300+
}
1301+
1302+
/* oa_tc6_sw_reset_macphy() function resets and clears the MAC-PHY reset
1303+
* complete status. IRQ is also asserted on reset completion and it is
1304+
* remain asserted until MAC-PHY receives a data chunk. So performing an
1305+
* empty data chunk transmission will deassert the IRQ. Refer section
1306+
* 7.7 and 9.2.8.8 in the OPEN Alliance specification for more details.
1307+
*/
1308+
tc6->int_flag = true;
1309+
wake_up_interruptible(&tc6->spi_wq);
1310+
12631311
return tc6;
12641312

1313+
kthread_stop:
1314+
kthread_stop(tc6->spi_thread);
12651315
phy_exit:
12661316
oa_tc6_phy_exit(tc6);
12671317
return NULL;

0 commit comments

Comments
 (0)