Skip to content

Commit 4e5d79b

Browse files
committed
Merge branch 'in_interrupt-cleanup-part-2'
Sebastian Andrzej Siewior says: ==================== in_interrupt() cleanup, part 2 in the discussion about preempt count consistency across kernel configurations: https://lore.kernel.org/r/20200914204209.256266093@linutronix.de/ Linus clearly requested that code in drivers and libraries which changes behaviour based on execution context should either be split up so that e.g. task context invocations and BH invocations have different interfaces or if that's not possible the context information has to be provided by the caller which knows in which context it is executing. This includes conditional locking, allocation mode (GFP_*) decisions and avoidance of code paths which might sleep. In the long run, usage of 'preemptible, in_*irq etc.' should be banned from driver code completely. This is part two addressing remaining drivers except for orinoco-usb. ==================== Cherry picking only Ethernet changes. Link: https://lore.kernel.org/r/20201027225454.3492351-1-bigeasy@linutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 68bb466 + beca928 commit 4e5d79b

File tree

4 files changed

+83
-66
lines changed

4 files changed

+83
-66
lines changed

drivers/net/ethernet/neterion/s2io.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ static int s2io_print_pci_mode(struct s2io_nic *nic)
11061106
* '-1' on failure
11071107
*/
11081108

1109-
static int init_tti(struct s2io_nic *nic, int link)
1109+
static int init_tti(struct s2io_nic *nic, int link, bool may_sleep)
11101110
{
11111111
struct XENA_dev_config __iomem *bar0 = nic->bar0;
11121112
register u64 val64 = 0;
@@ -1166,7 +1166,7 @@ static int init_tti(struct s2io_nic *nic, int link)
11661166

11671167
if (wait_for_cmd_complete(&bar0->tti_command_mem,
11681168
TTI_CMD_MEM_STROBE_NEW_CMD,
1169-
S2IO_BIT_RESET) != SUCCESS)
1169+
S2IO_BIT_RESET, may_sleep) != SUCCESS)
11701170
return FAILURE;
11711171
}
11721172

@@ -1659,7 +1659,7 @@ static int init_nic(struct s2io_nic *nic)
16591659
*/
16601660

16611661
/* Initialize TTI */
1662-
if (SUCCESS != init_tti(nic, nic->last_link_state))
1662+
if (SUCCESS != init_tti(nic, nic->last_link_state, true))
16631663
return -ENODEV;
16641664

16651665
/* RTI Initialization */
@@ -3331,7 +3331,7 @@ static void s2io_updt_xpak_counter(struct net_device *dev)
33313331
*/
33323332

33333333
static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
3334-
int bit_state)
3334+
int bit_state, bool may_sleep)
33353335
{
33363336
int ret = FAILURE, cnt = 0, delay = 1;
33373337
u64 val64;
@@ -3353,7 +3353,7 @@ static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
33533353
}
33543354
}
33553355

3356-
if (in_interrupt())
3356+
if (!may_sleep)
33573357
mdelay(delay);
33583358
else
33593359
msleep(delay);
@@ -4877,8 +4877,7 @@ static struct net_device_stats *s2io_get_stats(struct net_device *dev)
48774877
* Return value:
48784878
* void.
48794879
*/
4880-
4881-
static void s2io_set_multicast(struct net_device *dev)
4880+
static void s2io_set_multicast(struct net_device *dev, bool may_sleep)
48824881
{
48834882
int i, j, prev_cnt;
48844883
struct netdev_hw_addr *ha;
@@ -4903,7 +4902,7 @@ static void s2io_set_multicast(struct net_device *dev)
49034902
/* Wait till command completes */
49044903
wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
49054904
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4906-
S2IO_BIT_RESET);
4905+
S2IO_BIT_RESET, may_sleep);
49074906

49084907
sp->m_cast_flg = 1;
49094908
sp->all_multi_pos = config->max_mc_addr - 1;
@@ -4920,7 +4919,7 @@ static void s2io_set_multicast(struct net_device *dev)
49204919
/* Wait till command completes */
49214920
wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
49224921
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4923-
S2IO_BIT_RESET);
4922+
S2IO_BIT_RESET, may_sleep);
49244923

49254924
sp->m_cast_flg = 0;
49264925
sp->all_multi_pos = 0;
@@ -5000,7 +4999,7 @@ static void s2io_set_multicast(struct net_device *dev)
50004999
/* Wait for command completes */
50015000
if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
50025001
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5003-
S2IO_BIT_RESET)) {
5002+
S2IO_BIT_RESET, may_sleep)) {
50045003
DBG_PRINT(ERR_DBG,
50055004
"%s: Adding Multicasts failed\n",
50065005
dev->name);
@@ -5030,7 +5029,7 @@ static void s2io_set_multicast(struct net_device *dev)
50305029
/* Wait for command completes */
50315030
if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
50325031
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5033-
S2IO_BIT_RESET)) {
5032+
S2IO_BIT_RESET, may_sleep)) {
50345033
DBG_PRINT(ERR_DBG,
50355034
"%s: Adding Multicasts failed\n",
50365035
dev->name);
@@ -5041,6 +5040,12 @@ static void s2io_set_multicast(struct net_device *dev)
50415040
}
50425041
}
50435042

