Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge commit '71f0dd5a3293d75d26d405ffbaedfdda4836af32' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next into for-6.15/io_uring-rx-zc

Merge networking zerocopy receive tree, to get the prep patches for
the io_uring rx zc support.

* git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (63 commits)
net: add helpers for setting a memory provider on an rx queue
net: page_pool: add memory provider helpers
net: prepare for non devmem TCP memory providers
net: page_pool: add a mp hook to unregister_netdevice*
net: page_pool: add callback for mp info printing
netdev: add io_uring memory provider info
net: page_pool: create hooks for custom memory providers
net: generalise net_iov chunk owners
net: prefix devmem specific helpers
net: page_pool: don't cast mp param to devmem
tools: ynl: add all headers to makefile deps
eth: fbnic: set IFF_UNICAST_FLT to avoid enabling promiscuous mode when adding unicast addrs
eth: fbnic: add MAC address TCAM to debugfs
tools: ynl-gen: support limits using definitions
tools: ynl-gen: don't output external constants
net/mlx5e: Avoid WARN_ON when configuring MQPRIO with HTB offload enabled
net/mlx5e: Remove unused mlx5e_tc_flow_action struct
net/mlx5: Remove stray semicolon in LAG port selection table creation
net/mlx5e: Support FEC settings for 200G per lane link modes
net/mlx5: Add support for 200Gbps per lane link modes
...

