drivers/tty/n_gsm.c
Source file repositories/reference/linux-study-clean/drivers/tty/n_gsm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/n_gsm.c- Extension
.c- Size
- 116886 bytes
- Lines
- 4679
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/major.hlinux/errno.hlinux/signal.hlinux/fcntl.hlinux/sched/signal.hlinux/interrupt.hlinux/tty.hlinux/bitfield.hlinux/ctype.hlinux/mm.hlinux/math.hlinux/nospec.hlinux/string.hlinux/slab.hlinux/poll.hlinux/bitops.hlinux/file.hlinux/uaccess.hlinux/module.hlinux/timer.hlinux/tty_flip.hlinux/tty_driver.hlinux/serial.hlinux/kfifo.hlinux/skbuff.hnet/arp.hlinux/ip.hlinux/netdevice.hlinux/etherdevice.hlinux/gsmmux.htty.h
Detected Declarations
struct gsm_mux_netstruct gsm_msgstruct gsm_dlcistruct gsm_dlci_param_bitsstruct gsm_controlstruct gsm_muxenum gsm_dlci_stateenum gsm_dlci_modeenum gsm_encodingenum gsm_mux_statefunction gsm_fcs_addfunction gsm_fcs_add_blockfunction gsm_read_eafunction gsm_read_ea_valfunction bitsfunction gsm_hex_dump_bytesfunction gsm_encode_paramsfunction gsm_register_devicesfunction gsm_unregister_devicesfunction gsm_print_packetfunction gsm_stuff_framefunction gsm_sendfunction gsm_dlci_clear_queuesfunction gsm_responsefunction gsm_commandfunction gsm_send_packetfunction gsm_is_flow_ctrl_msgfunction gsm_data_kickfunction __gsm_data_queuefunction gsm_data_queuefunction gsm_dlci_data_outputfunction gsm_dlci_data_output_framedfunction gsm_dlci_modem_outputfunction gsm_dlci_data_sweepfunction gsm_dlci_data_kickfunction gsm_control_commandfunction gsm_control_replyfunction gsm_process_modemfunction gsm_process_negotiationfunction gsm_control_modemfunction gsm_control_negotiationfunction gsm_control_rlsfunction gsm_control_messagefunction gsm_control_responsefunction gsm_control_keep_alivefunction commandfunction gsm_control_retransmitfunction gsm_control_wait
Annotated Snippet
static const struct net_device_ops gsm_netdev_ops = {
.ndo_open = gsm_mux_net_open,
.ndo_stop = gsm_mux_net_close,
.ndo_start_xmit = gsm_mux_net_start_xmit,
.ndo_tx_timeout = gsm_mux_net_tx_timeout,
};
net->netdev_ops = &gsm_netdev_ops;
/* fill in the other fields */
net->watchdog_timeo = GSM_NET_TX_TIMEOUT;
net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
net->type = ARPHRD_NONE;
net->tx_queue_len = 10;
}
/* caller holds the dlci mutex */
static void gsm_destroy_network(struct gsm_dlci *dlci)
{
struct gsm_mux_net *mux_net;
pr_debug("destroy network interface\n");
if (!dlci->net)
return;
mux_net = netdev_priv(dlci->net);
muxnet_put(mux_net);
}
/* caller holds the dlci mutex */
static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc)
{
char *netname;
int retval = 0;
struct net_device *net;
struct gsm_mux_net *mux_net;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
/* Already in a non tty mode */
if (dlci->adaption > 2)
return -EBUSY;
if (nc->protocol != htons(ETH_P_IP))
return -EPROTONOSUPPORT;
if (nc->adaption != 3 && nc->adaption != 4)
return -EPROTONOSUPPORT;
pr_debug("create network interface\n");
netname = "gsm%d";
if (nc->if_name[0] != '\0')
netname = nc->if_name;
net = alloc_netdev(sizeof(struct gsm_mux_net), netname,
NET_NAME_UNKNOWN, gsm_mux_net_init);
if (!net) {
pr_err("alloc_netdev failed\n");
return -ENOMEM;
}
net->mtu = dlci->mtu;
net->min_mtu = MIN_MTU;
net->max_mtu = dlci->mtu;
mux_net = netdev_priv(net);
mux_net->dlci = dlci;
kref_init(&mux_net->ref);
strscpy(nc->if_name, net->name); /* return net name */
/* reconfigure dlci for network */
dlci->prev_adaption = dlci->adaption;
dlci->prev_data = dlci->data;
dlci->adaption = nc->adaption;
dlci->data = gsm_mux_rx_netchar;
dlci->net = net;
pr_debug("register netdev\n");
retval = register_netdev(net);
if (retval) {
pr_err("network register fail %d\n", retval);
dlci_net_free(dlci);
return retval;
}
return net->ifindex; /* return network index */
}
/* Line discipline for real tty */
static struct tty_ldisc_ops tty_ldisc_packet = {
.owner = THIS_MODULE,
Annotation
- Immediate include surface: `linux/types.h`, `linux/major.h`, `linux/errno.h`, `linux/signal.h`, `linux/fcntl.h`, `linux/sched/signal.h`, `linux/interrupt.h`, `linux/tty.h`.
- Detected declarations: `struct gsm_mux_net`, `struct gsm_msg`, `struct gsm_dlci`, `struct gsm_dlci_param_bits`, `struct gsm_control`, `struct gsm_mux`, `enum gsm_dlci_state`, `enum gsm_dlci_mode`, `enum gsm_encoding`, `enum gsm_mux_state`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.