5043+
/* NDO wrapper for s2io_set_multicast */
5044+
static void s2io_ndo_set_multicast(struct net_device *dev)
5045+
{
5046+
s2io_set_multicast(dev, false);
5047+
}
5048+
50445049
/* read from CAM unicast & multicast addresses and store it in
50455050
* def_mac_addr structure
50465051
*/
@@ -5127,7 +5132,7 @@ static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int off)
51275132
/* Wait till command completes */
51285133
if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
51295134
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5130-
S2IO_BIT_RESET)) {
5135+
S2IO_BIT_RESET, true)) {
51315136
DBG_PRINT(INFO_DBG, "do_s2io_add_mac failed\n");
51325137
return FAILURE;
51335138
}
@@ -5171,7 +5176,7 @@ static u64 do_s2io_read_unicast_mc(struct s2io_nic *sp, int offset)
51715176
/* Wait till command completes */
51725177
if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
51735178
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5174-
S2IO_BIT_RESET)) {
5179+
S2IO_BIT_RESET, true)) {
51755180
DBG_PRINT(INFO_DBG, "do_s2io_read_unicast_mc failed\n");
51765181
return FAILURE;
51775182
}
@@ -7141,7 +7146,7 @@ static int s2io_card_up(struct s2io_nic *sp)
71417146
}
71427147

71437148
/* Setting its receive mode */
7144-
s2io_set_multicast(dev);
7149+
s2io_set_multicast(dev, true);
71457150

71467151
if (dev->features & NETIF_F_LRO) {
71477152
/* Initialize max aggregatable pkts per session based on MTU */
@@ -7447,7 +7452,7 @@ static void s2io_link(struct s2io_nic *sp, int link)
74477452
struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
74487453

74497454
if (link != sp->last_link_state) {
7450-
init_tti(sp, link);
7455+
init_tti(sp, link, false);
74517456
if (link == LINK_DOWN) {
74527457
DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
74537458
s2io_stop_all_tx_queue(sp);
@@ -7604,7 +7609,7 @@ static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
76047609

76057610
return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
76067611
RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
7607-
S2IO_BIT_RESET);
7612+
S2IO_BIT_RESET, true);
76087613
}
76097614

76107615
static const struct net_device_ops s2io_netdev_ops = {
@@ -7613,7 +7618,7 @@ static const struct net_device_ops s2io_netdev_ops = {
76137618
.ndo_get_stats = s2io_get_stats,
76147619
.ndo_start_xmit = s2io_xmit,
76157620
.ndo_validate_addr = eth_validate_addr,
7616-
.ndo_set_rx_mode = s2io_set_multicast,
7621+
.ndo_set_rx_mode = s2io_ndo_set_multicast,
76177622
.ndo_do_ioctl = s2io_ioctl,
76187623
.ndo_set_mac_address = s2io_set_mac_addr,
76197624
.ndo_change_mtu = s2io_change_mtu,
@@ -7929,7 +7934,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
79297934
writeq(val64, &bar0->rmac_addr_cmd_mem);
79307935
wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
79317936
RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
7932-
S2IO_BIT_RESET);
7937+
S2IO_BIT_RESET, true);
79337938
tmp64 = readq(&bar0->rmac_addr_data0_mem);
79347939
mac_down = (u32)tmp64;
79357940
mac_up = (u32) (tmp64 >> 32);

drivers/net/ethernet/neterion/s2io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ static void tx_intr_handler(struct fifo_info *fifo_data);
10661066
static void s2io_handle_errors(void * dev_id);
10671067

10681068
static void s2io_tx_watchdog(struct net_device *dev, unsigned int txqueue);
1069-
static void s2io_set_multicast(struct net_device *dev);
1069+
static void s2io_set_multicast(struct net_device *dev, bool may_sleep);
10701070
static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp);
10711071
static void s2io_link(struct s2io_nic * sp, int link);
10721072
static void s2io_reset(struct s2io_nic * sp);
@@ -1087,7 +1087,7 @@ static int s2io_set_swapper(struct s2io_nic * sp);
10871087
static void s2io_card_down(struct s2io_nic *nic);
10881088
static int s2io_card_up(struct s2io_nic *nic);
10891089
static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
1090-
int bit_state);
1090+
int bit_state, bool may_sleep);
10911091
static int s2io_add_isr(struct s2io_nic * sp);
10921092
static void s2io_rem_isr(struct s2io_nic * sp);
10931093

drivers/net/ethernet/nvidia/forcedeth.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,7 @@ static void nv_update_stats(struct net_device *dev)
16661666
struct fe_priv *np = netdev_priv(dev);
16671667
u8 __iomem *base = get_hwbase(dev);
16681668

1669-
/* If it happens that this is run in top-half context, then
1670-
* replace the spin_lock of hwstats_lock with
1671-
* spin_lock_irqsave() in calling functions. */
1672-
WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half");
1673-
assert_spin_locked(&np->hwstats_lock);
1669+
lockdep_assert_held(&np->hwstats_lock);
16741670

16751671
/* query hardware */
16761672
np->estats.tx_bytes += readl(base + NvRegTxCnt);

0 commit comments

Comments
 (0)