+1570 -3359
+1 -1
Documentation/arch/s390/driver-model.rst
··· 244 244 -------------------- 245 245 246 246 The ccwgroup mechanism is designed to handle devices consisting of multiple ccw 247 - devices, like lcs or ctc. 247 + devices, like qeth or ctc. 248 248 249 249 The ccw driver provides a 'group' attribute. Piping bus ids of ccw devices to 250 250 this attributes creates a ccwgroup device consisting of these ccw devices (if
+3
Documentation/devicetree/bindings/net/faraday,ftgmac100.yaml
··· 44 44 phy-mode: 45 45 enum: 46 46 - rgmii 47 + - rgmii-id 48 + - rgmii-rxid 49 + - rgmii-txid 47 50 - rmii 48 51 49 52 phy-handle: true
+3 -2
Documentation/netlink/genetlink.yaml
··· 14 14 pattern: ^[0-9A-Za-z_-]+( - 1)?$ 15 15 minimum: 0 16 16 len-or-limit: 17 - # literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc. 17 + # literal int, const name, or limit based on fixed-width type 18 + # e.g. u8-min, u16-max, etc. 18 19 type: [ string, integer ] 19 - pattern: ^[su](8|16|32|64)-(min|max)$ 20 + pattern: ^[0-9A-Za-z_-]+$ 20 21 minimum: 0 21 22 22 23 # Schema for specs
+15
Documentation/netlink/specs/netdev.yaml
··· 115 115 type: u64 116 116 enum: xsk-flags 117 117 - 118 + name: io-uring-provider-info 119 + attributes: [] 120 + - 118 121 name: page-pool 119 122 attributes: 120 123 - ··· 174 171 name: dmabuf 175 172 doc: ID of the dmabuf this page-pool is attached to. 176 173 type: u32 174 + - 175 + name: io-uring 176 + doc: io-uring memory provider information. 177 + type: nest 178 + nested-attributes: io-uring-provider-info 177 179 - 178 180 name: page-pool-info 179 181 subset-of: page-pool ··· 304 296 name: dmabuf 305 297 doc: ID of the dmabuf attached to this queue, if any. 306 298 type: u32 299 + - 300 + name: io-uring 301 + doc: io_uring memory provider information. 302 + type: nest 303 + nested-attributes: io-uring-provider-info 307 304 308 305 - 309 306 name: qstats ··· 585 572 - inflight-mem 586 573 - detach-time 587 574 - dmabuf 575 + - io-uring 588 576 dump: 589 577 reply: *pp-reply 590 578 config-cond: page-pool ··· 651 637 - napi-id 652 638 - ifindex 653 639 - dmabuf 640 + - io-uring 654 641 dump: 655 642 request: 656 643 attributes:
-1
arch/s390/include/asm/irq.h
··· 54 54 IRQIO_C70, 55 55 IRQIO_TAP, 56 56 IRQIO_VMR, 57 - IRQIO_LCS, 58 57 IRQIO_CTC, 59 58 IRQIO_ADM, 60 59 IRQIO_CSC,
-1
arch/s390/kernel/irq.c
··· 84 84 {.irq = IRQIO_C70, .name = "C70", .desc = "[I/O] 3270"}, 85 85 {.irq = IRQIO_TAP, .name = "TAP", .desc = "[I/O] Tape"}, 86 86 {.irq = IRQIO_VMR, .name = "VMR", .desc = "[I/O] Unit Record Devices"}, 87 - {.irq = IRQIO_LCS, .name = "LCS", .desc = "[I/O] LCS"}, 88 87 {.irq = IRQIO_CTC, .name = "CTC", .desc = "[I/O] CTC"}, 89 88 {.irq = IRQIO_ADM, .name = "ADM", .desc = "[I/O] EADM Subchannel"}, 90 89 {.irq = IRQIO_CSC, .name = "CSC", .desc = "[I/O] CHSC Subchannel"},
-3
drivers/net/bonding/bond_main.c
··· 432 432 struct bonding *bond; 433 433 struct slave *slave; 434 434 435 - if (!bond_dev) 436 - return NULL; 437 - 438 435 bond = netdev_priv(bond_dev); 439 436 if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) 440 437 return NULL;
-1
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.h
··· 226 226 struct offload_port_info ports; 227 227 struct offload_ka_info kas; 228 228 struct offload_rr_info rrs; 229 - u8 buf[]; 230 229 }; 231 230 232 231 struct __packed hw_atl_utils_fw_rpc {
-16
drivers/net/ethernet/cavium/liquidio/octeon_device.c
··· 1433 1433 } 1434 1434 EXPORT_SYMBOL_GPL(octeon_wait_for_ddr_init); 1435 1435 1436 - /* Get the octeon id assigned to the octeon device passed as argument. 1437 - * This function is exported to other modules. 1438 - * @param dev - octeon device pointer passed as a void *. 1439 - * @return octeon device id 1440 - */ 1441 - int lio_get_device_id(void *dev) 1442 - { 1443 - struct octeon_device *octeon_dev = (struct octeon_device *)dev; 1444 - u32 i; 1445 - 1446 - for (i = 0; i < MAX_OCTEON_DEVICES; i++) 1447 - if (octeon_device[i] == octeon_dev) 1448 - return octeon_dev->octeon_id; 1449 - return -1; 1450 - } 1451 - 1452 1436 void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq) 1453 1437 { 1454 1438 u64 instr_cnt;
-7
drivers/net/ethernet/cavium/liquidio/octeon_device.h
··· 705 705 */ 706 706 struct octeon_device *lio_get_device(u32 octeon_id); 707 707 708 - /** Get the octeon id assigned to the octeon device passed as argument. 709 - * This function is exported to other modules. 710 - * @param dev - octeon device pointer passed as a void *. 711 - * @return octeon device id 712 - */ 713 - int lio_get_device_id(void *dev); 714 - 715 708 /** Read windowed register. 716 709 * @param oct - pointer to the Octeon device. 717 710 * @param addr - Address of the register to read.
+4 -3
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
··· 1211 1211 struct timer_list flower_stats_timer; 1212 1212 struct work_struct flower_stats_work; 1213 1213 1214 - /* Ethtool Dump */ 1215 - struct ethtool_dump eth_dump; 1216 - 1217 1214 /* HMA */ 1218 1215 struct hma_data hma; 1219 1216 ··· 1230 1233 1231 1234 /* Ethtool n-tuple */ 1232 1235 struct cxgb4_ethtool_filter *ethtool_filters; 1236 + 1237 + /* Ethtool Dump */ 1238 + /* Must be last - ends in a flex-array member. */ 1239 + struct ethtool_dump eth_dump; 1233 1240 }; 1234 1241 1235 1242 /* Support for "sched-class" command to allow a TX Scheduling Class to be
-22
drivers/net/ethernet/mellanox/mlx4/alloc.c
··· 526 526 return res; 527 527 } 528 528 529 - u32 mlx4_zone_free_entries(struct mlx4_zone_allocator *zones, u32 uid, u32 obj, u32 count) 530 - { 531 - struct mlx4_zone_entry *zone; 532 - int res = 0; 533 - 534 - spin_lock(&zones->lock); 535 - 536 - zone = __mlx4_find_zone_by_uid(zones, uid); 537 - 538 - if (NULL == zone) { 539 - res = -1; 540 - goto out; 541 - } 542 - 543 - __mlx4_free_from_zone(zone, obj, count); 544 - 545 - out: 546 - spin_unlock(&zones->lock); 547 - 548 - return res; 549 - } 550 - 551 529 u32 mlx4_zone_free_entries_unique(struct mlx4_zone_allocator *zones, u32 obj, u32 count) 552 530 { 553 531 struct mlx4_zone_entry *zone;
-6
drivers/net/ethernet/mellanox/mlx4/mlx4.h
··· 1478 1478 u32 mlx4_zone_alloc_entries(struct mlx4_zone_allocator *zones, u32 uid, int count, 1479 1479 int align, u32 skip_mask, u32 *puid); 1480 1480 1481 - /* Free <count> objects, start from <obj> of the uid <uid> from zone_allocator 1482 - * <zones>. 1483 - */ 1484 - u32 mlx4_zone_free_entries(struct mlx4_zone_allocator *zones, 1485 - u32 uid, u32 obj, u32 count); 1486 - 1487 1481 /* If <zones> was allocated with MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP, instead of 1488 1482 * specifying the uid when freeing an object, zone allocator could figure it by 1489 1483 * itself. Other parameters are similar to mlx4_zone_free.
-20
drivers/net/ethernet/mellanox/mlx4/port.c
··· 147 147 return err; 148 148 } 149 149 150 - int mlx4_find_cached_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *idx) 151 - { 152 - struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; 153 - struct mlx4_mac_table *table = &info->mac_table; 154 - int i; 155 - 156 - for (i = 0; i < MLX4_MAX_MAC_NUM; i++) { 157 - if (!table->refs[i]) 158 - continue; 159 - 160 - if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) { 161 - *idx = i; 162 - return 0; 163 - } 164 - } 165 - 166 - return -ENOENT; 167 - } 168 - EXPORT_SYMBOL_GPL(mlx4_find_cached_mac); 169 - 170 150 static bool mlx4_need_mf_bond(struct mlx4_dev *dev) 171 151 { 172 152 int i, num_eth_ports = 0;
+54 -10
drivers/net/ethernet/mellanox/mlx5/core/en/port.c
··· 296 296 MLX5E_FEC_SUPPORTED_LINK_MODE_200G_2X, 297 297 MLX5E_FEC_SUPPORTED_LINK_MODE_400G_4X, 298 298 MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X, 299 + MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X, 300 + MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X, 301 + MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X, 302 + MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X, 299 303 MLX5E_MAX_FEC_SUPPORTED_LINK_MODE, 300 304 }; 301 305 302 306 #define MLX5E_FEC_FIRST_50G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_50G_1X 303 307 #define MLX5E_FEC_FIRST_100G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_100G_1X 308 + #define MLX5E_FEC_FIRST_200G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X 304 309 305 310 #define MLX5E_FEC_OVERRIDE_ADMIN_POLICY(buf, policy, write, link) \ 306 311 do { \ ··· 325 320 return link_mode < MLX5E_FEC_FIRST_50G_PER_LANE_MODE || 326 321 (link_mode < MLX5E_FEC_FIRST_100G_PER_LANE_MODE && 327 322 MLX5_CAP_PCAM_FEATURE(dev, fec_50G_per_lane_in_pplm)) || 328 - (link_mode >= MLX5E_FEC_FIRST_100G_PER_LANE_MODE && 329 - MLX5_CAP_PCAM_FEATURE(dev, fec_100G_per_lane_in_pplm)); 323 + (link_mode < MLX5E_FEC_FIRST_200G_PER_LANE_MODE && 324 + MLX5_CAP_PCAM_FEATURE(dev, fec_100G_per_lane_in_pplm)) || 325 + (link_mode >= MLX5E_FEC_FIRST_200G_PER_LANE_MODE && 326 + MLX5_CAP_PCAM_FEATURE(dev, fec_200G_per_lane_in_pplm)); 330 327 } 331 328 332 329 /* get/set FEC admin field for a given speed */ ··· 374 367 break; 375 368 case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X: 376 369 MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 800g_8x); 370 + break; 371 + case MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X: 372 + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 200g_1x); 373 + break; 374 + case MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X: 375 + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 400g_2x); 376 + break; 377 + case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X: 378 + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 800g_4x); 379 + break; 380 + case MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X: 381 + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 1600g_8x); 377 382 break; 378 383 default: 379 384 return -EINVAL; ··· 439 420 break; 440 421 case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X: 441 422 *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 800g_8x); 423 + break; 424 + case MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X: 425 + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 200g_1x); 426 + break; 427 + case MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X: 428 + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 400g_2x); 429 + break; 430 + case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X: 431 + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 800g_4x); 432 + break; 433 + case MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X: 434 + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 1600g_8x); 442 435 break; 443 436 default: 444 437 return -EINVAL; ··· 525 494 return 0; 526 495 } 527 496 497 + static u16 mlx5e_remap_fec_conf_mode(enum mlx5e_fec_supported_link_mode link_mode, 498 + u16 conf_fec) 499 + { 500 + /* RS fec in ethtool is originally mapped to MLX5E_FEC_RS_528_514. 501 + * For link modes up to 25G per lane, the value is kept. 502 + * For 50G or 100G per lane, it's remapped to MLX5E_FEC_RS_544_514. 503 + * For 200G per lane, remapped to MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD. 504 + */ 505 + if (conf_fec != BIT(MLX5E_FEC_RS_528_514)) 506 + return conf_fec; 507 + 508 + if (link_mode >= MLX5E_FEC_FIRST_200G_PER_LANE_MODE) 509 + return BIT(MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD); 510 + 511 + if (link_mode >= MLX5E_FEC_FIRST_50G_PER_LANE_MODE) 512 + return BIT(MLX5E_FEC_RS_544_514); 513 + 514 + return conf_fec; 515 + } 516 + 528 517 int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u16 fec_policy) 529 518 { 530 519 bool fec_50g_per_lane = MLX5_CAP_PCAM_FEATURE(dev, fec_50G_per_lane_in_pplm); ··· 581 530 if (!mlx5e_is_fec_supported_link_mode(dev, i)) 582 531 break; 583 532 584 - /* RS fec in ethtool is mapped to MLX5E_FEC_RS_528_514 585 - * to link modes up to 25G per lane and to 586 - * MLX5E_FEC_RS_544_514 in the new link modes based on 587 - * 50G or 100G per lane 588 - */ 589 - if (conf_fec == (1 << MLX5E_FEC_RS_528_514) && 590 - i >= MLX5E_FEC_FIRST_50G_PER_LANE_MODE) 591 - conf_fec = (1 << MLX5E_FEC_RS_544_514); 533 + conf_fec = mlx5e_remap_fec_conf_mode(i, conf_fec); 592 534 593 535 mlx5e_get_fec_cap_field(out, &fec_caps, i); 594 536
+1
drivers/net/ethernet/mellanox/mlx5/core/en/port.h
··· 61 61 MLX5E_FEC_NOFEC, 62 62 MLX5E_FEC_FIRECODE, 63 63 MLX5E_FEC_RS_528_514, 64 + MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD = 4, 64 65 MLX5E_FEC_RS_544_514 = 7, 65 66 MLX5E_FEC_LLRS_272_257_1 = 9, 66 67 };
+2 -2
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
··· 326 326 int node; 327 327 328 328 sq->pdev = c->pdev; 329 - sq->clock = &mdev->clock; 329 + sq->clock = mdev->clock; 330 330 sq->mkey_be = c->mkey_be; 331 331 sq->netdev = c->netdev; 332 332 sq->priv = c->priv; ··· 696 696 rq->pdev = c->pdev; 697 697 rq->netdev = priv->netdev; 698 698 rq->priv = priv; 699 - rq->clock = &mdev->clock; 699 + rq->clock = mdev->clock; 700 700 rq->tstamp = &priv->tstamp; 701 701 rq->mdev = mdev; 702 702 rq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
-5
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.h
··· 73 73 bool is_terminating_action; 74 74 }; 75 75 76 - struct mlx5e_tc_flow_action { 77 - unsigned int num_entries; 78 - struct flow_action_entry **entries; 79 - }; 80 - 81 76 extern struct mlx5e_tc_act mlx5e_tc_act_drop; 82 77 extern struct mlx5e_tc_act mlx5e_tc_act_trap; 83 78 extern struct mlx5e_tc_act mlx5e_tc_act_accept;
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/en/trap.c
··· 46 46 rq->pdev = t->pdev; 47 47 rq->netdev = priv->netdev; 48 48 rq->priv = priv; 49 - rq->clock = &mdev->clock; 49 + rq->clock = mdev->clock; 50 50 rq->tstamp = &priv->tstamp; 51 51 rq->mdev = mdev; 52 52 rq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
+2 -2
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
··· 289 289 ts = get_cqe_ts(priv->cqe); 290 290 291 291 if (mlx5_is_real_time_rq(priv->cq->mdev) || mlx5_is_real_time_sq(priv->cq->mdev)) 292 - return mlx5_real_time_cyc2time(&priv->cq->mdev->clock, ts); 292 + return mlx5_real_time_cyc2time(priv->cq->mdev->clock, ts); 293 293 294 - return mlx5_timecounter_cyc2time(&priv->cq->mdev->clock, ts); 294 + return mlx5_timecounter_cyc2time(priv->cq->mdev->clock, ts); 295 295 } 296 296 297 297 static void mlx5e_xsk_request_checksum(u16 csum_start, u16 csum_offset, void *priv)
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
··· 72 72 rq->netdev = c->netdev; 73 73 rq->priv = c->priv; 74 74 rq->tstamp = c->tstamp; 75 - rq->clock = &mdev->clock; 75 + rq->clock = mdev->clock; 76 76 rq->icosq = &c->icosq; 77 77 rq->ix = c->ix; 78 78 rq->channel = c;
+22
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
··· 237 237 ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT, 238 238 ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT, 239 239 ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT); 240 + MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_200GAUI_1_200GBASE_CR1_KR1, ext, 241 + ETHTOOL_LINK_MODE_200000baseCR_Full_BIT, 242 + ETHTOOL_LINK_MODE_200000baseKR_Full_BIT, 243 + ETHTOOL_LINK_MODE_200000baseDR_Full_BIT, 244 + ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT, 245 + ETHTOOL_LINK_MODE_200000baseSR_Full_BIT, 246 + ETHTOOL_LINK_MODE_200000baseVR_Full_BIT); 247 + MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_400GAUI_2_400GBASE_CR2_KR2, ext, 248 + ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT, 249 + ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT, 250 + ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT, 251 + ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT, 252 + ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT, 253 + ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT); 254 + MLX5_BUILD_PTYS2ETHTOOL_CONFIG(MLX5E_800GAUI_4_800GBASE_CR4_KR4, ext, 255 + ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT, 256 + ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT, 257 + ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT, 258 + ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT, 259 + ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT, 260 + ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT); 240 261 } 241 262 242 263 static void mlx5e_ethtool_get_speed_arr(struct mlx5_core_dev *mdev, ··· 952 931 [MLX5E_FEC_RS_528_514] = ETHTOOL_FEC_RS, 953 932 [MLX5E_FEC_RS_544_514] = ETHTOOL_FEC_RS, 954 933 [MLX5E_FEC_LLRS_272_257_1] = ETHTOOL_FEC_LLRS, 934 + [MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD] = ETHTOOL_FEC_RS, 955 935 }; 956 936 957 937 static u32 pplm2ethtool_fec(u_long fec_mode, unsigned long size)
+7 -4
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
··· 737 737 rq->netdev = c->netdev; 738 738 rq->priv = c->priv; 739 739 rq->tstamp = c->tstamp; 740 - rq->clock = &mdev->clock; 740 + rq->clock = mdev->clock; 741 741 rq->icosq = &c->icosq; 742 742 rq->ix = c->ix; 743 743 rq->channel = c; ··· 1614 1614 int err; 1615 1615 1616 1616 sq->pdev = c->pdev; 1617 - sq->clock = &mdev->clock; 1617 + sq->clock = mdev->clock; 1618 1618 sq->mkey_be = c->mkey_be; 1619 1619 sq->netdev = c->netdev; 1620 1620 sq->mdev = c->mdev; ··· 3816 3816 /* MQPRIO is another toplevel qdisc that can't be attached 3817 3817 * simultaneously with the offloaded HTB. 3818 3818 */ 3819 - if (WARN_ON(mlx5e_selq_is_htb_enabled(&priv->selq))) 3820 - return -EINVAL; 3819 + if (mlx5e_selq_is_htb_enabled(&priv->selq)) { 3820 + NL_SET_ERR_MSG_MOD(mqprio->extack, 3821 + "MQPRIO cannot be configured when HTB offload is enabled."); 3822 + return -EOPNOTSUPP; 3823 + } 3821 3824 3822 3825 switch (mqprio->mode) { 3823 3826 case TC_MQPRIO_MODE_DCB:
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
··· 97 97 mlx5_del_flow_rules(lag_definer->rules[idx]); 98 98 } 99 99 j = ldev->buckets; 100 - }; 100 + } 101 101 goto destroy_fg; 102 102 } 103 103 }
+474 -112
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
··· 43 43 #include <linux/cpufeature.h> 44 44 #endif /* CONFIG_X86 */ 45 45 46 + #define MLX5_RT_CLOCK_IDENTITY_SIZE MLX5_FLD_SZ_BYTES(mrtcq_reg, rt_clock_identity) 47 + 46 48 enum { 47 49 MLX5_PIN_MODE_IN = 0x0, 48 50 MLX5_PIN_MODE_OUT = 0x1, ··· 79 77 MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX = 200000, 80 78 }; 81 79 80 + struct mlx5_clock_dev_state { 81 + struct mlx5_core_dev *mdev; 82 + struct mlx5_devcom_comp_dev *compdev; 83 + struct mlx5_nb pps_nb; 84 + struct work_struct out_work; 85 + }; 86 + 87 + struct mlx5_clock_priv { 88 + struct mlx5_clock clock; 89 + struct mlx5_core_dev *mdev; 90 + struct mutex lock; /* protect mdev and used in PTP callbacks */ 91 + struct mlx5_core_dev *event_mdev; 92 + }; 93 + 94 + static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock) 95 + { 96 + return container_of(clock, struct mlx5_clock_priv, clock); 97 + } 98 + 99 + static void mlx5_clock_lockdep_assert(struct mlx5_clock *clock) 100 + { 101 + if (!clock->shared) 102 + return; 103 + 104 + lockdep_assert(lockdep_is_held(&clock_priv(clock)->lock)); 105 + } 106 + 107 + static struct mlx5_core_dev *mlx5_clock_mdev_get(struct mlx5_clock *clock) 108 + { 109 + mlx5_clock_lockdep_assert(clock); 110 + 111 + return clock_priv(clock)->mdev; 112 + } 113 + 114 + static void mlx5_clock_lock(struct mlx5_clock *clock) 115 + { 116 + if (!clock->shared) 117 + return; 118 + 119 + mutex_lock(&clock_priv(clock)->lock); 120 + } 121 + 122 + static void mlx5_clock_unlock(struct mlx5_clock *clock) 123 + { 124 + if (!clock->shared) 125 + return; 126 + 127 + mutex_unlock(&clock_priv(clock)->lock); 128 + } 129 + 82 130 static bool mlx5_real_time_mode(struct mlx5_core_dev *mdev) 83 131 { 84 132 return (mlx5_is_real_time_rq(mdev) || mlx5_is_real_time_sq(mdev)); ··· 144 92 static bool mlx5_modify_mtutc_allowed(struct mlx5_core_dev *mdev) 145 93 { 146 94 return MLX5_CAP_MCAM_FEATURE(mdev, ptpcyc2realtime_modify); 95 + } 96 + 97 + static int mlx5_clock_identity_get(struct mlx5_core_dev *mdev, 98 + u8 identify[MLX5_RT_CLOCK_IDENTITY_SIZE]) 99 + { 100 + u32 out[MLX5_ST_SZ_DW(mrtcq_reg)] = {}; 101 + u32 in[MLX5_ST_SZ_DW(mrtcq_reg)] = {}; 102 + int err; 103 + 104 + err = mlx5_core_access_reg(mdev, in, sizeof(in), 105 + out, sizeof(out), MLX5_REG_MRTCQ, 0, 0); 106 + if (!err) 107 + memcpy(identify, MLX5_ADDR_OF(mrtcq_reg, out, rt_clock_identity), 108 + MLX5_RT_CLOCK_IDENTITY_SIZE); 109 + 110 + return err; 147 111 } 148 112 149 113 static u32 mlx5_ptp_shift_constant(u32 dev_freq_khz) ··· 187 119 ilog2((U32_MAX / NSEC_PER_MSEC) * dev_freq_khz)); 188 120 } 189 121 190 - static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp) 122 + static s32 mlx5_clock_getmaxphase(struct mlx5_core_dev *mdev) 191 123 { 192 - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 193 - struct mlx5_core_dev *mdev; 194 - 195 - mdev = container_of(clock, struct mlx5_core_dev, clock); 196 - 197 124 return MLX5_CAP_MCAM_FEATURE(mdev, mtutc_time_adjustment_extended_range) ? 198 125 MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX : 199 126 MLX5_MTUTC_OPERATION_ADJUST_TIME_MAX; 200 127 } 201 128 129 + static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp) 130 + { 131 + struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 132 + struct mlx5_core_dev *mdev; 133 + s32 ret; 134 + 135 + mlx5_clock_lock(clock); 136 + mdev = mlx5_clock_mdev_get(clock); 137 + ret = mlx5_clock_getmaxphase(mdev); 138 + mlx5_clock_unlock(clock); 139 + 140 + return ret; 141 + } 142 + 202 143 static bool mlx5_is_mtutc_time_adj_cap(struct mlx5_core_dev *mdev, s64 delta) 203 144 { 204 - s64 max = mlx5_ptp_getmaxphase(&mdev->clock.ptp_info); 145 + s64 max = mlx5_clock_getmaxphase(mdev); 205 146 206 147 if (delta < -max || delta > max) 207 148 return false; ··· 286 209 if (real_time_mode) 287 210 *device_time = ns_to_ktime(REAL_TIME_TO_NS(device >> 32, device & U32_MAX)); 288 211 else 289 - *device_time = mlx5_timecounter_cyc2time(&mdev->clock, device); 212 + *device_time = mlx5_timecounter_cyc2time(mdev->clock, device); 290 213 291 214 return 0; 292 215 } ··· 297 220 struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 298 221 struct system_time_snapshot history_begin = {0}; 299 222 struct mlx5_core_dev *mdev; 223 + int err; 300 224 301 - mdev = container_of(clock, struct mlx5_core_dev, clock); 225 + mlx5_clock_lock(clock); 226 + mdev = mlx5_clock_mdev_get(clock); 302 227 303 - if (!mlx5_is_ptm_source_time_available(mdev)) 304 - return -EBUSY; 228 + if (!mlx5_is_ptm_source_time_available(mdev)) { 229 + err = -EBUSY; 230 + goto unlock; 231 + } 305 232 306 233 ktime_get_snapshot(&history_begin); 307 234 308 - return get_device_system_crosststamp(mlx5_mtctr_syncdevicetime, mdev, 309 - &history_begin, cts); 235 + err = get_device_system_crosststamp(mlx5_mtctr_syncdevicetime, mdev, 236 + &history_begin, cts); 237 + unlock: 238 + mlx5_clock_unlock(clock); 239 + return err; 310 240 } 311 241 #endif /* CONFIG_X86 */ 312 242 ··· 347 263 { 348 264 struct mlx5_timer *timer = container_of(cc, struct mlx5_timer, cycles); 349 265 struct mlx5_clock *clock = container_of(timer, struct mlx5_clock, timer); 350 - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, 351 - clock); 266 + struct mlx5_core_dev *mdev = mlx5_clock_mdev_get(clock); 352 267 353 268 return mlx5_read_time(mdev, NULL, false) & cc->mask; 354 269 } ··· 355 272 static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev) 356 273 { 357 274 struct mlx5_ib_clock_info *clock_info = mdev->clock_info; 358 - struct mlx5_clock *clock = &mdev->clock; 275 + struct mlx5_clock *clock = mdev->clock; 359 276 struct mlx5_timer *timer; 360 277 u32 sign; 361 278 ··· 378 295 379 296 static void mlx5_pps_out(struct work_struct *work) 380 297 { 381 - struct mlx5_pps *pps_info = container_of(work, struct mlx5_pps, 382 - out_work); 383 - struct mlx5_clock *clock = container_of(pps_info, struct mlx5_clock, 384 - pps_info); 385 - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, 386 - clock); 298 + struct mlx5_clock_dev_state *clock_state = container_of(work, struct mlx5_clock_dev_state, 299 + out_work); 300 + struct mlx5_core_dev *mdev = clock_state->mdev; 301 + struct mlx5_clock *clock = mdev->clock; 387 302 u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0}; 388 303 unsigned long flags; 389 304 int i; ··· 411 330 unsigned long flags; 412 331 413 332 clock = container_of(ptp_info, struct mlx5_clock, ptp_info); 414 - mdev = container_of(clock, struct mlx5_core_dev, clock); 333 + mlx5_clock_lock(clock); 334 + mdev = mlx5_clock_mdev_get(clock); 415 335 timer = &clock->timer; 416 336 417 337 if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) ··· 424 342 write_sequnlock_irqrestore(&clock->lock, flags); 425 343 426 344 out: 345 + mlx5_clock_unlock(clock); 427 346 return timer->overflow_period; 428 347 } 429 348 ··· 444 361 return mlx5_set_mtutc(mdev, in, sizeof(in)); 445 362 } 446 363 447 - static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) 364 + static int mlx5_clock_settime(struct mlx5_core_dev *mdev, struct mlx5_clock *clock, 365 + const struct timespec64 *ts) 448 366 { 449 - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 450 367 struct mlx5_timer *timer = &clock->timer; 451 - struct mlx5_core_dev *mdev; 452 368 unsigned long flags; 453 - 454 - mdev = container_of(clock, struct mlx5_core_dev, clock); 455 369 456 370 if (mlx5_modify_mtutc_allowed(mdev)) { 457 371 int err = mlx5_ptp_settime_real_time(mdev, ts); ··· 463 383 write_sequnlock_irqrestore(&clock->lock, flags); 464 384 465 385 return 0; 386 + } 387 + 388 + static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts) 389 + { 390 + struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 391 + struct mlx5_core_dev *mdev; 392 + int err; 393 + 394 + mlx5_clock_lock(clock); 395 + mdev = mlx5_clock_mdev_get(clock); 396 + err = mlx5_clock_settime(mdev, clock, ts); 397 + mlx5_clock_unlock(clock); 398 + 399 + return err; 466 400 } 467 401 468 402 static ··· 498 404 struct mlx5_core_dev *mdev; 499 405 u64 cycles, ns; 500 406 501 - mdev = container_of(clock, struct mlx5_core_dev, clock); 407 + mlx5_clock_lock(clock); 408 + mdev = mlx5_clock_mdev_get(clock); 502 409 if (mlx5_real_time_mode(mdev)) { 503 410 *ts = mlx5_ptp_gettimex_real_time(mdev, sts); 504 411 goto out; ··· 509 414 ns = mlx5_timecounter_cyc2time(clock, cycles); 510 415 *ts = ns_to_timespec64(ns); 511 416 out: 417 + mlx5_clock_unlock(clock); 512 418 return 0; 513 419 } 514 420 ··· 540 444 struct mlx5_timer *timer = &clock->timer; 541 445 struct mlx5_core_dev *mdev; 542 446 unsigned long flags; 447 + int err = 0; 543 448 544 - mdev = container_of(clock, struct mlx5_core_dev, clock); 449 + mlx5_clock_lock(clock); 450 + mdev = mlx5_clock_mdev_get(clock); 545 451 546 452 if (mlx5_modify_mtutc_allowed(mdev)) { 547 - int err = mlx5_ptp_adjtime_real_time(mdev, delta); 453 + err = mlx5_ptp_adjtime_real_time(mdev, delta); 548 454 549 455 if (err) 550 - return err; 456 + goto unlock; 551 457 } 552 458 553 459 write_seqlock_irqsave(&clock->lock, flags); ··· 557 459 mlx5_update_clock_info_page(mdev); 558 460 write_sequnlock_irqrestore(&clock->lock, flags); 559 461 560 - return 0; 462 + unlock: 463 + mlx5_clock_unlock(clock); 464 + return err; 561 465 } 562 466 563 467 static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta) 564 468 { 565 469 struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); 566 470 struct mlx5_core_dev *mdev; 471 + int err; 567 472 568 - mdev = container_of(clock, struct mlx5_core_dev, clock); 473 + mlx5_clock_lock(clock); 474 + mdev = mlx5_clock_mdev_get(clock); 475 + err = mlx5_ptp_adjtime_real_time(mdev, delta); 476 + mlx5_clock_unlock(clock); 569 477 570 - return mlx5_ptp_adjtime_real_time(mdev, delta); 478 + return err; 571 479 } 572 480 573 481 static int mlx5_ptp_freq_adj_real_time(struct mlx5_core_dev *mdev, long scaled_ppm) ··· 602 498 struct mlx5_timer *timer = &clock->timer; 603 499 struct mlx5_core_dev *mdev; 604 500 unsigned long flags; 501 + int err = 0; 605 502 u32 mult; 606 503 607 - mdev = container_of(clock, struct mlx5_core_dev, clock); 504 + mlx5_clock_lock(clock); 505 + mdev = mlx5_clock_mdev_get(clock); 608 506 609 507 if (mlx5_modify_mtutc_allowed(mdev)) { 610 - int err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm); 508 + err = mlx5_ptp_freq_adj_real_time(mdev, scaled_ppm); 611 509 612 510 if (err) 613 - return err; 511 + goto unlock; 614 512 } 615 513 616 514 mult = (u32)adjust_by_scaled_ppm(timer->nominal_c_mult, scaled_ppm); ··· 624 518 write_sequnlock_irqrestore(&clock->lock, flags); 625 519 ptp_schedule_worker(clock->ptp, timer->overflow_period); 626 520 627 - return 0; 521 + unlock: 522 + mlx5_clock_unlock(clock); 523 + return err; 628 524 } 629 525 630 526 static int mlx5_extts_configure(struct ptp_clock_info *ptp, ··· 635 527 { 636 528 struct mlx5_clock *clock = 637 529 container_of(ptp, struct mlx5_clock, ptp_info); 638 - struct mlx5_core_dev *mdev = 639 - container_of(clock, struct mlx5_core_dev, clock); 640 530 u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0}; 531 + struct mlx5_core_dev *mdev; 641 532 u32 field_select = 0; 642 533 u8 pin_mode = 0; 643 534 u8 pattern = 0; 644 535 int pin = -1; 645 536 int err = 0; 646 - 647 - if (!MLX5_PPS_CAP(mdev)) 648 - return -EOPNOTSUPP; 649 537 650 538 /* Reject requests with unsupported flags */ 651 539 if (rq->extts.flags & ~(PTP_ENABLE_FEATURE | ··· 673 569 field_select = MLX5_MTPPS_FS_ENABLE; 674 570 } 675 571 572 + mlx5_clock_lock(clock); 573 + mdev = mlx5_clock_mdev_get(clock); 574 + 575 + if (!MLX5_PPS_CAP(mdev)) { 576 + err = -EOPNOTSUPP; 577 + goto unlock; 578 + } 579 + 676 580 MLX5_SET(mtpps_reg, in, pin, pin); 677 581 MLX5_SET(mtpps_reg, in, pin_mode, pin_mode); 678 582 MLX5_SET(mtpps_reg, in, pattern, pattern); ··· 689 577 690 578 err = mlx5_set_mtpps(mdev, in, sizeof(in)); 691 579 if (err) 692 - return err; 580 + goto unlock; 693 581 694 - return mlx5_set_mtppse(mdev, pin, 0, 695 - MLX5_EVENT_MODE_REPETETIVE & on); 582 + err = mlx5_set_mtppse(mdev, pin, 0, MLX5_EVENT_MODE_REPETETIVE & on); 583 + if (err) 584 + goto unlock; 585 + 586 + clock->pps_info.pin_armed[pin] = on; 587 + clock_priv(clock)->event_mdev = mdev; 588 + 589 + unlock: 590 + mlx5_clock_unlock(clock); 591 + return err; 696 592 } 697 593 698 594 static u64 find_target_cycles(struct mlx5_core_dev *mdev, s64 target_ns) 699 595 { 700 - struct mlx5_clock *clock = &mdev->clock; 596 + struct mlx5_clock *clock = mdev->clock; 701 597 u64 cycles_now, cycles_delta; 702 598 u64 nsec_now, nsec_delta; 703 599 struct mlx5_timer *timer; ··· 764 644 struct ptp_clock_request *rq, 765 645 u32 *out_pulse_duration_ns) 766 646 { 767 - struct mlx5_pps *pps_info = &mdev->clock.pps_info; 647 + struct mlx5_pps *pps_info = &mdev->clock->pps_info; 768 648 u32 out_pulse_duration; 769 649 struct timespec64 ts; 770 650 ··· 797 677 u32 *field_select, u32 *out_pulse_duration_ns, 798 678 u64 *period, u64 *time_stamp) 799 679 { 800 - struct mlx5_pps *pps_info = &mdev->clock.pps_info; 680 + struct mlx5_pps *pps_info = &mdev->clock->pps_info; 801 681 struct ptp_clock_time *time = &rq->perout.start; 802 682 struct timespec64 ts; 803 683 ··· 832 712 { 833 713 struct mlx5_clock *clock = 834 714 container_of(ptp, struct mlx5_clock, ptp_info); 835 - struct mlx5_core_dev *mdev = 836 - container_of(clock, struct mlx5_core_dev, clock); 837 - bool rt_mode = mlx5_real_time_mode(mdev); 838 715 u32 in[MLX5_ST_SZ_DW(mtpps_reg)] = {0}; 839 716 u32 out_pulse_duration_ns = 0; 717 + struct mlx5_core_dev *mdev; 840 718 u32 field_select = 0; 841 719 u64 npps_period = 0; 842 720 u64 time_stamp = 0; 843 721 u8 pin_mode = 0; 844 722 u8 pattern = 0; 723 + bool rt_mode; 845 724 int pin = -1; 846 725 int err = 0; 847 - 848 - if (!MLX5_PPS_CAP(mdev)) 849 - return -EOPNOTSUPP; 850 - 851 - /* Reject requests with unsupported flags */ 852 - if (mlx5_perout_verify_flags(mdev, rq->perout.flags)) 853 - return -EOPNOTSUPP; 854 726 855 727 if (rq->perout.index >= clock->ptp_info.n_pins) 856 728 return -EINVAL; ··· 852 740 if (pin < 0) 853 741 return -EBUSY; 854 742 855 - if (on) { 856 - bool rt_mode = mlx5_real_time_mode(mdev); 743 + mlx5_clock_lock(clock); 744 + mdev = mlx5_clock_mdev_get(clock); 745 + rt_mode = mlx5_real_time_mode(mdev); 857 746 747 + if (!MLX5_PPS_CAP(mdev)) { 748 + err = -EOPNOTSUPP; 749 + goto unlock; 750 + } 751 + 752 + /* Reject requests with unsupported flags */ 753 + if (mlx5_perout_verify_flags(mdev, rq->perout.flags)) { 754 + err = -EOPNOTSUPP; 755 + goto unlock; 756 + } 757 + 758 + if (on) { 858 759 pin_mode = MLX5_PIN_MODE_OUT; 859 760 pattern = MLX5_OUT_PATTERN_PERIODIC; 860 761 861 - if (rt_mode && rq->perout.start.sec > U32_MAX) 862 - return -EINVAL; 762 + if (rt_mode && rq->perout.start.sec > U32_MAX) { 763 + err = -EINVAL; 764 + goto unlock; 765 + } 863 766 864 767 field_select |= MLX5_MTPPS_FS_PIN_MODE | 865 768 MLX5_MTPPS_FS_PATTERN | ··· 887 760 else 888 761 err = perout_conf_1pps(mdev, rq, &time_stamp, rt_mode); 889 762 if (err) 890 - return err; 763 + goto unlock; 891 764 } 892 765 893 766 MLX5_SET(mtpps_reg, in, pin, pin); ··· 900 773 MLX5_SET(mtpps_reg, in, out_pulse_duration_ns, out_pulse_duration_ns); 901 774 err = mlx5_set_mtpps(mdev, in, sizeof(in)); 902 775 if (err) 903 - return err; 776 + goto unlock; 904 777 905 778 if (rt_mode) 906 - return 0; 779 + goto unlock; 907 780 908 - return mlx5_set_mtppse(mdev, pin, 0, 909 - MLX5_EVENT_MODE_REPETETIVE & on); 781 + err = mlx5_set_mtppse(mdev, pin, 0, MLX5_EVENT_MODE_REPETETIVE & on); 782 + 783 + unlock: 784 + mlx5_clock_unlock(clock); 785 + return err; 910 786 } 911 787 912 788 static int mlx5_pps_configure(struct ptp_clock_info *ptp, ··· 996 866 mtpps_size, MLX5_REG_MTPPS, 0, 0); 997 867 } 998 868 999 - static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin) 869 + static int mlx5_get_pps_pin_mode(struct mlx5_core_dev *mdev, u8 pin) 1000 870 { 1001 - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); 1002 - 1003 871 u32 out[MLX5_ST_SZ_DW(mtpps_reg)] = {}; 1004 872 u8 mode; 1005 873 int err; ··· 1016 888 return PTP_PF_NONE; 1017 889 } 1018 890 1019 - static void mlx5_init_pin_config(struct mlx5_clock *clock) 891 + static void mlx5_init_pin_config(struct mlx5_core_dev *mdev) 1020 892 { 893 + struct mlx5_clock *clock = mdev->clock; 1021 894 int i; 1022 895 1023 896 if (!clock->ptp_info.n_pins) ··· 1039 910 sizeof(clock->ptp_info.pin_config[i].name), 1040 911 "mlx5_pps%d", i); 1041 912 clock->ptp_info.pin_config[i].index = i; 1042 - clock->ptp_info.pin_config[i].func = mlx5_get_pps_pin_mode(clock, i); 913 + clock->ptp_info.pin_config[i].func = mlx5_get_pps_pin_mode(mdev, i); 1043 914 clock->ptp_info.pin_config[i].chan = 0; 1044 915 } 1045 916 } 1046 917 1047 918 static void mlx5_get_pps_caps(struct mlx5_core_dev *mdev) 1048 919 { 1049 - struct mlx5_clock *clock = &mdev->clock; 1050 920 u32 out[MLX5_ST_SZ_DW(mtpps_reg)] = {0}; 921 + struct mlx5_clock *clock = mdev->clock; 1051 922 1052 923 mlx5_query_mtpps(mdev, out, sizeof(out)); 1053 924 ··· 1097 968 static int mlx5_pps_event(struct notifier_block *nb, 1098 969 unsigned long type, void *data) 1099 970 { 1100 - struct mlx5_clock *clock = mlx5_nb_cof(nb, struct mlx5_clock, pps_nb); 971 + struct mlx5_clock_dev_state *clock_state = mlx5_nb_cof(nb, struct mlx5_clock_dev_state, 972 + pps_nb); 973 + struct mlx5_core_dev *mdev = clock_state->mdev; 974 + struct mlx5_clock *clock = mdev->clock; 1101 975 struct ptp_clock_event ptp_event; 1102 976 struct mlx5_eqe *eqe = data; 1103 977 int pin = eqe->data.pps.pin; 1104 - struct mlx5_core_dev *mdev; 1105 978 unsigned long flags; 1106 979 u64 ns; 1107 - 1108 - mdev = container_of(clock, struct mlx5_core_dev, clock); 1109 980 1110 981 switch (clock->ptp_info.pin_config[pin].func) { 1111 982 case PTP_PF_EXTTS: ··· 1126 997 ptp_clock_event(clock->ptp, &ptp_event); 1127 998 break; 1128 999 case PTP_PF_PEROUT: 1000 + if (clock->shared) { 1001 + mlx5_core_warn(mdev, " Received unexpected PPS out event\n"); 1002 + break; 1003 + } 1129 1004 ns = perout_conf_next_event_timer(mdev, clock); 1130 1005 write_seqlock_irqsave(&clock->lock, flags); 1131 1006 clock->pps_info.start[pin] = ns; 1132 1007 write_sequnlock_irqrestore(&clock->lock, flags); 1133 - schedule_work(&clock->pps_info.out_work); 1008 + schedule_work(&clock_state->out_work); 1134 1009 break; 1135 1010 default: 1136 1011 mlx5_core_err(mdev, " Unhandled clock PPS event, func %d\n", ··· 1146 1013 1147 1014 static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) 1148 1015 { 1149 - struct mlx5_clock *clock = &mdev->clock; 1016 + struct mlx5_clock *clock = mdev->clock; 1150 1017 struct mlx5_timer *timer = &clock->timer; 1151 1018 u32 dev_freq; 1152 1019 ··· 1162 1029 ktime_to_ns(ktime_get_real())); 1163 1030 } 1164 1031 1165 - static void mlx5_init_overflow_period(struct mlx5_clock *clock) 1032 + static void mlx5_init_overflow_period(struct mlx5_core_dev *mdev) 1166 1033 { 1167 - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); 1168 1034 struct mlx5_ib_clock_info *clock_info = mdev->clock_info; 1035 + struct mlx5_clock *clock = mdev->clock; 1169 1036 struct mlx5_timer *timer = &clock->timer; 1170 1037 u64 overflow_cycles; 1171 1038 u64 frac = 0; ··· 1198 1065 1199 1066 static void mlx5_init_clock_info(struct mlx5_core_dev *mdev) 1200 1067 { 1201 - struct mlx5_clock *clock = &mdev->clock; 1068 + struct mlx5_clock *clock = mdev->clock; 1202 1069 struct mlx5_ib_clock_info *info; 1203 1070 struct mlx5_timer *timer; 1204 1071 ··· 1221 1088 1222 1089 static void mlx5_init_timer_max_freq_adjustment(struct mlx5_core_dev *mdev) 1223 1090 { 1224 - struct mlx5_clock *clock = &mdev->clock; 1091 + struct mlx5_clock *clock = mdev->clock; 1225 1092 u32 out[MLX5_ST_SZ_DW(mtutc_reg)] = {}; 1226 1093 u32 in[MLX5_ST_SZ_DW(mtutc_reg)] = {}; 1227 1094 u8 log_max_freq_adjustment = 0; ··· 1240 1107 1241 1108 static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) 1242 1109 { 1243 - struct mlx5_clock *clock = &mdev->clock; 1110 + struct mlx5_clock *clock = mdev->clock; 1244 1111 1245 1112 /* Configure the PHC */ 1246 1113 clock->ptp_info = mlx5_ptp_clock_info; ··· 1256 1123 1257 1124 mlx5_timecounter_init(mdev); 1258 1125 mlx5_init_clock_info(mdev); 1259 - mlx5_init_overflow_period(clock); 1126 + mlx5_init_overflow_period(mdev); 1260 1127 1261 1128 if (mlx5_real_time_mode(mdev)) { 1262 1129 struct timespec64 ts; 1263 1130 1264 1131 ktime_get_real_ts64(&ts); 1265 - mlx5_ptp_settime(&clock->ptp_info, &ts); 1132 + mlx5_clock_settime(mdev, clock, &ts); 1266 1133 } 1267 1134 } 1268 1135 1269 1136 static void mlx5_init_pps(struct mlx5_core_dev *mdev) 1270 1137 { 1271 - struct mlx5_clock *clock = &mdev->clock; 1272 - 1273 1138 if (!MLX5_PPS_CAP(mdev)) 1274 1139 return; 1275 1140 1276 1141 mlx5_get_pps_caps(mdev); 1277 - mlx5_init_pin_config(clock); 1142 + mlx5_init_pin_config(mdev); 1278 1143 } 1279 1144 1280 - void mlx5_init_clock(struct mlx5_core_dev *mdev) 1145 + static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev) 1281 1146 { 1282 - struct mlx5_clock *clock = &mdev->clock; 1283 - 1284 - if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) { 1285 - mlx5_core_warn(mdev, "invalid device_frequency_khz, aborting HW clock init\n"); 1286 - return; 1287 - } 1147 + struct mlx5_clock *clock = mdev->clock; 1288 1148 1289 1149 seqlock_init(&clock->lock); 1290 - INIT_WORK(&clock->pps_info.out_work, mlx5_pps_out); 1291 1150 1292 1151 /* Initialize the device clock */ 1293 1152 mlx5_init_timer_clock(mdev); ··· 1288 1163 mlx5_init_pps(mdev); 1289 1164 1290 1165 clock->ptp = ptp_clock_register(&clock->ptp_info, 1291 - &mdev->pdev->dev); 1166 + clock->shared ? NULL : &mdev->pdev->dev); 1292 1167 if (IS_ERR(clock->ptp)) { 1293 - mlx5_core_warn(mdev, "ptp_clock_register failed %ld\n", 1168 + mlx5_core_warn(mdev, "%sptp_clock_register failed %ld\n", 1169 + clock->shared ? "shared clock " : "", 1294 1170 PTR_ERR(clock->ptp)); 1295 1171 clock->ptp = NULL; 1296 1172 } 1297 - 1298 - MLX5_NB_INIT(&clock->pps_nb, mlx5_pps_event, PPS_EVENT); 1299 - mlx5_eq_notifier_register(mdev, &clock->pps_nb); 1300 1173 1301 1174 if (clock->ptp) 1302 1175 ptp_schedule_worker(clock->ptp, 0); 1303 1176 } 1304 1177 1305 - void mlx5_cleanup_clock(struct mlx5_core_dev *mdev) 1178 + static void mlx5_destroy_clock_dev(struct mlx5_core_dev *mdev) 1306 1179 { 1307 - struct mlx5_clock *clock = &mdev->clock; 1180 + struct mlx5_clock *clock = mdev->clock; 1308 1181 1309 - if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) 1310 - return; 1311 - 1312 - mlx5_eq_notifier_unregister(mdev, &clock->pps_nb); 1313 1182 if (clock->ptp) { 1314 1183 ptp_clock_unregister(clock->ptp); 1315 1184 clock->ptp = NULL; 1316 1185 } 1317 - 1318 - cancel_work_sync(&clock->pps_info.out_work); 1319 1186 1320 1187 if (mdev->clock_info) { 1321 1188 free_page((unsigned long)mdev->clock_info); ··· 1315 1198 } 1316 1199 1317 1200 kfree(clock->ptp_info.pin_config); 1201 + } 1202 + 1203 + static void mlx5_clock_free(struct mlx5_core_dev *mdev) 1204 + { 1205 + struct mlx5_clock_priv *cpriv = clock_priv(mdev->clock); 1206 + 1207 + mlx5_destroy_clock_dev(mdev); 1208 + mutex_destroy(&cpriv->lock); 1209 + kfree(cpriv); 1210 + mdev->clock = NULL; 1211 + } 1212 + 1213 + static int mlx5_clock_alloc(struct mlx5_core_dev *mdev, bool shared) 1214 + { 1215 + struct mlx5_clock_priv *cpriv; 1216 + struct mlx5_clock *clock; 1217 + 1218 + cpriv = kzalloc(sizeof(*cpriv), GFP_KERNEL); 1219 + if (!cpriv) 1220 + return -ENOMEM; 1221 + 1222 + mutex_init(&cpriv->lock); 1223 + cpriv->mdev = mdev; 1224 + clock = &cpriv->clock; 1225 + clock->shared = shared; 1226 + mdev->clock = clock; 1227 + mlx5_clock_lock(clock); 1228 + mlx5_init_clock_dev(mdev); 1229 + mlx5_clock_unlock(clock); 1230 + 1231 + if (!clock->shared) 1232 + return 0; 1233 + 1234 + if (!clock->ptp) { 1235 + mlx5_core_warn(mdev, "failed to create ptp dev shared by multiple functions"); 1236 + mlx5_clock_free(mdev); 1237 + return -EINVAL; 1238 + } 1239 + 1240 + return 0; 1241 + } 1242 + 1243 + static void mlx5_shared_clock_register(struct mlx5_core_dev *mdev, u64 key) 1244 + { 1245 + struct mlx5_core_dev *peer_dev, *next = NULL; 1246 + struct mlx5_devcom_comp_dev *pos; 1247 + 1248 + mdev->clock_state->compdev = mlx5_devcom_register_component(mdev->priv.devc, 1249 + MLX5_DEVCOM_SHARED_CLOCK, 1250 + key, NULL, mdev); 1251 + if (IS_ERR(mdev->clock_state->compdev)) 1252 + return; 1253 + 1254 + mlx5_devcom_comp_lock(mdev->clock_state->compdev); 1255 + mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, peer_dev, pos) { 1256 + if (peer_dev->clock) { 1257 + next = peer_dev; 1258 + break; 1259 + } 1260 + } 1261 + 1262 + if (next) { 1263 + mdev->clock = next->clock; 1264 + /* clock info is shared among all the functions using the same clock */ 1265 + mdev->clock_info = next->clock_info; 1266 + } else { 1267 + mlx5_clock_alloc(mdev, true); 1268 + } 1269 + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); 1270 + 1271 + if (!mdev->clock) { 1272 + mlx5_devcom_unregister_component(mdev->clock_state->compdev); 1273 + mdev->clock_state->compdev = NULL; 1274 + } 1275 + } 1276 + 1277 + static void mlx5_shared_clock_unregister(struct mlx5_core_dev *mdev) 1278 + { 1279 + struct mlx5_core_dev *peer_dev, *next = NULL; 1280 + struct mlx5_clock *clock = mdev->clock; 1281 + struct mlx5_devcom_comp_dev *pos; 1282 + 1283 + mlx5_devcom_comp_lock(mdev->clock_state->compdev); 1284 + mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, peer_dev, pos) { 1285 + if (peer_dev->clock && peer_dev != mdev) { 1286 + next = peer_dev; 1287 + break; 1288 + } 1289 + } 1290 + 1291 + if (next) { 1292 + struct mlx5_clock_priv *cpriv = clock_priv(clock); 1293 + 1294 + mlx5_clock_lock(clock); 1295 + if (mdev == cpriv->mdev) 1296 + cpriv->mdev = next; 1297 + mlx5_clock_unlock(clock); 1298 + } else { 1299 + mlx5_clock_free(mdev); 1300 + } 1301 + 1302 + mdev->clock = NULL; 1303 + mdev->clock_info = NULL; 1304 + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); 1305 + 1306 + mlx5_devcom_unregister_component(mdev->clock_state->compdev); 1307 + } 1308 + 1309 + static void mlx5_clock_arm_pps_in_event(struct mlx5_clock *clock, 1310 + struct mlx5_core_dev *new_mdev, 1311 + struct mlx5_core_dev *old_mdev) 1312 + { 1313 + struct ptp_clock_info *ptp_info = &clock->ptp_info; 1314 + struct mlx5_clock_priv *cpriv = clock_priv(clock); 1315 + int i; 1316 + 1317 + for (i = 0; i < ptp_info->n_pins; i++) { 1318 + if (ptp_info->pin_config[i].func != PTP_PF_EXTTS || 1319 + !clock->pps_info.pin_armed[i]) 1320 + continue; 1321 + 1322 + if (new_mdev) { 1323 + mlx5_set_mtppse(new_mdev, i, 0, MLX5_EVENT_MODE_REPETETIVE); 1324 + cpriv->event_mdev = new_mdev; 1325 + } else { 1326 + cpriv->event_mdev = NULL; 1327 + } 1328 + 1329 + if (old_mdev) 1330 + mlx5_set_mtppse(old_mdev, i, 0, MLX5_EVENT_MODE_DISABLE); 1331 + } 1332 + } 1333 + 1334 + void mlx5_clock_load(struct mlx5_core_dev *mdev) 1335 + { 1336 + struct mlx5_clock *clock = mdev->clock; 1337 + struct mlx5_clock_priv *cpriv; 1338 + 1339 + if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) 1340 + return; 1341 + 1342 + INIT_WORK(&mdev->clock_state->out_work, mlx5_pps_out); 1343 + MLX5_NB_INIT(&mdev->clock_state->pps_nb, mlx5_pps_event, PPS_EVENT); 1344 + mlx5_eq_notifier_register(mdev, &mdev->clock_state->pps_nb); 1345 + 1346 + if (!clock->shared) { 1347 + mlx5_clock_arm_pps_in_event(clock, mdev, NULL); 1348 + return; 1349 + } 1350 + 1351 + cpriv = clock_priv(clock); 1352 + mlx5_devcom_comp_lock(mdev->clock_state->compdev); 1353 + mlx5_clock_lock(clock); 1354 + if (mdev == cpriv->mdev && mdev != cpriv->event_mdev) 1355 + mlx5_clock_arm_pps_in_event(clock, mdev, cpriv->event_mdev); 1356 + mlx5_clock_unlock(clock); 1357 + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); 1358 + } 1359 + 1360 + void mlx5_clock_unload(struct mlx5_core_dev *mdev) 1361 + { 1362 + struct mlx5_core_dev *peer_dev, *next = NULL; 1363 + struct mlx5_clock *clock = mdev->clock; 1364 + struct mlx5_devcom_comp_dev *pos; 1365 + 1366 + if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) 1367 + return; 1368 + 1369 + if (!clock->shared) { 1370 + mlx5_clock_arm_pps_in_event(clock, NULL, mdev); 1371 + goto out; 1372 + } 1373 + 1374 + mlx5_devcom_comp_lock(mdev->clock_state->compdev); 1375 + mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, peer_dev, pos) { 1376 + if (peer_dev->clock && peer_dev != mdev) { 1377 + next = peer_dev; 1378 + break; 1379 + } 1380 + } 1381 + 1382 + mlx5_clock_lock(clock); 1383 + if (mdev == clock_priv(clock)->event_mdev) 1384 + mlx5_clock_arm_pps_in_event(clock, next, mdev); 1385 + mlx5_clock_unlock(clock); 1386 + mlx5_devcom_comp_unlock(mdev->clock_state->compdev); 1387 + 1388 + out: 1389 + mlx5_eq_notifier_unregister(mdev, &mdev->clock_state->pps_nb); 1390 + cancel_work_sync(&mdev->clock_state->out_work); 1391 + } 1392 + 1393 + static struct mlx5_clock null_clock; 1394 + 1395 + int mlx5_init_clock(struct mlx5_core_dev *mdev) 1396 + { 1397 + u8 identity[MLX5_RT_CLOCK_IDENTITY_SIZE]; 1398 + struct mlx5_clock_dev_state *clock_state; 1399 + u64 key; 1400 + int err; 1401 + 1402 + if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) { 1403 + mdev->clock = &null_clock; 1404 + mlx5_core_warn(mdev, "invalid device_frequency_khz, aborting HW clock init\n"); 1405 + return 0; 1406 + } 1407 + 1408 + clock_state = kzalloc(sizeof(*clock_state), GFP_KERNEL); 1409 + if (!clock_state) 1410 + return -ENOMEM; 1411 + clock_state->mdev = mdev; 1412 + mdev->clock_state = clock_state; 1413 + 1414 + if (MLX5_CAP_MCAM_REG3(mdev, mrtcq) && mlx5_real_time_mode(mdev)) { 1415 + if (mlx5_clock_identity_get(mdev, identity)) { 1416 + mlx5_core_warn(mdev, "failed to get rt clock identity, create ptp dev per function\n"); 1417 + } else { 1418 + memcpy(&key, &identity, sizeof(key)); 1419 + mlx5_shared_clock_register(mdev, key); 1420 + } 1421 + } 1422 + 1423 + if (!mdev->clock) { 1424 + err = mlx5_clock_alloc(mdev, false); 1425 + if (err) { 1426 + kfree(clock_state); 1427 + mdev->clock_state = NULL; 1428 + return err; 1429 + } 1430 + } 1431 + 1432 + return 0; 1433 + } 1434 + 1435 + void mlx5_cleanup_clock(struct mlx5_core_dev *mdev) 1436 + { 1437 + if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) 1438 + return; 1439 + 1440 + if (mdev->clock->shared) 1441 + mlx5_shared_clock_unregister(mdev); 1442 + else 1443 + mlx5_clock_free(mdev); 1444 + kfree(mdev->clock_state); 1445 + mdev->clock_state = NULL; 1318 1446 }
+36 -3
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h
··· 33 33 #ifndef __LIB_CLOCK_H__ 34 34 #define __LIB_CLOCK_H__ 35 35 36 + #include <linux/ptp_clock_kernel.h> 37 + 38 + #define MAX_PIN_NUM 8 39 + struct mlx5_pps { 40 + u8 pin_caps[MAX_PIN_NUM]; 41 + u64 start[MAX_PIN_NUM]; 42 + u8 enabled; 43 + u64 min_npps_period; 44 + u64 min_out_pulse_duration_ns; 45 + bool pin_armed[MAX_PIN_NUM]; 46 + }; 47 + 48 + struct mlx5_timer { 49 + struct cyclecounter cycles; 50 + struct timecounter tc; 51 + u32 nominal_c_mult; 52 + unsigned long overflow_period; 53 + }; 54 + 55 + struct mlx5_clock { 56 + seqlock_t lock; 57 + struct hwtstamp_config hwtstamp_config; 58 + struct ptp_clock *ptp; 59 + struct ptp_clock_info ptp_info; 60 + struct mlx5_pps pps_info; 61 + struct mlx5_timer timer; 62 + bool shared; 63 + }; 64 + 36 65 static inline bool mlx5_is_real_time_rq(struct mlx5_core_dev *mdev) 37 66 { 38 67 u8 rq_ts_format_cap = MLX5_CAP_GEN(mdev, rq_ts_format); ··· 83 54 typedef ktime_t (*cqe_ts_to_ns)(struct mlx5_clock *, u64); 84 55 85 56 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK) 86 - void mlx5_init_clock(struct mlx5_core_dev *mdev); 57 + int mlx5_init_clock(struct mlx5_core_dev *mdev); 87 58 void mlx5_cleanup_clock(struct mlx5_core_dev *mdev); 59 + void mlx5_clock_load(struct mlx5_core_dev *mdev); 60 + void mlx5_clock_unload(struct mlx5_core_dev *mdev); 88 61 89 62 static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev) 90 63 { 91 - return mdev->clock.ptp ? ptp_clock_index(mdev->clock.ptp) : -1; 64 + return mdev->clock->ptp ? ptp_clock_index(mdev->clock->ptp) : -1; 92 65 } 93 66 94 67 static inline ktime_t mlx5_timecounter_cyc2time(struct mlx5_clock *clock, ··· 118 87 return ns_to_ktime(time); 119 88 } 120 89 #else 121 - static inline void mlx5_init_clock(struct mlx5_core_dev *mdev) {} 90 + static inline int mlx5_init_clock(struct mlx5_core_dev *mdev) { return 0; } 122 91 static inline void mlx5_cleanup_clock(struct mlx5_core_dev *mdev) {} 92 + static inline void mlx5_clock_load(struct mlx5_core_dev *mdev) {} 93 + static inline void mlx5_clock_unload(struct mlx5_core_dev *mdev) {} 123 94 static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev) 124 95 { 125 96 return -1;
+1
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h
··· 11 11 MLX5_DEVCOM_MPV, 12 12 MLX5_DEVCOM_HCA_PORTS, 13 13 MLX5_DEVCOM_SD_GROUP, 14 + MLX5_DEVCOM_SHARED_CLOCK, 14 15 MLX5_DEVCOM_NUM_COMPONENTS, 15 16 }; 16 17
+12 -3
drivers/net/ethernet/mellanox/mlx5/core/main.c
··· 1038 1038 1039 1039 mlx5_init_reserved_gids(dev); 1040 1040 1041 - mlx5_init_clock(dev); 1041 + err = mlx5_init_clock(dev); 1042 + if (err) { 1043 + mlx5_core_err(dev, "failed to initialize hardware clock\n"); 1044 + goto err_tables_cleanup; 1045 + } 1042 1046 1043 1047 dev->vxlan = mlx5_vxlan_create(dev); 1044 1048 dev->geneve = mlx5_geneve_create(dev); ··· 1050 1046 err = mlx5_init_rl_table(dev); 1051 1047 if (err) { 1052 1048 mlx5_core_err(dev, "Failed to init rate limiting\n"); 1053 - goto err_tables_cleanup; 1049 + goto err_clock_cleanup; 1054 1050 } 1055 1051 1056 1052 err = mlx5_mpfs_init(dev); ··· 1127 1123 mlx5_mpfs_cleanup(dev); 1128 1124 err_rl_cleanup: 1129 1125 mlx5_cleanup_rl_table(dev); 1130 - err_tables_cleanup: 1126 + err_clock_cleanup: 1131 1127 mlx5_geneve_destroy(dev->geneve); 1132 1128 mlx5_vxlan_destroy(dev->vxlan); 1133 1129 mlx5_cleanup_clock(dev); 1130 + err_tables_cleanup: 1134 1131 mlx5_cleanup_reserved_gids(dev); 1135 1132 mlx5_cq_debugfs_cleanup(dev); 1136 1133 mlx5_fw_reset_cleanup(dev); ··· 1364 1359 goto err_eq_table; 1365 1360 } 1366 1361 1362 + mlx5_clock_load(dev); 1363 + 1367 1364 err = mlx5_fw_tracer_init(dev->tracer); 1368 1365 if (err) { 1369 1366 mlx5_core_err(dev, "Failed to init FW tracer %d\n", err); ··· 1449 1442 mlx5_hv_vhca_cleanup(dev->hv_vhca); 1450 1443 mlx5_fw_reset_events_stop(dev); 1451 1444 mlx5_fw_tracer_cleanup(dev->tracer); 1445 + mlx5_clock_unload(dev); 1452 1446 mlx5_eq_table_destroy(dev); 1453 1447 err_eq_table: 1454 1448 mlx5_irq_table_destroy(dev); ··· 1476 1468 mlx5_hv_vhca_cleanup(dev->hv_vhca); 1477 1469 mlx5_fw_reset_events_stop(dev); 1478 1470 mlx5_fw_tracer_cleanup(dev->tracer); 1471 + mlx5_clock_unload(dev); 1479 1472 mlx5_eq_table_destroy(dev); 1480 1473 mlx5_irq_table_destroy(dev); 1481 1474 mlx5_pagealloc_stop(dev);
+3
drivers/net/ethernet/mellanox/mlx5/core/port.c
··· 1105 1105 [MLX5E_200GAUI_2_200GBASE_CR2_KR2] = 200000, 1106 1106 [MLX5E_400GAUI_4_400GBASE_CR4_KR4] = 400000, 1107 1107 [MLX5E_800GAUI_8_800GBASE_CR8_KR8] = 800000, 1108 + [MLX5E_200GAUI_1_200GBASE_CR1_KR1] = 200000, 1109 + [MLX5E_400GAUI_2_400GBASE_CR2_KR2] = 400000, 1110 + [MLX5E_800GAUI_4_800GBASE_CR4_KR4] = 800000, 1108 1111 }; 1109 1112 1110 1113 int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port, bool ext,
-24
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_domain.c
··· 516 516 return NULL; 517 517 } 518 518 519 - /* Assure synchronization of the device steering tables with updates made by SW 520 - * insertion. 521 - */ 522 - int mlx5dr_domain_sync(struct mlx5dr_domain *dmn, u32 flags) 523 - { 524 - int ret = 0; 525 - 526 - if (flags & MLX5DR_DOMAIN_SYNC_FLAGS_SW) { 527 - mlx5dr_domain_lock(dmn); 528 - ret = mlx5dr_send_ring_force_drain(dmn); 529 - mlx5dr_domain_unlock(dmn); 530 - if (ret) { 531 - mlx5dr_err(dmn, "Force drain failed flags: %d, ret: %d\n", 532 - flags, ret); 533 - return ret; 534 - } 535 - } 536 - 537 - if (flags & MLX5DR_DOMAIN_SYNC_FLAGS_HW) 538 - ret = mlx5dr_cmd_sync_steering(dmn->mdev); 539 - 540 - return ret; 541 - } 542 - 543 519 int mlx5dr_domain_destroy(struct mlx5dr_domain *dmn) 544 520 { 545 521 if (WARN_ON_ONCE(refcount_read(&dmn->refcount) > 1))
-33
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_send.c
··· 1331 1331 kfree(send_ring->sync_buff); 1332 1332 kfree(send_ring); 1333 1333 } 1334 - 1335 - int mlx5dr_send_ring_force_drain(struct mlx5dr_domain *dmn) 1336 - { 1337 - struct mlx5dr_send_ring *send_ring = dmn->send_ring; 1338 - struct postsend_info send_info = {}; 1339 - u8 data[DR_STE_SIZE]; 1340 - int num_of_sends_req; 1341 - int ret; 1342 - int i; 1343 - 1344 - /* Sending this amount of requests makes sure we will get drain */ 1345 - num_of_sends_req = send_ring->signal_th * TH_NUMS_TO_DRAIN / 2; 1346 - 1347 - /* Send fake requests forcing the last to be signaled */ 1348 - send_info.write.addr = (uintptr_t)data; 1349 - send_info.write.length = DR_STE_SIZE; 1350 - send_info.write.lkey = 0; 1351 - /* Using the sync_mr in order to write/read */ 1352 - send_info.remote_addr = (uintptr_t)send_ring->sync_mr->addr; 1353 - send_info.rkey = send_ring->sync_mr->mkey; 1354 - 1355 - for (i = 0; i < num_of_sends_req; i++) { 1356 - ret = dr_postsend_icm_data(dmn, &send_info); 1357 - if (ret) 1358 - return ret; 1359 - } 1360 - 1361 - spin_lock(&send_ring->lock); 1362 - ret = dr_handle_pending_wc(dmn, send_ring); 1363 - spin_unlock(&send_ring->lock); 1364 - 1365 - return ret; 1366 - }
-1
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_types.h
··· 1473 1473 int mlx5dr_send_ring_alloc(struct mlx5dr_domain *dmn); 1474 1474 void mlx5dr_send_ring_free(struct mlx5dr_domain *dmn, 1475 1475 struct mlx5dr_send_ring *send_ring); 1476 - int mlx5dr_send_ring_force_drain(struct mlx5dr_domain *dmn); 1477 1476 int mlx5dr_send_postsend_ste(struct mlx5dr_domain *dmn, 1478 1477 struct mlx5dr_ste *ste, 1479 1478 u8 *data,
-2
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/mlx5dr.h
··· 45 45 46 46 int mlx5dr_domain_destroy(struct mlx5dr_domain *domain); 47 47 48 - int mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags); 49 - 50 48 void mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn, 51 49 struct mlx5dr_domain *peer_dmn, 52 50 u16 peer_vhca_id);
-3
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
··· 754 754 mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); 755 755 void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp, 756 756 struct net_device *dev); 757 - bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp, 758 - const struct net_device *dev); 759 - u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev); 760 757 u16 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp); 761 758 int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id, 762 759 enum mlxsw_sp_l3proto ul_proto,
-48
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
··· 8184 8184 return NULL; 8185 8185 } 8186 8186 8187 - bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp, 8188 - const struct net_device *dev) 8189 - { 8190 - struct mlxsw_sp_rif *rif; 8191 - 8192 - mutex_lock(&mlxsw_sp->router->lock); 8193 - rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev); 8194 - mutex_unlock(&mlxsw_sp->router->lock); 8195 - 8196 - return rif; 8197 - } 8198 - 8199 - u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev) 8200 - { 8201 - struct mlxsw_sp_rif *rif; 8202 - u16 vid = 0; 8203 - 8204 - mutex_lock(&mlxsw_sp->router->lock); 8205 - rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev); 8206 - if (!rif) 8207 - goto out; 8208 - 8209 - /* We only return the VID for VLAN RIFs. Otherwise we return an 8210 - * invalid value (0). 8211 - */ 8212 - if (rif->ops->type != MLXSW_SP_RIF_TYPE_VLAN) 8213 - goto out; 8214 - 8215 - vid = mlxsw_sp_fid_8021q_vid(rif->fid); 8216 - 8217 - out: 8218 - mutex_unlock(&mlxsw_sp->router->lock); 8219 - return vid; 8220 - } 8221 - 8222 8187 static int mlxsw_sp_router_rif_disable(struct mlxsw_sp *mlxsw_sp, u16 rif) 8223 8188 { 8224 8189 char ritr_pl[MLXSW_REG_RITR_LEN]; ··· 8380 8415 u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *lb_rif) 8381 8416 { 8382 8417 return lb_rif->common.rif_index; 8383 - } 8384 - 8385 - u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif) 8386 - { 8387 - struct net_device *dev = mlxsw_sp_rif_dev(&lb_rif->common); 8388 - u32 ul_tb_id = mlxsw_sp_ipip_dev_ul_tb_id(dev); 8389 - struct mlxsw_sp_vr *ul_vr; 8390 - 8391 - ul_vr = mlxsw_sp_vr_get(lb_rif->common.mlxsw_sp, ul_tb_id, NULL); 8392 - if (WARN_ON(IS_ERR(ul_vr))) 8393 - return 0; 8394 - 8395 - return ul_vr->id; 8396 8418 } 8397 8419 8398 8420 u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif)
-1
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h
··· 90 90 struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp, 91 91 u16 rif_index); 92 92 u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif); 93 - u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif); 94 93 u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif); 95 94 u32 mlxsw_sp_ipip_dev_ul_tb_id(const struct net_device *ol_dev); 96 95 int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
+36
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c
··· 10 10 11 11 static struct dentry *fbnic_dbg_root; 12 12 13 + static void fbnic_dbg_desc_break(struct seq_file *s, int i) 14 + { 15 + while (i--) 16 + seq_putc(s, '-'); 17 + 18 + seq_putc(s, '\n'); 19 + } 20 + 21 + static int fbnic_dbg_mac_addr_show(struct seq_file *s, void *v) 22 + { 23 + struct fbnic_dev *fbd = s->private; 24 + char hdr[80]; 25 + int i; 26 + 27 + /* Generate Header */ 28 + snprintf(hdr, sizeof(hdr), "%3s %s %-17s %s\n", 29 + "Idx", "S", "TCAM Bitmap", "Addr/Mask"); 30 + seq_puts(s, hdr); 31 + fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr))); 32 + 33 + for (i = 0; i < FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES; i++) { 34 + struct fbnic_mac_addr *mac_addr = &fbd->mac_addr[i]; 35 + 36 + seq_printf(s, "%02d %d %64pb %pm\n", 37 + i, mac_addr->state, mac_addr->act_tcam, 38 + mac_addr->value.addr8); 39 + seq_printf(s, " %pm\n", 40 + mac_addr->mask.addr8); 41 + } 42 + 43 + return 0; 44 + } 45 + DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_mac_addr); 46 + 13 47 static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v) 14 48 { 15 49 struct fbnic_dev *fbd = s->private; ··· 82 48 fbd->dbg_fbd = debugfs_create_dir(name, fbnic_dbg_root); 83 49 debugfs_create_file("pcie_stats", 0400, fbd->dbg_fbd, fbd, 84 50 &fbnic_dbg_pcie_stats_fops); 51 + debugfs_create_file("mac_addr", 0400, fbd->dbg_fbd, fbd, 52 + &fbnic_dbg_mac_addr_fops); 85 53 } 86 54 87 55 void fbnic_dbg_fbd_exit(struct fbnic_dev *fbd)
+2
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
··· 628 628 fbnic_rss_key_fill(fbn->rss_key); 629 629 fbnic_rss_init_en_mask(fbn); 630 630 631 + netdev->priv_flags |= IFF_UNICAST_FLT; 632 + 631 633 netdev->features |= 632 634 NETIF_F_RXHASH | 633 635 NETIF_F_SG |
+4 -4
drivers/net/ethernet/qlogic/qed/qed_sriov.c
··· 3033 3033 u16 length; 3034 3034 int rc; 3035 3035 3036 - /* Valiate PF can send such a request */ 3036 + /* Validate PF can send such a request */ 3037 3037 if (!vf->vport_instance) { 3038 3038 DP_VERBOSE(p_hwfn, 3039 3039 QED_MSG_IOV, ··· 3312 3312 goto out; 3313 3313 } 3314 3314 3315 - /* Determine if the unicast filtering is acceptible by PF */ 3315 + /* Determine if the unicast filtering is acceptable by PF */ 3316 3316 if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) && 3317 3317 (params.type == QED_FILTER_VLAN || 3318 3318 params.type == QED_FILTER_MAC_VLAN)) { ··· 3729 3729 3730 3730 rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf); 3731 3731 if (rc) { 3732 - DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n", 3732 + DP_ERR(p_hwfn, "Failed to re-enable VF[%d] access\n", 3733 3733 vfid); 3734 3734 return rc; 3735 3735 } ··· 4480 4480 struct qed_ptt *ptt = qed_ptt_acquire(hwfn); 4481 4481 4482 4482 /* Failure to acquire the ptt in 100g creates an odd error 4483 - * where the first engine has already relased IOV. 4483 + * where the first engine has already released IOV. 4484 4484 */ 4485 4485 if (!ptt) { 4486 4486 DP_ERR(hwfn, "Failed to acquire ptt\n");
+2 -1
drivers/net/ethernet/realtek/Kconfig
··· 114 114 will be called r8169. This is recommended. 115 115 116 116 config R8169_LEDS 117 - def_bool R8169 && LEDS_TRIGGER_NETDEV 117 + bool "Support for controlling the NIC LEDs" 118 + depends on R8169 && LEDS_TRIGGER_NETDEV 118 119 depends on !(R8169=y && LEDS_CLASS=m) 119 120 help 120 121 Optional support for controlling the NIC LED's with the netdev
+1
drivers/net/ethernet/realtek/r8169_main.c
··· 5222 5222 new_bus->priv = tp; 5223 5223 new_bus->parent = &pdev->dev; 5224 5224 new_bus->irq[0] = PHY_MAC_INTERRUPT; 5225 + new_bus->phy_mask = GENMASK(31, 1); 5225 5226 snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x-%x", 5226 5227 pci_domain_nr(pdev->bus), pci_dev_id(pdev)); 5227 5228
+19 -1
drivers/net/phy/phy-core.c
··· 13 13 */ 14 14 const char *phy_speed_to_str(int speed) 15 15 { 16 - BUILD_BUG_ON_MSG(__ETHTOOL_LINK_MODE_MASK_NBITS != 103, 16 + BUILD_BUG_ON_MSG(__ETHTOOL_LINK_MODE_MASK_NBITS != 121, 17 17 "Enum ethtool_link_mode_bit_indices and phylib are out of sync. " 18 18 "If a speed or mode has been added please update phy_speed_to_str " 19 19 "and the PHY settings array.\n"); ··· 169 169 PHY_SETTING( 800000, FULL, 800000baseDR8_2_Full ), 170 170 PHY_SETTING( 800000, FULL, 800000baseSR8_Full ), 171 171 PHY_SETTING( 800000, FULL, 800000baseVR8_Full ), 172 + PHY_SETTING( 800000, FULL, 800000baseCR4_Full ), 173 + PHY_SETTING( 800000, FULL, 800000baseKR4_Full ), 174 + PHY_SETTING( 800000, FULL, 800000baseDR4_Full ), 175 + PHY_SETTING( 800000, FULL, 800000baseDR4_2_Full ), 176 + PHY_SETTING( 800000, FULL, 800000baseSR4_Full ), 177 + PHY_SETTING( 800000, FULL, 800000baseVR4_Full ), 172 178 /* 400G */ 173 179 PHY_SETTING( 400000, FULL, 400000baseCR8_Full ), 174 180 PHY_SETTING( 400000, FULL, 400000baseKR8_Full ), ··· 186 180 PHY_SETTING( 400000, FULL, 400000baseLR4_ER4_FR4_Full ), 187 181 PHY_SETTING( 400000, FULL, 400000baseDR4_Full ), 188 182 PHY_SETTING( 400000, FULL, 400000baseSR4_Full ), 183 + PHY_SETTING( 400000, FULL, 400000baseCR2_Full ), 184 + PHY_SETTING( 400000, FULL, 400000baseKR2_Full ), 185 + PHY_SETTING( 400000, FULL, 400000baseDR2_Full ), 186 + PHY_SETTING( 400000, FULL, 400000baseDR2_2_Full ), 187 + PHY_SETTING( 400000, FULL, 400000baseSR2_Full ), 188 + PHY_SETTING( 400000, FULL, 400000baseVR2_Full ), 189 189 /* 200G */ 190 190 PHY_SETTING( 200000, FULL, 200000baseCR4_Full ), 191 191 PHY_SETTING( 200000, FULL, 200000baseKR4_Full ), ··· 203 191 PHY_SETTING( 200000, FULL, 200000baseLR2_ER2_FR2_Full ), 204 192 PHY_SETTING( 200000, FULL, 200000baseDR2_Full ), 205 193 PHY_SETTING( 200000, FULL, 200000baseSR2_Full ), 194 + PHY_SETTING( 200000, FULL, 200000baseCR_Full ), 195 + PHY_SETTING( 200000, FULL, 200000baseKR_Full ), 196 + PHY_SETTING( 200000, FULL, 200000baseDR_Full ), 197 + PHY_SETTING( 200000, FULL, 200000baseDR_2_Full ), 198 + PHY_SETTING( 200000, FULL, 200000baseSR_Full ), 199 + PHY_SETTING( 200000, FULL, 200000baseVR_Full ), 206 200 /* 100G */ 207 201 PHY_SETTING( 100000, FULL, 100000baseCR4_Full ), 208 202 PHY_SETTING( 100000, FULL, 100000baseKR4_Full ),
+6 -2
drivers/net/phy/realtek/Kconfig
··· 4 4 help 5 5 Currently supports RTL821x/RTL822x and fast ethernet PHYs 6 6 7 + if REALTEK_PHY 8 + 7 9 config REALTEK_PHY_HWMON 8 - def_bool REALTEK_PHY && HWMON 9 - depends on !(REALTEK_PHY=y && HWMON=m) 10 + bool "HWMON support for Realtek PHYs" 11 + depends on HWMON && !(REALTEK_PHY=y && HWMON=m) 10 12 help 11 13 Optional hwmon support for the temperature sensor 14 + 15 + endif # REALTEK_PHY
+5 -4
drivers/net/phy/realtek/realtek_main.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/delay.h> 15 15 #include <linux/clk.h> 16 + #include <linux/string_choices.h> 16 17 17 18 #include "realtek.h" 18 19 ··· 423 422 } else if (ret) { 424 423 dev_dbg(dev, 425 424 "%s 2ns TX delay (and changing the value from pin-strapping RXD1 or the bootloader)\n", 426 - val_txdly ? "Enabling" : "Disabling"); 425 + str_enable_disable(val_txdly)); 427 426 } else { 428 427 dev_dbg(dev, 429 428 "2ns TX delay was already %s (by pin-strapping RXD1 or bootloader configuration)\n", 430 - val_txdly ? "enabled" : "disabled"); 429 + str_enabled_disabled(val_txdly)); 431 430 } 432 431 433 432 ret = phy_modify_paged_changed(phydev, 0xd08, 0x15, RTL8211F_RX_DELAY, ··· 438 437 } else if (ret) { 439 438 dev_dbg(dev, 440 439 "%s 2ns RX delay (and changing the value from pin-strapping RXD0 or the bootloader)\n", 441 - val_rxdly ? "Enabling" : "Disabling"); 440 + str_enable_disable(val_rxdly)); 442 441 } else { 443 442 dev_dbg(dev, 444 443 "2ns RX delay was already %s (by pin-strapping RXD0 or bootloader configuration)\n", 445 - val_rxdly ? "enabled" : "disabled"); 444 + str_enabled_disabled(val_rxdly)); 446 445 } 447 446 448 447 if (priv->has_phycr2) {
+19 -13
drivers/net/vxlan/vxlan_core.c
··· 227 227 be32_to_cpu(fdb->vni))) 228 228 goto nla_put_failure; 229 229 230 - ci.ndm_used = jiffies_to_clock_t(now - fdb->used); 230 + ci.ndm_used = jiffies_to_clock_t(now - READ_ONCE(fdb->used)); 231 231 ci.ndm_confirmed = 0; 232 - ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated); 232 + ci.ndm_updated = jiffies_to_clock_t(now - READ_ONCE(fdb->updated)); 233 233 ci.ndm_refcnt = 0; 234 234 235 235 if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci)) ··· 434 434 struct vxlan_fdb *f; 435 435 436 436 f = __vxlan_find_mac(vxlan, mac, vni); 437 - if (f && f->used != jiffies) 438 - f->used = jiffies; 437 + if (f) { 438 + unsigned long now = jiffies; 439 + 440 + if (READ_ONCE(f->used) != now) 441 + WRITE_ONCE(f->used, now); 442 + } 439 443 440 444 return f; 441 445 } ··· 1013 1009 !(f->flags & NTF_VXLAN_ADDED_BY_USER)) { 1014 1010 if (f->state != state) { 1015 1011 f->state = state; 1016 - f->updated = jiffies; 1017 1012 notify = 1; 1018 1013 } 1019 1014 if (f->flags != fdb_flags) { 1020 1015 f->flags = fdb_flags; 1021 - f->updated = jiffies; 1022 1016 notify = 1; 1023 1017 } 1024 1018 } ··· 1050 1048 } 1051 1049 1052 1050 if (ndm_flags & NTF_USE) 1053 - f->used = jiffies; 1051 + WRITE_ONCE(f->updated, jiffies); 1054 1052 1055 1053 if (notify) { 1056 1054 if (rd == NULL) 1057 1055 rd = first_remote_rtnl(f); 1058 1056 1057 + WRITE_ONCE(f->updated, jiffies); 1059 1058 err = vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH, 1060 1059 swdev_notify, extack); 1061 1060 if (err) ··· 1295 1292 struct vxlan_fdb *f; 1296 1293 int err = -ENOENT; 1297 1294 1298 - f = vxlan_find_mac(vxlan, addr, src_vni); 1295 + f = __vxlan_find_mac(vxlan, addr, src_vni); 1299 1296 if (!f) 1300 1297 return err; 1301 1298 ··· 1462 1459 ifindex = src_ifindex; 1463 1460 #endif 1464 1461 1465 - f = vxlan_find_mac(vxlan, src_mac, vni); 1462 + f = __vxlan_find_mac(vxlan, src_mac, vni); 1466 1463 if (likely(f)) { 1467 1464 struct vxlan_rdst *rdst = first_remote_rcu(f); 1465 + unsigned long now = jiffies; 1466 + 1467 + if (READ_ONCE(f->updated) != now) 1468 + WRITE_ONCE(f->updated, now); 1468 1469 1469 1470 if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && 1470 1471 rdst->remote_ifindex == ifindex)) ··· 1488 1481 src_mac, &rdst->remote_ip.sa, &src_ip->sa); 1489 1482 1490 1483 rdst->remote_ip = *src_ip; 1491 - f->updated = jiffies; 1492 1484 vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL); 1493 1485 } else { 1494 1486 u32 hash_index = fdb_head_index(vxlan, src_mac, vni); ··· 2858 2852 if (f->flags & NTF_EXT_LEARNED) 2859 2853 continue; 2860 2854 2861 - timeout = f->used + vxlan->cfg.age_interval * HZ; 2855 + timeout = READ_ONCE(f->updated) + vxlan->cfg.age_interval * HZ; 2862 2856 if (time_before_eq(timeout, jiffies)) { 2863 2857 netdev_dbg(vxlan->dev, 2864 2858 "garbage collect %pM\n", ··· 4774 4768 4775 4769 spin_lock_bh(&vxlan->hash_lock[hash_index]); 4776 4770 4777 - f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); 4771 + f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); 4778 4772 if (!f) 4779 4773 goto out; 4780 4774 ··· 4830 4824 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); 4831 4825 spin_lock_bh(&vxlan->hash_lock[hash_index]); 4832 4826 4833 - f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); 4827 + f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); 4834 4828 if (!f) 4835 4829 err = -ENOENT; 4836 4830 else if (f->flags & NTF_EXT_LEARNED)
+1 -10
drivers/s390/net/Kconfig
··· 2 2 menu "S/390 network device drivers" 3 3 depends on NETDEVICES && S390 4 4 5 - config LCS 6 - def_tristate m 7 - prompt "Lan Channel Station Interface" 8 - depends on CCW && NETDEVICES && ETHERNET 9 - help 10 - Select this option if you want to use LCS networking on IBM System z. 11 - To compile as a module, choose M. The module name is lcs. 12 - If you do not use LCS, choose N. 13 - 14 5 config CTCM 15 6 def_tristate m 16 7 prompt "CTC and MPC SNA device support" ··· 89 98 90 99 config CCWGROUP 91 100 tristate 92 - default (LCS || CTCM || QETH || SMC) 101 + default (CTCM || QETH || SMC) 93 102 94 103 config ISM 95 104 tristate "Support for ISM vPCI Adapter"
-1
drivers/s390/net/Makefile
··· 8 8 obj-$(CONFIG_NETIUCV) += netiucv.o fsm.o 9 9 obj-$(CONFIG_SMSGIUCV) += smsgiucv.o 10 10 obj-$(CONFIG_SMSGIUCV_EVENT) += smsgiucv_app.o 11 - obj-$(CONFIG_LCS) += lcs.o 12 11 qeth-y += qeth_core_sys.o qeth_core_main.o qeth_core_mpc.o qeth_ethtool.o 13 12 obj-$(CONFIG_QETH) += qeth.o 14 13 qeth_l2-y += qeth_l2_main.o qeth_l2_sys.o
-2385
drivers/s390/net/lcs.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * Linux for S/390 LAN channel station device driver 4 - * 5 - * Copyright IBM Corp. 1999, 2009 6 - * Author(s): Original Code written by 7 - * DJ Barrow <djbarrow@de.ibm.com,barrow_dj@yahoo.com> 8 - * Rewritten by 9 - * Frank Pavlic <fpavlic@de.ibm.com> and 10 - * Martin Schwidefsky <schwidefsky@de.ibm.com> 11 - */ 12 - 13 - #define KMSG_COMPONENT "lcs" 14 - #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 15 - 16 - #include <linux/module.h> 17 - #include <linux/if.h> 18 - #include <linux/netdevice.h> 19 - #include <linux/etherdevice.h> 20 - #include <linux/inetdevice.h> 21 - #include <linux/in.h> 22 - #include <linux/igmp.h> 23 - #include <linux/delay.h> 24 - #include <linux/kthread.h> 25 - #include <linux/slab.h> 26 - #include <net/arp.h> 27 - #include <net/ip.h> 28 - 29 - #include <asm/debug.h> 30 - #include <asm/idals.h> 31 - #include <asm/timex.h> 32 - #include <linux/device.h> 33 - #include <asm/ccwgroup.h> 34 - 35 - #include "lcs.h" 36 - 37 - 38 - /* 39 - * initialization string for output 40 - */ 41 - 42 - static char version[] __initdata = "LCS driver"; 43 - 44 - /* 45 - * the root device for lcs group devices 46 - */ 47 - static struct device *lcs_root_dev; 48 - 49 - /* 50 - * Some prototypes. 51 - */ 52 - static void lcs_tasklet(unsigned long); 53 - static void lcs_start_kernel_thread(struct work_struct *); 54 - static void lcs_get_frames_cb(struct lcs_channel *, struct lcs_buffer *); 55 - #ifdef CONFIG_IP_MULTICAST 56 - static int lcs_send_delipm(struct lcs_card *, struct lcs_ipm_list *); 57 - #endif /* CONFIG_IP_MULTICAST */ 58 - static int lcs_recovery(void *ptr); 59 - 60 - /* 61 - * Debug Facility Stuff 62 - */ 63 - static char debug_buffer[255]; 64 - static debug_info_t *lcs_dbf_setup; 65 - static debug_info_t *lcs_dbf_trace; 66 - 67 - /* 68 - * LCS Debug Facility functions 69 - */ 70 - static void 71 - lcs_unregister_debug_facility(void) 72 - { 73 - debug_unregister(lcs_dbf_setup); 74 - debug_unregister(lcs_dbf_trace); 75 - } 76 - 77 - static int 78 - lcs_register_debug_facility(void) 79 - { 80 - lcs_dbf_setup = debug_register("lcs_setup", 2, 1, 8); 81 - lcs_dbf_trace = debug_register("lcs_trace", 4, 1, 8); 82 - if (lcs_dbf_setup == NULL || lcs_dbf_trace == NULL) { 83 - pr_err("Not enough memory for debug facility.\n"); 84 - lcs_unregister_debug_facility(); 85 - return -ENOMEM; 86 - } 87 - debug_register_view(lcs_dbf_setup, &debug_hex_ascii_view); 88 - debug_set_level(lcs_dbf_setup, 2); 89 - debug_register_view(lcs_dbf_trace, &debug_hex_ascii_view); 90 - debug_set_level(lcs_dbf_trace, 2); 91 - return 0; 92 - } 93 - 94 - /* 95 - * Allocate io buffers. 96 - */ 97 - static int 98 - lcs_alloc_channel(struct lcs_channel *channel) 99 - { 100 - int cnt; 101 - 102 - LCS_DBF_TEXT(2, setup, "ichalloc"); 103 - for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 104 - /* alloc memory fo iobuffer */ 105 - channel->iob[cnt].data = 106 - kzalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL); 107 - if (channel->iob[cnt].data == NULL) 108 - break; 109 - channel->iob[cnt].state = LCS_BUF_STATE_EMPTY; 110 - } 111 - if (cnt < LCS_NUM_BUFFS) { 112 - /* Not all io buffers could be allocated. */ 113 - LCS_DBF_TEXT(2, setup, "echalloc"); 114 - while (cnt-- > 0) 115 - kfree(channel->iob[cnt].data); 116 - return -ENOMEM; 117 - } 118 - return 0; 119 - } 120 - 121 - /* 122 - * Free io buffers. 123 - */ 124 - static void 125 - lcs_free_channel(struct lcs_channel *channel) 126 - { 127 - int cnt; 128 - 129 - LCS_DBF_TEXT(2, setup, "ichfree"); 130 - for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 131 - kfree(channel->iob[cnt].data); 132 - channel->iob[cnt].data = NULL; 133 - } 134 - } 135 - 136 - /* 137 - * Cleanup channel. 138 - */ 139 - static void 140 - lcs_cleanup_channel(struct lcs_channel *channel) 141 - { 142 - LCS_DBF_TEXT(3, setup, "cleanch"); 143 - /* Kill write channel tasklets. */ 144 - tasklet_kill(&channel->irq_tasklet); 145 - /* Free channel buffers. */ 146 - lcs_free_channel(channel); 147 - } 148 - 149 - /* 150 - * LCS free memory for card and channels. 151 - */ 152 - static void 153 - lcs_free_card(struct lcs_card *card) 154 - { 155 - LCS_DBF_TEXT(2, setup, "remcard"); 156 - LCS_DBF_HEX(2, setup, &card, sizeof(void*)); 157 - kfree(card); 158 - } 159 - 160 - /* 161 - * LCS alloc memory for card and channels 162 - */ 163 - static struct lcs_card * 164 - lcs_alloc_card(void) 165 - { 166 - struct lcs_card *card; 167 - int rc; 168 - 169 - LCS_DBF_TEXT(2, setup, "alloclcs"); 170 - 171 - card = kzalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA); 172 - if (card == NULL) 173 - return NULL; 174 - card->lan_type = LCS_FRAME_TYPE_AUTO; 175 - card->pkt_seq = 0; 176 - card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT; 177 - /* Allocate io buffers for the read channel. */ 178 - rc = lcs_alloc_channel(&card->read); 179 - if (rc){ 180 - LCS_DBF_TEXT(2, setup, "iccwerr"); 181 - lcs_free_card(card); 182 - return NULL; 183 - } 184 - /* Allocate io buffers for the write channel. */ 185 - rc = lcs_alloc_channel(&card->write); 186 - if (rc) { 187 - LCS_DBF_TEXT(2, setup, "iccwerr"); 188 - lcs_cleanup_channel(&card->read); 189 - lcs_free_card(card); 190 - return NULL; 191 - } 192 - 193 - #ifdef CONFIG_IP_MULTICAST 194 - INIT_LIST_HEAD(&card->ipm_list); 195 - #endif 196 - LCS_DBF_HEX(2, setup, &card, sizeof(void*)); 197 - return card; 198 - } 199 - 200 - /* 201 - * Setup read channel. 202 - */ 203 - static void 204 - lcs_setup_read_ccws(struct lcs_card *card) 205 - { 206 - int cnt; 207 - 208 - LCS_DBF_TEXT(2, setup, "ireadccw"); 209 - /* Setup read ccws. */ 210 - memset(card->read.ccws, 0, sizeof (struct ccw1) * (LCS_NUM_BUFFS + 1)); 211 - for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 212 - card->read.ccws[cnt].cmd_code = LCS_CCW_READ; 213 - card->read.ccws[cnt].count = LCS_IOBUFFERSIZE; 214 - card->read.ccws[cnt].flags = 215 - CCW_FLAG_CC | CCW_FLAG_SLI | CCW_FLAG_PCI; 216 - /* 217 - * Note: we have allocated the buffer with GFP_DMA, so 218 - * we do not need to do set_normalized_cda. 219 - */ 220 - card->read.ccws[cnt].cda = 221 - virt_to_dma32(card->read.iob[cnt].data); 222 - ((struct lcs_header *) 223 - card->read.iob[cnt].data)->offset = LCS_ILLEGAL_OFFSET; 224 - card->read.iob[cnt].callback = lcs_get_frames_cb; 225 - card->read.iob[cnt].state = LCS_BUF_STATE_READY; 226 - card->read.iob[cnt].count = LCS_IOBUFFERSIZE; 227 - } 228 - card->read.ccws[0].flags &= ~CCW_FLAG_PCI; 229 - card->read.ccws[LCS_NUM_BUFFS - 1].flags &= ~CCW_FLAG_PCI; 230 - card->read.ccws[LCS_NUM_BUFFS - 1].flags |= CCW_FLAG_SUSPEND; 231 - /* Last ccw is a tic (transfer in channel). */ 232 - card->read.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER; 233 - card->read.ccws[LCS_NUM_BUFFS].cda = virt_to_dma32(card->read.ccws); 234 - /* Setg initial state of the read channel. */ 235 - card->read.state = LCS_CH_STATE_INIT; 236 - 237 - card->read.io_idx = 0; 238 - card->read.buf_idx = 0; 239 - } 240 - 241 - static void 242 - lcs_setup_read(struct lcs_card *card) 243 - { 244 - LCS_DBF_TEXT(3, setup, "initread"); 245 - 246 - lcs_setup_read_ccws(card); 247 - /* Initialize read channel tasklet. */ 248 - card->read.irq_tasklet.data = (unsigned long) &card->read; 249 - card->read.irq_tasklet.func = lcs_tasklet; 250 - /* Initialize waitqueue. */ 251 - init_waitqueue_head(&card->read.wait_q); 252 - } 253 - 254 - /* 255 - * Setup write channel. 256 - */ 257 - static void 258 - lcs_setup_write_ccws(struct lcs_card *card) 259 - { 260 - int cnt; 261 - 262 - LCS_DBF_TEXT(3, setup, "iwritccw"); 263 - /* Setup write ccws. */ 264 - memset(card->write.ccws, 0, sizeof(struct ccw1) * (LCS_NUM_BUFFS + 1)); 265 - for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 266 - card->write.ccws[cnt].cmd_code = LCS_CCW_WRITE; 267 - card->write.ccws[cnt].count = 0; 268 - card->write.ccws[cnt].flags = 269 - CCW_FLAG_SUSPEND | CCW_FLAG_CC | CCW_FLAG_SLI; 270 - /* 271 - * Note: we have allocated the buffer with GFP_DMA, so 272 - * we do not need to do set_normalized_cda. 273 - */ 274 - card->write.ccws[cnt].cda = 275 - virt_to_dma32(card->write.iob[cnt].data); 276 - } 277 - /* Last ccw is a tic (transfer in channel). */ 278 - card->write.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER; 279 - card->write.ccws[LCS_NUM_BUFFS].cda = virt_to_dma32(card->write.ccws); 280 - /* Set initial state of the write channel. */ 281 - card->read.state = LCS_CH_STATE_INIT; 282 - 283 - card->write.io_idx = 0; 284 - card->write.buf_idx = 0; 285 - } 286 - 287 - static void 288 - lcs_setup_write(struct lcs_card *card) 289 - { 290 - LCS_DBF_TEXT(3, setup, "initwrit"); 291 - 292 - lcs_setup_write_ccws(card); 293 - /* Initialize write channel tasklet. */ 294 - card->write.irq_tasklet.data = (unsigned long) &card->write; 295 - card->write.irq_tasklet.func = lcs_tasklet; 296 - /* Initialize waitqueue. */ 297 - init_waitqueue_head(&card->write.wait_q); 298 - } 299 - 300 - static void 301 - lcs_set_allowed_threads(struct lcs_card *card, unsigned long threads) 302 - { 303 - unsigned long flags; 304 - 305 - spin_lock_irqsave(&card->mask_lock, flags); 306 - card->thread_allowed_mask = threads; 307 - spin_unlock_irqrestore(&card->mask_lock, flags); 308 - wake_up(&card->wait_q); 309 - } 310 - static int lcs_threads_running(struct lcs_card *card, unsigned long threads) 311 - { 312 - unsigned long flags; 313 - int rc = 0; 314 - 315 - spin_lock_irqsave(&card->mask_lock, flags); 316 - rc = (card->thread_running_mask & threads); 317 - spin_unlock_irqrestore(&card->mask_lock, flags); 318 - return rc; 319 - } 320 - 321 - static int 322 - lcs_wait_for_threads(struct lcs_card *card, unsigned long threads) 323 - { 324 - return wait_event_interruptible(card->wait_q, 325 - lcs_threads_running(card, threads) == 0); 326 - } 327 - 328 - static int lcs_set_thread_start_bit(struct lcs_card *card, unsigned long thread) 329 - { 330 - unsigned long flags; 331 - 332 - spin_lock_irqsave(&card->mask_lock, flags); 333 - if ( !(card->thread_allowed_mask & thread) || 334 - (card->thread_start_mask & thread) ) { 335 - spin_unlock_irqrestore(&card->mask_lock, flags); 336 - return -EPERM; 337 - } 338 - card->thread_start_mask |= thread; 339 - spin_unlock_irqrestore(&card->mask_lock, flags); 340 - return 0; 341 - } 342 - 343 - static void 344 - lcs_clear_thread_running_bit(struct lcs_card *card, unsigned long thread) 345 - { 346 - unsigned long flags; 347 - 348 - spin_lock_irqsave(&card->mask_lock, flags); 349 - card->thread_running_mask &= ~thread; 350 - spin_unlock_irqrestore(&card->mask_lock, flags); 351 - wake_up(&card->wait_q); 352 - } 353 - 354 - static int __lcs_do_run_thread(struct lcs_card *card, unsigned long thread) 355 - { 356 - unsigned long flags; 357 - int rc = 0; 358 - 359 - spin_lock_irqsave(&card->mask_lock, flags); 360 - if (card->thread_start_mask & thread){ 361 - if ((card->thread_allowed_mask & thread) && 362 - !(card->thread_running_mask & thread)){ 363 - rc = 1; 364 - card->thread_start_mask &= ~thread; 365 - card->thread_running_mask |= thread; 366 - } else 367 - rc = -EPERM; 368 - } 369 - spin_unlock_irqrestore(&card->mask_lock, flags); 370 - return rc; 371 - } 372 - 373 - static int 374 - lcs_do_run_thread(struct lcs_card *card, unsigned long thread) 375 - { 376 - int rc = 0; 377 - wait_event(card->wait_q, 378 - (rc = __lcs_do_run_thread(card, thread)) >= 0); 379 - return rc; 380 - } 381 - 382 - static int 383 - lcs_do_start_thread(struct lcs_card *card, unsigned long thread) 384 - { 385 - unsigned long flags; 386 - int rc = 0; 387 - 388 - spin_lock_irqsave(&card->mask_lock, flags); 389 - LCS_DBF_TEXT_(4, trace, " %02x%02x%02x", 390 - (u8) card->thread_start_mask, 391 - (u8) card->thread_allowed_mask, 392 - (u8) card->thread_running_mask); 393 - rc = (card->thread_start_mask & thread); 394 - spin_unlock_irqrestore(&card->mask_lock, flags); 395 - return rc; 396 - } 397 - 398 - /* 399 - * Initialize channels,card and state machines. 400 - */ 401 - static void 402 - lcs_setup_card(struct lcs_card *card) 403 - { 404 - LCS_DBF_TEXT(2, setup, "initcard"); 405 - LCS_DBF_HEX(2, setup, &card, sizeof(void*)); 406 - 407 - lcs_setup_read(card); 408 - lcs_setup_write(card); 409 - /* Set cards initial state. */ 410 - card->state = DEV_STATE_DOWN; 411 - card->tx_buffer = NULL; 412 - card->tx_emitted = 0; 413 - 414 - init_waitqueue_head(&card->wait_q); 415 - spin_lock_init(&card->lock); 416 - spin_lock_init(&card->ipm_lock); 417 - spin_lock_init(&card->mask_lock); 418 - #ifdef CONFIG_IP_MULTICAST 419 - INIT_LIST_HEAD(&card->ipm_list); 420 - #endif 421 - INIT_LIST_HEAD(&card->lancmd_waiters); 422 - } 423 - 424 - static void lcs_clear_multicast_list(struct lcs_card *card) 425 - { 426 - #ifdef CONFIG_IP_MULTICAST 427 - struct lcs_ipm_list *ipm; 428 - unsigned long flags; 429 - 430 - /* Free multicast list. */ 431 - LCS_DBF_TEXT(3, setup, "clmclist"); 432 - spin_lock_irqsave(&card->ipm_lock, flags); 433 - while (!list_empty(&card->ipm_list)){ 434 - ipm = list_entry(card->ipm_list.next, 435 - struct lcs_ipm_list, list); 436 - list_del(&ipm->list); 437 - if (ipm->ipm_state != LCS_IPM_STATE_SET_REQUIRED){ 438 - spin_unlock_irqrestore(&card->ipm_lock, flags); 439 - lcs_send_delipm(card, ipm); 440 - spin_lock_irqsave(&card->ipm_lock, flags); 441 - } 442 - kfree(ipm); 443 - } 444 - spin_unlock_irqrestore(&card->ipm_lock, flags); 445 - #endif 446 - } 447 - 448 - /* 449 - * Cleanup channels,card and state machines. 450 - */ 451 - static void 452 - lcs_cleanup_card(struct lcs_card *card) 453 - { 454 - 455 - LCS_DBF_TEXT(3, setup, "cleancrd"); 456 - LCS_DBF_HEX(2,setup,&card,sizeof(void*)); 457 - 458 - if (card->dev != NULL) 459 - free_netdev(card->dev); 460 - /* Cleanup channels. */ 461 - lcs_cleanup_channel(&card->write); 462 - lcs_cleanup_channel(&card->read); 463 - } 464 - 465 - /* 466 - * Start channel. 467 - */ 468 - static int 469 - lcs_start_channel(struct lcs_channel *channel) 470 - { 471 - unsigned long flags; 472 - int rc; 473 - 474 - LCS_DBF_TEXT_(4, trace,"ssch%s", dev_name(&channel->ccwdev->dev)); 475 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 476 - rc = ccw_device_start(channel->ccwdev, 477 - channel->ccws + channel->io_idx, 0, 0, 478 - DOIO_DENY_PREFETCH | DOIO_ALLOW_SUSPEND); 479 - if (rc == 0) 480 - channel->state = LCS_CH_STATE_RUNNING; 481 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 482 - if (rc) { 483 - LCS_DBF_TEXT_(4,trace,"essh%s", 484 - dev_name(&channel->ccwdev->dev)); 485 - dev_err(&channel->ccwdev->dev, 486 - "Starting an LCS device resulted in an error," 487 - " rc=%d!\n", rc); 488 - } 489 - return rc; 490 - } 491 - 492 - static int 493 - lcs_clear_channel(struct lcs_channel *channel) 494 - { 495 - unsigned long flags; 496 - int rc; 497 - 498 - LCS_DBF_TEXT(4,trace,"clearch"); 499 - LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev)); 500 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 501 - rc = ccw_device_clear(channel->ccwdev, 0); 502 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 503 - if (rc) { 504 - LCS_DBF_TEXT_(4, trace, "ecsc%s", 505 - dev_name(&channel->ccwdev->dev)); 506 - return rc; 507 - } 508 - wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_CLEARED)); 509 - channel->state = LCS_CH_STATE_STOPPED; 510 - return rc; 511 - } 512 - 513 - 514 - /* 515 - * Stop channel. 516 - */ 517 - static int 518 - lcs_stop_channel(struct lcs_channel *channel) 519 - { 520 - unsigned long flags; 521 - int rc; 522 - 523 - if (channel->state == LCS_CH_STATE_STOPPED) 524 - return 0; 525 - LCS_DBF_TEXT(4,trace,"haltsch"); 526 - LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev)); 527 - channel->state = LCS_CH_STATE_INIT; 528 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 529 - rc = ccw_device_halt(channel->ccwdev, 0); 530 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 531 - if (rc) { 532 - LCS_DBF_TEXT_(4, trace, "ehsc%s", 533 - dev_name(&channel->ccwdev->dev)); 534 - return rc; 535 - } 536 - /* Asynchronous halt initialted. Wait for its completion. */ 537 - wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_HALTED)); 538 - lcs_clear_channel(channel); 539 - return 0; 540 - } 541 - 542 - /* 543 - * start read and write channel 544 - */ 545 - static int 546 - lcs_start_channels(struct lcs_card *card) 547 - { 548 - int rc; 549 - 550 - LCS_DBF_TEXT(2, trace, "chstart"); 551 - /* start read channel */ 552 - rc = lcs_start_channel(&card->read); 553 - if (rc) 554 - return rc; 555 - /* start write channel */ 556 - rc = lcs_start_channel(&card->write); 557 - if (rc) 558 - lcs_stop_channel(&card->read); 559 - return rc; 560 - } 561 - 562 - /* 563 - * stop read and write channel 564 - */ 565 - static int 566 - lcs_stop_channels(struct lcs_card *card) 567 - { 568 - LCS_DBF_TEXT(2, trace, "chhalt"); 569 - lcs_stop_channel(&card->read); 570 - lcs_stop_channel(&card->write); 571 - return 0; 572 - } 573 - 574 - /* 575 - * Get empty buffer. 576 - */ 577 - static struct lcs_buffer * 578 - __lcs_get_buffer(struct lcs_channel *channel) 579 - { 580 - int index; 581 - 582 - LCS_DBF_TEXT(5, trace, "_getbuff"); 583 - index = channel->io_idx; 584 - do { 585 - if (channel->iob[index].state == LCS_BUF_STATE_EMPTY) { 586 - channel->iob[index].state = LCS_BUF_STATE_LOCKED; 587 - return channel->iob + index; 588 - } 589 - index = (index + 1) & (LCS_NUM_BUFFS - 1); 590 - } while (index != channel->io_idx); 591 - return NULL; 592 - } 593 - 594 - static struct lcs_buffer * 595 - lcs_get_buffer(struct lcs_channel *channel) 596 - { 597 - struct lcs_buffer *buffer; 598 - unsigned long flags; 599 - 600 - LCS_DBF_TEXT(5, trace, "getbuff"); 601 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 602 - buffer = __lcs_get_buffer(channel); 603 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 604 - return buffer; 605 - } 606 - 607 - /* 608 - * Resume channel program if the channel is suspended. 609 - */ 610 - static int 611 - __lcs_resume_channel(struct lcs_channel *channel) 612 - { 613 - int rc; 614 - 615 - if (channel->state != LCS_CH_STATE_SUSPENDED) 616 - return 0; 617 - if (channel->ccws[channel->io_idx].flags & CCW_FLAG_SUSPEND) 618 - return 0; 619 - LCS_DBF_TEXT_(5, trace, "rsch%s", dev_name(&channel->ccwdev->dev)); 620 - rc = ccw_device_resume(channel->ccwdev); 621 - if (rc) { 622 - LCS_DBF_TEXT_(4, trace, "ersc%s", 623 - dev_name(&channel->ccwdev->dev)); 624 - dev_err(&channel->ccwdev->dev, 625 - "Sending data from the LCS device to the LAN failed" 626 - " with rc=%d\n",rc); 627 - } else 628 - channel->state = LCS_CH_STATE_RUNNING; 629 - return rc; 630 - 631 - } 632 - 633 - /* 634 - * Make a buffer ready for processing. 635 - */ 636 - static void __lcs_ready_buffer_bits(struct lcs_channel *channel, int index) 637 - { 638 - int prev, next; 639 - 640 - LCS_DBF_TEXT(5, trace, "rdybits"); 641 - prev = (index - 1) & (LCS_NUM_BUFFS - 1); 642 - next = (index + 1) & (LCS_NUM_BUFFS - 1); 643 - /* Check if we may clear the suspend bit of this buffer. */ 644 - if (channel->ccws[next].flags & CCW_FLAG_SUSPEND) { 645 - /* Check if we have to set the PCI bit. */ 646 - if (!(channel->ccws[prev].flags & CCW_FLAG_SUSPEND)) 647 - /* Suspend bit of the previous buffer is not set. */ 648 - channel->ccws[index].flags |= CCW_FLAG_PCI; 649 - /* Suspend bit of the next buffer is set. */ 650 - channel->ccws[index].flags &= ~CCW_FLAG_SUSPEND; 651 - } 652 - } 653 - 654 - static int 655 - lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) 656 - { 657 - unsigned long flags; 658 - int index, rc; 659 - 660 - LCS_DBF_TEXT(5, trace, "rdybuff"); 661 - BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED && 662 - buffer->state != LCS_BUF_STATE_PROCESSED); 663 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 664 - buffer->state = LCS_BUF_STATE_READY; 665 - index = buffer - channel->iob; 666 - /* Set length. */ 667 - channel->ccws[index].count = buffer->count; 668 - /* Check relevant PCI/suspend bits. */ 669 - __lcs_ready_buffer_bits(channel, index); 670 - rc = __lcs_resume_channel(channel); 671 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 672 - return rc; 673 - } 674 - 675 - /* 676 - * Mark the buffer as processed. Take care of the suspend bit 677 - * of the previous buffer. This function is called from 678 - * interrupt context, so the lock must not be taken. 679 - */ 680 - static int 681 - __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) 682 - { 683 - int index, prev, next; 684 - 685 - LCS_DBF_TEXT(5, trace, "prcsbuff"); 686 - BUG_ON(buffer->state != LCS_BUF_STATE_READY); 687 - buffer->state = LCS_BUF_STATE_PROCESSED; 688 - index = buffer - channel->iob; 689 - prev = (index - 1) & (LCS_NUM_BUFFS - 1); 690 - next = (index + 1) & (LCS_NUM_BUFFS - 1); 691 - /* Set the suspend bit and clear the PCI bit of this buffer. */ 692 - channel->ccws[index].flags |= CCW_FLAG_SUSPEND; 693 - channel->ccws[index].flags &= ~CCW_FLAG_PCI; 694 - /* Check the suspend bit of the previous buffer. */ 695 - if (channel->iob[prev].state == LCS_BUF_STATE_READY) { 696 - /* 697 - * Previous buffer is in state ready. It might have 698 - * happened in lcs_ready_buffer that the suspend bit 699 - * has not been cleared to avoid an endless loop. 700 - * Do it now. 701 - */ 702 - __lcs_ready_buffer_bits(channel, prev); 703 - } 704 - /* Clear PCI bit of next buffer. */ 705 - channel->ccws[next].flags &= ~CCW_FLAG_PCI; 706 - return __lcs_resume_channel(channel); 707 - } 708 - 709 - /* 710 - * Put a processed buffer back to state empty. 711 - */ 712 - static void 713 - lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) 714 - { 715 - unsigned long flags; 716 - 717 - LCS_DBF_TEXT(5, trace, "relbuff"); 718 - BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED && 719 - buffer->state != LCS_BUF_STATE_PROCESSED); 720 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 721 - buffer->state = LCS_BUF_STATE_EMPTY; 722 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 723 - } 724 - 725 - /* 726 - * Get buffer for a lan command. 727 - */ 728 - static struct lcs_buffer * 729 - lcs_get_lancmd(struct lcs_card *card, int count) 730 - { 731 - struct lcs_buffer *buffer; 732 - struct lcs_cmd *cmd; 733 - 734 - LCS_DBF_TEXT(4, trace, "getlncmd"); 735 - /* Get buffer and wait if none is available. */ 736 - wait_event(card->write.wait_q, 737 - ((buffer = lcs_get_buffer(&card->write)) != NULL)); 738 - count += sizeof(struct lcs_header); 739 - *(__u16 *)(buffer->data + count) = 0; 740 - buffer->count = count + sizeof(__u16); 741 - buffer->callback = lcs_release_buffer; 742 - cmd = (struct lcs_cmd *) buffer->data; 743 - cmd->offset = count; 744 - cmd->type = LCS_FRAME_TYPE_CONTROL; 745 - cmd->slot = 0; 746 - return buffer; 747 - } 748 - 749 - 750 - static void 751 - lcs_get_reply(struct lcs_reply *reply) 752 - { 753 - refcount_inc(&reply->refcnt); 754 - } 755 - 756 - static void 757 - lcs_put_reply(struct lcs_reply *reply) 758 - { 759 - if (refcount_dec_and_test(&reply->refcnt)) 760 - kfree(reply); 761 - } 762 - 763 - static struct lcs_reply * 764 - lcs_alloc_reply(struct lcs_cmd *cmd) 765 - { 766 - struct lcs_reply *reply; 767 - 768 - LCS_DBF_TEXT(4, trace, "getreply"); 769 - 770 - reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC); 771 - if (!reply) 772 - return NULL; 773 - refcount_set(&reply->refcnt, 1); 774 - reply->sequence_no = cmd->sequence_no; 775 - reply->received = 0; 776 - reply->rc = 0; 777 - init_waitqueue_head(&reply->wait_q); 778 - 779 - return reply; 780 - } 781 - 782 - /* 783 - * Notifier function for lancmd replies. Called from read irq. 784 - */ 785 - static void 786 - lcs_notify_lancmd_waiters(struct lcs_card *card, struct lcs_cmd *cmd) 787 - { 788 - struct list_head *l, *n; 789 - struct lcs_reply *reply; 790 - 791 - LCS_DBF_TEXT(4, trace, "notiwait"); 792 - spin_lock(&card->lock); 793 - list_for_each_safe(l, n, &card->lancmd_waiters) { 794 - reply = list_entry(l, struct lcs_reply, list); 795 - if (reply->sequence_no == cmd->sequence_no) { 796 - lcs_get_reply(reply); 797 - list_del_init(&reply->list); 798 - if (reply->callback != NULL) 799 - reply->callback(card, cmd); 800 - reply->received = 1; 801 - reply->rc = cmd->return_code; 802 - wake_up(&reply->wait_q); 803 - lcs_put_reply(reply); 804 - break; 805 - } 806 - } 807 - spin_unlock(&card->lock); 808 - } 809 - 810 - /* 811 - * Emit buffer of a lan command. 812 - */ 813 - static void 814 - lcs_lancmd_timeout(struct timer_list *t) 815 - { 816 - struct lcs_reply *reply = from_timer(reply, t, timer); 817 - struct lcs_reply *list_reply, *r; 818 - unsigned long flags; 819 - 820 - LCS_DBF_TEXT(4, trace, "timeout"); 821 - spin_lock_irqsave(&reply->card->lock, flags); 822 - list_for_each_entry_safe(list_reply, r, 823 - &reply->card->lancmd_waiters,list) { 824 - if (reply == list_reply) { 825 - lcs_get_reply(reply); 826 - list_del_init(&reply->list); 827 - spin_unlock_irqrestore(&reply->card->lock, flags); 828 - reply->received = 1; 829 - reply->rc = -ETIME; 830 - wake_up(&reply->wait_q); 831 - lcs_put_reply(reply); 832 - return; 833 - } 834 - } 835 - spin_unlock_irqrestore(&reply->card->lock, flags); 836 - } 837 - 838 - static int 839 - lcs_send_lancmd(struct lcs_card *card, struct lcs_buffer *buffer, 840 - void (*reply_callback)(struct lcs_card *, struct lcs_cmd *)) 841 - { 842 - struct lcs_reply *reply; 843 - struct lcs_cmd *cmd; 844 - unsigned long flags; 845 - int rc; 846 - 847 - LCS_DBF_TEXT(4, trace, "sendcmd"); 848 - cmd = (struct lcs_cmd *) buffer->data; 849 - cmd->return_code = 0; 850 - cmd->sequence_no = card->sequence_no++; 851 - reply = lcs_alloc_reply(cmd); 852 - if (!reply) 853 - return -ENOMEM; 854 - reply->callback = reply_callback; 855 - reply->card = card; 856 - spin_lock_irqsave(&card->lock, flags); 857 - list_add_tail(&reply->list, &card->lancmd_waiters); 858 - spin_unlock_irqrestore(&card->lock, flags); 859 - 860 - buffer->callback = lcs_release_buffer; 861 - rc = lcs_ready_buffer(&card->write, buffer); 862 - if (rc) 863 - return rc; 864 - timer_setup(&reply->timer, lcs_lancmd_timeout, 0); 865 - mod_timer(&reply->timer, jiffies + HZ * card->lancmd_timeout); 866 - wait_event(reply->wait_q, reply->received); 867 - del_timer_sync(&reply->timer); 868 - LCS_DBF_TEXT_(4, trace, "rc:%d",reply->rc); 869 - rc = reply->rc; 870 - lcs_put_reply(reply); 871 - return rc ? -EIO : 0; 872 - } 873 - 874 - /* 875 - * LCS startup command 876 - */ 877 - static int 878 - lcs_send_startup(struct lcs_card *card, __u8 initiator) 879 - { 880 - struct lcs_buffer *buffer; 881 - struct lcs_cmd *cmd; 882 - 883 - LCS_DBF_TEXT(2, trace, "startup"); 884 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 885 - cmd = (struct lcs_cmd *) buffer->data; 886 - cmd->cmd_code = LCS_CMD_STARTUP; 887 - cmd->initiator = initiator; 888 - cmd->cmd.lcs_startup.buff_size = LCS_IOBUFFERSIZE; 889 - return lcs_send_lancmd(card, buffer, NULL); 890 - } 891 - 892 - /* 893 - * LCS shutdown command 894 - */ 895 - static int 896 - lcs_send_shutdown(struct lcs_card *card) 897 - { 898 - struct lcs_buffer *buffer; 899 - struct lcs_cmd *cmd; 900 - 901 - LCS_DBF_TEXT(2, trace, "shutdown"); 902 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 903 - cmd = (struct lcs_cmd *) buffer->data; 904 - cmd->cmd_code = LCS_CMD_SHUTDOWN; 905 - cmd->initiator = LCS_INITIATOR_TCPIP; 906 - return lcs_send_lancmd(card, buffer, NULL); 907 - } 908 - 909 - /* 910 - * LCS lanstat command 911 - */ 912 - static void 913 - __lcs_lanstat_cb(struct lcs_card *card, struct lcs_cmd *cmd) 914 - { 915 - LCS_DBF_TEXT(2, trace, "statcb"); 916 - memcpy(card->mac, cmd->cmd.lcs_lanstat_cmd.mac_addr, LCS_MAC_LENGTH); 917 - } 918 - 919 - static int 920 - lcs_send_lanstat(struct lcs_card *card) 921 - { 922 - struct lcs_buffer *buffer; 923 - struct lcs_cmd *cmd; 924 - 925 - LCS_DBF_TEXT(2,trace, "cmdstat"); 926 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 927 - cmd = (struct lcs_cmd *) buffer->data; 928 - /* Setup lanstat command. */ 929 - cmd->cmd_code = LCS_CMD_LANSTAT; 930 - cmd->initiator = LCS_INITIATOR_TCPIP; 931 - cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; 932 - cmd->cmd.lcs_std_cmd.portno = card->portno; 933 - return lcs_send_lancmd(card, buffer, __lcs_lanstat_cb); 934 - } 935 - 936 - /* 937 - * send stoplan command 938 - */ 939 - static int 940 - lcs_send_stoplan(struct lcs_card *card, __u8 initiator) 941 - { 942 - struct lcs_buffer *buffer; 943 - struct lcs_cmd *cmd; 944 - 945 - LCS_DBF_TEXT(2, trace, "cmdstpln"); 946 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 947 - cmd = (struct lcs_cmd *) buffer->data; 948 - cmd->cmd_code = LCS_CMD_STOPLAN; 949 - cmd->initiator = initiator; 950 - cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; 951 - cmd->cmd.lcs_std_cmd.portno = card->portno; 952 - return lcs_send_lancmd(card, buffer, NULL); 953 - } 954 - 955 - /* 956 - * send startlan command 957 - */ 958 - static void 959 - __lcs_send_startlan_cb(struct lcs_card *card, struct lcs_cmd *cmd) 960 - { 961 - LCS_DBF_TEXT(2, trace, "srtlancb"); 962 - card->lan_type = cmd->cmd.lcs_std_cmd.lan_type; 963 - card->portno = cmd->cmd.lcs_std_cmd.portno; 964 - } 965 - 966 - static int 967 - lcs_send_startlan(struct lcs_card *card, __u8 initiator) 968 - { 969 - struct lcs_buffer *buffer; 970 - struct lcs_cmd *cmd; 971 - 972 - LCS_DBF_TEXT(2, trace, "cmdstaln"); 973 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 974 - cmd = (struct lcs_cmd *) buffer->data; 975 - cmd->cmd_code = LCS_CMD_STARTLAN; 976 - cmd->initiator = initiator; 977 - cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; 978 - cmd->cmd.lcs_std_cmd.portno = card->portno; 979 - return lcs_send_lancmd(card, buffer, __lcs_send_startlan_cb); 980 - } 981 - 982 - #ifdef CONFIG_IP_MULTICAST 983 - /* 984 - * send setipm command (Multicast) 985 - */ 986 - static int 987 - lcs_send_setipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list) 988 - { 989 - struct lcs_buffer *buffer; 990 - struct lcs_cmd *cmd; 991 - 992 - LCS_DBF_TEXT(2, trace, "cmdsetim"); 993 - buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE); 994 - cmd = (struct lcs_cmd *) buffer->data; 995 - cmd->cmd_code = LCS_CMD_SETIPM; 996 - cmd->initiator = LCS_INITIATOR_TCPIP; 997 - cmd->cmd.lcs_qipassist.lan_type = card->lan_type; 998 - cmd->cmd.lcs_qipassist.portno = card->portno; 999 - cmd->cmd.lcs_qipassist.version = 4; 1000 - cmd->cmd.lcs_qipassist.num_ip_pairs = 1; 1001 - memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair, 1002 - &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair)); 1003 - LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr); 1004 - return lcs_send_lancmd(card, buffer, NULL); 1005 - } 1006 - 1007 - /* 1008 - * send delipm command (Multicast) 1009 - */ 1010 - static int 1011 - lcs_send_delipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list) 1012 - { 1013 - struct lcs_buffer *buffer; 1014 - struct lcs_cmd *cmd; 1015 - 1016 - LCS_DBF_TEXT(2, trace, "cmddelim"); 1017 - buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE); 1018 - cmd = (struct lcs_cmd *) buffer->data; 1019 - cmd->cmd_code = LCS_CMD_DELIPM; 1020 - cmd->initiator = LCS_INITIATOR_TCPIP; 1021 - cmd->cmd.lcs_qipassist.lan_type = card->lan_type; 1022 - cmd->cmd.lcs_qipassist.portno = card->portno; 1023 - cmd->cmd.lcs_qipassist.version = 4; 1024 - cmd->cmd.lcs_qipassist.num_ip_pairs = 1; 1025 - memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair, 1026 - &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair)); 1027 - LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr); 1028 - return lcs_send_lancmd(card, buffer, NULL); 1029 - } 1030 - 1031 - /* 1032 - * check if multicast is supported by LCS 1033 - */ 1034 - static void 1035 - __lcs_check_multicast_cb(struct lcs_card *card, struct lcs_cmd *cmd) 1036 - { 1037 - LCS_DBF_TEXT(2, trace, "chkmccb"); 1038 - card->ip_assists_supported = 1039 - cmd->cmd.lcs_qipassist.ip_assists_supported; 1040 - card->ip_assists_enabled = 1041 - cmd->cmd.lcs_qipassist.ip_assists_enabled; 1042 - } 1043 - 1044 - static int 1045 - lcs_check_multicast_support(struct lcs_card *card) 1046 - { 1047 - struct lcs_buffer *buffer; 1048 - struct lcs_cmd *cmd; 1049 - int rc; 1050 - 1051 - LCS_DBF_TEXT(2, trace, "cmdqipa"); 1052 - /* Send query ipassist. */ 1053 - buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); 1054 - cmd = (struct lcs_cmd *) buffer->data; 1055 - cmd->cmd_code = LCS_CMD_QIPASSIST; 1056 - cmd->initiator = LCS_INITIATOR_TCPIP; 1057 - cmd->cmd.lcs_qipassist.lan_type = card->lan_type; 1058 - cmd->cmd.lcs_qipassist.portno = card->portno; 1059 - cmd->cmd.lcs_qipassist.version = 4; 1060 - cmd->cmd.lcs_qipassist.num_ip_pairs = 1; 1061 - rc = lcs_send_lancmd(card, buffer, __lcs_check_multicast_cb); 1062 - if (rc != 0) { 1063 - pr_err("Query IPAssist failed. Assuming unsupported!\n"); 1064 - return -EOPNOTSUPP; 1065 - } 1066 - if (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) 1067 - return 0; 1068 - return -EOPNOTSUPP; 1069 - } 1070 - 1071 - /* 1072 - * set or del multicast address on LCS card 1073 - */ 1074 - static void 1075 - lcs_fix_multicast_list(struct lcs_card *card) 1076 - { 1077 - struct list_head failed_list; 1078 - struct lcs_ipm_list *ipm, *tmp; 1079 - unsigned long flags; 1080 - int rc; 1081 - 1082 - LCS_DBF_TEXT(4,trace, "fixipm"); 1083 - INIT_LIST_HEAD(&failed_list); 1084 - spin_lock_irqsave(&card->ipm_lock, flags); 1085 - list_modified: 1086 - list_for_each_entry_safe(ipm, tmp, &card->ipm_list, list){ 1087 - switch (ipm->ipm_state) { 1088 - case LCS_IPM_STATE_SET_REQUIRED: 1089 - /* del from ipm_list so no one else can tamper with 1090 - * this entry */ 1091 - list_del_init(&ipm->list); 1092 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1093 - rc = lcs_send_setipm(card, ipm); 1094 - spin_lock_irqsave(&card->ipm_lock, flags); 1095 - if (rc) { 1096 - pr_info("Adding multicast address failed." 1097 - " Table possibly full!\n"); 1098 - /* store ipm in failed list -> will be added 1099 - * to ipm_list again, so a retry will be done 1100 - * during the next call of this function */ 1101 - list_add_tail(&ipm->list, &failed_list); 1102 - } else { 1103 - ipm->ipm_state = LCS_IPM_STATE_ON_CARD; 1104 - /* re-insert into ipm_list */ 1105 - list_add_tail(&ipm->list, &card->ipm_list); 1106 - } 1107 - goto list_modified; 1108 - case LCS_IPM_STATE_DEL_REQUIRED: 1109 - list_del(&ipm->list); 1110 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1111 - lcs_send_delipm(card, ipm); 1112 - spin_lock_irqsave(&card->ipm_lock, flags); 1113 - kfree(ipm); 1114 - goto list_modified; 1115 - case LCS_IPM_STATE_ON_CARD: 1116 - break; 1117 - } 1118 - } 1119 - /* re-insert all entries from the failed_list into ipm_list */ 1120 - list_for_each_entry_safe(ipm, tmp, &failed_list, list) 1121 - list_move_tail(&ipm->list, &card->ipm_list); 1122 - 1123 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1124 - } 1125 - 1126 - /* 1127 - * get mac address for the relevant Multicast address 1128 - */ 1129 - static void 1130 - lcs_get_mac_for_ipm(__be32 ipm, char *mac, struct net_device *dev) 1131 - { 1132 - LCS_DBF_TEXT(4,trace, "getmac"); 1133 - ip_eth_mc_map(ipm, mac); 1134 - } 1135 - 1136 - /* 1137 - * function called by net device to handle multicast address relevant things 1138 - */ 1139 - static void lcs_remove_mc_addresses(struct lcs_card *card, 1140 - struct in_device *in4_dev) 1141 - { 1142 - struct ip_mc_list *im4; 1143 - struct list_head *l; 1144 - struct lcs_ipm_list *ipm; 1145 - unsigned long flags; 1146 - char buf[MAX_ADDR_LEN]; 1147 - 1148 - LCS_DBF_TEXT(4, trace, "remmclst"); 1149 - spin_lock_irqsave(&card->ipm_lock, flags); 1150 - list_for_each(l, &card->ipm_list) { 1151 - ipm = list_entry(l, struct lcs_ipm_list, list); 1152 - for (im4 = rcu_dereference(in4_dev->mc_list); 1153 - im4 != NULL; im4 = rcu_dereference(im4->next_rcu)) { 1154 - lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev); 1155 - if ( (ipm->ipm.ip_addr == im4->multiaddr) && 1156 - (memcmp(buf, &ipm->ipm.mac_addr, 1157 - LCS_MAC_LENGTH) == 0) ) 1158 - break; 1159 - } 1160 - if (im4 == NULL) 1161 - ipm->ipm_state = LCS_IPM_STATE_DEL_REQUIRED; 1162 - } 1163 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1164 - } 1165 - 1166 - static struct lcs_ipm_list *lcs_check_addr_entry(struct lcs_card *card, 1167 - struct ip_mc_list *im4, 1168 - char *buf) 1169 - { 1170 - struct lcs_ipm_list *tmp, *ipm = NULL; 1171 - struct list_head *l; 1172 - unsigned long flags; 1173 - 1174 - LCS_DBF_TEXT(4, trace, "chkmcent"); 1175 - spin_lock_irqsave(&card->ipm_lock, flags); 1176 - list_for_each(l, &card->ipm_list) { 1177 - tmp = list_entry(l, struct lcs_ipm_list, list); 1178 - if ( (tmp->ipm.ip_addr == im4->multiaddr) && 1179 - (memcmp(buf, &tmp->ipm.mac_addr, 1180 - LCS_MAC_LENGTH) == 0) ) { 1181 - ipm = tmp; 1182 - break; 1183 - } 1184 - } 1185 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1186 - return ipm; 1187 - } 1188 - 1189 - static void lcs_set_mc_addresses(struct lcs_card *card, 1190 - struct in_device *in4_dev) 1191 - { 1192 - 1193 - struct ip_mc_list *im4; 1194 - struct lcs_ipm_list *ipm; 1195 - char buf[MAX_ADDR_LEN]; 1196 - unsigned long flags; 1197 - 1198 - LCS_DBF_TEXT(4, trace, "setmclst"); 1199 - for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL; 1200 - im4 = rcu_dereference(im4->next_rcu)) { 1201 - lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev); 1202 - ipm = lcs_check_addr_entry(card, im4, buf); 1203 - if (ipm != NULL) 1204 - continue; /* Address already in list. */ 1205 - ipm = kzalloc(sizeof(struct lcs_ipm_list), GFP_ATOMIC); 1206 - if (ipm == NULL) { 1207 - pr_info("Not enough memory to add" 1208 - " new multicast entry!\n"); 1209 - break; 1210 - } 1211 - memcpy(&ipm->ipm.mac_addr, buf, LCS_MAC_LENGTH); 1212 - ipm->ipm.ip_addr = im4->multiaddr; 1213 - ipm->ipm_state = LCS_IPM_STATE_SET_REQUIRED; 1214 - spin_lock_irqsave(&card->ipm_lock, flags); 1215 - LCS_DBF_HEX(2,trace,&ipm->ipm.ip_addr,4); 1216 - list_add(&ipm->list, &card->ipm_list); 1217 - spin_unlock_irqrestore(&card->ipm_lock, flags); 1218 - } 1219 - } 1220 - 1221 - static int 1222 - lcs_register_mc_addresses(void *data) 1223 - { 1224 - struct lcs_card *card; 1225 - struct in_device *in4_dev; 1226 - 1227 - card = (struct lcs_card *) data; 1228 - 1229 - if (!lcs_do_run_thread(card, LCS_SET_MC_THREAD)) 1230 - return 0; 1231 - LCS_DBF_TEXT(4, trace, "regmulti"); 1232 - 1233 - in4_dev = in_dev_get(card->dev); 1234 - if (in4_dev == NULL) 1235 - goto out; 1236 - rcu_read_lock(); 1237 - lcs_remove_mc_addresses(card,in4_dev); 1238 - lcs_set_mc_addresses(card, in4_dev); 1239 - rcu_read_unlock(); 1240 - in_dev_put(in4_dev); 1241 - 1242 - netif_carrier_off(card->dev); 1243 - netif_tx_disable(card->dev); 1244 - wait_event(card->write.wait_q, 1245 - (card->write.state != LCS_CH_STATE_RUNNING)); 1246 - lcs_fix_multicast_list(card); 1247 - if (card->state == DEV_STATE_UP) { 1248 - netif_carrier_on(card->dev); 1249 - netif_wake_queue(card->dev); 1250 - } 1251 - out: 1252 - lcs_clear_thread_running_bit(card, LCS_SET_MC_THREAD); 1253 - return 0; 1254 - } 1255 - #endif /* CONFIG_IP_MULTICAST */ 1256 - 1257 - /* 1258 - * function called by net device to 1259 - * handle multicast address relevant things 1260 - */ 1261 - static void 1262 - lcs_set_multicast_list(struct net_device *dev) 1263 - { 1264 - #ifdef CONFIG_IP_MULTICAST 1265 - struct lcs_card *card; 1266 - 1267 - LCS_DBF_TEXT(4, trace, "setmulti"); 1268 - card = (struct lcs_card *) dev->ml_priv; 1269 - 1270 - if (!lcs_set_thread_start_bit(card, LCS_SET_MC_THREAD)) 1271 - schedule_work(&card->kernel_thread_starter); 1272 - #endif /* CONFIG_IP_MULTICAST */ 1273 - } 1274 - 1275 - static long 1276 - lcs_check_irb_error(struct ccw_device *cdev, struct irb *irb) 1277 - { 1278 - if (!IS_ERR(irb)) 1279 - return 0; 1280 - 1281 - switch (PTR_ERR(irb)) { 1282 - case -EIO: 1283 - dev_warn(&cdev->dev, 1284 - "An I/O-error occurred on the LCS device\n"); 1285 - LCS_DBF_TEXT(2, trace, "ckirberr"); 1286 - LCS_DBF_TEXT_(2, trace, " rc%d", -EIO); 1287 - break; 1288 - case -ETIMEDOUT: 1289 - dev_warn(&cdev->dev, 1290 - "A command timed out on the LCS device\n"); 1291 - LCS_DBF_TEXT(2, trace, "ckirberr"); 1292 - LCS_DBF_TEXT_(2, trace, " rc%d", -ETIMEDOUT); 1293 - break; 1294 - default: 1295 - dev_warn(&cdev->dev, 1296 - "An error occurred on the LCS device, rc=%ld\n", 1297 - PTR_ERR(irb)); 1298 - LCS_DBF_TEXT(2, trace, "ckirberr"); 1299 - LCS_DBF_TEXT(2, trace, " rc???"); 1300 - } 1301 - return PTR_ERR(irb); 1302 - } 1303 - 1304 - static int 1305 - lcs_get_problem(struct ccw_device *cdev, struct irb *irb) 1306 - { 1307 - int dstat, cstat; 1308 - char *sense; 1309 - 1310 - sense = (char *) irb->ecw; 1311 - cstat = irb->scsw.cmd.cstat; 1312 - dstat = irb->scsw.cmd.dstat; 1313 - 1314 - if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK | 1315 - SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK | 1316 - SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) { 1317 - LCS_DBF_TEXT(2, trace, "CGENCHK"); 1318 - return 1; 1319 - } 1320 - if (dstat & DEV_STAT_UNIT_CHECK) { 1321 - if (sense[LCS_SENSE_BYTE_1] & 1322 - LCS_SENSE_RESETTING_EVENT) { 1323 - LCS_DBF_TEXT(2, trace, "REVIND"); 1324 - return 1; 1325 - } 1326 - if (sense[LCS_SENSE_BYTE_0] & 1327 - LCS_SENSE_CMD_REJECT) { 1328 - LCS_DBF_TEXT(2, trace, "CMDREJ"); 1329 - return 0; 1330 - } 1331 - if ((!sense[LCS_SENSE_BYTE_0]) && 1332 - (!sense[LCS_SENSE_BYTE_1]) && 1333 - (!sense[LCS_SENSE_BYTE_2]) && 1334 - (!sense[LCS_SENSE_BYTE_3])) { 1335 - LCS_DBF_TEXT(2, trace, "ZEROSEN"); 1336 - return 0; 1337 - } 1338 - LCS_DBF_TEXT(2, trace, "DGENCHK"); 1339 - return 1; 1340 - } 1341 - return 0; 1342 - } 1343 - 1344 - static void 1345 - lcs_schedule_recovery(struct lcs_card *card) 1346 - { 1347 - LCS_DBF_TEXT(2, trace, "startrec"); 1348 - if (!lcs_set_thread_start_bit(card, LCS_RECOVERY_THREAD)) 1349 - schedule_work(&card->kernel_thread_starter); 1350 - } 1351 - 1352 - /* 1353 - * IRQ Handler for LCS channels 1354 - */ 1355 - static void 1356 - lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) 1357 - { 1358 - struct lcs_card *card; 1359 - struct lcs_channel *channel; 1360 - int rc, index; 1361 - int cstat, dstat; 1362 - 1363 - if (lcs_check_irb_error(cdev, irb)) 1364 - return; 1365 - 1366 - card = CARD_FROM_DEV(cdev); 1367 - if (card->read.ccwdev == cdev) 1368 - channel = &card->read; 1369 - else 1370 - channel = &card->write; 1371 - 1372 - cstat = irb->scsw.cmd.cstat; 1373 - dstat = irb->scsw.cmd.dstat; 1374 - LCS_DBF_TEXT_(5, trace, "Rint%s", dev_name(&cdev->dev)); 1375 - LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.cstat, 1376 - irb->scsw.cmd.dstat); 1377 - LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.fctl, 1378 - irb->scsw.cmd.actl); 1379 - 1380 - /* Check for channel and device errors presented */ 1381 - rc = lcs_get_problem(cdev, irb); 1382 - if (rc || (dstat & DEV_STAT_UNIT_EXCEP)) { 1383 - dev_warn(&cdev->dev, 1384 - "The LCS device stopped because of an error," 1385 - " dstat=0x%X, cstat=0x%X \n", 1386 - dstat, cstat); 1387 - if (rc) { 1388 - channel->state = LCS_CH_STATE_ERROR; 1389 - } 1390 - } 1391 - if (channel->state == LCS_CH_STATE_ERROR) { 1392 - lcs_schedule_recovery(card); 1393 - wake_up(&card->wait_q); 1394 - return; 1395 - } 1396 - /* How far in the ccw chain have we processed? */ 1397 - if ((channel->state != LCS_CH_STATE_INIT) && 1398 - (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) && 1399 - (irb->scsw.cmd.cpa != 0)) { 1400 - index = (struct ccw1 *)dma32_to_virt(irb->scsw.cmd.cpa) 1401 - - channel->ccws; 1402 - if ((irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) || 1403 - (irb->scsw.cmd.cstat & SCHN_STAT_PCI)) 1404 - /* Bloody io subsystem tells us lies about cpa... */ 1405 - index = (index - 1) & (LCS_NUM_BUFFS - 1); 1406 - while (channel->io_idx != index) { 1407 - __lcs_processed_buffer(channel, 1408 - channel->iob + channel->io_idx); 1409 - channel->io_idx = 1410 - (channel->io_idx + 1) & (LCS_NUM_BUFFS - 1); 1411 - } 1412 - } 1413 - 1414 - if ((irb->scsw.cmd.dstat & DEV_STAT_DEV_END) || 1415 - (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) || 1416 - (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)) 1417 - /* Mark channel as stopped. */ 1418 - channel->state = LCS_CH_STATE_STOPPED; 1419 - else if (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) 1420 - /* CCW execution stopped on a suspend bit. */ 1421 - channel->state = LCS_CH_STATE_SUSPENDED; 1422 - if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) { 1423 - if (irb->scsw.cmd.cc != 0) { 1424 - ccw_device_halt(channel->ccwdev, 0); 1425 - return; 1426 - } 1427 - /* The channel has been stopped by halt_IO. */ 1428 - channel->state = LCS_CH_STATE_HALTED; 1429 - } 1430 - if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) 1431 - channel->state = LCS_CH_STATE_CLEARED; 1432 - /* Do the rest in the tasklet. */ 1433 - tasklet_schedule(&channel->irq_tasklet); 1434 - } 1435 - 1436 - /* 1437 - * Tasklet for IRQ handler 1438 - */ 1439 - static void 1440 - lcs_tasklet(unsigned long data) 1441 - { 1442 - unsigned long flags; 1443 - struct lcs_channel *channel; 1444 - struct lcs_buffer *iob; 1445 - int buf_idx; 1446 - 1447 - channel = (struct lcs_channel *) data; 1448 - LCS_DBF_TEXT_(5, trace, "tlet%s", dev_name(&channel->ccwdev->dev)); 1449 - 1450 - /* Check for processed buffers. */ 1451 - iob = channel->iob; 1452 - buf_idx = channel->buf_idx; 1453 - while (iob[buf_idx].state == LCS_BUF_STATE_PROCESSED) { 1454 - /* Do the callback thing. */ 1455 - if (iob[buf_idx].callback != NULL) 1456 - iob[buf_idx].callback(channel, iob + buf_idx); 1457 - buf_idx = (buf_idx + 1) & (LCS_NUM_BUFFS - 1); 1458 - } 1459 - channel->buf_idx = buf_idx; 1460 - 1461 - if (channel->state == LCS_CH_STATE_STOPPED) 1462 - lcs_start_channel(channel); 1463 - spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 1464 - if (channel->state == LCS_CH_STATE_SUSPENDED && 1465 - channel->iob[channel->io_idx].state == LCS_BUF_STATE_READY) 1466 - __lcs_resume_channel(channel); 1467 - spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 1468 - 1469 - /* Something happened on the channel. Wake up waiters. */ 1470 - wake_up(&channel->wait_q); 1471 - } 1472 - 1473 - /* 1474 - * Finish current tx buffer and make it ready for transmit. 1475 - */ 1476 - static void 1477 - __lcs_emit_txbuffer(struct lcs_card *card) 1478 - { 1479 - LCS_DBF_TEXT(5, trace, "emittx"); 1480 - *(__u16 *)(card->tx_buffer->data + card->tx_buffer->count) = 0; 1481 - card->tx_buffer->count += 2; 1482 - lcs_ready_buffer(&card->write, card->tx_buffer); 1483 - card->tx_buffer = NULL; 1484 - card->tx_emitted++; 1485 - } 1486 - 1487 - /* 1488 - * Callback for finished tx buffers. 1489 - */ 1490 - static void 1491 - lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer) 1492 - { 1493 - struct lcs_card *card; 1494 - 1495 - LCS_DBF_TEXT(5, trace, "txbuffcb"); 1496 - /* Put buffer back to pool. */ 1497 - lcs_release_buffer(channel, buffer); 1498 - card = container_of(channel, struct lcs_card, write); 1499 - if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev)) 1500 - netif_wake_queue(card->dev); 1501 - spin_lock(&card->lock); 1502 - card->tx_emitted--; 1503 - if (card->tx_emitted <= 0 && card->tx_buffer != NULL) 1504 - /* 1505 - * Last running tx buffer has finished. Submit partially 1506 - * filled current buffer. 1507 - */ 1508 - __lcs_emit_txbuffer(card); 1509 - spin_unlock(&card->lock); 1510 - } 1511 - 1512 - /* 1513 - * Packet transmit function called by network stack 1514 - */ 1515 - static netdev_tx_t __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb, 1516 - struct net_device *dev) 1517 - { 1518 - struct lcs_header *header; 1519 - int rc = NETDEV_TX_OK; 1520 - 1521 - LCS_DBF_TEXT(5, trace, "hardxmit"); 1522 - if (skb == NULL) { 1523 - card->stats.tx_dropped++; 1524 - card->stats.tx_errors++; 1525 - return NETDEV_TX_OK; 1526 - } 1527 - if (card->state != DEV_STATE_UP) { 1528 - dev_kfree_skb(skb); 1529 - card->stats.tx_dropped++; 1530 - card->stats.tx_errors++; 1531 - card->stats.tx_carrier_errors++; 1532 - return NETDEV_TX_OK; 1533 - } 1534 - if (skb->protocol == htons(ETH_P_IPV6)) { 1535 - dev_kfree_skb(skb); 1536 - return NETDEV_TX_OK; 1537 - } 1538 - netif_stop_queue(card->dev); 1539 - spin_lock(&card->lock); 1540 - if (card->tx_buffer != NULL && 1541 - card->tx_buffer->count + sizeof(struct lcs_header) + 1542 - skb->len + sizeof(u16) > LCS_IOBUFFERSIZE) 1543 - /* skb too big for current tx buffer. */ 1544 - __lcs_emit_txbuffer(card); 1545 - if (card->tx_buffer == NULL) { 1546 - /* Get new tx buffer */ 1547 - card->tx_buffer = lcs_get_buffer(&card->write); 1548 - if (card->tx_buffer == NULL) { 1549 - card->stats.tx_dropped++; 1550 - rc = NETDEV_TX_BUSY; 1551 - goto out; 1552 - } 1553 - card->tx_buffer->callback = lcs_txbuffer_cb; 1554 - card->tx_buffer->count = 0; 1555 - } 1556 - header = (struct lcs_header *) 1557 - (card->tx_buffer->data + card->tx_buffer->count); 1558 - card->tx_buffer->count += skb->len + sizeof(struct lcs_header); 1559 - header->offset = card->tx_buffer->count; 1560 - header->type = card->lan_type; 1561 - header->slot = card->portno; 1562 - skb_copy_from_linear_data(skb, header + 1, skb->len); 1563 - spin_unlock(&card->lock); 1564 - card->stats.tx_bytes += skb->len; 1565 - card->stats.tx_packets++; 1566 - dev_kfree_skb(skb); 1567 - netif_wake_queue(card->dev); 1568 - spin_lock(&card->lock); 1569 - if (card->tx_emitted <= 0 && card->tx_buffer != NULL) 1570 - /* If this is the first tx buffer emit it immediately. */ 1571 - __lcs_emit_txbuffer(card); 1572 - out: 1573 - spin_unlock(&card->lock); 1574 - return rc; 1575 - } 1576 - 1577 - static netdev_tx_t lcs_start_xmit(struct sk_buff *skb, struct net_device *dev) 1578 - { 1579 - struct lcs_card *card; 1580 - int rc; 1581 - 1582 - LCS_DBF_TEXT(5, trace, "pktxmit"); 1583 - card = (struct lcs_card *) dev->ml_priv; 1584 - rc = __lcs_start_xmit(card, skb, dev); 1585 - return rc; 1586 - } 1587 - 1588 - /* 1589 - * send startlan and lanstat command to make LCS device ready 1590 - */ 1591 - static int 1592 - lcs_startlan_auto(struct lcs_card *card) 1593 - { 1594 - int rc; 1595 - 1596 - LCS_DBF_TEXT(2, trace, "strtauto"); 1597 - card->lan_type = LCS_FRAME_TYPE_ENET; 1598 - rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); 1599 - if (rc == 0) 1600 - return 0; 1601 - 1602 - return -EIO; 1603 - } 1604 - 1605 - static int 1606 - lcs_startlan(struct lcs_card *card) 1607 - { 1608 - int rc, i; 1609 - 1610 - LCS_DBF_TEXT(2, trace, "startlan"); 1611 - rc = 0; 1612 - if (card->portno != LCS_INVALID_PORT_NO) { 1613 - if (card->lan_type == LCS_FRAME_TYPE_AUTO) 1614 - rc = lcs_startlan_auto(card); 1615 - else 1616 - rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); 1617 - } else { 1618 - for (i = 0; i <= 16; i++) { 1619 - card->portno = i; 1620 - if (card->lan_type != LCS_FRAME_TYPE_AUTO) 1621 - rc = lcs_send_startlan(card, 1622 - LCS_INITIATOR_TCPIP); 1623 - else 1624 - /* autodetecting lan type */ 1625 - rc = lcs_startlan_auto(card); 1626 - if (rc == 0) 1627 - break; 1628 - } 1629 - } 1630 - if (rc == 0) 1631 - return lcs_send_lanstat(card); 1632 - return rc; 1633 - } 1634 - 1635 - /* 1636 - * LCS detect function 1637 - * setup channels and make them I/O ready 1638 - */ 1639 - static int 1640 - lcs_detect(struct lcs_card *card) 1641 - { 1642 - int rc = 0; 1643 - 1644 - LCS_DBF_TEXT(2, setup, "lcsdetct"); 1645 - /* start/reset card */ 1646 - if (card->dev) 1647 - netif_stop_queue(card->dev); 1648 - rc = lcs_stop_channels(card); 1649 - if (rc == 0) { 1650 - rc = lcs_start_channels(card); 1651 - if (rc == 0) { 1652 - rc = lcs_send_startup(card, LCS_INITIATOR_TCPIP); 1653 - if (rc == 0) 1654 - rc = lcs_startlan(card); 1655 - } 1656 - } 1657 - if (rc == 0) { 1658 - card->state = DEV_STATE_UP; 1659 - } else { 1660 - card->state = DEV_STATE_DOWN; 1661 - card->write.state = LCS_CH_STATE_INIT; 1662 - card->read.state = LCS_CH_STATE_INIT; 1663 - } 1664 - return rc; 1665 - } 1666 - 1667 - /* 1668 - * LCS Stop card 1669 - */ 1670 - static int 1671 - lcs_stopcard(struct lcs_card *card) 1672 - { 1673 - int rc; 1674 - 1675 - LCS_DBF_TEXT(3, setup, "stopcard"); 1676 - 1677 - if (card->read.state != LCS_CH_STATE_STOPPED && 1678 - card->write.state != LCS_CH_STATE_STOPPED && 1679 - card->read.state != LCS_CH_STATE_ERROR && 1680 - card->write.state != LCS_CH_STATE_ERROR && 1681 - card->state == DEV_STATE_UP) { 1682 - lcs_clear_multicast_list(card); 1683 - rc = lcs_send_stoplan(card,LCS_INITIATOR_TCPIP); 1684 - rc = lcs_send_shutdown(card); 1685 - } 1686 - rc = lcs_stop_channels(card); 1687 - card->state = DEV_STATE_DOWN; 1688 - 1689 - return rc; 1690 - } 1691 - 1692 - /* 1693 - * Kernel Thread helper functions for LGW initiated commands 1694 - */ 1695 - static void 1696 - lcs_start_kernel_thread(struct work_struct *work) 1697 - { 1698 - struct lcs_card *card = container_of(work, struct lcs_card, kernel_thread_starter); 1699 - LCS_DBF_TEXT(5, trace, "krnthrd"); 1700 - if (lcs_do_start_thread(card, LCS_RECOVERY_THREAD)) 1701 - kthread_run(lcs_recovery, card, "lcs_recover"); 1702 - #ifdef CONFIG_IP_MULTICAST 1703 - if (lcs_do_start_thread(card, LCS_SET_MC_THREAD)) 1704 - kthread_run(lcs_register_mc_addresses, card, "regipm"); 1705 - #endif 1706 - } 1707 - 1708 - /* 1709 - * Process control frames. 1710 - */ 1711 - static void 1712 - lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd) 1713 - { 1714 - LCS_DBF_TEXT(5, trace, "getctrl"); 1715 - if (cmd->initiator == LCS_INITIATOR_LGW) { 1716 - switch(cmd->cmd_code) { 1717 - case LCS_CMD_STARTUP: 1718 - case LCS_CMD_STARTLAN: 1719 - lcs_schedule_recovery(card); 1720 - break; 1721 - case LCS_CMD_STOPLAN: 1722 - if (card->dev) { 1723 - pr_warn("Stoplan for %s initiated by LGW\n", 1724 - card->dev->name); 1725 - netif_carrier_off(card->dev); 1726 - } 1727 - break; 1728 - default: 1729 - LCS_DBF_TEXT(5, trace, "noLGWcmd"); 1730 - break; 1731 - } 1732 - } else 1733 - lcs_notify_lancmd_waiters(card, cmd); 1734 - } 1735 - 1736 - /* 1737 - * Unpack network packet. 1738 - */ 1739 - static void 1740 - lcs_get_skb(struct lcs_card *card, char *skb_data, unsigned int skb_len) 1741 - { 1742 - struct sk_buff *skb; 1743 - 1744 - LCS_DBF_TEXT(5, trace, "getskb"); 1745 - if (card->dev == NULL || 1746 - card->state != DEV_STATE_UP) 1747 - /* The card isn't up. Ignore the packet. */ 1748 - return; 1749 - 1750 - skb = dev_alloc_skb(skb_len); 1751 - if (skb == NULL) { 1752 - dev_err(&card->dev->dev, 1753 - " Allocating a socket buffer to interface %s failed\n", 1754 - card->dev->name); 1755 - card->stats.rx_dropped++; 1756 - return; 1757 - } 1758 - skb_put_data(skb, skb_data, skb_len); 1759 - skb->protocol = card->lan_type_trans(skb, card->dev); 1760 - card->stats.rx_bytes += skb_len; 1761 - card->stats.rx_packets++; 1762 - if (skb->protocol == htons(ETH_P_802_2)) 1763 - *((__u32 *)skb->cb) = ++card->pkt_seq; 1764 - netif_rx(skb); 1765 - } 1766 - 1767 - /* 1768 - * LCS main routine to get packets and lancmd replies from the buffers 1769 - */ 1770 - static void 1771 - lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer) 1772 - { 1773 - struct lcs_card *card; 1774 - struct lcs_header *lcs_hdr; 1775 - __u16 offset; 1776 - 1777 - LCS_DBF_TEXT(5, trace, "lcsgtpkt"); 1778 - lcs_hdr = (struct lcs_header *) buffer->data; 1779 - if (lcs_hdr->offset == LCS_ILLEGAL_OFFSET) { 1780 - LCS_DBF_TEXT(4, trace, "-eiogpkt"); 1781 - return; 1782 - } 1783 - card = container_of(channel, struct lcs_card, read); 1784 - offset = 0; 1785 - while (lcs_hdr->offset != 0) { 1786 - if (lcs_hdr->offset <= 0 || 1787 - lcs_hdr->offset > LCS_IOBUFFERSIZE || 1788 - lcs_hdr->offset < offset) { 1789 - /* Offset invalid. */ 1790 - card->stats.rx_length_errors++; 1791 - card->stats.rx_errors++; 1792 - return; 1793 - } 1794 - if (lcs_hdr->type == LCS_FRAME_TYPE_CONTROL) 1795 - lcs_get_control(card, (struct lcs_cmd *) lcs_hdr); 1796 - else if (lcs_hdr->type == LCS_FRAME_TYPE_ENET) 1797 - lcs_get_skb(card, (char *)(lcs_hdr + 1), 1798 - lcs_hdr->offset - offset - 1799 - sizeof(struct lcs_header)); 1800 - else 1801 - dev_info_once(&card->dev->dev, 1802 - "Unknown frame type %d\n", 1803 - lcs_hdr->type); 1804 - offset = lcs_hdr->offset; 1805 - lcs_hdr->offset = LCS_ILLEGAL_OFFSET; 1806 - lcs_hdr = (struct lcs_header *) (buffer->data + offset); 1807 - } 1808 - /* The buffer is now empty. Make it ready again. */ 1809 - lcs_ready_buffer(&card->read, buffer); 1810 - } 1811 - 1812 - /* 1813 - * get network statistics for ifconfig and other user programs 1814 - */ 1815 - static struct net_device_stats * 1816 - lcs_getstats(struct net_device *dev) 1817 - { 1818 - struct lcs_card *card; 1819 - 1820 - LCS_DBF_TEXT(4, trace, "netstats"); 1821 - card = (struct lcs_card *) dev->ml_priv; 1822 - return &card->stats; 1823 - } 1824 - 1825 - /* 1826 - * stop lcs device 1827 - * This function will be called by user doing ifconfig xxx down 1828 - */ 1829 - static int 1830 - lcs_stop_device(struct net_device *dev) 1831 - { 1832 - struct lcs_card *card; 1833 - int rc; 1834 - 1835 - LCS_DBF_TEXT(2, trace, "stopdev"); 1836 - card = (struct lcs_card *) dev->ml_priv; 1837 - netif_carrier_off(dev); 1838 - netif_tx_disable(dev); 1839 - dev->flags &= ~IFF_UP; 1840 - wait_event(card->write.wait_q, 1841 - (card->write.state != LCS_CH_STATE_RUNNING)); 1842 - rc = lcs_stopcard(card); 1843 - if (rc) 1844 - dev_err(&card->dev->dev, 1845 - " Shutting down the LCS device failed\n"); 1846 - return rc; 1847 - } 1848 - 1849 - /* 1850 - * start lcs device and make it runnable 1851 - * This function will be called by user doing ifconfig xxx up 1852 - */ 1853 - static int 1854 - lcs_open_device(struct net_device *dev) 1855 - { 1856 - struct lcs_card *card; 1857 - int rc; 1858 - 1859 - LCS_DBF_TEXT(2, trace, "opendev"); 1860 - card = (struct lcs_card *) dev->ml_priv; 1861 - /* initialize statistics */ 1862 - rc = lcs_detect(card); 1863 - if (rc) { 1864 - pr_err("Error in opening device!\n"); 1865 - 1866 - } else { 1867 - dev->flags |= IFF_UP; 1868 - netif_carrier_on(dev); 1869 - netif_wake_queue(dev); 1870 - card->state = DEV_STATE_UP; 1871 - } 1872 - return rc; 1873 - } 1874 - 1875 - /* 1876 - * show function for portno called by cat or similar things 1877 - */ 1878 - static ssize_t 1879 - lcs_portno_show (struct device *dev, struct device_attribute *attr, char *buf) 1880 - { 1881 - struct lcs_card *card; 1882 - 1883 - card = dev_get_drvdata(dev); 1884 - 1885 - if (!card) 1886 - return 0; 1887 - 1888 - return sysfs_emit(buf, "%d\n", card->portno); 1889 - } 1890 - 1891 - /* 1892 - * store the value which is piped to file portno 1893 - */ 1894 - static ssize_t 1895 - lcs_portno_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1896 - { 1897 - struct lcs_card *card; 1898 - int rc; 1899 - s16 value; 1900 - 1901 - card = dev_get_drvdata(dev); 1902 - 1903 - if (!card) 1904 - return 0; 1905 - 1906 - rc = kstrtos16(buf, 0, &value); 1907 - if (rc) 1908 - return -EINVAL; 1909 - /* TODO: sanity checks */ 1910 - card->portno = value; 1911 - if (card->dev) 1912 - card->dev->dev_port = card->portno; 1913 - 1914 - return count; 1915 - 1916 - } 1917 - 1918 - static DEVICE_ATTR(portno, 0644, lcs_portno_show, lcs_portno_store); 1919 - 1920 - static const char *lcs_type[] = { 1921 - "not a channel", 1922 - "2216 parallel", 1923 - "2216 channel", 1924 - "OSA LCS card", 1925 - "unknown channel type", 1926 - "unsupported channel type", 1927 - }; 1928 - 1929 - static ssize_t 1930 - lcs_type_show(struct device *dev, struct device_attribute *attr, char *buf) 1931 - { 1932 - struct ccwgroup_device *cgdev; 1933 - 1934 - cgdev = to_ccwgroupdev(dev); 1935 - if (!cgdev) 1936 - return -ENODEV; 1937 - 1938 - return sysfs_emit(buf, "%s\n", 1939 - lcs_type[cgdev->cdev[0]->id.driver_info]); 1940 - } 1941 - 1942 - static DEVICE_ATTR(type, 0444, lcs_type_show, NULL); 1943 - 1944 - static ssize_t 1945 - lcs_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) 1946 - { 1947 - struct lcs_card *card; 1948 - 1949 - card = dev_get_drvdata(dev); 1950 - 1951 - return card ? sysfs_emit(buf, "%u\n", card->lancmd_timeout) : 0; 1952 - } 1953 - 1954 - static ssize_t 1955 - lcs_timeout_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1956 - { 1957 - struct lcs_card *card; 1958 - unsigned int value; 1959 - int rc; 1960 - 1961 - card = dev_get_drvdata(dev); 1962 - 1963 - if (!card) 1964 - return 0; 1965 - 1966 - rc = kstrtouint(buf, 0, &value); 1967 - if (rc) 1968 - return -EINVAL; 1969 - /* TODO: sanity checks */ 1970 - card->lancmd_timeout = value; 1971 - 1972 - return count; 1973 - 1974 - } 1975 - 1976 - static DEVICE_ATTR(lancmd_timeout, 0644, lcs_timeout_show, lcs_timeout_store); 1977 - 1978 - static ssize_t 1979 - lcs_dev_recover_store(struct device *dev, struct device_attribute *attr, 1980 - const char *buf, size_t count) 1981 - { 1982 - struct lcs_card *card = dev_get_drvdata(dev); 1983 - char *tmp; 1984 - int i; 1985 - 1986 - if (!card) 1987 - return -EINVAL; 1988 - if (card->state != DEV_STATE_UP) 1989 - return -EPERM; 1990 - i = simple_strtoul(buf, &tmp, 16); 1991 - if (i == 1) 1992 - lcs_schedule_recovery(card); 1993 - return count; 1994 - } 1995 - 1996 - static DEVICE_ATTR(recover, 0200, NULL, lcs_dev_recover_store); 1997 - 1998 - static struct attribute * lcs_attrs[] = { 1999 - &dev_attr_portno.attr, 2000 - &dev_attr_type.attr, 2001 - &dev_attr_lancmd_timeout.attr, 2002 - &dev_attr_recover.attr, 2003 - NULL, 2004 - }; 2005 - static struct attribute_group lcs_attr_group = { 2006 - .attrs = lcs_attrs, 2007 - }; 2008 - static const struct attribute_group *lcs_attr_groups[] = { 2009 - &lcs_attr_group, 2010 - NULL, 2011 - }; 2012 - static const struct device_type lcs_devtype = { 2013 - .name = "lcs", 2014 - .groups = lcs_attr_groups, 2015 - }; 2016 - 2017 - /* 2018 - * lcs_probe_device is called on establishing a new ccwgroup_device. 2019 - */ 2020 - static int 2021 - lcs_probe_device(struct ccwgroup_device *ccwgdev) 2022 - { 2023 - struct lcs_card *card; 2024 - 2025 - if (!get_device(&ccwgdev->dev)) 2026 - return -ENODEV; 2027 - 2028 - LCS_DBF_TEXT(2, setup, "add_dev"); 2029 - card = lcs_alloc_card(); 2030 - if (!card) { 2031 - LCS_DBF_TEXT_(2, setup, " rc%d", -ENOMEM); 2032 - put_device(&ccwgdev->dev); 2033 - return -ENOMEM; 2034 - } 2035 - dev_set_drvdata(&ccwgdev->dev, card); 2036 - ccwgdev->cdev[0]->handler = lcs_irq; 2037 - ccwgdev->cdev[1]->handler = lcs_irq; 2038 - card->gdev = ccwgdev; 2039 - INIT_WORK(&card->kernel_thread_starter, lcs_start_kernel_thread); 2040 - card->thread_start_mask = 0; 2041 - card->thread_allowed_mask = 0; 2042 - card->thread_running_mask = 0; 2043 - ccwgdev->dev.type = &lcs_devtype; 2044 - 2045 - return 0; 2046 - } 2047 - 2048 - static int 2049 - lcs_register_netdev(struct ccwgroup_device *ccwgdev) 2050 - { 2051 - struct lcs_card *card; 2052 - 2053 - LCS_DBF_TEXT(2, setup, "regnetdv"); 2054 - card = dev_get_drvdata(&ccwgdev->dev); 2055 - if (card->dev->reg_state != NETREG_UNINITIALIZED) 2056 - return 0; 2057 - SET_NETDEV_DEV(card->dev, &ccwgdev->dev); 2058 - return register_netdev(card->dev); 2059 - } 2060 - 2061 - /* 2062 - * lcs_new_device will be called by setting the group device online. 2063 - */ 2064 - static const struct net_device_ops lcs_netdev_ops = { 2065 - .ndo_open = lcs_open_device, 2066 - .ndo_stop = lcs_stop_device, 2067 - .ndo_get_stats = lcs_getstats, 2068 - .ndo_start_xmit = lcs_start_xmit, 2069 - }; 2070 - 2071 - static const struct net_device_ops lcs_mc_netdev_ops = { 2072 - .ndo_open = lcs_open_device, 2073 - .ndo_stop = lcs_stop_device, 2074 - .ndo_get_stats = lcs_getstats, 2075 - .ndo_start_xmit = lcs_start_xmit, 2076 - .ndo_set_rx_mode = lcs_set_multicast_list, 2077 - }; 2078 - 2079 - static int 2080 - lcs_new_device(struct ccwgroup_device *ccwgdev) 2081 - { 2082 - struct lcs_card *card; 2083 - struct net_device *dev=NULL; 2084 - enum lcs_dev_states recover_state; 2085 - int rc; 2086 - 2087 - card = dev_get_drvdata(&ccwgdev->dev); 2088 - if (!card) 2089 - return -ENODEV; 2090 - 2091 - LCS_DBF_TEXT(2, setup, "newdev"); 2092 - LCS_DBF_HEX(3, setup, &card, sizeof(void*)); 2093 - card->read.ccwdev = ccwgdev->cdev[0]; 2094 - card->write.ccwdev = ccwgdev->cdev[1]; 2095 - 2096 - recover_state = card->state; 2097 - rc = ccw_device_set_online(card->read.ccwdev); 2098 - if (rc) 2099 - goto out_err; 2100 - rc = ccw_device_set_online(card->write.ccwdev); 2101 - if (rc) 2102 - goto out_werr; 2103 - 2104 - LCS_DBF_TEXT(3, setup, "lcsnewdv"); 2105 - 2106 - lcs_setup_card(card); 2107 - rc = lcs_detect(card); 2108 - if (rc) { 2109 - LCS_DBF_TEXT(2, setup, "dtctfail"); 2110 - dev_err(&ccwgdev->dev, 2111 - "Detecting a network adapter for LCS devices" 2112 - " failed with rc=%d (0x%x)\n", rc, rc); 2113 - lcs_stopcard(card); 2114 - goto out; 2115 - } 2116 - if (card->dev) { 2117 - LCS_DBF_TEXT(2, setup, "samedev"); 2118 - LCS_DBF_HEX(3, setup, &card, sizeof(void*)); 2119 - goto netdev_out; 2120 - } 2121 - switch (card->lan_type) { 2122 - case LCS_FRAME_TYPE_ENET: 2123 - card->lan_type_trans = eth_type_trans; 2124 - dev = alloc_etherdev(0); 2125 - break; 2126 - default: 2127 - LCS_DBF_TEXT(3, setup, "errinit"); 2128 - pr_err(" Initialization failed\n"); 2129 - goto out; 2130 - } 2131 - if (!dev) 2132 - goto out; 2133 - card->dev = dev; 2134 - card->dev->ml_priv = card; 2135 - card->dev->netdev_ops = &lcs_netdev_ops; 2136 - card->dev->dev_port = card->portno; 2137 - eth_hw_addr_set(card->dev, card->mac); 2138 - #ifdef CONFIG_IP_MULTICAST 2139 - if (!lcs_check_multicast_support(card)) 2140 - card->dev->netdev_ops = &lcs_mc_netdev_ops; 2141 - #endif 2142 - netdev_out: 2143 - lcs_set_allowed_threads(card,0xffffffff); 2144 - if (recover_state == DEV_STATE_RECOVER) { 2145 - lcs_set_multicast_list(card->dev); 2146 - card->dev->flags |= IFF_UP; 2147 - netif_carrier_on(card->dev); 2148 - netif_wake_queue(card->dev); 2149 - card->state = DEV_STATE_UP; 2150 - } else { 2151 - lcs_stopcard(card); 2152 - } 2153 - 2154 - if (lcs_register_netdev(ccwgdev) != 0) 2155 - goto out; 2156 - 2157 - /* Print out supported assists: IPv6 */ 2158 - pr_info("LCS device %s %s IPv6 support\n", card->dev->name, 2159 - (card->ip_assists_supported & LCS_IPASS_IPV6_SUPPORT) ? 2160 - "with" : "without"); 2161 - /* Print out supported assist: Multicast */ 2162 - pr_info("LCS device %s %s Multicast support\n", card->dev->name, 2163 - (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) ? 2164 - "with" : "without"); 2165 - return 0; 2166 - out: 2167 - 2168 - ccw_device_set_offline(card->write.ccwdev); 2169 - out_werr: 2170 - ccw_device_set_offline(card->read.ccwdev); 2171 - out_err: 2172 - return -ENODEV; 2173 - } 2174 - 2175 - /* 2176 - * lcs_shutdown_device, called when setting the group device offline. 2177 - */ 2178 - static int 2179 - __lcs_shutdown_device(struct ccwgroup_device *ccwgdev, int recovery_mode) 2180 - { 2181 - struct lcs_card *card; 2182 - enum lcs_dev_states recover_state; 2183 - int ret = 0, ret2 = 0, ret3 = 0; 2184 - 2185 - LCS_DBF_TEXT(3, setup, "shtdndev"); 2186 - card = dev_get_drvdata(&ccwgdev->dev); 2187 - if (!card) 2188 - return -ENODEV; 2189 - if (recovery_mode == 0) { 2190 - lcs_set_allowed_threads(card, 0); 2191 - if (lcs_wait_for_threads(card, LCS_SET_MC_THREAD)) 2192 - return -ERESTARTSYS; 2193 - } 2194 - LCS_DBF_HEX(3, setup, &card, sizeof(void*)); 2195 - recover_state = card->state; 2196 - 2197 - ret = lcs_stop_device(card->dev); 2198 - ret2 = ccw_device_set_offline(card->read.ccwdev); 2199 - ret3 = ccw_device_set_offline(card->write.ccwdev); 2200 - if (!ret) 2201 - ret = (ret2) ? ret2 : ret3; 2202 - if (ret) 2203 - LCS_DBF_TEXT_(3, setup, "1err:%d", ret); 2204 - if (recover_state == DEV_STATE_UP) { 2205 - card->state = DEV_STATE_RECOVER; 2206 - } 2207 - return 0; 2208 - } 2209 - 2210 - static int 2211 - lcs_shutdown_device(struct ccwgroup_device *ccwgdev) 2212 - { 2213 - return __lcs_shutdown_device(ccwgdev, 0); 2214 - } 2215 - 2216 - /* 2217 - * drive lcs recovery after startup and startlan initiated by Lan Gateway 2218 - */ 2219 - static int 2220 - lcs_recovery(void *ptr) 2221 - { 2222 - struct lcs_card *card; 2223 - struct ccwgroup_device *gdev; 2224 - int rc; 2225 - 2226 - card = (struct lcs_card *) ptr; 2227 - 2228 - LCS_DBF_TEXT(4, trace, "recover1"); 2229 - if (!lcs_do_run_thread(card, LCS_RECOVERY_THREAD)) 2230 - return 0; 2231 - LCS_DBF_TEXT(4, trace, "recover2"); 2232 - gdev = card->gdev; 2233 - dev_warn(&gdev->dev, 2234 - "A recovery process has been started for the LCS device\n"); 2235 - rc = __lcs_shutdown_device(gdev, 1); 2236 - rc = lcs_new_device(gdev); 2237 - if (!rc) 2238 - pr_info("Device %s successfully recovered!\n", 2239 - card->dev->name); 2240 - else 2241 - pr_info("Device %s could not be recovered!\n", 2242 - card->dev->name); 2243 - lcs_clear_thread_running_bit(card, LCS_RECOVERY_THREAD); 2244 - return 0; 2245 - } 2246 - 2247 - /* 2248 - * lcs_remove_device, free buffers and card 2249 - */ 2250 - static void 2251 - lcs_remove_device(struct ccwgroup_device *ccwgdev) 2252 - { 2253 - struct lcs_card *card; 2254 - 2255 - card = dev_get_drvdata(&ccwgdev->dev); 2256 - if (!card) 2257 - return; 2258 - 2259 - LCS_DBF_TEXT(3, setup, "remdev"); 2260 - LCS_DBF_HEX(3, setup, &card, sizeof(void*)); 2261 - if (ccwgdev->state == CCWGROUP_ONLINE) { 2262 - lcs_shutdown_device(ccwgdev); 2263 - } 2264 - if (card->dev) 2265 - unregister_netdev(card->dev); 2266 - lcs_cleanup_card(card); 2267 - lcs_free_card(card); 2268 - dev_set_drvdata(&ccwgdev->dev, NULL); 2269 - put_device(&ccwgdev->dev); 2270 - } 2271 - 2272 - static struct ccw_device_id lcs_ids[] = { 2273 - {CCW_DEVICE(0x3088, 0x08), .driver_info = lcs_channel_type_parallel}, 2274 - {CCW_DEVICE(0x3088, 0x1f), .driver_info = lcs_channel_type_2216}, 2275 - {CCW_DEVICE(0x3088, 0x60), .driver_info = lcs_channel_type_osa2}, 2276 - {}, 2277 - }; 2278 - MODULE_DEVICE_TABLE(ccw, lcs_ids); 2279 - 2280 - static struct ccw_driver lcs_ccw_driver = { 2281 - .driver = { 2282 - .owner = THIS_MODULE, 2283 - .name = "lcs", 2284 - }, 2285 - .ids = lcs_ids, 2286 - .probe = ccwgroup_probe_ccwdev, 2287 - .remove = ccwgroup_remove_ccwdev, 2288 - .int_class = IRQIO_LCS, 2289 - }; 2290 - 2291 - /* 2292 - * LCS ccwgroup driver registration 2293 - */ 2294 - static struct ccwgroup_driver lcs_group_driver = { 2295 - .driver = { 2296 - .owner = THIS_MODULE, 2297 - .name = "lcs", 2298 - }, 2299 - .ccw_driver = &lcs_ccw_driver, 2300 - .setup = lcs_probe_device, 2301 - .remove = lcs_remove_device, 2302 - .set_online = lcs_new_device, 2303 - .set_offline = lcs_shutdown_device, 2304 - }; 2305 - 2306 - static ssize_t group_store(struct device_driver *ddrv, const char *buf, 2307 - size_t count) 2308 - { 2309 - int err; 2310 - err = ccwgroup_create_dev(lcs_root_dev, &lcs_group_driver, 2, buf); 2311 - return err ? err : count; 2312 - } 2313 - static DRIVER_ATTR_WO(group); 2314 - 2315 - static struct attribute *lcs_drv_attrs[] = { 2316 - &driver_attr_group.attr, 2317 - NULL, 2318 - }; 2319 - static struct attribute_group lcs_drv_attr_group = { 2320 - .attrs = lcs_drv_attrs, 2321 - }; 2322 - static const struct attribute_group *lcs_drv_attr_groups[] = { 2323 - &lcs_drv_attr_group, 2324 - NULL, 2325 - }; 2326 - 2327 - /* 2328 - * LCS Module/Kernel initialization function 2329 - */ 2330 - static int 2331 - __init lcs_init_module(void) 2332 - { 2333 - int rc; 2334 - 2335 - pr_info("Loading %s\n", version); 2336 - rc = lcs_register_debug_facility(); 2337 - LCS_DBF_TEXT(0, setup, "lcsinit"); 2338 - if (rc) 2339 - goto out_err; 2340 - lcs_root_dev = root_device_register("lcs"); 2341 - rc = PTR_ERR_OR_ZERO(lcs_root_dev); 2342 - if (rc) 2343 - goto register_err; 2344 - rc = ccw_driver_register(&lcs_ccw_driver); 2345 - if (rc) 2346 - goto ccw_err; 2347 - lcs_group_driver.driver.groups = lcs_drv_attr_groups; 2348 - rc = ccwgroup_driver_register(&lcs_group_driver); 2349 - if (rc) 2350 - goto ccwgroup_err; 2351 - return 0; 2352 - 2353 - ccwgroup_err: 2354 - ccw_driver_unregister(&lcs_ccw_driver); 2355 - ccw_err: 2356 - root_device_unregister(lcs_root_dev); 2357 - register_err: 2358 - lcs_unregister_debug_facility(); 2359 - out_err: 2360 - pr_err("Initializing the lcs device driver failed\n"); 2361 - return rc; 2362 - } 2363 - 2364 - 2365 - /* 2366 - * LCS module cleanup function 2367 - */ 2368 - static void 2369 - __exit lcs_cleanup_module(void) 2370 - { 2371 - pr_info("Terminating lcs module.\n"); 2372 - LCS_DBF_TEXT(0, trace, "cleanup"); 2373 - ccwgroup_driver_unregister(&lcs_group_driver); 2374 - ccw_driver_unregister(&lcs_ccw_driver); 2375 - root_device_unregister(lcs_root_dev); 2376 - lcs_unregister_debug_facility(); 2377 - } 2378 - 2379 - module_init(lcs_init_module); 2380 - module_exit(lcs_cleanup_module); 2381 - 2382 - MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>"); 2383 - MODULE_DESCRIPTION("S/390 LAN channel station device driver"); 2384 - MODULE_LICENSE("GPL"); 2385 -
-342
drivers/s390/net/lcs.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /*lcs.h*/ 3 - 4 - #include <linux/interrupt.h> 5 - #include <linux/netdevice.h> 6 - #include <linux/skbuff.h> 7 - #include <linux/workqueue.h> 8 - #include <linux/refcount.h> 9 - #include <asm/ccwdev.h> 10 - 11 - #define LCS_DBF_TEXT(level, name, text) \ 12 - do { \ 13 - debug_text_event(lcs_dbf_##name, level, text); \ 14 - } while (0) 15 - 16 - #define LCS_DBF_HEX(level,name,addr,len) \ 17 - do { \ 18 - debug_event(lcs_dbf_##name,level,(void*)(addr),len); \ 19 - } while (0) 20 - 21 - #define LCS_DBF_TEXT_(level,name,text...) \ 22 - do { \ 23 - if (debug_level_enabled(lcs_dbf_##name, level)) { \ 24 - scnprintf(debug_buffer, sizeof(debug_buffer), text); \ 25 - debug_text_event(lcs_dbf_##name, level, debug_buffer); \ 26 - } \ 27 - } while (0) 28 - 29 - /** 30 - * sysfs related stuff 31 - */ 32 - #define CARD_FROM_DEV(cdev) \ 33 - (struct lcs_card *) dev_get_drvdata( \ 34 - &((struct ccwgroup_device *)dev_get_drvdata(&cdev->dev))->dev); 35 - 36 - /** 37 - * Enum for classifying detected devices. 38 - */ 39 - enum lcs_channel_types { 40 - /* Device is not a channel */ 41 - lcs_channel_type_none, 42 - 43 - /* Device is a 2216 channel */ 44 - lcs_channel_type_parallel, 45 - 46 - /* Device is a 2216 channel */ 47 - lcs_channel_type_2216, 48 - 49 - /* Device is a OSA2 card */ 50 - lcs_channel_type_osa2 51 - }; 52 - 53 - /** 54 - * CCW commands used in this driver 55 - */ 56 - #define LCS_CCW_WRITE 0x01 57 - #define LCS_CCW_READ 0x02 58 - #define LCS_CCW_TRANSFER 0x08 59 - 60 - /** 61 - * LCS device status primitives 62 - */ 63 - #define LCS_CMD_STARTLAN 0x01 64 - #define LCS_CMD_STOPLAN 0x02 65 - #define LCS_CMD_LANSTAT 0x04 66 - #define LCS_CMD_STARTUP 0x07 67 - #define LCS_CMD_SHUTDOWN 0x08 68 - #define LCS_CMD_QIPASSIST 0xb2 69 - #define LCS_CMD_SETIPM 0xb4 70 - #define LCS_CMD_DELIPM 0xb5 71 - 72 - #define LCS_INITIATOR_TCPIP 0x00 73 - #define LCS_INITIATOR_LGW 0x01 74 - #define LCS_STD_CMD_SIZE 16 75 - #define LCS_MULTICAST_CMD_SIZE 404 76 - 77 - /** 78 - * LCS IPASSIST MASKS,only used when multicast is switched on 79 - */ 80 - /* Not supported by LCS */ 81 - #define LCS_IPASS_ARP_PROCESSING 0x0001 82 - #define LCS_IPASS_IN_CHECKSUM_SUPPORT 0x0002 83 - #define LCS_IPASS_OUT_CHECKSUM_SUPPORT 0x0004 84 - #define LCS_IPASS_IP_FRAG_REASSEMBLY 0x0008 85 - #define LCS_IPASS_IP_FILTERING 0x0010 86 - /* Supported by lcs 3172 */ 87 - #define LCS_IPASS_IPV6_SUPPORT 0x0020 88 - #define LCS_IPASS_MULTICAST_SUPPORT 0x0040 89 - 90 - /** 91 - * LCS sense byte definitions 92 - */ 93 - #define LCS_SENSE_BYTE_0 0 94 - #define LCS_SENSE_BYTE_1 1 95 - #define LCS_SENSE_BYTE_2 2 96 - #define LCS_SENSE_BYTE_3 3 97 - #define LCS_SENSE_INTERFACE_DISCONNECT 0x01 98 - #define LCS_SENSE_EQUIPMENT_CHECK 0x10 99 - #define LCS_SENSE_BUS_OUT_CHECK 0x20 100 - #define LCS_SENSE_INTERVENTION_REQUIRED 0x40 101 - #define LCS_SENSE_CMD_REJECT 0x80 102 - #define LCS_SENSE_RESETTING_EVENT 0x80 103 - #define LCS_SENSE_DEVICE_ONLINE 0x20 104 - 105 - /** 106 - * LCS packet type definitions 107 - */ 108 - #define LCS_FRAME_TYPE_CONTROL 0 109 - #define LCS_FRAME_TYPE_ENET 1 110 - #define LCS_FRAME_TYPE_TR 2 111 - #define LCS_FRAME_TYPE_FDDI 7 112 - #define LCS_FRAME_TYPE_AUTO -1 113 - 114 - /** 115 - * some more definitions,we will sort them later 116 - */ 117 - #define LCS_ILLEGAL_OFFSET 0xffff 118 - #define LCS_IOBUFFERSIZE 0x5000 119 - #define LCS_NUM_BUFFS 32 /* needs to be power of 2 */ 120 - #define LCS_MAC_LENGTH 6 121 - #define LCS_INVALID_PORT_NO -1 122 - #define LCS_LANCMD_TIMEOUT_DEFAULT 5 123 - 124 - /** 125 - * Multicast state 126 - */ 127 - #define LCS_IPM_STATE_SET_REQUIRED 0 128 - #define LCS_IPM_STATE_DEL_REQUIRED 1 129 - #define LCS_IPM_STATE_ON_CARD 2 130 - 131 - /** 132 - * LCS IP Assist declarations 133 - * seems to be only used for multicast 134 - */ 135 - #define LCS_IPASS_ARP_PROCESSING 0x0001 136 - #define LCS_IPASS_INBOUND_CSUM_SUPP 0x0002 137 - #define LCS_IPASS_OUTBOUND_CSUM_SUPP 0x0004 138 - #define LCS_IPASS_IP_FRAG_REASSEMBLY 0x0008 139 - #define LCS_IPASS_IP_FILTERING 0x0010 140 - #define LCS_IPASS_IPV6_SUPPORT 0x0020 141 - #define LCS_IPASS_MULTICAST_SUPPORT 0x0040 142 - 143 - /** 144 - * LCS Buffer states 145 - */ 146 - enum lcs_buffer_states { 147 - LCS_BUF_STATE_EMPTY, /* buffer is empty */ 148 - LCS_BUF_STATE_LOCKED, /* buffer is locked, don't touch */ 149 - LCS_BUF_STATE_READY, /* buffer is ready for read/write */ 150 - LCS_BUF_STATE_PROCESSED, 151 - }; 152 - 153 - /** 154 - * LCS Channel State Machine declarations 155 - */ 156 - enum lcs_channel_states { 157 - LCS_CH_STATE_INIT, 158 - LCS_CH_STATE_HALTED, 159 - LCS_CH_STATE_STOPPED, 160 - LCS_CH_STATE_RUNNING, 161 - LCS_CH_STATE_SUSPENDED, 162 - LCS_CH_STATE_CLEARED, 163 - LCS_CH_STATE_ERROR, 164 - }; 165 - 166 - /** 167 - * LCS device state machine 168 - */ 169 - enum lcs_dev_states { 170 - DEV_STATE_DOWN, 171 - DEV_STATE_UP, 172 - DEV_STATE_RECOVER, 173 - }; 174 - 175 - enum lcs_threads { 176 - LCS_SET_MC_THREAD = 1, 177 - LCS_RECOVERY_THREAD = 2, 178 - }; 179 - 180 - /** 181 - * LCS struct declarations 182 - */ 183 - struct lcs_header { 184 - __u16 offset; 185 - __u8 type; 186 - __u8 slot; 187 - } __attribute__ ((packed)); 188 - 189 - struct lcs_ip_mac_pair { 190 - __be32 ip_addr; 191 - __u8 mac_addr[LCS_MAC_LENGTH]; 192 - __u8 reserved[2]; 193 - } __attribute__ ((packed)); 194 - 195 - struct lcs_ipm_list { 196 - struct list_head list; 197 - struct lcs_ip_mac_pair ipm; 198 - __u8 ipm_state; 199 - }; 200 - 201 - struct lcs_cmd { 202 - __u16 offset; 203 - __u8 type; 204 - __u8 slot; 205 - __u8 cmd_code; 206 - __u8 initiator; 207 - __u16 sequence_no; 208 - __u16 return_code; 209 - union { 210 - struct { 211 - __u8 lan_type; 212 - __u8 portno; 213 - __u16 parameter_count; 214 - __u8 operator_flags[3]; 215 - __u8 reserved[3]; 216 - } lcs_std_cmd; 217 - struct { 218 - __u16 unused1; 219 - __u16 buff_size; 220 - __u8 unused2[6]; 221 - } lcs_startup; 222 - struct { 223 - __u8 lan_type; 224 - __u8 portno; 225 - __u8 unused[10]; 226 - __u8 mac_addr[LCS_MAC_LENGTH]; 227 - __u32 num_packets_deblocked; 228 - __u32 num_packets_blocked; 229 - __u32 num_packets_tx_on_lan; 230 - __u32 num_tx_errors_detected; 231 - __u32 num_tx_packets_disgarded; 232 - __u32 num_packets_rx_from_lan; 233 - __u32 num_rx_errors_detected; 234 - __u32 num_rx_discarded_nobuffs_avail; 235 - __u32 num_rx_packets_too_large; 236 - } lcs_lanstat_cmd; 237 - #ifdef CONFIG_IP_MULTICAST 238 - struct { 239 - __u8 lan_type; 240 - __u8 portno; 241 - __u16 num_ip_pairs; 242 - __u16 ip_assists_supported; 243 - __u16 ip_assists_enabled; 244 - __u16 version; 245 - struct { 246 - struct lcs_ip_mac_pair 247 - ip_mac_pair[32]; 248 - __u32 response_data; 249 - } lcs_ipass_ctlmsg __attribute ((packed)); 250 - } lcs_qipassist __attribute__ ((packed)); 251 - #endif /*CONFIG_IP_MULTICAST */ 252 - } cmd __attribute__ ((packed)); 253 - } __attribute__ ((packed)); 254 - 255 - /** 256 - * Forward declarations. 257 - */ 258 - struct lcs_card; 259 - struct lcs_channel; 260 - 261 - /** 262 - * Definition of an lcs buffer. 263 - */ 264 - struct lcs_buffer { 265 - enum lcs_buffer_states state; 266 - void *data; 267 - int count; 268 - /* Callback for completion notification. */ 269 - void (*callback)(struct lcs_channel *, struct lcs_buffer *); 270 - }; 271 - 272 - struct lcs_reply { 273 - struct list_head list; 274 - __u16 sequence_no; 275 - refcount_t refcnt; 276 - /* Callback for completion notification. */ 277 - void (*callback)(struct lcs_card *, struct lcs_cmd *); 278 - wait_queue_head_t wait_q; 279 - struct lcs_card *card; 280 - struct timer_list timer; 281 - int received; 282 - int rc; 283 - }; 284 - 285 - /** 286 - * Definition of an lcs channel 287 - */ 288 - struct lcs_channel { 289 - enum lcs_channel_states state; 290 - struct ccw_device *ccwdev; 291 - struct ccw1 ccws[LCS_NUM_BUFFS + 1]; 292 - wait_queue_head_t wait_q; 293 - struct tasklet_struct irq_tasklet; 294 - struct lcs_buffer iob[LCS_NUM_BUFFS]; 295 - int io_idx; 296 - int buf_idx; 297 - }; 298 - 299 - 300 - /** 301 - * definition of the lcs card 302 - */ 303 - struct lcs_card { 304 - spinlock_t lock; 305 - spinlock_t ipm_lock; 306 - enum lcs_dev_states state; 307 - struct net_device *dev; 308 - struct net_device_stats stats; 309 - __be16 (*lan_type_trans)(struct sk_buff *skb, 310 - struct net_device *dev); 311 - struct ccwgroup_device *gdev; 312 - struct lcs_channel read; 313 - struct lcs_channel write; 314 - struct lcs_buffer *tx_buffer; 315 - int tx_emitted; 316 - struct list_head lancmd_waiters; 317 - int lancmd_timeout; 318 - 319 - struct work_struct kernel_thread_starter; 320 - spinlock_t mask_lock; 321 - unsigned long thread_start_mask; 322 - unsigned long thread_running_mask; 323 - unsigned long thread_allowed_mask; 324 - wait_queue_head_t wait_q; 325 - 326 - #ifdef CONFIG_IP_MULTICAST 327 - struct list_head ipm_list; 328 - #endif 329 - __u8 mac[LCS_MAC_LENGTH]; 330 - __u16 ip_assists_supported; 331 - __u16 ip_assists_enabled; 332 - __s8 lan_type; 333 - __u32 pkt_seq; 334 - __u16 sequence_no; 335 - __s16 portno; 336 - /* Some info copied from probeinfo */ 337 - u8 device_forced; 338 - u8 max_port_no; 339 - u8 hint_port_no; 340 - s16 port_protocol_no; 341 - } __attribute__ ((aligned(8))); 342 -
-1
include/linux/mlx4/device.h
··· 1415 1415 bool *vlan_offload_disabled); 1416 1416 void mlx4_handle_eth_header_mcast_prio(struct mlx4_net_trans_rule_hw_ctrl *ctrl, 1417 1417 struct _rule_hw *eth_header); 1418 - int mlx4_find_cached_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *idx); 1419 1418 int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx); 1420 1419 int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index); 1421 1420 void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan);
+4 -29
include/linux/mlx5/driver.h
··· 54 54 #include <linux/mlx5/doorbell.h> 55 55 #include <linux/mlx5/eq.h> 56 56 #include <linux/timecounter.h> 57 - #include <linux/ptp_clock_kernel.h> 58 57 #include <net/devlink.h> 59 58 60 59 #define MLX5_ADEV_NAME "mlx5_core" ··· 678 679 struct ida ida; 679 680 }; 680 681 681 - #define MAX_PIN_NUM 8 682 - struct mlx5_pps { 683 - u8 pin_caps[MAX_PIN_NUM]; 684 - struct work_struct out_work; 685 - u64 start[MAX_PIN_NUM]; 686 - u8 enabled; 687 - u64 min_npps_period; 688 - u64 min_out_pulse_duration_ns; 689 - }; 690 - 691 - struct mlx5_timer { 692 - struct cyclecounter cycles; 693 - struct timecounter tc; 694 - u32 nominal_c_mult; 695 - unsigned long overflow_period; 696 - }; 697 - 698 - struct mlx5_clock { 699 - struct mlx5_nb pps_nb; 700 - seqlock_t lock; 701 - struct hwtstamp_config hwtstamp_config; 702 - struct ptp_clock *ptp; 703 - struct ptp_clock_info ptp_info; 704 - struct mlx5_pps pps_info; 705 - struct mlx5_timer timer; 706 - }; 707 - 682 + struct mlx5_clock; 683 + struct mlx5_clock_dev_state; 708 684 struct mlx5_dm; 709 685 struct mlx5_fw_tracer; 710 686 struct mlx5_vxlan; ··· 763 789 #ifdef CONFIG_MLX5_FPGA 764 790 struct mlx5_fpga_device *fpga; 765 791 #endif 766 - struct mlx5_clock clock; 792 + struct mlx5_clock *clock; 793 + struct mlx5_clock_dev_state *clock_state; 767 794 struct mlx5_ib_clock_info *clock_info; 768 795 struct mlx5_fw_tracer *tracer; 769 796 struct mlx5_rsc_dump *rsc_dump;
+3
include/linux/mlx5/port.h
··· 115 115 MLX5E_100GAUI_1_100GBASE_CR_KR = 11, 116 116 MLX5E_200GAUI_4_200GBASE_CR4_KR4 = 12, 117 117 MLX5E_200GAUI_2_200GBASE_CR2_KR2 = 13, 118 + MLX5E_200GAUI_1_200GBASE_CR1_KR1 = 14, 118 119 MLX5E_400GAUI_8_400GBASE_CR8 = 15, 119 120 MLX5E_400GAUI_4_400GBASE_CR4_KR4 = 16, 121 + MLX5E_400GAUI_2_400GBASE_CR2_KR2 = 17, 120 122 MLX5E_800GAUI_8_800GBASE_CR8_KR8 = 19, 123 + MLX5E_800GAUI_4_800GBASE_CR4_KR4 = 20, 121 124 MLX5E_EXT_LINK_MODES_NUMBER, 122 125 }; 123 126
+1
include/linux/netdevice.h
··· 658 658 struct Qdisc __rcu *qdisc_sleeping; 659 659 #ifdef CONFIG_SYSFS 660 660 struct kobject kobj; 661 + const struct attribute_group **groups; 661 662 #endif 662 663 unsigned long tx_maxrate; 663 664 /*
+1
include/linux/rtnetlink.h
··· 43 43 extern void rtnl_unlock(void); 44 44 extern int rtnl_trylock(void); 45 45 extern int rtnl_is_locked(void); 46 + extern int rtnl_lock_interruptible(void); 46 47 extern int rtnl_lock_killable(void); 47 48 extern bool refcount_dec_and_rtnl_lock(refcount_t *r); 48 49
+1
include/net/netdev_rx_queue.h
··· 16 16 struct rps_dev_flow_table __rcu *rps_flow_table; 17 17 #endif 18 18 struct kobject kobj; 19 + const struct attribute_group **groups; 19 20 struct net_device *dev; 20 21 netdevice_tracker dev_tracker; 21 22
+20 -1
include/net/netmem.h
··· 24 24 unsigned long __unused_padding; 25 25 unsigned long pp_magic; 26 26 struct page_pool *pp; 27 - struct dmabuf_genpool_chunk_owner *owner; 27 + struct net_iov_area *owner; 28 28 unsigned long dma_addr; 29 29 atomic_long_t pp_ref_count; 30 + }; 31 + 32 + struct net_iov_area { 33 + /* Array of net_iovs for this area. */ 34 + struct net_iov *niovs; 35 + size_t num_niovs; 36 + 37 + /* Offset into the dma-buf where this chunk starts. */ 38 + unsigned long base_virtual; 30 39 }; 31 40 32 41 /* These fields in struct page are used by the page_pool and net stack: ··· 62 53 NET_IOV_ASSERT_OFFSET(dma_addr, dma_addr); 63 54 NET_IOV_ASSERT_OFFSET(pp_ref_count, pp_ref_count); 64 55 #undef NET_IOV_ASSERT_OFFSET 56 + 57 + static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov) 58 + { 59 + return niov->owner; 60 + } 61 + 62 + static inline unsigned int net_iov_idx(const struct net_iov *niov) 63 + { 64 + return niov - net_iov_owner(niov)->niovs; 65 + } 65 66 66 67 /* netmem */ 67 68
+45
include/net/page_pool/memory_provider.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _NET_PAGE_POOL_MEMORY_PROVIDER_H 3 + #define _NET_PAGE_POOL_MEMORY_PROVIDER_H 4 + 5 + #include <net/netmem.h> 6 + #include <net/page_pool/types.h> 7 + 8 + struct netdev_rx_queue; 9 + struct sk_buff; 10 + 11 + struct memory_provider_ops { 12 + netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp); 13 + bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem); 14 + int (*init)(struct page_pool *pool); 15 + void (*destroy)(struct page_pool *pool); 16 + int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, 17 + struct netdev_rx_queue *rxq); 18 + void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); 19 + }; 20 + 21 + bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); 22 + void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov); 23 + void net_mp_niov_clear_page_pool(struct net_iov *niov); 24 + 25 + int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, 26 + struct pp_memory_provider_params *p); 27 + void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, 28 + struct pp_memory_provider_params *old_p); 29 + 30 + /** 31 + * net_mp_netmem_place_in_cache() - give a netmem to a page pool 32 + * @pool: the page pool to place the netmem into 33 + * @netmem: netmem to give 34 + * 35 + * Push an accounted netmem into the page pool's allocation cache. The caller 36 + * must ensure that there is space in the cache. It should only be called off 37 + * the mp_ops->alloc_netmems() path. 38 + */ 39 + static inline void net_mp_netmem_place_in_cache(struct page_pool *pool, 40 + netmem_ref netmem) 41 + { 42 + pool->alloc.cache[pool->alloc.count++] = netmem; 43 + } 44 + 45 + #endif
+4
include/net/page_pool/types.h
··· 152 152 */ 153 153 #define PAGE_POOL_FRAG_GROUP_ALIGN (4 * sizeof(long)) 154 154 155 + struct memory_provider_ops; 156 + 155 157 struct pp_memory_provider_params { 156 158 void *mp_priv; 159 + const struct memory_provider_ops *mp_ops; 157 160 }; 158 161 159 162 struct page_pool { ··· 219 216 struct ptr_ring ring; 220 217 221 218 void *mp_priv; 219 + const struct memory_provider_ops *mp_ops; 222 220 223 221 #ifdef CONFIG_PAGE_POOL_STATS 224 222 /* recycle stats are per-cpu to avoid locking */
+18
include/uapi/linux/ethtool.h
··· 2059 2059 ETHTOOL_LINK_MODE_10baseT1S_Half_BIT = 100, 2060 2060 ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT = 101, 2061 2061 ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT = 102, 2062 + ETHTOOL_LINK_MODE_200000baseCR_Full_BIT = 103, 2063 + ETHTOOL_LINK_MODE_200000baseKR_Full_BIT = 104, 2064 + ETHTOOL_LINK_MODE_200000baseDR_Full_BIT = 105, 2065 + ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT = 106, 2066 + ETHTOOL_LINK_MODE_200000baseSR_Full_BIT = 107, 2067 + ETHTOOL_LINK_MODE_200000baseVR_Full_BIT = 108, 2068 + ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT = 109, 2069 + ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT = 110, 2070 + ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT = 111, 2071 + ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT = 112, 2072 + ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT = 113, 2073 + ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT = 114, 2074 + ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT = 115, 2075 + ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT = 116, 2076 + ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT = 117, 2077 + ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT = 118, 2078 + ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT = 119, 2079 + ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT = 120, 2062 2080 2063 2081 /* must be last entry */ 2064 2082 __ETHTOOL_LINK_MODE_MASK_NBITS
+7
include/uapi/linux/netdev.h
··· 87 87 }; 88 88 89 89 enum { 90 + __NETDEV_A_IO_URING_PROVIDER_INFO_MAX, 91 + NETDEV_A_IO_URING_PROVIDER_INFO_MAX = (__NETDEV_A_IO_URING_PROVIDER_INFO_MAX - 1) 92 + }; 93 + 94 + enum { 90 95 NETDEV_A_PAGE_POOL_ID = 1, 91 96 NETDEV_A_PAGE_POOL_IFINDEX, 92 97 NETDEV_A_PAGE_POOL_NAPI_ID, ··· 99 94 NETDEV_A_PAGE_POOL_INFLIGHT_MEM, 100 95 NETDEV_A_PAGE_POOL_DETACH_TIME, 101 96 NETDEV_A_PAGE_POOL_DMABUF, 97 + NETDEV_A_PAGE_POOL_IO_URING, 102 98 103 99 __NETDEV_A_PAGE_POOL_MAX, 104 100 NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1) ··· 142 136 NETDEV_A_QUEUE_TYPE, 143 137 NETDEV_A_QUEUE_NAPI_ID, 144 138 NETDEV_A_QUEUE_DMABUF, 139 + NETDEV_A_QUEUE_IO_URING, 145 140 146 141 __NETDEV_A_QUEUE_MAX, 147 142 NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
+1 -1
net/bridge/br_mdb.c
··· 1040 1040 1041 1041 /* host join */ 1042 1042 if (!port) { 1043 - if (mp->host_joined) { 1043 + if (mp->host_joined && !(cfg->nlflags & NLM_F_REPLACE)) { 1044 1044 NL_SET_ERR_MSG_MOD(extack, "Group is already joined by host"); 1045 1045 return -EEXIST; 1046 1046 }
+26 -5
net/core/dev.c
··· 159 159 #include <net/netdev_rx_queue.h> 160 160 #include <net/page_pool/types.h> 161 161 #include <net/page_pool/helpers.h> 162 + #include <net/page_pool/memory_provider.h> 162 163 #include <net/rps.h> 163 164 #include <linux/phy_link_topology.h> 164 165 ··· 6120 6119 static void flush_backlog(struct work_struct *work) 6121 6120 { 6122 6121 struct sk_buff *skb, *tmp; 6122 + struct sk_buff_head list; 6123 6123 struct softnet_data *sd; 6124 6124 6125 + __skb_queue_head_init(&list); 6125 6126 local_bh_disable(); 6126 6127 sd = this_cpu_ptr(&softnet_data); 6127 6128 6128 6129 backlog_lock_irq_disable(sd); 6129 6130 skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) { 6130 - if (skb->dev->reg_state == NETREG_UNREGISTERING) { 6131 + if (READ_ONCE(skb->dev->reg_state) == NETREG_UNREGISTERING) { 6131 6132 __skb_unlink(skb, &sd->input_pkt_queue); 6132 - dev_kfree_skb_irq(skb); 6133 + __skb_queue_tail(&list, skb); 6133 6134 rps_input_queue_head_incr(sd); 6134 6135 } 6135 6136 } ··· 6139 6136 6140 6137 local_lock_nested_bh(&softnet_data.process_queue_bh_lock); 6141 6138 skb_queue_walk_safe(&sd->process_queue, skb, tmp) { 6142 - if (skb->dev->reg_state == NETREG_UNREGISTERING) { 6139 + if (READ_ONCE(skb->dev->reg_state) == NETREG_UNREGISTERING) { 6143 6140 __skb_unlink(skb, &sd->process_queue); 6144 - kfree_skb(skb); 6141 + __skb_queue_tail(&list, skb); 6145 6142 rps_input_queue_head_incr(sd); 6146 6143 } 6147 6144 } 6148 6145 local_unlock_nested_bh(&softnet_data.process_queue_bh_lock); 6149 6146 local_bh_enable(); 6147 + 6148 + __skb_queue_purge_reason(&list, SKB_DROP_REASON_DEV_READY); 6150 6149 } 6151 6150 6152 6151 static bool flush_required(int cpu) ··· 7075 7070 7076 7071 if (!test_and_clear_bit(NAPI_STATE_LISTED, &napi->state)) 7077 7072 return; 7073 + 7074 + /* Make sure NAPI is disabled (or was never enabled). */ 7075 + WARN_ON(!test_bit(NAPI_STATE_SCHED, &napi->state)); 7078 7076 7079 7077 if (napi->config) { 7080 7078 napi->index = -1; ··· 11746 11738 } 11747 11739 EXPORT_SYMBOL(unregister_netdevice_queue); 11748 11740 11741 + static void dev_memory_provider_uninstall(struct net_device *dev) 11742 + { 11743 + unsigned int i; 11744 + 11745 + for (i = 0; i < dev->real_num_rx_queues; i++) { 11746 + struct netdev_rx_queue *rxq = &dev->_rx[i]; 11747 + struct pp_memory_provider_params *p = &rxq->mp_params; 11748 + 11749 + if (p->mp_ops && p->mp_ops->uninstall) 11750 + p->mp_ops->uninstall(rxq->mp_params.mp_priv, rxq); 11751 + } 11752 + } 11753 + 11749 11754 void unregister_netdevice_many_notify(struct list_head *head, 11750 11755 u32 portid, const struct nlmsghdr *nlh) 11751 11756 { ··· 11813 11792 dev_tcx_uninstall(dev); 11814 11793 dev_xdp_uninstall(dev); 11815 11794 bpf_dev_bound_netdev_unregister(dev); 11816 - dev_dmabuf_uninstall(dev); 11795 + dev_memory_provider_uninstall(dev); 11817 11796 11818 11797 netdev_offload_xstats_disable_all(dev); 11819 11798
+59 -34
net/core/devmem.c
··· 16 16 #include <net/netdev_queues.h> 17 17 #include <net/netdev_rx_queue.h> 18 18 #include <net/page_pool/helpers.h> 19 + #include <net/page_pool/memory_provider.h> 19 20 #include <trace/events/page_pool.h> 20 21 21 22 #include "devmem.h" ··· 28 27 /* Protected by rtnl_lock() */ 29 28 static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1); 30 29 30 + static const struct memory_provider_ops dmabuf_devmem_ops; 31 + 32 + bool net_is_devmem_iov(struct net_iov *niov) 33 + { 34 + return niov->pp->mp_ops == &dmabuf_devmem_ops; 35 + } 36 + 31 37 static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool, 32 38 struct gen_pool_chunk *chunk, 33 39 void *not_used) 34 40 { 35 41 struct dmabuf_genpool_chunk_owner *owner = chunk->owner; 36 42 37 - kvfree(owner->niovs); 43 + kvfree(owner->area.niovs); 38 44 kfree(owner); 39 45 } 40 46 41 47 static dma_addr_t net_devmem_get_dma_addr(const struct net_iov *niov) 42 48 { 43 - struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov); 49 + struct dmabuf_genpool_chunk_owner *owner; 44 50 51 + owner = net_devmem_iov_to_chunk_owner(niov); 45 52 return owner->base_dma_addr + 46 53 ((dma_addr_t)net_iov_idx(niov) << PAGE_SHIFT); 47 54 } ··· 92 83 93 84 offset = dma_addr - owner->base_dma_addr; 94 85 index = offset / PAGE_SIZE; 95 - niov = &owner->niovs[index]; 86 + niov = &owner->area.niovs[index]; 96 87 97 88 niov->pp_magic = 0; 98 89 niov->pp = NULL; ··· 103 94 104 95 void net_devmem_free_dmabuf(struct net_iov *niov) 105 96 { 106 - struct net_devmem_dmabuf_binding *binding = net_iov_binding(niov); 97 + struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov); 107 98 unsigned long dma_addr = net_devmem_get_dma_addr(niov); 108 99 109 100 if (WARN_ON(!gen_pool_has_addr(binding->chunk_pool, dma_addr, ··· 126 117 WARN_ON(rxq->mp_params.mp_priv != binding); 127 118 128 119 rxq->mp_params.mp_priv = NULL; 120 + rxq->mp_params.mp_ops = NULL; 129 121 130 122 rxq_idx = get_netdev_rx_queue_index(rxq); 131 123 ··· 162 152 } 163 153 164 154 rxq = __netif_get_rx_queue(dev, rxq_idx); 165 - if (rxq->mp_params.mp_priv) { 155 + if (rxq->mp_params.mp_ops) { 166 156 NL_SET_ERR_MSG(extack, "designated queue already memory provider bound"); 167 157 return -EEXIST; 168 158 } ··· 180 170 return err; 181 171 182 172 rxq->mp_params.mp_priv = binding; 173 + rxq->mp_params.mp_ops = &dmabuf_devmem_ops; 183 174 184 175 err = netdev_rx_queue_restart(dev, rxq_idx); 185 176 if (err) ··· 190 179 191 180 err_xa_erase: 192 181 rxq->mp_params.mp_priv = NULL; 182 + rxq->mp_params.mp_ops = NULL; 193 183 xa_erase(&binding->bound_rxqs, xa_idx); 194 184 195 185 return err; ··· 273 261 goto err_free_chunks; 274 262 } 275 263 276 - owner->base_virtual = virtual; 264 + owner->area.base_virtual = virtual; 277 265 owner->base_dma_addr = dma_addr; 278 - owner->num_niovs = len / PAGE_SIZE; 266 + owner->area.num_niovs = len / PAGE_SIZE; 279 267 owner->binding = binding; 280 268 281 269 err = gen_pool_add_owner(binding->chunk_pool, dma_addr, ··· 287 275 goto err_free_chunks; 288 276 } 289 277 290 - owner->niovs = kvmalloc_array(owner->num_niovs, 291 - sizeof(*owner->niovs), 292 - GFP_KERNEL); 293 - if (!owner->niovs) { 278 + owner->area.niovs = kvmalloc_array(owner->area.num_niovs, 279 + sizeof(*owner->area.niovs), 280 + GFP_KERNEL); 281 + if (!owner->area.niovs) { 294 282 err = -ENOMEM; 295 283 goto err_free_chunks; 296 284 } 297 285 298 - for (i = 0; i < owner->num_niovs; i++) { 299 - niov = &owner->niovs[i]; 300 - niov->owner = owner; 286 + for (i = 0; i < owner->area.num_niovs; i++) { 287 + niov = &owner->area.niovs[i]; 288 + niov->owner = &owner->area; 301 289 page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), 302 290 net_devmem_get_dma_addr(niov)); 303 291 } ··· 323 311 err_put_dmabuf: 324 312 dma_buf_put(dmabuf); 325 313 return ERR_PTR(err); 326 - } 327 - 328 - void dev_dmabuf_uninstall(struct net_device *dev) 329 - { 330 - struct net_devmem_dmabuf_binding *binding; 331 - struct netdev_rx_queue *rxq; 332 - unsigned long xa_idx; 333 - unsigned int i; 334 - 335 - for (i = 0; i < dev->real_num_rx_queues; i++) { 336 - binding = dev->_rx[i].mp_params.mp_priv; 337 - if (!binding) 338 - continue; 339 - 340 - xa_for_each(&binding->bound_rxqs, xa_idx, rxq) 341 - if (rxq == &dev->_rx[i]) { 342 - xa_erase(&binding->bound_rxqs, xa_idx); 343 - break; 344 - } 345 - } 346 314 } 347 315 348 316 /*** "Dmabuf devmem memory provider" ***/ ··· 390 398 /* We don't want the page pool put_page()ing our net_iovs. */ 391 399 return false; 392 400 } 401 + 402 + static int mp_dmabuf_devmem_nl_fill(void *mp_priv, struct sk_buff *rsp, 403 + struct netdev_rx_queue *rxq) 404 + { 405 + const struct net_devmem_dmabuf_binding *binding = mp_priv; 406 + int type = rxq ? NETDEV_A_QUEUE_DMABUF : NETDEV_A_PAGE_POOL_DMABUF; 407 + 408 + return nla_put_u32(rsp, type, binding->id); 409 + } 410 + 411 + static void mp_dmabuf_devmem_uninstall(void *mp_priv, 412 + struct netdev_rx_queue *rxq) 413 + { 414 + struct net_devmem_dmabuf_binding *binding = mp_priv; 415 + struct netdev_rx_queue *bound_rxq; 416 + unsigned long xa_idx; 417 + 418 + xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) { 419 + if (bound_rxq == rxq) { 420 + xa_erase(&binding->bound_rxqs, xa_idx); 421 + break; 422 + } 423 + } 424 + } 425 + 426 + static const struct memory_provider_ops dmabuf_devmem_ops = { 427 + .init = mp_dmabuf_devmem_init, 428 + .destroy = mp_dmabuf_devmem_destroy, 429 + .alloc_netmems = mp_dmabuf_devmem_alloc_netmems, 430 + .release_netmem = mp_dmabuf_devmem_release_page, 431 + .nl_fill = mp_dmabuf_devmem_nl_fill, 432 + .uninstall = mp_dmabuf_devmem_uninstall, 433 + };
+23 -28
net/core/devmem.h
··· 10 10 #ifndef _NET_DEVMEM_H 11 11 #define _NET_DEVMEM_H 12 12 13 + #include <net/netmem.h> 14 + 13 15 struct netlink_ext_ack; 14 16 15 17 struct net_devmem_dmabuf_binding { ··· 53 51 * allocations from this chunk. 54 52 */ 55 53 struct dmabuf_genpool_chunk_owner { 56 - /* Offset into the dma-buf where this chunk starts. */ 57 - unsigned long base_virtual; 54 + struct net_iov_area area; 55 + struct net_devmem_dmabuf_binding *binding; 58 56 59 57 /* dma_addr of the start of the chunk. */ 60 58 dma_addr_t base_dma_addr; 61 - 62 - /* Array of net_iovs for this chunk. */ 63 - struct net_iov *niovs; 64 - size_t num_niovs; 65 - 66 - struct net_devmem_dmabuf_binding *binding; 67 59 }; 68 60 69 61 void __net_devmem_dmabuf_binding_free(struct net_devmem_dmabuf_binding *binding); ··· 68 72 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, 69 73 struct net_devmem_dmabuf_binding *binding, 70 74 struct netlink_ext_ack *extack); 71 - void dev_dmabuf_uninstall(struct net_device *dev); 72 75 73 76 static inline struct dmabuf_genpool_chunk_owner * 74 - net_iov_owner(const struct net_iov *niov) 77 + net_devmem_iov_to_chunk_owner(const struct net_iov *niov) 75 78 { 76 - return niov->owner; 77 - } 79 + struct net_iov_area *owner = net_iov_owner(niov); 78 80 79 - static inline unsigned int net_iov_idx(const struct net_iov *niov) 80 - { 81 - return niov - net_iov_owner(niov)->niovs; 81 + return container_of(owner, struct dmabuf_genpool_chunk_owner, area); 82 82 } 83 83 84 84 static inline struct net_devmem_dmabuf_binding * 85 - net_iov_binding(const struct net_iov *niov) 85 + net_devmem_iov_binding(const struct net_iov *niov) 86 86 { 87 - return net_iov_owner(niov)->binding; 87 + return net_devmem_iov_to_chunk_owner(niov)->binding; 88 + } 89 + 90 + static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) 91 + { 92 + return net_devmem_iov_binding(niov)->id; 88 93 } 89 94 90 95 static inline unsigned long net_iov_virtual_addr(const struct net_iov *niov) 91 96 { 92 - struct dmabuf_genpool_chunk_owner *owner = net_iov_owner(niov); 97 + struct net_iov_area *owner = net_iov_owner(niov); 93 98 94 99 return owner->base_virtual + 95 100 ((unsigned long)net_iov_idx(niov) << PAGE_SHIFT); 96 - } 97 - 98 - static inline u32 net_iov_binding_id(const struct net_iov *niov) 99 - { 100 - return net_iov_owner(niov)->binding->id; 101 101 } 102 102 103 103 static inline void ··· 114 122 struct net_iov * 115 123 net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding); 116 124 void net_devmem_free_dmabuf(struct net_iov *ppiov); 125 + 126 + bool net_is_devmem_iov(struct net_iov *niov); 117 127 118 128 #else 119 129 struct net_devmem_dmabuf_binding; ··· 146 152 return -EOPNOTSUPP; 147 153 } 148 154 149 - static inline void dev_dmabuf_uninstall(struct net_device *dev) 150 - { 151 - } 152 - 153 155 static inline struct net_iov * 154 156 net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding) 155 157 { ··· 161 171 return 0; 162 172 } 163 173 164 - static inline u32 net_iov_binding_id(const struct net_iov *niov) 174 + static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov) 165 175 { 166 176 return 0; 177 + } 178 + 179 + static inline bool net_is_devmem_iov(struct net_iov *niov) 180 + { 181 + return false; 167 182 } 168 183 #endif 169 184
+1 -8
net/core/neighbour.c
··· 832 832 return -ENOENT; 833 833 } 834 834 835 - static void neigh_parms_destroy(struct neigh_parms *parms); 836 - 837 835 static inline void neigh_parms_put(struct neigh_parms *parms) 838 836 { 839 837 if (refcount_dec_and_test(&parms->refcnt)) 840 - neigh_parms_destroy(parms); 838 + kfree(parms); 841 839 } 842 840 843 841 /* ··· 1710 1712 call_rcu(&parms->rcu_head, neigh_rcu_free_parms); 1711 1713 } 1712 1714 EXPORT_SYMBOL(neigh_parms_release); 1713 - 1714 - static void neigh_parms_destroy(struct neigh_parms *parms) 1715 - { 1716 - kfree(parms); 1717 - } 1718 1715 1719 1716 static struct lock_class_key neigh_table_proxy_queue_class; 1720 1717
+276 -118
net/core/net-sysfs.c
··· 42 42 return READ_ONCE(dev->reg_state) <= NETREG_REGISTERED; 43 43 } 44 44 45 + /* There is a possible ABBA deadlock between rtnl_lock and kernfs_node->active, 46 + * when unregistering a net device and accessing associated sysfs files. The 47 + * potential deadlock is as follow: 48 + * 49 + * CPU 0 CPU 1 50 + * 51 + * rtnl_lock vfs_read 52 + * unregister_netdevice_many kernfs_seq_start 53 + * device_del / kobject_put kernfs_get_active (kn->active++) 54 + * kernfs_drain sysfs_kf_seq_show 55 + * wait_event( rtnl_lock 56 + * kn->active == KN_DEACTIVATED_BIAS) -> waits on CPU 0 to release 57 + * -> waits on CPU 1 to decrease kn->active the rtnl lock. 58 + * 59 + * The historical fix was to use rtnl_trylock with restart_syscall to bail out 60 + * of sysfs operations when the lock couldn't be taken. This fixed the above 61 + * issue as it allowed CPU 1 to bail out of the ABBA situation. 62 + * 63 + * But it came with performances issues, as syscalls are being restarted in 64 + * loops when there was contention on the rtnl lock, with huge slow downs in 65 + * specific scenarios (e.g. lots of virtual interfaces created and userspace 66 + * daemons querying their attributes). 67 + * 68 + * The idea below is to bail out of the active kernfs_node protection 69 + * (kn->active) while trying to take the rtnl lock. 70 + * 71 + * This replaces rtnl_lock() and still has to be used with rtnl_unlock(). The 72 + * net device is guaranteed to be alive if this returns successfully. 73 + */ 74 + static int sysfs_rtnl_lock(struct kobject *kobj, struct attribute *attr, 75 + struct net_device *ndev) 76 + { 77 + struct kernfs_node *kn; 78 + int ret = 0; 79 + 80 + /* First, we hold a reference to the net device as the unregistration 81 + * path might run in parallel. This will ensure the net device and the 82 + * associated sysfs objects won't be freed while we try to take the rtnl 83 + * lock. 84 + */ 85 + dev_hold(ndev); 86 + /* sysfs_break_active_protection was introduced to allow self-removal of 87 + * devices and their associated sysfs files by bailing out of the 88 + * sysfs/kernfs protection. We do this here to allow the unregistration 89 + * path to complete in parallel. The following takes a reference on the 90 + * kobject and the kernfs_node being accessed. 91 + * 92 + * This works because we hold a reference onto the net device and the 93 + * unregistration path will wait for us eventually in netdev_run_todo 94 + * (outside an rtnl lock section). 95 + */ 96 + kn = sysfs_break_active_protection(kobj, attr); 97 + /* We can now try to take the rtnl lock. This can't deadlock us as the 98 + * unregistration path is able to drain sysfs files (kernfs_node) thanks 99 + * to the above dance. 100 + */ 101 + if (rtnl_lock_interruptible()) { 102 + ret = -ERESTARTSYS; 103 + goto unbreak; 104 + } 105 + /* Check dismantle on the device hasn't started, otherwise deny the 106 + * operation. 107 + */ 108 + if (!dev_isalive(ndev)) { 109 + rtnl_unlock(); 110 + ret = -ENODEV; 111 + goto unbreak; 112 + } 113 + /* We are now sure the device dismantle hasn't started nor that it can 114 + * start before we exit the locking section as we hold the rtnl lock. 115 + * There's no need to keep unbreaking the sysfs protection nor to hold 116 + * a net device reference from that point; that was only needed to take 117 + * the rtnl lock. 118 + */ 119 + unbreak: 120 + sysfs_unbreak_active_protection(kn); 121 + dev_put(ndev); 122 + 123 + return ret; 124 + } 125 + 45 126 /* use same locking rules as GIF* ioctl's */ 46 127 static ssize_t netdev_show(const struct device *dev, 47 128 struct device_attribute *attr, char *buf, ··· 176 95 if (ret) 177 96 goto err; 178 97 179 - if (!rtnl_trylock()) 180 - return restart_syscall(); 98 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 99 + if (ret) 100 + goto err; 181 101 182 - if (dev_isalive(netdev)) { 183 - ret = (*set)(netdev, new); 184 - if (ret == 0) 185 - ret = len; 186 - } 102 + ret = (*set)(netdev, new); 103 + if (ret == 0) 104 + ret = len; 105 + 187 106 rtnl_unlock(); 188 107 err: 189 108 return ret; ··· 301 220 struct net_device *netdev = to_net_dev(dev); 302 221 303 222 /* The check is also done in change_carrier; this helps returning early 304 - * without hitting the trylock/restart in netdev_store. 223 + * without hitting the locking section in netdev_store. 305 224 */ 306 225 if (!netdev->netdev_ops->ndo_change_carrier) 307 226 return -EOPNOTSUPP; ··· 315 234 struct net_device *netdev = to_net_dev(dev); 316 235 int ret = -EINVAL; 317 236 318 - if (!rtnl_trylock()) 319 - return restart_syscall(); 237 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 238 + if (ret) 239 + return ret; 320 240 321 241 if (netif_running(netdev)) { 322 242 /* Synchronize carrier state with link watch, ··· 327 245 328 246 ret = sysfs_emit(buf, fmt_dec, !!netif_carrier_ok(netdev)); 329 247 } 330 - rtnl_unlock(); 331 248 249 + rtnl_unlock(); 332 250 return ret; 333 251 } 334 252 static DEVICE_ATTR_RW(carrier); ··· 340 258 int ret = -EINVAL; 341 259 342 260 /* The check is also done in __ethtool_get_link_ksettings; this helps 343 - * returning early without hitting the trylock/restart below. 261 + * returning early without hitting the locking section below. 344 262 */ 345 263 if (!netdev->ethtool_ops->get_link_ksettings) 346 264 return ret; 347 265 348 - if (!rtnl_trylock()) 349 - return restart_syscall(); 266 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 267 + if (ret) 268 + return ret; 350 269 351 270 if (netif_running(netdev)) { 352 271 struct ethtool_link_ksettings cmd; ··· 367 284 int ret = -EINVAL; 368 285 369 286 /* The check is also done in __ethtool_get_link_ksettings; this helps 370 - * returning early without hitting the trylock/restart below. 287 + * returning early without hitting the locking section below. 371 288 */ 372 289 if (!netdev->ethtool_ops->get_link_ksettings) 373 290 return ret; 374 291 375 - if (!rtnl_trylock()) 376 - return restart_syscall(); 292 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 293 + if (ret) 294 + return ret; 377 295 378 296 if (netif_running(netdev)) { 379 297 struct ethtool_link_ksettings cmd; ··· 574 490 if (len > 0 && buf[len - 1] == '\n') 575 491 --count; 576 492 577 - if (!rtnl_trylock()) 578 - return restart_syscall(); 493 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 494 + if (ret) 495 + return ret; 579 496 580 - if (dev_isalive(netdev)) { 581 - ret = dev_set_alias(netdev, buf, count); 582 - if (ret < 0) 583 - goto err; 584 - ret = len; 585 - netdev_state_change(netdev); 586 - } 497 + ret = dev_set_alias(netdev, buf, count); 498 + if (ret < 0) 499 + goto err; 500 + ret = len; 501 + netdev_state_change(netdev); 587 502 err: 588 503 rtnl_unlock(); 589 504 ··· 634 551 struct device_attribute *attr, char *buf) 635 552 { 636 553 struct net_device *netdev = to_net_dev(dev); 554 + struct netdev_phys_item_id ppid; 637 555 ssize_t ret = -EINVAL; 638 556 639 557 /* The check is also done in dev_get_phys_port_id; this helps returning 640 - * early without hitting the trylock/restart below. 558 + * early without hitting the locking section below. 641 559 */ 642 560 if (!netdev->netdev_ops->ndo_get_phys_port_id) 643 561 return -EOPNOTSUPP; 644 562 645 - if (!rtnl_trylock()) 646 - return restart_syscall(); 563 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 564 + if (ret) 565 + return ret; 647 566 648 - if (dev_isalive(netdev)) { 649 - struct netdev_phys_item_id ppid; 567 + ret = dev_get_phys_port_id(netdev, &ppid); 568 + if (!ret) 569 + ret = sysfs_emit(buf, "%*phN\n", ppid.id_len, ppid.id); 650 570 651 - ret = dev_get_phys_port_id(netdev, &ppid); 652 - if (!ret) 653 - ret = sysfs_emit(buf, "%*phN\n", ppid.id_len, ppid.id); 654 - } 655 571 rtnl_unlock(); 656 572 657 573 return ret; ··· 662 580 { 663 581 struct net_device *netdev = to_net_dev(dev); 664 582 ssize_t ret = -EINVAL; 583 + char name[IFNAMSIZ]; 665 584 666 585 /* The checks are also done in dev_get_phys_port_name; this helps 667 - * returning early without hitting the trylock/restart below. 586 + * returning early without hitting the locking section below. 668 587 */ 669 588 if (!netdev->netdev_ops->ndo_get_phys_port_name && 670 589 !netdev->devlink_port) 671 590 return -EOPNOTSUPP; 672 591 673 - if (!rtnl_trylock()) 674 - return restart_syscall(); 592 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 593 + if (ret) 594 + return ret; 675 595 676 - if (dev_isalive(netdev)) { 677 - char name[IFNAMSIZ]; 596 + ret = dev_get_phys_port_name(netdev, name, sizeof(name)); 597 + if (!ret) 598 + ret = sysfs_emit(buf, "%s\n", name); 678 599 679 - ret = dev_get_phys_port_name(netdev, name, sizeof(name)); 680 - if (!ret) 681 - ret = sysfs_emit(buf, "%s\n", name); 682 - } 683 600 rtnl_unlock(); 684 601 685 602 return ret; ··· 689 608 struct device_attribute *attr, char *buf) 690 609 { 691 610 struct net_device *netdev = to_net_dev(dev); 611 + struct netdev_phys_item_id ppid = { }; 692 612 ssize_t ret = -EINVAL; 693 613 694 614 /* The checks are also done in dev_get_phys_port_name; this helps 695 - * returning early without hitting the trylock/restart below. This works 615 + * returning early without hitting the locking section below. This works 696 616 * because recurse is false when calling dev_get_port_parent_id. 697 617 */ 698 618 if (!netdev->netdev_ops->ndo_get_port_parent_id && 699 619 !netdev->devlink_port) 700 620 return -EOPNOTSUPP; 701 621 702 - if (!rtnl_trylock()) 703 - return restart_syscall(); 622 + ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 623 + if (ret) 624 + return ret; 704 625 705 - if (dev_isalive(netdev)) { 706 - struct netdev_phys_item_id ppid = { }; 626 + ret = dev_get_port_parent_id(netdev, &ppid, false); 627 + if (!ret) 628 + ret = sysfs_emit(buf, "%*phN\n", ppid.id_len, ppid.id); 707 629 708 - ret = dev_get_port_parent_id(netdev, &ppid, false); 709 - if (!ret) 710 - ret = sysfs_emit(buf, "%*phN\n", ppid.id_len, ppid.id); 711 - } 712 630 rtnl_unlock(); 713 631 714 632 return ret; ··· 1188 1108 static const struct kobj_type rx_queue_ktype = { 1189 1109 .sysfs_ops = &rx_queue_sysfs_ops, 1190 1110 .release = rx_queue_release, 1191 - .default_groups = rx_queue_default_groups, 1192 1111 .namespace = rx_queue_namespace, 1193 1112 .get_ownership = rx_queue_get_ownership, 1194 1113 }; ··· 1210 1131 struct kobject *kobj = &queue->kobj; 1211 1132 int error = 0; 1212 1133 1134 + /* Rx queues are cleared in rx_queue_release to allow later 1135 + * re-registration. This is triggered when their kobj refcount is 1136 + * dropped. 1137 + * 1138 + * If a queue is removed while both a read (or write) operation and a 1139 + * the re-addition of the same queue are pending (waiting on rntl_lock) 1140 + * it might happen that the re-addition will execute before the read, 1141 + * making the initial removal to never happen (queue's kobj refcount 1142 + * won't drop enough because of the pending read). In such rare case, 1143 + * return to allow the removal operation to complete. 1144 + */ 1145 + if (unlikely(kobj->state_initialized)) { 1146 + netdev_warn_once(dev, "Cannot re-add rx queues before their removal completed"); 1147 + return -EAGAIN; 1148 + } 1149 + 1213 1150 /* Kobject_put later will trigger rx_queue_release call which 1214 1151 * decreases dev refcount: Take that reference here 1215 1152 */ ··· 1237 1142 if (error) 1238 1143 goto err; 1239 1144 1145 + queue->groups = rx_queue_default_groups; 1146 + error = sysfs_create_groups(kobj, queue->groups); 1147 + if (error) 1148 + goto err; 1149 + 1240 1150 if (dev->sysfs_rx_queue_group) { 1241 1151 error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group); 1242 1152 if (error) 1243 - goto err; 1153 + goto err_default_groups; 1244 1154 } 1245 1155 1246 1156 error = rx_queue_default_mask(dev, queue); 1247 1157 if (error) 1248 - goto err; 1158 + goto err_default_groups; 1249 1159 1250 1160 kobject_uevent(kobj, KOBJ_ADD); 1251 1161 1252 1162 return error; 1253 1163 1164 + err_default_groups: 1165 + sysfs_remove_groups(kobj, queue->groups); 1254 1166 err: 1255 1167 kobject_put(kobj); 1256 1168 return error; ··· 1302 1200 } 1303 1201 1304 1202 while (--i >= new_num) { 1305 - struct kobject *kobj = &dev->_rx[i].kobj; 1203 + struct netdev_rx_queue *queue = &dev->_rx[i]; 1204 + struct kobject *kobj = &queue->kobj; 1306 1205 1307 1206 if (!refcount_read(&dev_net(dev)->ns.count)) 1308 1207 kobj->uevent_suppress = 1; 1309 1208 if (dev->sysfs_rx_queue_group) 1310 1209 sysfs_remove_group(kobj, dev->sysfs_rx_queue_group); 1210 + sysfs_remove_groups(kobj, queue->groups); 1311 1211 kobject_put(kobj); 1312 1212 } 1313 1213 ··· 1348 1244 */ 1349 1245 struct netdev_queue_attribute { 1350 1246 struct attribute attr; 1351 - ssize_t (*show)(struct netdev_queue *queue, char *buf); 1352 - ssize_t (*store)(struct netdev_queue *queue, 1353 - const char *buf, size_t len); 1247 + ssize_t (*show)(struct kobject *kobj, struct attribute *attr, 1248 + struct netdev_queue *queue, char *buf); 1249 + ssize_t (*store)(struct kobject *kobj, struct attribute *attr, 1250 + struct netdev_queue *queue, const char *buf, 1251 + size_t len); 1354 1252 }; 1355 1253 #define to_netdev_queue_attr(_attr) \ 1356 1254 container_of(_attr, struct netdev_queue_attribute, attr) ··· 1369 1263 if (!attribute->show) 1370 1264 return -EIO; 1371 1265 1372 - return attribute->show(queue, buf); 1266 + return attribute->show(kobj, attr, queue, buf); 1373 1267 } 1374 1268 1375 1269 static ssize_t netdev_queue_attr_store(struct kobject *kobj, ··· 1383 1277 if (!attribute->store) 1384 1278 return -EIO; 1385 1279 1386 - return attribute->store(queue, buf, count); 1280 + return attribute->store(kobj, attr, queue, buf, count); 1387 1281 } 1388 1282 1389 1283 static const struct sysfs_ops netdev_queue_sysfs_ops = { ··· 1391 1285 .store = netdev_queue_attr_store, 1392 1286 }; 1393 1287 1394 - static ssize_t tx_timeout_show(struct netdev_queue *queue, char *buf) 1288 + static ssize_t tx_timeout_show(struct kobject *kobj, struct attribute *attr, 1289 + struct netdev_queue *queue, char *buf) 1395 1290 { 1396 1291 unsigned long trans_timeout = atomic_long_read(&queue->trans_timeout); 1397 1292 ··· 1410 1303 return i; 1411 1304 } 1412 1305 1413 - static ssize_t traffic_class_show(struct netdev_queue *queue, 1414 - char *buf) 1306 + static ssize_t traffic_class_show(struct kobject *kobj, struct attribute *attr, 1307 + struct netdev_queue *queue, char *buf) 1415 1308 { 1416 1309 struct net_device *dev = queue->dev; 1417 - int num_tc, tc; 1418 - int index; 1310 + int num_tc, tc, index, ret; 1419 1311 1420 1312 if (!netif_is_multiqueue(dev)) 1421 1313 return -ENOENT; 1422 1314 1423 - if (!rtnl_trylock()) 1424 - return restart_syscall(); 1315 + ret = sysfs_rtnl_lock(kobj, attr, queue->dev); 1316 + if (ret) 1317 + return ret; 1425 1318 1426 1319 index = get_netdev_queue_index(queue); 1427 1320 ··· 1448 1341 } 1449 1342 1450 1343 #ifdef CONFIG_XPS 1451 - static ssize_t tx_maxrate_show(struct netdev_queue *queue, 1452 - char *buf) 1344 + static ssize_t tx_maxrate_show(struct kobject *kobj, struct attribute *attr, 1345 + struct netdev_queue *queue, char *buf) 1453 1346 { 1454 1347 return sysfs_emit(buf, "%lu\n", queue->tx_maxrate); 1455 1348 } 1456 1349 1457 - static ssize_t tx_maxrate_store(struct netdev_queue *queue, 1458 - const char *buf, size_t len) 1350 + static ssize_t tx_maxrate_store(struct kobject *kobj, struct attribute *attr, 1351 + struct netdev_queue *queue, const char *buf, 1352 + size_t len) 1459 1353 { 1460 - struct net_device *dev = queue->dev; 1461 1354 int err, index = get_netdev_queue_index(queue); 1355 + struct net_device *dev = queue->dev; 1462 1356 u32 rate = 0; 1463 1357 1464 1358 if (!capable(CAP_NET_ADMIN)) 1465 1359 return -EPERM; 1466 1360 1467 1361 /* The check is also done later; this helps returning early without 1468 - * hitting the trylock/restart below. 1362 + * hitting the locking section below. 1469 1363 */ 1470 1364 if (!dev->netdev_ops->ndo_set_tx_maxrate) 1471 1365 return -EOPNOTSUPP; ··· 1475 1367 if (err < 0) 1476 1368 return err; 1477 1369 1478 - if (!rtnl_trylock()) 1479 - return restart_syscall(); 1370 + err = sysfs_rtnl_lock(kobj, attr, dev); 1371 + if (err) 1372 + return err; 1480 1373 1481 1374 err = -EOPNOTSUPP; 1482 1375 if (dev->netdev_ops->ndo_set_tx_maxrate) 1483 1376 err = dev->netdev_ops->ndo_set_tx_maxrate(dev, index, rate); 1484 1377 1485 - rtnl_unlock(); 1486 1378 if (!err) { 1487 1379 queue->tx_maxrate = rate; 1380 + rtnl_unlock(); 1488 1381 return len; 1489 1382 } 1383 + 1384 + rtnl_unlock(); 1490 1385 return err; 1491 1386 } 1492 1387 ··· 1533 1422 return count; 1534 1423 } 1535 1424 1536 - static ssize_t bql_show_hold_time(struct netdev_queue *queue, 1537 - char *buf) 1425 + static ssize_t bql_show_hold_time(struct kobject *kobj, struct attribute *attr, 1426 + struct netdev_queue *queue, char *buf) 1538 1427 { 1539 1428 struct dql *dql = &queue->dql; 1540 1429 1541 1430 return sysfs_emit(buf, "%u\n", jiffies_to_msecs(dql->slack_hold_time)); 1542 1431 } 1543 1432 1544 - static ssize_t bql_set_hold_time(struct netdev_queue *queue, 1545 - const char *buf, size_t len) 1433 + static ssize_t bql_set_hold_time(struct kobject *kobj, struct attribute *attr, 1434 + struct netdev_queue *queue, const char *buf, 1435 + size_t len) 1546 1436 { 1547 1437 struct dql *dql = &queue->dql; 1548 1438 unsigned int value; ··· 1562 1450 = __ATTR(hold_time, 0644, 1563 1451 bql_show_hold_time, bql_set_hold_time); 1564 1452 1565 - static ssize_t bql_show_stall_thrs(struct netdev_queue *queue, char *buf) 1453 + static ssize_t bql_show_stall_thrs(struct kobject *kobj, struct attribute *attr, 1454 + struct netdev_queue *queue, char *buf) 1566 1455 { 1567 1456 struct dql *dql = &queue->dql; 1568 1457 1569 1458 return sysfs_emit(buf, "%u\n", jiffies_to_msecs(dql->stall_thrs)); 1570 1459 } 1571 1460 1572 - static ssize_t bql_set_stall_thrs(struct netdev_queue *queue, 1573 - const char *buf, size_t len) 1461 + static ssize_t bql_set_stall_thrs(struct kobject *kobj, struct attribute *attr, 1462 + struct netdev_queue *queue, const char *buf, 1463 + size_t len) 1574 1464 { 1575 1465 struct dql *dql = &queue->dql; 1576 1466 unsigned int value; ··· 1598 1484 static struct netdev_queue_attribute bql_stall_thrs_attribute __ro_after_init = 1599 1485 __ATTR(stall_thrs, 0644, bql_show_stall_thrs, bql_set_stall_thrs); 1600 1486 1601 - static ssize_t bql_show_stall_max(struct netdev_queue *queue, char *buf) 1487 + static ssize_t bql_show_stall_max(struct kobject *kobj, struct attribute *attr, 1488 + struct netdev_queue *queue, char *buf) 1602 1489 { 1603 1490 return sysfs_emit(buf, "%u\n", READ_ONCE(queue->dql.stall_max)); 1604 1491 } 1605 1492 1606 - static ssize_t bql_set_stall_max(struct netdev_queue *queue, 1607 - const char *buf, size_t len) 1493 + static ssize_t bql_set_stall_max(struct kobject *kobj, struct attribute *attr, 1494 + struct netdev_queue *queue, const char *buf, 1495 + size_t len) 1608 1496 { 1609 1497 WRITE_ONCE(queue->dql.stall_max, 0); 1610 1498 return len; ··· 1615 1499 static struct netdev_queue_attribute bql_stall_max_attribute __ro_after_init = 1616 1500 __ATTR(stall_max, 0644, bql_show_stall_max, bql_set_stall_max); 1617 1501 1618 - static ssize_t bql_show_stall_cnt(struct netdev_queue *queue, char *buf) 1502 + static ssize_t bql_show_stall_cnt(struct kobject *kobj, struct attribute *attr, 1503 + struct netdev_queue *queue, char *buf) 1619 1504 { 1620 1505 struct dql *dql = &queue->dql; 1621 1506 ··· 1626 1509 static struct netdev_queue_attribute bql_stall_cnt_attribute __ro_after_init = 1627 1510 __ATTR(stall_cnt, 0444, bql_show_stall_cnt, NULL); 1628 1511 1629 - static ssize_t bql_show_inflight(struct netdev_queue *queue, 1630 - char *buf) 1512 + static ssize_t bql_show_inflight(struct kobject *kobj, struct attribute *attr, 1513 + struct netdev_queue *queue, char *buf) 1631 1514 { 1632 1515 struct dql *dql = &queue->dql; 1633 1516 ··· 1638 1521 __ATTR(inflight, 0444, bql_show_inflight, NULL); 1639 1522 1640 1523 #define BQL_ATTR(NAME, FIELD) \ 1641 - static ssize_t bql_show_ ## NAME(struct netdev_queue *queue, \ 1642 - char *buf) \ 1524 + static ssize_t bql_show_ ## NAME(struct kobject *kobj, \ 1525 + struct attribute *attr, \ 1526 + struct netdev_queue *queue, char *buf) \ 1643 1527 { \ 1644 1528 return bql_show(buf, queue->dql.FIELD); \ 1645 1529 } \ 1646 1530 \ 1647 - static ssize_t bql_set_ ## NAME(struct netdev_queue *queue, \ 1531 + static ssize_t bql_set_ ## NAME(struct kobject *kobj, \ 1532 + struct attribute *attr, \ 1533 + struct netdev_queue *queue, \ 1648 1534 const char *buf, size_t len) \ 1649 1535 { \ 1650 1536 return bql_set(buf, len, &queue->dql.FIELD); \ ··· 1733 1613 return len < PAGE_SIZE ? len : -EINVAL; 1734 1614 } 1735 1615 1736 - static ssize_t xps_cpus_show(struct netdev_queue *queue, char *buf) 1616 + static ssize_t xps_cpus_show(struct kobject *kobj, struct attribute *attr, 1617 + struct netdev_queue *queue, char *buf) 1737 1618 { 1738 1619 struct net_device *dev = queue->dev; 1739 1620 unsigned int index; 1740 - int len, tc; 1621 + int len, tc, ret; 1741 1622 1742 1623 if (!netif_is_multiqueue(dev)) 1743 1624 return -ENOENT; 1744 1625 1745 1626 index = get_netdev_queue_index(queue); 1746 1627 1747 - if (!rtnl_trylock()) 1748 - return restart_syscall(); 1628 + ret = sysfs_rtnl_lock(kobj, attr, queue->dev); 1629 + if (ret) 1630 + return ret; 1749 1631 1750 1632 /* If queue belongs to subordinate dev use its map */ 1751 1633 dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev; ··· 1758 1636 return -EINVAL; 1759 1637 } 1760 1638 1761 - /* Make sure the subordinate device can't be freed */ 1762 - get_device(&dev->dev); 1639 + /* Increase the net device refcnt to make sure it won't be freed while 1640 + * xps_queue_show is running. 1641 + */ 1642 + dev_hold(dev); 1763 1643 rtnl_unlock(); 1764 1644 1765 1645 len = xps_queue_show(dev, index, tc, buf, XPS_CPUS); 1766 1646 1767 - put_device(&dev->dev); 1647 + dev_put(dev); 1768 1648 return len; 1769 1649 } 1770 1650 1771 - static ssize_t xps_cpus_store(struct netdev_queue *queue, 1772 - const char *buf, size_t len) 1651 + static ssize_t xps_cpus_store(struct kobject *kobj, struct attribute *attr, 1652 + struct netdev_queue *queue, const char *buf, 1653 + size_t len) 1773 1654 { 1774 1655 struct net_device *dev = queue->dev; 1775 1656 unsigned int index; ··· 1796 1671 return err; 1797 1672 } 1798 1673 1799 - if (!rtnl_trylock()) { 1674 + err = sysfs_rtnl_lock(kobj, attr, dev); 1675 + if (err) { 1800 1676 free_cpumask_var(mask); 1801 - return restart_syscall(); 1677 + return err; 1802 1678 } 1803 1679 1804 1680 err = netif_set_xps_queue(dev, mask, index); ··· 1813 1687 static struct netdev_queue_attribute xps_cpus_attribute __ro_after_init 1814 1688 = __ATTR_RW(xps_cpus); 1815 1689 1816 - static ssize_t xps_rxqs_show(struct netdev_queue *queue, char *buf) 1690 + static ssize_t xps_rxqs_show(struct kobject *kobj, struct attribute *attr, 1691 + struct netdev_queue *queue, char *buf) 1817 1692 { 1818 1693 struct net_device *dev = queue->dev; 1819 1694 unsigned int index; 1820 - int tc; 1695 + int tc, ret; 1821 1696 1822 1697 index = get_netdev_queue_index(queue); 1823 1698 1824 - if (!rtnl_trylock()) 1825 - return restart_syscall(); 1699 + ret = sysfs_rtnl_lock(kobj, attr, dev); 1700 + if (ret) 1701 + return ret; 1826 1702 1827 1703 tc = netdev_txq_to_tc(dev, index); 1828 - rtnl_unlock(); 1829 - if (tc < 0) 1830 - return -EINVAL; 1831 1704 1832 - return xps_queue_show(dev, index, tc, buf, XPS_RXQS); 1705 + /* Increase the net device refcnt to make sure it won't be freed while 1706 + * xps_queue_show is running. 1707 + */ 1708 + dev_hold(dev); 1709 + rtnl_unlock(); 1710 + 1711 + ret = tc >= 0 ? xps_queue_show(dev, index, tc, buf, XPS_RXQS) : -EINVAL; 1712 + dev_put(dev); 1713 + return ret; 1833 1714 } 1834 1715 1835 - static ssize_t xps_rxqs_store(struct netdev_queue *queue, const char *buf, 1716 + static ssize_t xps_rxqs_store(struct kobject *kobj, struct attribute *attr, 1717 + struct netdev_queue *queue, const char *buf, 1836 1718 size_t len) 1837 1719 { 1838 1720 struct net_device *dev = queue->dev; ··· 1864 1730 return err; 1865 1731 } 1866 1732 1867 - if (!rtnl_trylock()) { 1733 + err = sysfs_rtnl_lock(kobj, attr, dev); 1734 + if (err) { 1868 1735 bitmap_free(mask); 1869 - return restart_syscall(); 1736 + return err; 1870 1737 } 1871 1738 1872 1739 cpus_read_lock(); ··· 1927 1792 static const struct kobj_type netdev_queue_ktype = { 1928 1793 .sysfs_ops = &netdev_queue_sysfs_ops, 1929 1794 .release = netdev_queue_release, 1930 - .default_groups = netdev_queue_default_groups, 1931 1795 .namespace = netdev_queue_namespace, 1932 1796 .get_ownership = netdev_queue_get_ownership, 1933 1797 }; ··· 1945 1811 struct kobject *kobj = &queue->kobj; 1946 1812 int error = 0; 1947 1813 1814 + /* Tx queues are cleared in netdev_queue_release to allow later 1815 + * re-registration. This is triggered when their kobj refcount is 1816 + * dropped. 1817 + * 1818 + * If a queue is removed while both a read (or write) operation and a 1819 + * the re-addition of the same queue are pending (waiting on rntl_lock) 1820 + * it might happen that the re-addition will execute before the read, 1821 + * making the initial removal to never happen (queue's kobj refcount 1822 + * won't drop enough because of the pending read). In such rare case, 1823 + * return to allow the removal operation to complete. 1824 + */ 1825 + if (unlikely(kobj->state_initialized)) { 1826 + netdev_warn_once(dev, "Cannot re-add tx queues before their removal completed"); 1827 + return -EAGAIN; 1828 + } 1829 + 1948 1830 /* Kobject_put later will trigger netdev_queue_release call 1949 1831 * which decreases dev refcount: Take that reference here 1950 1832 */ ··· 1972 1822 if (error) 1973 1823 goto err; 1974 1824 1825 + queue->groups = netdev_queue_default_groups; 1826 + error = sysfs_create_groups(kobj, queue->groups); 1827 + if (error) 1828 + goto err; 1829 + 1975 1830 if (netdev_uses_bql(dev)) { 1976 1831 error = sysfs_create_group(kobj, &dql_group); 1977 1832 if (error) 1978 - goto err; 1833 + goto err_default_groups; 1979 1834 } 1980 1835 1981 1836 kobject_uevent(kobj, KOBJ_ADD); 1982 1837 return 0; 1983 1838 1839 + err_default_groups: 1840 + sysfs_remove_groups(kobj, queue->groups); 1984 1841 err: 1985 1842 kobject_put(kobj); 1986 1843 return error; ··· 2042 1885 if (netdev_uses_bql(dev)) 2043 1886 sysfs_remove_group(&queue->kobj, &dql_group); 2044 1887 1888 + sysfs_remove_groups(&queue->kobj, queue->groups); 2045 1889 kobject_put(&queue->kobj); 2046 1890 } 2047 1891
+6 -5
net/core/netdev-genl.c
··· 10 10 #include <net/sock.h> 11 11 #include <net/xdp.h> 12 12 #include <net/xdp_sock.h> 13 + #include <net/page_pool/memory_provider.h> 13 14 14 15 #include "dev.h" 15 16 #include "devmem.h" ··· 369 368 netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, 370 369 u32 q_idx, u32 q_type, const struct genl_info *info) 371 370 { 372 - struct net_devmem_dmabuf_binding *binding; 371 + struct pp_memory_provider_params *params; 373 372 struct netdev_rx_queue *rxq; 374 373 struct netdev_queue *txq; 375 374 void *hdr; ··· 386 385 switch (q_type) { 387 386 case NETDEV_QUEUE_TYPE_RX: 388 387 rxq = __netif_get_rx_queue(netdev, q_idx); 388 + 389 389 if (rxq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID, 390 390 rxq->napi->napi_id)) 391 391 goto nla_put_failure; 392 392 393 - binding = rxq->mp_params.mp_priv; 394 - if (binding && 395 - nla_put_u32(rsp, NETDEV_A_QUEUE_DMABUF, binding->id)) 393 + params = &rxq->mp_params; 394 + if (params->mp_ops && 395 + params->mp_ops->nl_fill(params->mp_priv, rsp, rxq)) 396 396 goto nla_put_failure; 397 - 398 397 break; 399 398 case NETDEV_QUEUE_TYPE_TX: 400 399 txq = netdev_get_tx_queue(netdev, q_idx);
+69
net/core/netdev_rx_queue.c
··· 3 3 #include <linux/netdevice.h> 4 4 #include <net/netdev_queues.h> 5 5 #include <net/netdev_rx_queue.h> 6 + #include <net/page_pool/memory_provider.h> 6 7 7 8 #include "page_pool_priv.h" 8 9 ··· 81 80 return err; 82 81 } 83 82 EXPORT_SYMBOL_NS_GPL(netdev_rx_queue_restart, "NETDEV_INTERNAL"); 83 + 84 + static int __net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, 85 + struct pp_memory_provider_params *p) 86 + { 87 + struct netdev_rx_queue *rxq; 88 + int ret; 89 + 90 + if (ifq_idx >= dev->real_num_rx_queues) 91 + return -EINVAL; 92 + ifq_idx = array_index_nospec(ifq_idx, dev->real_num_rx_queues); 93 + 94 + rxq = __netif_get_rx_queue(dev, ifq_idx); 95 + if (rxq->mp_params.mp_ops) 96 + return -EEXIST; 97 + 98 + rxq->mp_params = *p; 99 + ret = netdev_rx_queue_restart(dev, ifq_idx); 100 + if (ret) { 101 + rxq->mp_params.mp_ops = NULL; 102 + rxq->mp_params.mp_priv = NULL; 103 + } 104 + return ret; 105 + } 106 + 107 + int net_mp_open_rxq(struct net_device *dev, unsigned ifq_idx, 108 + struct pp_memory_provider_params *p) 109 + { 110 + int ret; 111 + 112 + rtnl_lock(); 113 + ret = __net_mp_open_rxq(dev, ifq_idx, p); 114 + rtnl_unlock(); 115 + return ret; 116 + } 117 + 118 + static void __net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, 119 + struct pp_memory_provider_params *old_p) 120 + { 121 + struct netdev_rx_queue *rxq; 122 + 123 + if (WARN_ON_ONCE(ifq_idx >= dev->real_num_rx_queues)) 124 + return; 125 + 126 + rxq = __netif_get_rx_queue(dev, ifq_idx); 127 + 128 + /* Callers holding a netdev ref may get here after we already 129 + * went thru shutdown via dev_memory_provider_uninstall(). 130 + */ 131 + if (dev->reg_state > NETREG_REGISTERED && 132 + !rxq->mp_params.mp_ops) 133 + return; 134 + 135 + if (WARN_ON_ONCE(rxq->mp_params.mp_ops != old_p->mp_ops || 136 + rxq->mp_params.mp_priv != old_p->mp_priv)) 137 + return; 138 + 139 + rxq->mp_params.mp_ops = NULL; 140 + rxq->mp_params.mp_priv = NULL; 141 + WARN_ON(netdev_rx_queue_restart(dev, ifq_idx)); 142 + } 143 + 144 + void net_mp_close_rxq(struct net_device *dev, unsigned ifq_idx, 145 + struct pp_memory_provider_params *old_p) 146 + { 147 + rtnl_lock(); 148 + __net_mp_close_rxq(dev, ifq_idx, old_p); 149 + rtnl_unlock(); 150 + }
+43 -8
net/core/page_pool.c
··· 13 13 14 14 #include <net/netdev_rx_queue.h> 15 15 #include <net/page_pool/helpers.h> 16 + #include <net/page_pool/memory_provider.h> 16 17 #include <net/xdp.h> 17 18 18 19 #include <linux/dma-direction.h> ··· 286 285 rxq = __netif_get_rx_queue(pool->slow.netdev, 287 286 pool->slow.queue_idx); 288 287 pool->mp_priv = rxq->mp_params.mp_priv; 288 + pool->mp_ops = rxq->mp_params.mp_ops; 289 289 } 290 290 291 - if (pool->mp_priv) { 291 + if (pool->mp_ops) { 292 292 if (!pool->dma_map || !pool->dma_sync) 293 293 return -EOPNOTSUPP; 294 294 295 - err = mp_dmabuf_devmem_init(pool); 295 + if (WARN_ON(!is_kernel_rodata((unsigned long)pool->mp_ops))) { 296 + err = -EFAULT; 297 + goto free_ptr_ring; 298 + } 299 + 300 + err = pool->mp_ops->init(pool); 296 301 if (err) { 297 302 pr_warn("%s() mem-provider init failed %d\n", __func__, 298 303 err); ··· 594 587 return netmem; 595 588 596 589 /* Slow-path: cache empty, do real allocation */ 597 - if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv) 598 - netmem = mp_dmabuf_devmem_alloc_netmems(pool, gfp); 590 + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) 591 + netmem = pool->mp_ops->alloc_netmems(pool, gfp); 599 592 else 600 593 netmem = __page_pool_alloc_pages_slow(pool, gfp); 601 594 return netmem; ··· 686 679 bool put; 687 680 688 681 put = true; 689 - if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv) 690 - put = mp_dmabuf_devmem_release_page(pool, netmem); 682 + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) 683 + put = pool->mp_ops->release_netmem(pool, netmem); 691 684 else 692 685 __page_pool_release_page_dma(pool, netmem); 693 686 ··· 1055 1048 page_pool_unlist(pool); 1056 1049 page_pool_uninit(pool); 1057 1050 1058 - if (pool->mp_priv) { 1059 - mp_dmabuf_devmem_destroy(pool); 1051 + if (pool->mp_ops) { 1052 + pool->mp_ops->destroy(pool); 1060 1053 static_branch_dec(&page_pool_mem_providers); 1061 1054 } 1062 1055 ··· 1197 1190 } 1198 1191 } 1199 1192 EXPORT_SYMBOL(page_pool_update_nid); 1193 + 1194 + bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr) 1195 + { 1196 + return page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov), addr); 1197 + } 1198 + 1199 + /* Associate a niov with a page pool. Should follow with a matching 1200 + * net_mp_niov_clear_page_pool() 1201 + */ 1202 + void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov) 1203 + { 1204 + netmem_ref netmem = net_iov_to_netmem(niov); 1205 + 1206 + page_pool_set_pp_info(pool, netmem); 1207 + 1208 + pool->pages_state_hold_cnt++; 1209 + trace_page_pool_state_hold(pool, netmem, pool->pages_state_hold_cnt); 1210 + } 1211 + 1212 + /* Disassociate a niov from a page pool. Should only be used in the 1213 + * ->release_netmem() path. 1214 + */ 1215 + void net_mp_niov_clear_page_pool(struct net_iov *niov) 1216 + { 1217 + netmem_ref netmem = net_iov_to_netmem(niov); 1218 + 1219 + page_pool_clear_pp_info(netmem); 1220 + }
+3 -4
net/core/page_pool_user.c
··· 8 8 #include <net/netdev_rx_queue.h> 9 9 #include <net/page_pool/helpers.h> 10 10 #include <net/page_pool/types.h> 11 + #include <net/page_pool/memory_provider.h> 11 12 #include <net/sock.h> 12 13 13 - #include "devmem.h" 14 14 #include "page_pool_priv.h" 15 15 #include "netdev-genl-gen.h" 16 16 ··· 216 216 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, 217 217 const struct genl_info *info) 218 218 { 219 - struct net_devmem_dmabuf_binding *binding = pool->mp_priv; 220 219 size_t inflight, refsz; 221 220 unsigned int napi_id; 222 221 void *hdr; ··· 248 249 pool->user.detach_time)) 249 250 goto err_cancel; 250 251 251 - if (binding && nla_put_u32(rsp, NETDEV_A_PAGE_POOL_DMABUF, binding->id)) 252 + if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL)) 252 253 goto err_cancel; 253 254 254 255 genlmsg_end(rsp, hdr); ··· 355 356 int page_pool_check_memory_provider(struct net_device *dev, 356 357 struct netdev_rx_queue *rxq) 357 358 { 358 - struct net_devmem_dmabuf_binding *binding = rxq->mp_params.mp_priv; 359 + void *binding = rxq->mp_params.mp_priv; 359 360 struct page_pool *pool; 360 361 struct hlist_node *n; 361 362
+5
net/core/rtnetlink.c
··· 80 80 } 81 81 EXPORT_SYMBOL(rtnl_lock); 82 82 83 + int rtnl_lock_interruptible(void) 84 + { 85 + return mutex_lock_interruptible(&rtnl_mutex); 86 + } 87 + 83 88 int rtnl_lock_killable(void) 84 89 { 85 90 return mutex_lock_killable(&rtnl_mutex);
+42
net/ethtool/common.c
··· 213 213 __DEFINE_LINK_MODE_NAME(10, T1S, Half), 214 214 __DEFINE_LINK_MODE_NAME(10, T1S_P2MP, Half), 215 215 __DEFINE_LINK_MODE_NAME(10, T1BRR, Full), 216 + __DEFINE_LINK_MODE_NAME(200000, CR, Full), 217 + __DEFINE_LINK_MODE_NAME(200000, KR, Full), 218 + __DEFINE_LINK_MODE_NAME(200000, DR, Full), 219 + __DEFINE_LINK_MODE_NAME(200000, DR_2, Full), 220 + __DEFINE_LINK_MODE_NAME(200000, SR, Full), 221 + __DEFINE_LINK_MODE_NAME(200000, VR, Full), 222 + __DEFINE_LINK_MODE_NAME(400000, CR2, Full), 223 + __DEFINE_LINK_MODE_NAME(400000, KR2, Full), 224 + __DEFINE_LINK_MODE_NAME(400000, DR2, Full), 225 + __DEFINE_LINK_MODE_NAME(400000, DR2_2, Full), 226 + __DEFINE_LINK_MODE_NAME(400000, SR2, Full), 227 + __DEFINE_LINK_MODE_NAME(400000, VR2, Full), 228 + __DEFINE_LINK_MODE_NAME(800000, CR4, Full), 229 + __DEFINE_LINK_MODE_NAME(800000, KR4, Full), 230 + __DEFINE_LINK_MODE_NAME(800000, DR4, Full), 231 + __DEFINE_LINK_MODE_NAME(800000, DR4_2, Full), 232 + __DEFINE_LINK_MODE_NAME(800000, SR4, Full), 233 + __DEFINE_LINK_MODE_NAME(800000, VR4, Full), 216 234 }; 217 235 static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS); 218 236 ··· 239 221 #define __LINK_MODE_LANES_CR4 4 240 222 #define __LINK_MODE_LANES_CR8 8 241 223 #define __LINK_MODE_LANES_DR 1 224 + #define __LINK_MODE_LANES_DR_2 1 242 225 #define __LINK_MODE_LANES_DR2 2 226 + #define __LINK_MODE_LANES_DR2_2 2 243 227 #define __LINK_MODE_LANES_DR4 4 228 + #define __LINK_MODE_LANES_DR4_2 4 244 229 #define __LINK_MODE_LANES_DR8 8 245 230 #define __LINK_MODE_LANES_KR 1 246 231 #define __LINK_MODE_LANES_KR2 2 ··· 272 251 #define __LINK_MODE_LANES_T1L 1 273 252 #define __LINK_MODE_LANES_T1S 1 274 253 #define __LINK_MODE_LANES_T1S_P2MP 1 254 + #define __LINK_MODE_LANES_VR 1 255 + #define __LINK_MODE_LANES_VR2 2 256 + #define __LINK_MODE_LANES_VR4 4 275 257 #define __LINK_MODE_LANES_VR8 8 276 258 #define __LINK_MODE_LANES_DR8_2 8 277 259 #define __LINK_MODE_LANES_T1BRR 1 ··· 402 378 __DEFINE_LINK_MODE_PARAMS(10, T1S, Half), 403 379 __DEFINE_LINK_MODE_PARAMS(10, T1S_P2MP, Half), 404 380 __DEFINE_LINK_MODE_PARAMS(10, T1BRR, Full), 381 + __DEFINE_LINK_MODE_PARAMS(200000, CR, Full), 382 + __DEFINE_LINK_MODE_PARAMS(200000, KR, Full), 383 + __DEFINE_LINK_MODE_PARAMS(200000, DR, Full), 384 + __DEFINE_LINK_MODE_PARAMS(200000, DR_2, Full), 385 + __DEFINE_LINK_MODE_PARAMS(200000, SR, Full), 386 + __DEFINE_LINK_MODE_PARAMS(200000, VR, Full), 387 + __DEFINE_LINK_MODE_PARAMS(400000, CR2, Full), 388 + __DEFINE_LINK_MODE_PARAMS(400000, KR2, Full), 389 + __DEFINE_LINK_MODE_PARAMS(400000, DR2, Full), 390 + __DEFINE_LINK_MODE_PARAMS(400000, DR2_2, Full), 391 + __DEFINE_LINK_MODE_PARAMS(400000, SR2, Full), 392 + __DEFINE_LINK_MODE_PARAMS(400000, VR2, Full), 393 + __DEFINE_LINK_MODE_PARAMS(800000, CR4, Full), 394 + __DEFINE_LINK_MODE_PARAMS(800000, KR4, Full), 395 + __DEFINE_LINK_MODE_PARAMS(800000, DR4, Full), 396 + __DEFINE_LINK_MODE_PARAMS(800000, DR4_2, Full), 397 + __DEFINE_LINK_MODE_PARAMS(800000, SR4, Full), 398 + __DEFINE_LINK_MODE_PARAMS(800000, VR4, Full), 405 399 }; 406 400 static_assert(ARRAY_SIZE(link_mode_params) == __ETHTOOL_LINK_MODE_MASK_NBITS); 407 401
+10 -6
net/ipv4/ip_gre.c
··· 141 141 const struct iphdr *iph; 142 142 const int type = icmp_hdr(skb)->type; 143 143 const int code = icmp_hdr(skb)->code; 144 - unsigned int data_len = 0; 145 144 struct ip_tunnel *t; 146 145 147 146 if (tpi->proto == htons(ETH_P_TEB)) ··· 181 182 case ICMP_TIME_EXCEEDED: 182 183 if (code != ICMP_EXC_TTL) 183 184 return 0; 184 - data_len = icmp_hdr(skb)->un.reserved[1] * 4; /* RFC 4884 4.1 */ 185 185 break; 186 186 187 187 case ICMP_REDIRECT: ··· 188 190 } 189 191 190 192 #if IS_ENABLED(CONFIG_IPV6) 191 - if (tpi->proto == htons(ETH_P_IPV6) && 192 - !ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4 + tpi->hdr_len, 193 - type, data_len)) 194 - return 0; 193 + if (tpi->proto == htons(ETH_P_IPV6)) { 194 + unsigned int data_len = 0; 195 + 196 + if (type == ICMP_TIME_EXCEEDED) 197 + data_len = icmp_hdr(skb)->un.reserved[1] * 4; /* RFC 4884 4.1 */ 198 + 199 + if (!ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4 + tpi->hdr_len, 200 + type, data_len)) 201 + return 0; 202 + } 195 203 #endif 196 204 197 205 if (t->parms.iph.daddr == 0 ||
+6 -1
net/ipv4/tcp.c
··· 2476 2476 } 2477 2477 2478 2478 niov = skb_frag_net_iov(frag); 2479 + if (!net_is_devmem_iov(niov)) { 2480 + err = -ENODEV; 2481 + goto out; 2482 + } 2483 + 2479 2484 end = start + skb_frag_size(frag); 2480 2485 copy = end - offset; 2481 2486 ··· 2499 2494 2500 2495 /* Will perform the exchange later */ 2501 2496 dmabuf_cmsg.frag_token = tcp_xa_pool.tokens[tcp_xa_pool.idx]; 2502 - dmabuf_cmsg.dmabuf_id = net_iov_binding_id(niov); 2497 + dmabuf_cmsg.dmabuf_id = net_devmem_iov_binding_id(niov); 2503 2498 2504 2499 offset += copy; 2505 2500 remaining_len -= copy;
+7
tools/include/uapi/linux/netdev.h
··· 87 87 }; 88 88 89 89 enum { 90 + __NETDEV_A_IO_URING_PROVIDER_INFO_MAX, 91 + NETDEV_A_IO_URING_PROVIDER_INFO_MAX = (__NETDEV_A_IO_URING_PROVIDER_INFO_MAX - 1) 92 + }; 93 + 94 + enum { 90 95 NETDEV_A_PAGE_POOL_ID = 1, 91 96 NETDEV_A_PAGE_POOL_IFINDEX, 92 97 NETDEV_A_PAGE_POOL_NAPI_ID, ··· 99 94 NETDEV_A_PAGE_POOL_INFLIGHT_MEM, 100 95 NETDEV_A_PAGE_POOL_DETACH_TIME, 101 96 NETDEV_A_PAGE_POOL_DMABUF, 97 + NETDEV_A_PAGE_POOL_IO_URING, 102 98 103 99 __NETDEV_A_PAGE_POOL_MAX, 104 100 NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1) ··· 142 136 NETDEV_A_QUEUE_TYPE, 143 137 NETDEV_A_QUEUE_NAPI_ID, 144 138 NETDEV_A_QUEUE_DMABUF, 139 + NETDEV_A_QUEUE_IO_URING, 145 140 146 141 __NETDEV_A_QUEUE_MAX, 147 142 NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
+3 -1
tools/net/ynl/Makefile.deps
··· 17 17 CFLAGS_devlink:=$(call get_hdr_inc,_LINUX_DEVLINK_H_,devlink.h) 18 18 CFLAGS_dpll:=$(call get_hdr_inc,_LINUX_DPLL_H,dpll.h) 19 19 CFLAGS_ethtool:=$(call get_hdr_inc,_LINUX_ETHTOOL_H,ethtool.h) \ 20 - $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h) 20 + $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h) \ 21 + $(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_GENERATED_H,ethtool_netlink_generated.h) 21 22 CFLAGS_handshake:=$(call get_hdr_inc,_LINUX_HANDSHAKE_H,handshake.h) 22 23 CFLAGS_mptcp_pm:=$(call get_hdr_inc,_LINUX_MPTCP_PM_H,mptcp_pm.h) 24 + CFLAGS_net_shaper:=$(call get_hdr_inc,_LINUX_NET_SHAPER_H,net_shaper.h) 23 25 CFLAGS_netdev:=$(call get_hdr_inc,_LINUX_NETDEV_H,netdev.h) 24 26 CFLAGS_nlctrl:=$(call get_hdr_inc,__LINUX_GENERIC_NETLINK_H,genetlink.h) 25 27 CFLAGS_nfsd:=$(call get_hdr_inc,_LINUX_NFSD_NETLINK_H,nfsd_netlink.h)
+7 -1
tools/net/ynl/pyynl/ynl_gen_c.py
··· 100 100 if isinstance(value, int): 101 101 return value 102 102 if value in self.family.consts: 103 - raise Exception("Resolving family constants not implemented, yet") 103 + return self.family.consts[value]["value"] 104 104 return limit_to_number(value) 105 105 106 106 def get_limit_str(self, limit, default=None, suffix=''): ··· 110 110 if isinstance(value, int): 111 111 return str(value) + suffix 112 112 if value in self.family.consts: 113 + const = self.family.consts[value] 114 + if const.get('header'): 115 + return c_upper(value) 113 116 return c_upper(f"{self.family['name']}-{value}") 114 117 return c_upper(value) 115 118 ··· 2552 2549 2553 2550 defines = [] 2554 2551 for const in family['definitions']: 2552 + if const.get('header'): 2553 + continue 2554 + 2555 2555 if const['type'] != 'const': 2556 2556 cw.writes_defines(defines) 2557 2557 defines = []
+1
tools/testing/selftests/drivers/net/Makefile
··· 7 7 8 8 TEST_PROGS := \ 9 9 netcons_basic.sh \ 10 + netcons_fragmented_msg.sh \ 10 11 netcons_overflow.sh \ 11 12 ping.py \ 12 13 queues.py \
+7
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
··· 110 110 echo 1 > "${NETCONS_PATH}"/enabled 111 111 } 112 112 113 + # Do not append the release to the header of the message 114 + function disable_release_append() { 115 + echo 0 > "${NETCONS_PATH}"/enabled 116 + echo 0 > "${NETCONS_PATH}"/release 117 + echo 1 > "${NETCONS_PATH}"/enabled 118 + } 119 + 113 120 function cleanup() { 114 121 local NSIM_DEV_SYS_DEL="/sys/bus/netdevsim/del_device" 115 122
+122
tools/testing/selftests/drivers/net/netcons_fragmented_msg.sh
··· 1 + #!/usr/bin/env bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # Test netconsole's message fragmentation functionality. 5 + # 6 + # When a message exceeds the maximum packet size, netconsole splits it into 7 + # multiple fragments for transmission. This test verifies: 8 + # - Correct fragmentation of large messages 9 + # - Proper reassembly of fragments at the receiver 10 + # - Preservation of userdata across fragments 11 + # - Behavior with and without kernel release version appending 12 + # 13 + # Author: Breno Leitao <leitao@debian.org> 14 + 15 + set -euo pipefail 16 + 17 + SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 18 + 19 + source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh 20 + 21 + modprobe netdevsim 2> /dev/null || true 22 + modprobe netconsole 2> /dev/null || true 23 + 24 + # The content of kmsg will be save to the following file 25 + OUTPUT_FILE="/tmp/${TARGET}" 26 + 27 + # set userdata to a long value. In this case, it is "1-2-3-4...50-" 28 + USERDATA_VALUE=$(printf -- '%.2s-' {1..60}) 29 + 30 + # Convert the header string in a regexp, so, we can remove 31 + # the second header as well. 32 + # A header looks like "13,468,514729715,-,ncfrag=0/1135;". If 33 + # release is appended, you might find something like:L 34 + # "6.13.0-04048-g4f561a87745a,13,468,514729715,-,ncfrag=0/1135;" 35 + function header_to_regex() { 36 + # header is everything before ; 37 + local HEADER="${1}" 38 + REGEX=$(echo "${HEADER}" | cut -d'=' -f1) 39 + echo "${REGEX}=[0-9]*\/[0-9]*;" 40 + } 41 + 42 + # We have two headers in the message. Remove both to get the full message, 43 + # and extract the full message. 44 + function extract_msg() { 45 + local MSGFILE="${1}" 46 + # Extract the header, which is the very first thing that arrives in the 47 + # first list. 48 + HEADER=$(sed -n '1p' "${MSGFILE}" | cut -d';' -f1) 49 + HEADER_REGEX=$(header_to_regex "${HEADER}") 50 + 51 + # Remove the two headers from the received message 52 + # This will return the message without any header, similarly to what 53 + # was sent. 54 + sed "s/""${HEADER_REGEX}""//g" "${MSGFILE}" 55 + } 56 + 57 + # Validate the message, which has two messages glued together. 58 + # unwrap them to make sure all the characters were transmitted. 59 + # File will look like the following: 60 + # 13,468,514729715,-,ncfrag=0/1135;<message> 61 + # key=<part of key>-13,468,514729715,-,ncfrag=967/1135;<rest of the key> 62 + function validate_fragmented_result() { 63 + # Discard the netconsole headers, and assemble the full message 64 + RCVMSG=$(extract_msg "${1}") 65 + 66 + # check for the main message 67 + if ! echo "${RCVMSG}" | grep -q "${MSG}"; then 68 + echo "Message body doesn't match." >&2 69 + echo "msg received=" "${RCVMSG}" >&2 70 + exit "${ksft_fail}" 71 + fi 72 + 73 + # check userdata 74 + if ! echo "${RCVMSG}" | grep -q "${USERDATA_VALUE}"; then 75 + echo "message userdata doesn't match" >&2 76 + echo "msg received=" "${RCVMSG}" >&2 77 + exit "${ksft_fail}" 78 + fi 79 + # test passed. hooray 80 + } 81 + 82 + # Check for basic system dependency and exit if not found 83 + check_for_dependencies 84 + # Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) 85 + echo "6 5" > /proc/sys/kernel/printk 86 + # Remove the namespace, interfaces and netconsole target on exit 87 + trap cleanup EXIT 88 + # Create one namespace and two interfaces 89 + set_network 90 + # Create a dynamic target for netconsole 91 + create_dynamic_target 92 + # Set userdata "key" with the "value" value 93 + set_user_data 94 + 95 + 96 + # TEST 1: Send message and userdata. They will fragment 97 + # ======= 98 + MSG=$(printf -- 'MSG%.3s=' {1..150}) 99 + 100 + # Listen for netconsole port inside the namespace and destination interface 101 + listen_port_and_save_to "${OUTPUT_FILE}" & 102 + # Wait for socat to start and listen to the port. 103 + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp 104 + # Send the message 105 + echo "${MSG}: ${TARGET}" > /dev/kmsg 106 + # Wait until socat saves the file to disk 107 + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 108 + # Check if the message was not corrupted 109 + validate_fragmented_result "${OUTPUT_FILE}" 110 + 111 + # TEST 2: Test with smaller message, and without release appended 112 + # ======= 113 + MSG=$(printf -- 'FOOBAR%.3s=' {1..100}) 114 + # Let's disable release and test again. 115 + disable_release_append 116 + 117 + listen_port_and_save_to "${OUTPUT_FILE}" & 118 + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp 119 + echo "${MSG}: ${TARGET}" > /dev/kmsg 120 + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 121 + validate_fragmented_result "${OUTPUT_FILE}" 122 + exit "${ksft_pass}"
+1 -1
tools/testing/selftests/net/forwarding/bridge_mdb.sh
··· 149 149 check_err $? "Failed to add $name host entry" 150 150 151 151 bridge mdb replace dev br0 port br0 grp $grp $state vid 10 &> /dev/null 152 - check_fail $? "Managed to replace $name host entry" 152 + check_err $? "Failed to replace $name host entry" 153 153 154 154 bridge mdb del dev br0 port br0 grp $grp $state vid 10 155 155 bridge mdb get dev br0 grp $grp vid 10 &> /dev/null
+2
tools/testing/selftests/net/forwarding/vxlan_bridge_1d.sh
··· 740 740 741 741 vxlan_flood_test $mac $dst 0 10 0 742 742 743 + # The entry should age out when it only forwards traffic 744 + $MZ $h1 -c 50 -d 1sec -p 64 -b $mac -B $dst -t icmp -q & 743 745 sleep 60 744 746 745 747 bridge fdb show brport vx1 | grep $mac | grep -q self
+2 -1
tools/testing/selftests/net/ynl.mk
··· 27 27 28 28 $(OUTPUT)/libynl.a: $(YNL_SPECS) $(OUTPUT)/.libynl-$(YNL_GENS_HASH).sig 29 29 $(Q)rm -f $(top_srcdir)/tools/net/ynl/libynl.a 30 - $(Q)$(MAKE) -C $(top_srcdir)/tools/net/ynl GENS="$(YNL_GENS)" libynl.a 30 + $(Q)$(MAKE) -C $(top_srcdir)/tools/net/ynl \ 31 + GENS="$(YNL_GENS)" RSTS="" libynl.a 31 32 $(Q)cp $(top_srcdir)/tools/net/ynl/libynl.a $(OUTPUT)/libynl.a 32 33 33 34 EXTRA_CLEAN += \