The Linux Kernel API

The Linux Kernel API
This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more details see the file COPYING in the source distribution of Linux.

Table of Contents
1. The Linux VFS.....................................................................................................................................10 The Directory Cache ........................................................................................................................10 d_invalidate.............................................................................................................................10 d_find_alias.............................................................................................................................10 prune_dcache ..........................................................................................................................11 shrink_dcache_sb ...................................................................................................................12 have_submounts .....................................................................................................................12 shrink_dcache_parent .............................................................................................................13 d_alloc ....................................................................................................................................13 d_instantiate............................................................................................................................14 d_alloc_root ............................................................................................................................15 d_lookup .................................................................................................................................16 d_validate................................................................................................................................16 d_delete...................................................................................................................................17 d_rehash..................................................................................................................................18 d_move ...................................................................................................................................18 __d_path .................................................................................................................................19 is_subdir .................................................................................................................................20 find_inode_number .................................................................................................................21 d_drop .....................................................................................................................................22 d_add ......................................................................................................................................22 dget .........................................................................................................................................23 d_unhashed .............................................................................................................................24 Inode Handling.................................................................................................................................24 __mark_inode_dirty ...............................................................................................................25 write_inode_now ....................................................................................................................25 clear_inode .............................................................................................................................26 invalidate_inodes ....................................................................................................................26 get_empty_inode ....................................................................................................................27 iunique ....................................................................................................................................28 insert_inode_hash ...................................................................................................................29 remove_inode_hash ................................................................................................................29 iput ..........................................................................................................................................30 bmap .......................................................................................................................................30 update_atime...........................................................................................................................31 make_bad_inode .....................................................................................................................32 is_bad_inode ...........................................................................................................................32 Registration and Superblocks...........................................................................................................33

3

..................................................................................................................44 skb_queue_tail ..............................................47 skb_unlink .....................................................................................54 skb_orphan ........................................................................34 get_super..............................................................33 unregister_filesystem ......................................................................................................................................42 __skb_queue_head .........................................................................................................40 skb_peek_tail ........................................................................................................43 __skb_queue_tail ..............................................................................................................................................................................................................................................................................................................................................................................................................................42 skb_queue_head ......................................................................................................................................................37 skb_get.................................................................55 __skb_queue_purge ..38 skb_shared .......................................................55 skb_queue_purge .......................................................................................................................41 skb_queue_len ...........................................................................................................................................................................................................................................................................36 2.........................................................................37 skb_queue_empty .............................................................................................37 kfree_skb ...............................................................................................................38 skb_cloned ..............................................................48 __skb_dequeue_tail ................................................................................................................................................................................................................52 skb_tailroom ..........................................................................................................58 4 .....................................................................................................................................................................................................................................................................................53 skb_trim ....................................................................................37 Socket Buffer Functions.............53 skb_reserve ..........................................49 skb_dequeue_tail .........................................................................................................................................................................................................................................................................................57 skb_over_panic ..............49 skb_put ......................................................45 __skb_dequeue .................51 skb_headroom............................................................................................40 skb_peek .........................................................................................................................................34 __wait_on_super.........45 skb_dequeue ......................................................................................................57 skb_cow .........................................................................50 skb_push .........................................................................................................................................................................................................................................................................................................35 get_empty_super..........................................................................................................................................................................................46 skb_insert..........56 dev_alloc_skb ...............................................................................................................................................................................................................................register_filesystem .............................................................................................................................................................................................................................................................. Linux Networking ....................................................47 skb_append ......................................................................39 skb_unshare .............................................................51 skb_pull ......................................................................................

.............................................................................................................................................................................................................................................................................................................................68 dev_get.........82 register_netdevice ........................................................................................................................................................70 dev_get_by_index...............................................................................73 dev_load........................................76 dev_queue_xmit...............84 8390 Based Network Cards......................61 skb_clone ....................................................................72 netdev_state_change .......................................................................................................................................................68 dev_get_by_name ................. Network device support...............................................................................................................................................................................80 dev_set_allmulti.....................................................................................77 net_call_rx_atomic ................................................................................................77 netif_rx .....................................................62 skb_copy_expand ................................................................................................................................................................................................................67 __dev_get_by_name ...............61 skb_copy.....................................................................................................................................................................................................................................................................................................................................................................79 dev_set_promiscuity ............................................................................................66 Driver Support................................................................................................................................................................................................................................................................................................................................................................................64 3.................................................................................................................................................................................................................................................................................................................................................................................................75 register_netdevice_notifier .............................................................78 register_gifconf...........................64 sk_run_filter....................70 dev_alloc_name ...................................................................................................................................................................................................73 dev_open...........................................................75 unregister_netdevice_notifier ...............................81 dev_ioctl .........................................66 dev_remove_pack .............................................................................................................................................................................................................................................................................................................................................................................................74 dev_close .........................................................................................79 netdev_set_master ..........................................................................................................................85 ei_open ......................71 dev_alloc...............................................................................66 dev_add_pack ......................................................................60 __kfree_skb ..........................69 __dev_get_by_index......................63 Socket Filter ...................................................................................................................................................................................................................................................................................................................................................................................66 init_etherdev ....skb_under_panic ......................................84 unregister_netdevice ....................................................................................................................81 dev_new_index ............83 netdev_finish_unregister.......................................................................59 alloc_skb......85 5 .....................................................................................................................................................................................................................

.95 5......................................................................................96 enable_irq ..............................................ei_close ..........................................................................................................................................................................................................................................................................................................................................................................100 PCI Support Library.......................................................................................................................................................................96 Interrupt Handling ..............................................................................................................................................................................................................................................................................................................................................90 sppp_reopen.....................................................91 sppp_do_ioctl ....105 MCA Device Functions .......................................................................................................................................................................................................................................................................................................................................................................98 MTRR Handling ..............104 pci_enable_device ......................................... Module Loading .............................................................................................................101 pci_find_device........................................................................................................................................................................................................................................................................................................................................................................105 mca_find_adapter ....................................................................110 6 ..................................................106 mca_read_stored_pos...........................................................98 mtrr_del ........................................................................................................................101 pci_find_class ..........................................................................................................................................................100 pci_find_slot ............................................................96 disable_irq ..............................................................................................................................................98 mtrr_add ................................109 mca_set_adapter_procfn ..............87 NS8390_init............93 4.....88 sppp_input .......................................................................................................................................................................................................................................................................................................................................88 sppp_close ...........................................................................................92 sppp_attach ...............................................................................95 request_module ...................................................................................................................................................................................................................107 mca_read_pos ..........108 mca_set_adapter_name .............................................................................................................................................................................................................................................................................................................................89 sppp_open ....................................104 MCA Architecture..............................................................................................................................................................85 ei_interrupt ........................................................................... Hardware Interfaces..........................................................102 pci_find_parent_resource ................92 sppp_detach ...........................................................................103 pci_set_power_state........................................................96 disable_irq_nosync ...........105 mca_find_unused_adapter....................................................................................................................................................................................................................107 mca_write_pos ..........................................................................................................................................87 Synchronous PPP ................................86 ethdev_init ...........................................................90 sppp_change_mtu ......................................................................................................97 probe_irq_mask ....

...................................133 devfs_get_next_sibling....................................................................................................................................................................122 devfs_mk_symlink ..................................111 mca_mark_as_used ............113 mca_isenabled.........................................................................................................................................................................117 mca_get_dma_residue....................................................................114 MCA Bus DMA .........................................................................129 devfs_set_file_size ..............................................................................................................................................................................................................................................................................................................................123 devfs_mk_dir...........130 devfs_get_info ...........................................................................................121 devfs_register ..............................................139 pm_register.........127 devfs_get_handle_from_inode .................................116 mca_get_dma_addr ............................................................................................................................................................................................137 devfs_unregister_blkdev ................ Power Management .....................................................................................................................................................mca_is_adapter_used ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................114 mca_disable_dma......118 mca_set_dma_io ............................. The Device File System.................................................................................................................................................................133 devfs_auto_unregister ......................................................................................119 6................................................................................125 devfs_get_flags...........................................................135 devfs_register_blkdev .....................................131 devfs_get_parent .................................................................................................................................124 devfs_find_handle .............................................................................................................................................................................................................................................................................................................................................115 mca_set_dma_addr ..............................................................................................................................131 devfs_set_info .....................................................111 mca_mark_as_unused ........................................................................................................................................................................................................................................................................................................113 mca_isadapter ......................114 mca_enable_dma...........................................................................................................134 devfs_register_chrdev .......................134 devfs_get_unregister_slave .........................................................................118 mca_set_dma_mode.............................................................................................................121 devfs_unregister .........................136 devfs_unregister_chrdev ......................................................................................................................................................................................................................................................................128 devfs_get_ops............138 7..............112 mca_get_adapter_name.........132 devfs_get_first_child .........................................................................................................128 devfs_generate_path ..........................................................................................................................................................................................126 devfs_get_maj_min .....................................................116 mca_set_dma_count........................................................................................................................................139 7 ..........................

.................................................................149 register_sound_dsp......... 16x50 UART Driver ......150 unregister_sound_special ........................................................................................146 10................162 z8530_shutdown ..............................................................................................................................................................................................................................159 z8530_sync_dma_close ...158 z8530_sync_dma_open ..........144 9.............152 unregister_sound_dsp........................................142 8..........164 z8530_null_rx ......148 register_sound_special ..............................142 pm_find ........................................................................................157 z8530_interrupt ......................................................................................................................................................................................................................................................................152 unregister_sound_midi .......................................................................................................................................................................................................................................................................................................................................................................................................165 8 ..........................................................153 unregister_sound_synth...................................................................................139 pm_unregister_all..................................................................................................................................................................................................................................................................................................................................................................144 misc_deregister ..........151 unregister_sound_mixer ...........................................................................................................................................................155 register_serial ................................................................................................................................................................................................................................................................................................................................................................................................................................162 z8530_init.....................................................................................................................155 unregister_serial .....................................................................................................................144 misc_register ............160 z8530_sync_txdma_open.....................................................................................................................................................................................................................................................................................................................154 11........................................................... Miscellaneous Devices .............................................................................................................163 z8530_channel_load...............160 z8530_sync_txdma_close ............pm_unregister...........................................................155 12...................................................................................................................146 video_register_device........................................................................................................................................................................................................................................................................................................................................................................................................ Video4Linux .................................................................. Sound Devices................................................................148 register_sound_midi ..............................................................................157 z8530_sync_close .161 z8530_describe......164 z8530_queue_xmit .................................140 pm_send ...................................................................................................................146 video_unregister_device.............148 register_sound_mixer ...................................................................................................................................................157 z8530_sync_open ..................................................................................................................................................141 pm_send_all ................................................................................................................................................................................................................................. Z85230 Support Library ..........................................................................150 register_sound_synth.........................................................................................................................................

.................................166 9 ...........................................................................z8530_get_stats ...................

If there are other dentries that can be reached through this one we can’t delete it and we return -EBUSY.Chapter 1. Arguments dentry dentry to invalidate Description Try to invalidate the dentry if it turns out to be possible. The Linux VFS The Directory Cache d_invalidate Name d_invalidate — invalidate a dentry Synopsis int d_invalidate (struct dentry * dentry). On success we return 0. d_find_alias Name d_find_alias — grab a hashed alias of inode 10 .

acquire the reference to alias and return it.Chapter 1. Arguments count number of entries to try and free Description 11 . Arguments inode inode in question Description If inode has a hashed alias . The Linux VFS Synopsis struct dentry * d_find_alias (struct inode * inode). prune_dcache Name prune_dcache — shrink the dcache Synopsis void prune_dcache (int count). Otherwise return NULL. Notice that if inode is a directory there can be only one alias and it can be unhashed only if it has no children.

This is done when we need more memory. or simply when we need to unmount something (at which point we need to unuse all dentries). shrink_dcache_sb Name shrink_dcache_sb — shrink dcache for a superblock Synopsis void shrink_dcache_sb (struct super_block * sb). Arguments sb superblock Description Shrink the dcache for the specified super block. This function may fail to free any resources if all the dentries are in use.Chapter 1. This is used to free the dcache before unmounting a file system have_submounts Name have_submounts — check for mounts over a dentry 12 . The Linux VFS Shrink the dcache.

13 . Arguments parent parent of entries to prune Description Prune the dcache to remove unused children of the parent dentry. Description Return true if the parent or its subdirectories contain a mount point shrink_dcache_parent Name shrink_dcache_parent — prune dcache Synopsis void shrink_dcache_parent (struct dentry * parent).Chapter 1. Arguments parent dentry to check. The Linux VFS Synopsis int have_submounts (struct dentry * parent).

Chapter 1. The Linux VFS

d_alloc
Name d_alloc — allocate a dcache entry Synopsis
struct dentry * d_alloc (struct dentry * parent, const struct qstr * name);

Arguments
parent parent of entry to allocate name qstr of the name

Description
Allocates a dentry. It returns NULL if there is insufficient memory available. On a success the dentry is returned. The name passed in is copied and the copy passed in may be reused after this call.

d_instantiate
Name d_instantiate — fill in inode information for a dentry Synopsis
void d_instantiate (struct dentry * entry, struct inode * inode);

14

Chapter 1. The Linux VFS

Arguments
entry dentry to complete inode inode to attach to this dentry

Description
Fill in inode information in the entry. This turns negative dentries into productive full members of society. NOTE! This assumes that the inode count has been incremented (or otherwise set) by the caller to indicate that it is now in use by the dcache.

d_alloc_root
Name d_alloc_root — allocate root dentry Synopsis
struct dentry * d_alloc_root (struct inode * root_inode);

Arguments
root_inode inode to allocate the root for

Description

15

Chapter 1. The Linux VFS

Allocate a root (“/”) dentry for the inode given. The inode is instantiated and returned. NULL is returned if there is insufficient memory or the inode passed is NULL.

d_lookup
Name d_lookup — search for a dentry Synopsis
struct dentry * d_lookup (struct dentry * parent, struct qstr * name);

Arguments
parent parent dentry name qstr of name we wish to find

Description
Searches the children of the parent dentry for the name in question. If the dentry is found its reference count is incremented and the dentry is returned. The caller must use d_put to free the entry when it has finished using it. NULL is returned on failure.

d_validate
Name d_validate — verify dentry provided from insecure source

16

here we verify it.. Zero is returned in the dentry is invalid. d_delete Name d_delete — delete a dentry 17 . NOTE This function does _not_ dereference the pointers before we have validated them. Arguments dentry The dentry alleged to be valid dparent The parent dentry hash Hash of the dentry len Length of the name Description An insecure source has sent us a dentry.Chapter 1. unsigned int hash. This is used by ncpfs in its readdir implementation. The Linux VFS Synopsis int d_validate (struct dentry * dentry. unsigned int len). We can test the pointer values. but we must not actually use them until we have found a valid copy of the pointer in kernel space. struct dentry * dparent.

18 .Chapter 1. otherwise remove it from the hash queues so it can be deleted later d_rehash Name d_rehash — add an entry back to the hash Synopsis void d_rehash (struct dentry * entry). The Linux VFS Synopsis void d_delete (struct dentry * dentry). Arguments entry dentry to add to the hash Description Adds a dentry to the hash according to its name. Arguments dentry The dentry to delete Description Turn the dentry into a negative dentry if possible.

The Linux VFS d_move Name d_move — move a dentry Synopsis void d_move (struct dentry * dentry. struct vfsmount * rootmnt. char * buffer. struct dentry * target). struct dentry * root. Arguments dentry entry to move target new dentry Description Update the dcache to reflect the move of a file name. Negative dcache entries should not be moved in this way. struct vfsmount * vfsmnt.Chapter 1. 19 . int buflen). __d_path Name __d_path — return the path of a dentry Synopsis char * __d_path (struct dentry * dentry.

struct dentry * old_dentry ). If the entry has been deleted the string “ (deleted)” is appended. Returns the buffer. The Linux VFS Arguments dentry dentry to report vfsmnt – undescribed – root – undescribed – rootmnt – undescribed – buffer buffer to return value in buflen buffer length Description Convert a dentry into an ASCII path name. Note that this is ambiguous. 20 .Chapter 1. is_subdir Name is_subdir — is new dentry a subdirectory of old_dentry Synopsis int is_subdir (struct dentry * new_dentry . “buflen” should be PAGE_SIZE or more.

Returns 0 otherwise. The Linux VFS Arguments new_dentry new dentry old_dentry old dentry Description Returns 1 if new_dentry is a subdirectory of the parent (at any depth). Arguments dir directory to check name Name to find. Description 21 . struct qstr * name). find_inode_number Name find_inode_number — check for dentry with name Synopsis ino_t find_inode_number (struct dentry * dir.Chapter 1.

Otherwise 0 is returned. and is necessary to keep getcwd working. so that it won’t be found through a VFS lookup any more.Chapter 1. d_drop Name d_drop — drop a dentry Synopsis void d_drop (struct dentry * dentry). d_drop is used mainly for stuff that wants to invalidate a dentry for some reason (NFS timeouts or autofs deletes). Arguments dentry dentry to drop Description d_drop unhashes the entry from the parent dentry hashes. and return the inode number if it has an inode.d_delete will try to mark the dentry negative if possible. The Linux VFS Check whether a dentry already exists for the given name. Note that this is different from deleting the dentry . 22 . This routine is used to post-process directory listings for filesystems using synthetic inode numbers. while d_drop will just make the cache lookup fail. giving a successful _negative_ lookup.

The entry was actually filled in earlier during d_alloc. dget Name dget — get a reference to a dentry Synopsis struct dentry * dget (struct dentry * dentry). 23 . struct inode * inode).Chapter 1. The Linux VFS d_add Name d_add — add dentry to hash queues Synopsis void d_add (struct dentry * entry. Arguments entry dentry to add inode The inode to attach to this dentry Description This adds the entry to the hash queues and initializes inode.

d_unhashed Name d_unhashed — is dentry hashed Synopsis int d_unhashed (struct dentry * dentry). 24 . The Linux VFS Arguments dentry dentry to get a reference to Description Given a dentry or NULL pointer increment the reference count if appropriate and return the dentry. Arguments dentry entry to check Description Returns true if the dentry passed is not currently hashed. A dentry will not be destroyed when it has references.Chapter 1.

Chapter 1. 25 . Arguments inode inode to mark Description Mark an inode as dirty. write_inode_now Name write_inode_now — write an inode to disk Synopsis void write_inode_now (struct inode * inode). The Linux VFS Inode Handling __mark_inode_dirty Name __mark_inode_dirty — internal function Synopsis void __mark_inode_dirty (struct inode * inode). Callers should use mark_inode_dirty.

clear_inode Name clear_inode — clear an inode Synopsis void clear_inode (struct inode * inode). Arguments inode inode to clear Description This is called by the filesystem to tell us that the inode is no longer useful. The Linux VFS Arguments inode inode to write to disk Description This function commits an inode to disk immediately if it is dirty.Chapter 1. This is primarily needed by knfsd. 26 . We just terminate it with extreme prejudice.

Arguments sb superblock Description Discard all of the inodes for a given superblock. If the discard is successful all the inodes have been discarded. The Linux VFS invalidate_inodes Name invalidate_inodes — discard the inodes on a device Synopsis int invalidate_inodes (struct super_block * sb). get_empty_inode Name get_empty_inode — obtain an inode Synopsis struct inode * get_empty_inode ( void). If the discard fails because there are busy inodes then a non zero value is returned.Chapter 1. Arguments 27 .

or filesystems that allocate new inodes with no pre-existing information. An inode number is returned that is higher than the reserved limit but unique. 28 . The Linux VFS void no arguments Description This is called by things like the networking layer etc that want to get an inode without any inode number. ino_t max_reserved). On a successful return the inode pointer is returned. Arguments sb superblock max_reserved highest reserved inode number Description Obtain an inode number that is unique on the system for a given superblock. This is used by file systems that have no natural permanent inode numbering system. On a failure a NULL pointer is returned. iunique Name iunique — get a unique inode number Synopsis ino_t iunique (struct super_block * sb. The returned inode is not on any superblock lists.Chapter 1.

remove_inode_hash Name remove_inode_hash — remove an inode from the hash Synopsis void remove_inode_hash (struct inode * inode). insert_inode_hash Name insert_inode_hash — hash an inode Synopsis void insert_inode_hash (struct inode * inode). Arguments inode unhashed inode Description Add an inode to the inode hash for this superblock. The Linux VFS BUGS With a large number of inodes live on the file system this function currently becomes quite slow.Chapter 1. If the inode has no superblock it is added to a separate anonymous chain. 29 .

dropping its usage count. The Linux VFS Arguments inode inode to unhash Description Remove an inode from the superblock or anonymous hash.Chapter 1. Arguments inode inode to put Description Puts an inode. iput Name iput — put an inode Synopsis void iput (struct inode * inode). If the inode use count hits zero the inode is also then freed and may be destroyed. 30 .

Chapter 1. That is. int block). The Linux VFS bmap Name bmap — find a block number in a file Synopsis int bmap (struct inode * inode. Arguments inode inode of file block block to find Description Returns the block number on the device holding the inode that is the disk block number for the block of the file requested. asked for block 4 of inode 1 the function will return the disk block relative to the disk start that holds that block of the file. update_atime Name update_atime — update the access time Synopsis void update_atime (struct inode * inode). 31 .

Chapter 1. make_bad_inode Name make_bad_inode — mark an inode bad due to an I/O error Synopsis void make_bad_inode (struct inode * inode). 32 . Arguments inode Inode to mark bad Description When an inode cannot be read due to a media or remote network failure this function makes the inode “bad” and causes I/O operations on it to fail from this point on. as well as the “noatime” flag and inode specific “noatime” markers. The Linux VFS Arguments inode inode accessed Description Update the accessed time on an inode and mark it for writeback. This function automatically handles read only file systems and media.

Chapter 1. 33 . Registration and Superblocks register_filesystem Name register_filesystem — register a new filesystem Synopsis int register_filesystem (struct file_system_type * fs). Arguments inode inode to test Description Returns true if the inode in question has been marked as bad. The Linux VFS is_bad_inode Name is_bad_inode — is an inode errored Synopsis int is_bad_inode (struct inode * inode).

or a negative errno code on an error. 34 . The Linux VFS Arguments fs the file system structure Description Adds the file system passed to the list of file systems the kernel is aware of for mount and other syscalls.Chapter 1. Arguments fs filesystem to unregister Description Remove a file system that was previously successfully registered with the kernel. Zero is returned on a success. An error is returned if the file system is not found. unregister_filesystem Name unregister_filesystem — unregister a file system Synopsis int unregister_filesystem (struct file_system_type * fs). The &struct file_system_type that is passed is linked into the kernel structures and must not be freed until the file system has been unregistered. Once this function has returned the &struct file_system_type structure may be freed or reused. Returns 0 on success.

This is an internal function.Chapter 1. See wait_on_super. Arguments sb superblock to wait on Description Waits for a superblock to become unlocked and then returns. The Linux VFS __wait_on_super Name __wait_on_super — wait on a superblock Synopsis void __wait_on_super (struct super_block * sb). It does not take the lock. Arguments 35 . get_super Name get_super — get the superblock of a device Synopsis struct super_block * get_super (kdev_t dev).

A free superblock is found and returned. The Linux VFS dev device to get the superblock for Description Scans the superblock list and finds the superblock of the file system mounted on the device given. 36 .Chapter 1. Arguments void no arguments Description Find a superblock with no device assigned. NULL is returned if no match is found. NULL is returned if there are insufficient resources to complete the request. If neccessary new superblocks are allocated. get_empty_super Name get_empty_super — find empty superblocks Synopsis struct super_block * get_empty_super ( void).

false otherwise. 37 .Chapter 2. Linux Networking Socket Buffer Functions skb_queue_empty Name skb_queue_empty — check if a queue is empty Synopsis int skb_queue_empty (struct sk_buff_head * list). skb_get Name skb_get — reference buffer Synopsis struct sk_buff * skb_get (struct sk_buff * skb). Arguments list queue head Description Returns true if the queue is empty.

38 .Chapter 2. Linux Networking Arguments skb buffer to reference Description Makes another reference to a socket buffer and returns a pointer to the buffer. Arguments skb buffer to free Description Drop a reference to the buffer and free it if the usage count has hit zero. kfree_skb Name kfree_skb — free an sk_buff Synopsis void kfree_skb (struct sk_buff * skb).

Arguments 39 .Chapter 2. skb_shared Name skb_shared — is the buffer shared Synopsis int skb_shared (struct sk_buff * skb). Arguments skb buffer to check Description Returns true if the buffer was generated with skb_clone and is one of multiple shared copies of the buffer. Linux Networking skb_cloned Name skb_cloned — is the buffer a clone Synopsis int skb_cloned (struct sk_buff * skb). Cloned buffers are shared data so must not be written to under normal circumstances.

Arguments skb buffer to check pri priority for memory allocation Description If the socket buffer is a clone then this function creates a new copy of the data. 40 . skb_unshare Name skb_unshare — make a copy of a shared buffer Synopsis struct sk_buff * skb_unshare (struct sk_buff * skb. drops a reference count on the old copy and returns the new copy with the reference count at 1. When called with a spinlock held or from interrupt state pri must be GFP_ATOMIC NULL is returned on a memory allocation failure. Linux Networking skb buffer to check Description Returns true if more than one person has a reference to this buffer.Chapter 2. int pri). If the buffer is not a clone the original buffer is returned.

Use with caution. Linux Networking skb_peek Name skb_peek — Synopsis struct sk_buff * skb_peek (struct sk_buff_head * list_).Chapter 2. 41 . The reference count is not incremented and the reference is therefore volatile. A peek leaves the buffer on the list and someone else may run off with it. You must hold the appropriate locks or have a private queue to do this. skb_peek_tail Name skb_peek_tail — Synopsis struct sk_buff * skb_peek_tail (struct sk_buff_head * list_). Returns NULL for an empty list or a pointer to the head element. Unlike most other operations you _MUST_ be careful with this one. Arguments list_ list to peek at Description Peek an &sk_buff.

Chapter 2. 42 . Linux Networking Arguments list_ list to peek at Description Peek an &sk_buff. Use with caution. You must hold the appropriate locks or have a private queue to do this. skb_queue_len Name skb_queue_len — get queue length Synopsis __u32 skb_queue_len (struct sk_buff_head * list_). Returns NULL for an empty list or a pointer to the tail element. A peek leaves the buffer on the list and someone else may run off with it. The reference count is not incremented and the reference is therefore volatile. Arguments list_ list to measure Description Return the length of an &sk_buff queue. Unlike most other operations you _MUST_ be careful with this one.

A buffer cannot be placed on two lists at the same time. struct sk_buff * newsk). Arguments list list to use newsk buffer to queue Description Queue a buffer at the start of a list. This function takes no locks and you must therefore hold required locks before calling it.Chapter 2. struct sk_buff * newsk). Linux Networking __skb_queue_head Name __skb_queue_head — queue a buffer at the list head Synopsis void __skb_queue_head (struct sk_buff_head * list. 43 . skb_queue_head Name skb_queue_head — queue a buffer at the list head Synopsis void skb_queue_head (struct sk_buff_head * list.

__skb_queue_tail Name __skb_queue_tail — queue a buffer at the list tail Synopsis void __skb_queue_tail (struct sk_buff_head * list. Linux Networking Arguments list list to use newsk buffer to queue Description Queue a buffer at the start of the list. A buffer cannot be placed on two lists at the same time. Arguments list list to use newsk buffer to queue 44 . This function takes the list lock and can be used safely with other locking &sk_buff functions safely.Chapter 2. struct sk_buff * newsk).

This function takes the list lock and can be used safely with other locking &sk_buff functions safely. skb_queue_tail Name skb_queue_tail — queue a buffer at the list tail Synopsis void skb_queue_tail (struct sk_buff_head * list.Chapter 2. Arguments list list to use newsk buffer to queue Description Queue a buffer at the tail of the list. A buffer cannot be placed on two lists at the same time. Linux Networking Description Queue a buffer at the end of a list. struct sk_buff * newsk). A buffer cannot be placed on two lists at the same time. This function takes no locks and you must therefore hold required locks before calling it. 45 .

Arguments list list to dequeue from Description Remove the head of the list. This function does not take any locks so must be used with appropriate locks held only. skb_dequeue Name skb_dequeue — remove from the head of the queue Synopsis struct sk_buff * skb_dequeue (struct sk_buff_head * list). Linux Networking __skb_dequeue Name __skb_dequeue — remove from the head of the queue Synopsis struct sk_buff * __skb_dequeue (struct sk_buff_head * list).Chapter 2. The head item is returned or NULL if the list is empty. Arguments 46 .

The list lock is taken so the function may be used safely with other locking list functions. struct sk_buff * newsk). 47 . skb_insert Name skb_insert — insert a buffer Synopsis void skb_insert (struct sk_buff * old. Arguments old buffer to insert before newsk buffer to insert Description Place a packet before a given packet in a list. Linux Networking list list to dequeue from Description Remove the head of the list.Chapter 2. The head item is returned or NULL if the list is empty. The list locks are taken and this function is atomic with respect to other list locked calls A buffer cannot be placed on two lists at the same time.

Chapter 2. 48 . The list locks are taken and this function is atomic with respect to other list locked calls. A buffer cannot be placed on two lists at the same time. struct sk_buff * newsk). skb_unlink Name skb_unlink — remove a buffer from a list Synopsis void skb_unlink (struct sk_buff * skb). Arguments old buffer to insert after newsk buffer to insert Description Place a packet after a given packet in a list. Linux Networking skb_append Name skb_append — append a buffer Synopsis void skb_append (struct sk_buff * old.

Thus a list must have its contents unlinked before it is destroyed. __skb_dequeue_tail Name __skb_dequeue_tail — remove from the tail of the queue Synopsis struct sk_buff * __skb_dequeue_tail (struct sk_buff_head * list). 49 .Chapter 2. This function does not take any locks so must be used with appropriate locks held only. The list locks are taken and this function is atomic with respect to other list locked calls Works even without knowing the list it is sitting on. which can be handy at times. Arguments list list to dequeue from Description Remove the tail of the list. Linux Networking Arguments skb buffer to remove Description Place a packet after a given packet in a list. The tail item is returned or NULL if the list is empty. It also means that THE LIST MUST EXIST when you unlink.

Chapter 2. skb_put Name skb_put — add data to a buffer Synopsis unsigned char * skb_put (struct sk_buff * skb. unsigned int len). Arguments 50 . Arguments list list to dequeue from Description Remove the head of the list. The tail item is returned or NULL if the list is empty. Linux Networking skb_dequeue_tail Name skb_dequeue_tail — remove from the head of the queue Synopsis struct sk_buff * skb_dequeue_tail (struct sk_buff_head * list). The list lock is taken so the function may be used safely with other locking list functions.

A pointer to the first byte of the extra data is returned.Chapter 2. 51 . skb_push Name skb_push — add data to the start of a buffer Synopsis unsigned char * skb_push (struct sk_buff * skb. A pointer to the first byte of the extra data is returned. unsigned int len). Linux Networking skb buffer to use len amount of data to add Description This function extends the used data area of the buffer. If this would exceed the total buffer size the kernel will panic. Arguments skb buffer to use len amount of data to add Description This function extends the used data area of the buffer at the buffer start. If this would exceed the total buffer headroom the kernel will panic.

skb_headroom Name skb_headroom — bytes at buffer head Synopsis int skb_headroom (const struct sk_buff * skb). returning the memory to the headroom. Once the data has been pulled future pushes will overwrite the old data. unsigned int len). 52 . Linux Networking skb_pull Name skb_pull — remove data from the start of a buffer Synopsis unsigned char * skb_pull (struct sk_buff * skb. A pointer to the next data in the buffer is returned.Chapter 2. Arguments skb buffer to use len amount of data to remove Description This function removes data from the start of a buffer.

Arguments skb buffer to check Description Return the number of bytes of free space at the tail of an sk_buff 53 .Chapter 2. Linux Networking Arguments skb buffer to check Description Return the number of bytes of free space at the head of an &sk_buff. skb_tailroom Name skb_tailroom — bytes at buffer end Synopsis int skb_tailroom (const struct sk_buff * skb).

Chapter 2. skb_trim Name skb_trim — remove end from a buffer Synopsis void skb_trim (struct sk_buff * skb. 54 . unsigned int len). Arguments skb buffer to alter len bytes to move Description Increase the headroom of an empty &sk_buff by reducing the tail room. Linux Networking skb_reserve Name skb_reserve — adjust headroom Synopsis void skb_reserve (struct sk_buff * skb. This is only allowed for an empty buffer. unsigned int len).

Linux Networking Arguments skb buffer to alter len new length Description Cut the length of a buffer down by removing data from the tail. The buffer continues to exist but is no longer charged to its former owner. If the buffer is already under the length specified it is not modified.Chapter 2. Arguments skb buffer to orphan Description If a buffer currently has an owner then we call the owner’s destructor function and make the skb unowned. skb_orphan Name skb_orphan — orphan a buffer Synopsis void skb_orphan (struct sk_buff * skb). 55 .

Arguments list list to empty Description Delete all buffers on an &sk_buff list. Arguments 56 .Chapter 2. Linux Networking skb_queue_purge Name skb_queue_purge — empty a list Synopsis void skb_queue_purge (struct sk_buff_head * list). Each buffer is removed from the list and one reference dropped. This function takes the list lock and is atomic with respect to other list locking functions. __skb_queue_purge Name __skb_queue_purge — empty a list Synopsis void __skb_queue_purge (struct sk_buff_head * list).

The buffer has unspecified headroom built in.Chapter 2. Linux Networking list list to empty Description Delete all buffers on an &sk_buff list. Although this function allocates memory it can be called from an interrupt. 57 . Arguments length length to allocate Description Allocate a new &sk_buff and assign it a usage count of one. dev_alloc_skb Name dev_alloc_skb — allocate an skbuff for sending Synopsis struct sk_buff * dev_alloc_skb (unsigned int length). NULL is returned in there is no free memory. Users should allocate the headroom they think they need without accounting for the built in space. This function does not take the list lock and the caller must hold the relevant locks to use it. The built in space is used for optimisations. Each buffer is removed from the list and one reference dropped.

skb_over_panic Name skb_over_panic — private function 58 .Chapter 2. The new buffer is returned if a copy was made (and the old one dropped a reference). The existing buffer is returned otherwise. Arguments skb buffer to copy headroom needed headroom Description If the buffer passed lacks sufficient headroom or is a clone then it is copied and the additional headroom made available. Linux Networking skb_cow Name skb_cow — copy a buffer if need be Synopsis struct sk_buff * skb_cow (struct sk_buff * skb. This function primarily exists to avoid making two copies when making a writable copy of a buffer and then growing the headroom. unsigned int headroom). If there is no free memory NULL is returned.

void * here). int sz. Arguments 59 . skb_under_panic Name skb_under_panic — private function Synopsis void skb_under_panic (struct sk_buff * skb.Chapter 2. void * here). Arguments skb buffer sz size here address Description Out of line support code for skb_put. Linux Networking Synopsis void skb_over_panic (struct sk_buff * skb. int sz. Not user callable.

alloc_skb Name alloc_skb — allocate a network buffer Synopsis struct sk_buff * alloc_skb (unsigned int size. Not user callable. Arguments size size to allocate gfp_mask allocation mask Description 60 .Chapter 2. int gfp_mask). Linux Networking skb buffer sz size here address Description Out of line support code for skb_push.

The object has a reference count of one. Users should always call kfree_skb skb_clone Name skb_clone — duplicate an sk_buff 61 . The returned buffer has no headroom and a tail room of size bytes. This is an internal helper function. Buffers may only be allocated from interrupts using a gfp_mask of GFP_ATOMIC. The return is the buffer. Linux Networking Allocate a new &sk_buff. Arguments skb buffer Description Free an sk_buff. On a failure the return is NULL. Clean the state. __kfree_skb Name __kfree_skb — private function Synopsis void __kfree_skb (struct sk_buff * skb).Chapter 2. Release anything attached to the buffer.

Arguments 62 . skb_copy Name skb_copy — copy an sk_buff Synopsis struct sk_buff * skb_copy (const struct sk_buff * skb. int gfp_mask). The new one is not owned by a socket. Linux Networking Synopsis struct sk_buff * skb_clone (struct sk_buff * skb.Chapter 2. int gfp_mask). The new buffer has a reference count of 1. Arguments skb buffer to clone gfp_mask allocation priority Description Duplicate an &sk_buff. If this function is called from an interrupt gfp_mask must be GFP_ATOMIC. Both copies share the same packet data but not structure. If the allocation fails the function returns NULL otherwise the new buffer is returned.

int newtailroom. The returned buffer has a reference count of 1. This is used when the caller wishes to modify the data and needs a private copy of the data to alter. Arguments skb buffer to copy newheadroom new free bytes at head newtailroom new free bytes at tail 63 . int newheadroom. Linux Networking skb buffer to copy gfp_mask allocation priority Description Make a copy of both an &sk_buff and its data. You must pass GFP_ATOMIC as the allocation priority if this function is called from an interrupt. skb_copy_expand Name skb_copy_expand — copy and expand sk_buff Synopsis struct sk_buff * skb_copy_expand (const struct sk_buff * skb. Returns NULL on failure or the pointer to the buffer on success.Chapter 2. int gfp_mask).

This is used when the caller wishes to modify the data and needs a private copy of the data to alter as well as more space for new fields. Socket Filter sk_run_filter Name sk_run_filter — run a filter on a socket Synopsis int sk_run_filter (struct sk_buff * skb. Linux Networking gfp_mask allocation priority Description Make a copy of both an &sk_buff and its data and while doing so allocate additional space. struct sock_filter * filter. Returns NULL on failure or the pointer to the buffer on success. You must pass GFP_ATOMIC as the allocation priority if this function is called from an interrupt. Arguments skb buffer to run the filter on filter filter to apply 64 . int flen).Chapter 2. The returned buffer has a reference count of 1.

filter is the array of filter instructions.   65 . Return length to keep. skb is the data we are filtering.Chapter 2.data. 0 for none. Linux Networking flen length of filter Description Decode and apply filter instructions to the skb. and len is the number of filter blocks in the array.

a new name string is constructed. Network device support Driver Support init_etherdev Name init_etherdev — Register ethernet device Synopsis struct net_device * init_etherdev (struct net_device * dev. int sizeof_priv ). A 32-byte (not bit) alignment is enforced for this private data area. a new one is constructed. If an empty string area is passed as dev. sizeof_priv Size of additional driver-private structure to be allocated for this ethernet device Description Fill in the fields of the device structure with ethernet-generic values. ¡ 66 .Chapter 3.name. or NULL if a new struct should be allocated. Arguments dev An ethernet device structure to be filled in. If no device structure is passed. or a new structure is made. complete with a private data area of size sizeof_priv .

The passed &packet_type is linked into kernel lists and may not be freed until it has been removed from the kernel lists. Network device support dev_add_pack Name dev_add_pack — add packet handler Synopsis void dev_add_pack (struct packet_type * pt). Arguments 67 . Arguments pt packet type declaration Description Add a protocol handler to the networking stack. dev_remove_pack Name dev_remove_pack — remove packet handler Synopsis void dev_remove_pack (struct packet_type * pt).Chapter 3.

Must be called under RTNL semaphore or dev_base_lock. The passed &packet_type is removed from the kernel lists and can be freed or reused once this function returns. If the name is not found then NULL is returned. 68 . Arguments name name to find Description Find an interface by name. Network device support pt packet type declaration Description Remove a protocol handler that was previously added to the kernel protocol handlers by dev_add_pack. The reference counters are not incremented so the caller must be careful with locks.Chapter 3. If the name is found a pointer to the device is returned. __dev_get_by_name Name __dev_get_by_name — find a device by its name Synopsis struct net_device * __dev_get_by_name (const char * name).

Chapter 3. Network device support

dev_get_by_name
Name dev_get_by_name — find a device by its name Synopsis
struct net_device * dev_get_by_name (const char * name);

Arguments
name name to find

Description
Find an interface by name. This can be called from any context and does its own locking. The returned handle has the usage count incremented and the caller must use dev_put to release it when it is no longer needed. NULL is returned if no matching device is found.

dev_get
Name dev_get — test if a device exists Synopsis
int dev_get (const char * name);

69

Chapter 3. Network device support

Arguments
name name to test for

Description
Test if a name exists. Returns true if the name is found. In order to be sure the name is not allocated or removed during the test the caller must hold the rtnl semaphore. This function primarily exists for back compatibility with older drivers.

__dev_get_by_index
Name __dev_get_by_index — find a device by its ifindex Synopsis
struct net_device * __dev_get_by_index (int ifindex);

Arguments
ifindex index of device

Description
Search for an interface by index. Returns NULL if the device is not found or a pointer to the device. The device has not had its reference counter increased so the caller must be careful about locking. The caller must hold either the RTNL semaphore or dev_base_lock.

70

Chapter 3. Network device support

dev_get_by_index
Name dev_get_by_index — find a device by its ifindex Synopsis
struct net_device * dev_get_by_index (int ifindex);

Arguments
ifindex index of device

Description
Search for an interface by index. Returns NULL if the device is not found or a pointer to the device. The device returned has had a reference added and the pointer is safe until the user calls dev_put to indicate they have finished with it.

dev_alloc_name
Name dev_alloc_name — allocate a name for a device Synopsis
int dev_alloc_name (struct net_device * dev, const char * name);

71

not called a lot. Arguments name name format string err error return pointer 72 . Returns the number of the unit assigned or a negative errno code. Network device support Arguments dev device name name format string Description Passed a format string . dev_alloc Name dev_alloc — allocate a network device and name Synopsis struct net_device * dev_alloc (const char * name.Chapter 3. Not efficient for many devices. int * err). The caller must hold the dev_base or rtnl lock while allocating the name and adding the device in order to avoid duplicates.eg “ltd” it will try and find a suitable id.

eg. This function calls the notifier chains for netdev_chain and sends a NEWLINK message to the routing socket. NULL is returned if the name allocation failed. netdev_state_change Name netdev_state_change — device changes state Synopsis void netdev_state_change (struct net_device * dev). dev_load Name dev_load — load a network module 73 . Network device support Description Passed a format string. The cause of an error is returned as a negative errno code in the variable err points to. Arguments dev device to cause notification Description Called to indicate a device has changed state. “ltd”. The caller must hold the dev_base or RTNL locks when doing this in order to avoid duplicate name allocations. If the allocation succeeds then the name is assigned and the device pointer returned.Chapter 3. it will allocate a network device and space for the name. NULL is returned if no memory is available.

Chapter 3. If module loading is not available in this kernel then it becomes a nop. Synopsis int dev_open (struct net_device * dev). Arguments dev device to open Description 74 . dev_open Name dev_open — prepare an interface for use. Arguments name name of interface Description If a network interface is not present and the process has suitable privileges this function loads the module. Network device support Synopsis void dev_load (const char * name).

register_netdevice_notifier Name register_netdevice_notifier — register a network notifier block 75 . Arguments dev device to shutdown Description This function moves an active device into down state. Network device support Takes a device from down to up state. On a failure a negative errno code is returned. The device’s private open function is invoked and then the multicast lists are loaded. dev_close Name dev_close — shutdown an interface.Chapter 3. The device is then deactivated and finally a NETDEV_DOWN is sent to the notifier chain. Synopsis int dev_close (struct net_device * dev). Calling this function on an active interface is a nop. A NETDEV_GOING_DOWN is sent to the netdev notifier chain. Finally the device is moved into the up state and a NETDEV_UP message is sent to the netdev notifier chain.

Network device support Synopsis int register_netdevice_notifier (struct notifier_block * nb).Chapter 3. The notifier passed is linked into the kernel structures and must not be reused until it has been unregistered. unregister_netdevice_notifier Name unregister_netdevice_notifier — unregister a network notifier block Synopsis int unregister_netdevice_notifier (struct notifier_block * nb). A negative errno code is returned on a failure. Arguments nb notifier Description Register a notifier to be called when network device events occur. Arguments nb notifier Description 76 .

The caller must have set the device and priority and built the buffer before calling this function. Arguments skb buffer to transmit Description Queue a buffer for transmission to a network device. Network device support Unregister a notifier previously registered by register_netdevice_notifier .Chapter 3. A negative errno code is returned on a failure. The function can be called from an interrupt. dev_queue_xmit Name dev_queue_xmit — transmit a buffer Synopsis int dev_queue_xmit (struct sk_buff * skb). netif_rx Name netif_rx — post buffer to the network code 77 . The notifier is unlinked into the kernel structures and may then be reused. A negative errno code is returned on a failure. A success does not guarantee the frame will be transmitted as it may be dropped due to congestion or traffic shaping.

It always succeeds. The buffer may be dropped during processing for congestion control or by the protocol layers. Arguments skb buffer to post Description This function receives a packet from a device driver and queues it for the upper (protocol) levels to process. net_call_rx_atomic Name net_call_rx_atomic — Synopsis void net_call_rx_atomic (void (*fn) (void)).Chapter 3. Network device support Synopsis void netif_rx (struct sk_buff * skb). Arguments fn function to call Description 78 .

Network device support Make a function call that is atomic with respect to the protocol layers. The handler that is passed must not be freed or reused until it has been replaced by another handler.Chapter 3. register_gifconf Name register_gifconf — register a SIOCGIF handler Synopsis int register_gifconf (unsigned int family. netdev_set_master Name netdev_set_master — set up master/slave pair 79 . Arguments family Address family gifconf Function handler Description Register protocol dependent address dumping routines. gifconf_func_t * gifconf).

Arguments dev device 80 . dev_set_promiscuity Name dev_set_promiscuity — update promiscuity count on a device Synopsis void dev_set_promiscuity (struct net_device * dev. struct net_device * master). The caller must hold the RTNL semaphore. int inc). On a failure a negative errno code is returned.Chapter 3. Arguments slave slave device master new master device Description Changes the master device of the slave. Pass NULL to break the bonding. RTM_NEWLINK is sent to the routing socket and the function returns zero. Network device support Synopsis int netdev_set_master (struct net_device * slave. On success the reference counts are adjusted.

Chapter 3. A negative inc value is used to drop promiscuity on the device. While the count in the device remains above zero the interface remains promiscuous. Once it hits zero the device reverts back to normal filtering operation. Arguments dev device inc modifier Description Add or remove reception of all multicast frames to a device. 81 . int inc). A negative inc value is used to drop the counter when releasing a resource needing all multicasts. dev_set_allmulti Name dev_set_allmulti — update allmulti count on a device Synopsis void dev_set_allmulti (struct net_device * dev. Network device support inc modifier Description Add or remove promsicuity from a device. While the count in the device remains above zero the interface remains listening to all interfaces. Once it hits zero the device reverts back to normal filtering operation.

dev_new_index Name dev_new_index — allocate an ifindex Synopsis int dev_new_index ( void). The return value is the return from the syscall if positive or a negative errno code on error. 82 . Arguments cmd command to issue arg pointer to a struct ifreq in user space Description Issue ioctl functions to devices. void * arg). Network device support dev_ioctl Name dev_ioctl — network device ioctl Synopsis int dev_ioctl (unsigned int cmd.Chapter 3. This is normally called by the user space syscall interfaces but can sometimes be useful for other purposes.

A NETDEV_REGISTER message is sent to the netdev notifier chain. register_netdevice Name register_netdevice — register a network device Synopsis int register_netdevice (struct net_device * dev). Network device support Arguments void no arguments Description Returns a suitable unique value for a new device interface number. The caller must hold the rtnl semaphore to be sure it remains unique. Arguments dev device to register Description Take a completed network device structure and add it to the kernel interfaces. or if the name is a duplicate.Chapter 3. A negative errno code is returned on a failure to set up the device. BUGS 83 . 0 is returned on success.

A value of zero is returned on success. netdev_finish_unregister Name netdev_finish_unregister — complete unregistration Synopsis int netdev_finish_unregister (struct net_device * dev). 84 . unregister_netdevice Name unregister_netdevice — remove device from the kernel Synopsis int unregister_netdevice (struct net_device * dev). Arguments dev device Description Destroy and free a dead device.Chapter 3. Network device support The locking appears insufficient to guarantee two parallel registers will not get the same name.

setting everything up anew at each open. 85 . Arguments dev network device to initialize Description This routine goes all-out. On success 0 is returned. Network device support Arguments dev device Description This function shuts down a device interface and removes it from the kernel tables. Synopsis int ei_open (struct net_device * dev). even though many of these registers should only need to be set once at boot.Chapter 3. on a failure a negative errno code is returned. 8390 Based Network Cards ei_open Name ei_open — Open/initialize the board.

Chapter 3. Arguments dev network device to close Description £ ¢ Opposite of ei_open. struct pt_regs * regs). Only used when “ifconfig devname down” is done. void * dev_id. ei_interrupt Name ei_interrupt — handle the interrupts from an 8390 Synopsis void ei_interrupt (int irq. Network device support ei_close Name ei_close — shut down network device Synopsis int ei_close (struct net_device * dev). Arguments 86 .

87 . Do NOT __init this. ethdev_init Name ethdev_init — init rest of 8390 device struct Synopsis int ethdev_init (struct net_device * dev). Network device support irq interrupt number dev_id a pointer to the net_device regs unused Description Handle the ether interface interrupts. as it is used by 8390 based modular drivers too. We pull packets from the 8390 via the card specific functions and fire them at the networking stack. We also update the counters and do other housekeeping as needed. Arguments dev network device structure to init Description Initialize the rest of the 8390 device structure. We also handle transmit completions and wake the transmit path if neccessary.Chapter 3.

Synchronous PPP sppp_input Name sppp_input — receive and process a WAN PPP frame 88 .Chapter 3. Network device support NS8390_init Name NS8390_init — initialize 8390 hardware Synopsis void NS8390_init (struct net_device * dev. int startp). non-zero value to initiate chip processing Description Must be called with lock held. Arguments dev network device to initialize startp boolean.

Arguments 89 .Chapter 3. sppp_close Name sppp_close — close down a synchronous PPP or Cisco HDLC link Synopsis int sppp_close (struct net_device * dev). We process the options in the card. If it is a control from it is processed and discarded here. Arguments dev The device it arrived on skb The buffer to process Description This can be called directly by cards that do not have timing constraints but is normally called from the network layer after interrupt servicing to process frames queued via netif_rx. Network device support Synopsis void sppp_input (struct net_device * dev. struct sk_buff * skb). If the frame is destined for the protocol stacks then it requeues the frame for the upper level protocol.

Network device support dev The network device to drop the link of Description This drops the logical interface to the channel. Any timeouts are killed. sppp_open Name sppp_open — open a synchronous PPP or Cisco HDLC link Synopsis int sppp_open (struct net_device * dev). It is not done politely as we assume we will also be dropping DTR. Arguments dev Network device to activate Description Close down any existing synchronous session and commence from scratch. In the PPP case this means negotiating LCP/IPCP and friends.Chapter 3. while for Cisco HDLC we simply need to staet sending keepalives sppp_reopen Name sppp_reopen — notify of physical link loss 90 .

This function may be called from an interrupt context. int new_mtu).21) We increment the magic numbers to ensure that if the other end failed to notice we will correctly start a new session. Arguments dev Device to change MTU on 91 . Network device support Synopsis int sppp_reopen (struct net_device * dev).Chapter 3. Arguments dev Device that lost the link Description This function informs the synchronous protocol code that the underlying link died (for example a carrier drop on X. Having done this we go back to negotiating. It happens do to the nature of telco circuits is that you can lose carrier on one endonly. sppp_change_mtu Name sppp_change_mtu — Change the link MTU Synopsis int sppp_change_mtu (struct net_device * dev.

This function is intended to be wrapped by callers who wish to add additional ioctl calls of their own. sppp_do_ioctl Name sppp_do_ioctl — Ioctl handler for ppp/hdlc Synopsis int sppp_do_ioctl (struct net_device * dev. 92 . struct ifreq * ifr. int cmd). It does both busy and security checks. Network device support new_mtu New MTU Description Change the MTU on the link.Chapter 3. This can only be called with the link down. It returns an error if the link is up or the mtu is out of range. Arguments dev Device subject to ioctl ifr Interface request block from the user cmd Command that is being issued Description This function handles the ioctls that may be issued by the user to control the settings of a PPP/HDLC link.

The interface should not yet be registered. Network device support sppp_attach Name sppp_attach — attach synchronous PPP/HDLC to a device Synopsis void sppp_attach (struct ppp_device * pd). sppp_detach Name sppp_detach — release PPP resources from a device Synopsis void sppp_detach (struct net_device * dev). Arguments 93 . Arguments pd PPP device to initialise Description This initialises the PPP/HDLC support on an interface. At the time of calling the dev element must point to the network device that this interface is attached to.Chapter 3.

Chapter 3. Network device support dev Network device to release Description Stop and free up any PPP/HDLC resources used by this interface. 94 . This must be called before the device is freed.

Module Loading request_module Name request_module — try to load a kernel module Synopsis int request_module (const char * module_name). If module auto-loading support is disabled then this function becomes a no-operation. Note that a successful module load does not mean the module did not then unload and exit on an error of its own. 95 . Arguments module_name Name of module Description Load a module using the user mode module loader. Callers must check that the service they requested is now available not blindly invoke it.Chapter 4. The function returns zero on success or a negative errno code on failure.

this function does not ensure existing instances of the IRQ handler have completed before returning. This function may be called from IRQ context. Hardware Interfaces Interrupt Handling disable_irq_nosync Name disable_irq_nosync — disable an irq without waiting Synopsis void inline disable_irq_nosync (unsigned int irq). Unlike disable_irq. Disables of an interrupt stack. disable_irq Name disable_irq — disable an irq and wait for completion 96 .Chapter 5. Arguments irq Interrupt to disable Description Disable the selected interrupt line.

Disables of an interrupt stack. Hardware Interfaces Synopsis void disable_irq (unsigned int irq).Chapter 5. If you use this function while holding a resource the IRQ handler may need you will deadlock. enable_irq Name enable_irq — enable interrupt handling on an irq Synopsis void enable_irq (unsigned int irq).with care .from IRQ context. Arguments irq Interrupt to enable 97 . Arguments irq Interrupt to disable Description Disable the selected interrupt line. This function may be called . This function waits for any pending IRQ handlers for this interrupt to complete before returning. That is for two disables you need two enables.

This function may be called from IRQ context. The interrupt probe logic state is then returned to its previous value. Arguments val mask of interrupts to consider Description Scan the ISA bus interrupt lines and return a bitmap of active interrupts. MTRR Handling mtrr_add Name mtrr_add — Add a memory type region 98 . probe_irq_mask Name probe_irq_mask — scan a bitmap of interrupt lines Synopsis unsigned int probe_irq_mask (unsigned long val). Hardware Interfaces Description Re-enables the processing of interrupts on this IRQ line providing no disable_irq calls are now in effect.Chapter 5.

On a multiprocessor machine the changes are made to all processors. but should be treated as a cookie only. This is required on x86 by the Intel processors. On success the register number for this entry is returned. This function allows drivers to request an MTRR is added. unsigned int type. Arguments base Physical base address of region size Physical size of region type Type of MTRR desired increment If this is true do usage counting on the region Description Memory type region registers control the caching on newer Intel and non Intel processors. The details and hardware specifics of each processor’s implementation are hidden from the caller. but nevertheless the caller should expect to need to provide a power of two size on an equivalent power of two boundary. The available types are MTRR_TYPE_UNCACHEABLE . If the region cannot be added either because all regions are in use or the CPU cannot support it a negative value is returned.No caching MTRR_TYPE_WRITEBACK . Hardware Interfaces Synopsis int mtrr_add (unsigned long base.Write data back soon but allow bursts 99 .Write data back in bursts whenever MTRR_TYPE_WRCOMB . unsigned long size.Chapter 5. char increment).

Arguments reg Register returned by mtrr_add base Physical base address size Size of region Description If register is supplied then base and size are ignored. If the usage count drops to zero the register is freed and the region returns to default state. unsigned long size). Hardware Interfaces MTRR_TYPE_WRTHROUGH . On success the register is returned.Chapter 5. mtrr_del Name mtrr_del — delete a memory type region Synopsis int mtrr_del (int reg. 100 . This is how drivers should call it.Cache reads but not writes BUGS Needs a quiet flag for the cases where drivers do not mind failures and do not wish system log messages to be sent. unsigned long base. on failure a negative error code. Releases an MTRR region.

NULL is returned. Hardware Interfaces PCI Support Library pci_find_slot Name pci_find_slot — locate PCI device from a given PCI slot Synopsis struct pci_dev * pci_find_slot (unsigned int bus. If no device is found. a pointer to its data structure is returned.Chapter 5. unsigned int devfn). pci_find_device Name pci_find_device — begin or continue searching for a PCI device by vendor/device id 101 . Arguments bus number of PCI bus on which desired PCI device resides devfn number of PCI slot in which desired PCI device resides Description Given a PCI bus and slot number. the desired PCI device is located in system global list of PCI devices. If the device is found.

or PCI_ANY_ID to match all vendor ids from Previous PCI device found in search. 102 .Chapter 5. const struct pci_dev * from). pci_find_class Name pci_find_class — begin or continue searching for a PCI device by class Synopsis struct pci_dev * pci_find_class (unsigned int class. If a PCI device is found with a matching vendor and device. or NULL for new search. Otherwise if from is not null. A new search is initiated by passing NULL to the from argument. Arguments vendor PCI vendor id to match. const struct pci_dev * from). unsigned int device. or PCI_ANY_ID to match all vendor ids device PCI device id to match. Hardware Interfaces Synopsis struct pci_dev * pci_find_device (unsigned int vendor. searches continue from that point. NULL is returned. Description Iterates through the list of known PCI devices. Otherwise. a pointer to its device structure is returned.

Arguments dev PCI device structure contains resources to be searched res child resource record for which parent is sought 103 . struct resource * res). A new search is initiated by passing NULL to the from argument. Otherwise if from is not null. a pointer to its device structure is returned. Description Iterates through the list of known PCI devices. NULL is returned. Hardware Interfaces Arguments class search for a PCI device with this class designation from Previous PCI device found in search.Chapter 5. If a PCI device is found with a matching class. pci_find_parent_resource Name pci_find_parent_resource — return resource region of parent bus of given region Synopsis struct resource * pci_find_parent_resource (const struct pci_dev * dev. searches continue from that point. Otherwise. or NULL for new search.

For transitions from state D3 it isn’t as straightforward as one could assume since many devices forget their configuration space during wakeup. Returns old power state. 3 == D3. etc. Synopsis int pci_set_power_state (struct pci_dev * dev. pci_enable_device Name pci_enable_device — Initialize device before it’s used by a driver.Chapter 5.) Description Set power management state of a device. Hardware Interfaces Description For given resource region of given device. Arguments dev PCI device for which PM is set new_state new power management statement (0 == D0. 104 . pci_set_power_state Name pci_set_power_state — Set power management state of a device. return the resource region of parent bus the given region is contained in or where it should be allocated from. int new_state).

Wake up the device if it was suspended.Chapter 5. int start). Ask low-level code to enable I/O and memory. this function can fail. MCA Architecture MCA Device Functions mca_find_adapter Name mca_find_adapter — scan for adapters Synopsis int mca_find_adapter (int id. Arguments 105 . Arguments dev PCI device to be initialized Description Initialize device before it’s used by a driver. Hardware Interfaces Synopsis int pci_enable_device (struct pci_dev * dev). Beware.

int start). The first time it should be called with start as zero and then further calls made passing the return value of the previous call until MCA_NOTFOUND is returned. Arguments id MCA identification to search for start starting slot Description 106 . Hardware Interfaces id MCA identification to search for start starting slot Description Search the MCA configuration for adapters matching the 16bit ID given. mca_find_unused_adapter Name mca_find_unused_adapter — scan for unused adapters Synopsis int mca_find_unused_adapter (int id. Disabled adapters are not reported.Chapter 5.

Chapter 5. Arguments slot slot number to read from reg register to read from Description Fetch a POS value that was stored at boot time by the kernel when it scanned the MCA space. This function thus allows a driver to scan for further cards when some may already be driven. 107 . The register value is returned. Missing or invalid registers report 0. Hardware Interfaces Search the MCA configuration for adapters matching the 16bit ID given. mca_read_stored_pos Name mca_read_stored_pos — read POS register from boot data Synopsis unsigned char mca_read_stored_pos (int slot. The first time it should be called with start as zero and then further calls made passing the return value of the previous call until MCA_NOTFOUND is returned. int reg). Adapters that have been claimed by drivers and those that are disabled are not reported.

Hardware Interfaces mca_read_pos Name mca_read_pos — read POS register from card Synopsis unsigned char mca_read_pos (int slot. This is much slower than mca_read_stored_pos and may not be invoked from interrupt context. 108 . int reg). Arguments slot slot number to read from reg register to read from Description Fetch a POS value directly from the hardware to obtain the current value. mca_write_pos Name mca_write_pos — read POS register from card Synopsis void mca_write_pos (int slot. unsigned char byte).Chapter 5. It handles the deep magic required for onboard devices transparently. int reg.

so you might see magic smoke if someone screws up.Chapter 5. char* name). However. Doing this wrongly can damage the hardware. Hardware Interfaces Arguments slot slot number to read from reg register to read from byte byte to write to the POS registers Description Store a POS value directly from the hardware. 109 . but I like my drivers to work. as IBM tech stuff says you should only set POS values through their utilities. This function may not be used from interrupt context. some devices such as the 3c523 recommend that you write back some data to make sure the configuration is consistent. mca_set_adapter_name Name mca_set_adapter_name — Set the description of the card Synopsis void mca_set_adapter_name (int slot. I’d say that IBM is right. This function can’t do checks to see if multiple devices end up with the same resources. Note that this a technically a Bad Thing. You should not normally need to use this function and should have a very good knowledge of MCA bus before you do so.

MCA_ProcFn procfn. Setting a name deletes any previous name. void* dev).Chapter 5. This is for user information only. Arguments slot slot to configure procfn callback function to call for /proc dev device information passed to the callback 110 . Hardware Interfaces Arguments slot slot to name name text string for the namen Description This function sets the name reported via /proc for this adapter slot. mca_set_adapter_procfn Name mca_set_adapter_procfn — Set the /proc callback Synopsis void mca_set_adapter_procfn (int slot.

Chapter 5. and is expected to put useful information into the buffer. and device pointer (or some equally informative context information. The adapter name. and POS registers get printed before this is called though. or nothing. This should be called with a NULL procfn when a module unregisters. ID. Arguments slot slot to check Description Returns 1 if the slot has been claimed by a driver mca_mark_as_used Name mca_mark_as_used — claim an MCA device 111 . Hardware Interfaces Description This sets up an information callback for /proc/mca/slot?. The function is called with the buffer. slot. if you prefer). mca_is_adapter_used Name mca_is_adapter_used — check if claimed by driver Synopsis int mca_is_adapter_used (int slot). thus preventing kernel crashes and other such nastiness. so don’t do it again.

If the slot is already taken the function returns 1. mca_mark_as_unused Name mca_mark_as_unused — release an MCA device Synopsis void mca_mark_as_unused (int slot). Arguments slot slot to claim Description 112 . Hardware Interfaces Synopsis int mca_mark_as_used (int slot). if it is not taken it is claimed and 0 is returned.Chapter 5. Arguments slot slot to claim FIXME should we make this threadsafe Claim an MCA slot for a device driver.

Hardware Interfaces Release the slot for other drives to use. mca_get_adapter_name Name mca_get_adapter_name — get the adapter description Synopsis char * mca_get_adapter_name (int slot). If it has not been set or the slot is out range then return NULL.Chapter 5. Arguments slot slot to query Description Return the adapter description if set. mca_isadapter Name mca_isadapter — check if the slot holds an adapter Synopsis int mca_isadapter (int slot). 113 .

MCA Bus DMA 114 . non zero if it does. Hardware Interfaces Arguments slot slot to query Description Returns zero if the slot does not hold an adapter. mca_isenabled Name mca_isenabled — check if the slot holds an adapter Synopsis int mca_isenabled (int slot). Arguments slot slot to query Description Returns a non zero value if the slot holds an enabled adapter and zero for any other case.Chapter 5.

mca_disable_dma Name mca_disable_dma — channel to disable DMA on Synopsis void mca_disable_dma (unsigned int dmanr).Chapter 5. Arguments 115 . Hardware Interfaces mca_enable_dma Name mca_enable_dma — channel to enable DMA on Synopsis void mca_enable_dma (unsigned int dmanr). Arguments dmanr DMA channel Description Enable the MCA bus DMA on a channel. This can be called from IRQ context.

mca_set_dma_addr Name mca_set_dma_addr — load a 24bit DMA address Synopsis void mca_set_dma_addr (unsigned int dmanr. This has a 24bit limitation (16Mb). 116 .Chapter 5. Hardware Interfaces dmanr DMA channel Description Enable the MCA bus DMA on a channel. Arguments dmanr DMA channel a 24bit bus address Description Load the address register in the DMA controller. unsigned int a). This can be called from IRQ context.

Chapter 5. Arguments 117 . Arguments dmanr DMA channel Description Read the address register in the DMA controller. The return is a bus address. mca_set_dma_count Name mca_set_dma_count — load a 16bit transfer count Synopsis void mca_set_dma_count (unsigned int dmanr. unsigned int count). Hardware Interfaces mca_get_dma_addr Name mca_get_dma_addr — load a 24bit DMA address Synopsis unsigned int mca_get_dma_addr (unsigned int dmanr). This has a 24bit limitation (16Mb).

Chapter 5. Setting a count of zero will not do what you expect. Hardware Interfaces dmanr DMA channel count count Description Set the DMA count for this channel. mca_get_dma_residue Name mca_get_dma_residue — get the remaining bytes to transfer Synopsis unsigned int mca_get_dma_residue (unsigned int dmanr). This can be up to 64Kbytes. Arguments dmanr DMA channel Description This function returns the number of bytes left to transfer on this DMA channel. 118 .

Hardware Interfaces mca_set_dma_io Name mca_set_dma_io — set the port for an I/O transfer Synopsis void mca_set_dma_io (unsigned int dmanr. mca_set_dma_mode Name mca_set_dma_mode — set the DMA mode Synopsis void mca_set_dma_mode (unsigned int dmanr. unsigned int io_addr). 119 . unsigned int mode).Chapter 5. Arguments dmanr DMA channel io_addr an I/O port number Description Unlike the ISA bus DMA controllers the DMA on MCA bus can transfer with an I/O port target.

MCA_DMA_MODE_IO to do DMA to or from an I/O port. MCA_DMA_MODE_WRITE to writing to the DMA device. MCA_DMA_MODE_16 to do 16bit transfers. The mode values you can set are MCA_DMA_MODE_READ when reading from the DMA device.Chapter 5. 120 . Hardware Interfaces Arguments dmanr DMA channel mode mode to set Description The DMA controller supports several modes.

Chapter 6. The Device File System
devfs_register
Name devfs_register — Register a device entry. Synopsis
devfs_handle_t devfs_register (devfs_handle_t dir, const char * name, unsigned int namelen, unsigned int flags, unsigned int major, unsigned int minor, umode_t mode, uid_t uid, gid_t gid, void * ops, void * info);

Arguments
dir The handle to the parent devfs directory entry. If this is NULL the new name is relative to the root of the devfs. name The name of the entry. namelen The number of characters in name, not including a NULL terminator. If this is 0, then name must be NULL-terminated and the length is computed internally. flags A set of bitwise-ORed flags (DEVFS_FL_*). major The major number. Not needed for regular files. minor The minor number. Not needed for regular files.

121

Chapter 6. The Device File System

mode The default file mode. uid The default UID of the file. gid – undescribed – ops The &file_operations or &block_device_operations structure. This must not be externally deallocated. info An arbitrary pointer which will be written to the private_data field of the &file structure passed to the device driver. You can set this to whatever you like, and change it once the file is opened (the next file opened will not see this change).

Description
Returns a handle which may later be used in a call to devfs_unregister . On failure NULL is returned.

devfs_unregister
Name devfs_unregister — Unregister a device entry. Synopsis
void devfs_unregister (devfs_handle_t de);

Arguments

122

Chapter 6. The Device File System

de – undescribed –

de
A handle previously created by devfs_register or returned from devfs_find_handle . If this is NULL the routine does nothing.

devfs_mk_symlink
Name devfs_mk_symlink — Synopsis
int devfs_mk_symlink (devfs_handle_t dir, const char * name, unsigned int namelen, unsigned int flags, const char * link, unsigned int linklength, devfs_handle_t * handle, void * info);

Arguments
dir The handle to the parent devfs directory entry. If this is NULL the new name is relative to the root of the devfs. name The name of the entry. namelen The number of characters in name, not including a NULL terminator. If this is 0, then name must be NULL-terminated and the length is computed internally.

123

The Device File System flags A set of bitwise-ORed flags (DEVFS_FL_*). else a negative error code is returned. Arguments 124 . This may be NULL.Chapter 6. not including a NULL terminator. If this is 0. handle The handle to the symlink entry is written here. Synopsis devfs_handle_t devfs_mk_dir (devfs_handle_t dir. devfs_mk_dir Name devfs_mk_dir — Create a directory in the devfs namespace. void * info). Description Returns 0 on success. const char * name. unsigned int namelen. linklength The number of characters in link. info An arbitrary pointer which will be associated with the entry. then link must be NULL-terminated and the length is computed internally. link The destination name.

The devfs_register function will automatically create intermediate directories as needed. int traverse_symlinks). const char * name. The Device File System dir The handle to the parent devfs directory entry. If this is 0. as it provides a handle to a directory. devfs_find_handle Name devfs_find_handle — Find the handle of a devfs entry. char type. unsigned int namelen. info An arbitrary pointer which will be associated with the entry. Synopsis devfs_handle_t devfs_find_handle (devfs_handle_t dir. If this is NULL the new name is relative to the root of the devfs. namelen The number of characters in name. Description Use of this function is optional. unsigned int minor. This function is provided for efficiency reasons. unsigned int major. On failure NULL is returned. not including a NULL terminator.Chapter 6. name The name of the entry. Arguments 125 . then name must be NULL-terminated and the length is computed internally. Returns a handle which may later be used in a call to devfs_unregister .

traverse_symlinks If TRUE then symlink entries in the devfs namespace are traversed. On failure NULL is returned. namelen The number of characters in name.Chapter 6. or devfs_set_flags . name The name of the entry. Symlink traversal consumes stack space. devfs_get_flags . major The major number. The Device File System dir The handle to the parent devfs directory entry. This may be either DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLK . Symlinks pointing out of the devfs namespace will cause a failure. Description Returns a handle which may later be used in a call to devfs_unregister . If this is 0. This is used if name is NULL. This is used if name is NULL. 126 . not including a NULL terminator. If this is NULL the name is relative to the root of the devfs. then name must be NULL-terminated and the length is computed internally. devfs_get_flags Name devfs_get_flags — Get the flags for a devfs entry. type The type of special file to search for. minor The minor number.

127 . unsigned int * major. else a negative error code. unsigned int * minor). Arguments de The handle to the device entry. devfs_get_maj_min Name devfs_get_maj_min — Get the major and minor numbers for a devfs entry.Chapter 6. unsigned int * flags). Synopsis int devfs_get_maj_min (devfs_handle_t de. The Device File System Synopsis int devfs_get_flags (devfs_handle_t de. Arguments de The handle to the device entry. flags The flags are written here. Description Returns 0 on success.

Synopsis devfs_handle_t devfs_get_handle_from_inode (struct inode * inode). This may be NULL. devfs_get_handle_from_inode Name devfs_get_handle_from_inode — Get the devfs handle for a VFS inode. The Device File System major The major number is written here. Description Returns 0 on success. else a negative error code. minor The minor number is written here. This may be NULL. Arguments inode The VFS inode. else NULL. Description Returns the devfs handle on success.Chapter 6. 128 .

The Device File System devfs_generate_path Name devfs_generate_path — Generate a pathname for an entry. The pathname and ’\0’ terminator will be written at the end of the buffer.Chapter 6. relative to the devfs root. Synopsis int devfs_generate_path (devfs_handle_t de. Description Returns the offset in the buffer where the pathname starts on success. path The buffer to write the pathname to. else a negative error code. Arguments de The devfs entry. int buflen). devfs_get_ops Name devfs_get_ops — Get the device operations for a devfs entry. 129 . buflen The length of the buffer. char * path.

else NULL.Chapter 6. Arguments de The handle to the device entry. Synopsis int devfs_set_file_size (devfs_handle_t de. unsigned long size). The Device File System Synopsis void * devfs_get_ops (devfs_handle_t de). Arguments de – undescribed – size – undescribed – 130 . devfs_set_file_size Name devfs_set_file_size — Set the file size for a devfs regular file. Description Returns a pointer to the device operations on success.

131 . Returns 0 on success. else a negative error code.Chapter 6. Arguments de The handle to the device entry. The Device File System de The handle to the device entry. devfs_get_info Name devfs_get_info — Get the info pointer written to private_data of @de upon open. Description Returns the info pointer. Synopsis void * devfs_get_info (devfs_handle_t de). devfs_set_info Name devfs_set_info — Set the info pointer written to private_data upon open. size The new file size.

Arguments de The handle to the device entry. void * info). Synopsis devfs_handle_t devfs_get_parent (devfs_handle_t de).Chapter 6. Arguments de The handle to the device entry. info – undescribed – Description Returns 0 on success. devfs_get_parent Name devfs_get_parent — Get the parent device entry. else a negative error code. The Device File System Synopsis int devfs_set_info (devfs_handle_t de. 132 .

133 . devfs_get_first_child Name devfs_get_first_child — Get the first leaf node in a directory. Description Returns the leaf node device entry if it exists.Chapter 6. else NULL. else NULL. Synopsis devfs_handle_t devfs_get_next_sibling (devfs_handle_t de). The Device File System Description Returns the parent device entry if it exists. for a device entry. Synopsis devfs_handle_t devfs_get_first_child (devfs_handle_t de). Arguments de The handle to the device entry. devfs_get_next_sibling Name devfs_get_next_sibling — Get the next sibling leaf node.

Description Returns the leaf node device entry if it exists. Synopsis void devfs_auto_unregister (devfs_handle_t master.Chapter 6. slave The devfs entry which will be automatically unregistered when the master entry is unregistered. else NULL. It is illegal to call devfs_unregister on this entry. The Device File System Arguments de The handle to the device entry. Only one slave may be registered. devfs_auto_unregister Name devfs_auto_unregister — Configure a devfs entry to be automatically unregistered. devfs_handle_t slave). Arguments master The master devfs entry. 134 .

Chapter 6. The Device File System

devfs_get_unregister_slave
Name devfs_get_unregister_slave — Get the slave entry which will be automatically unregistered. Synopsis
devfs_handle_t devfs_get_unregister_slave (devfs_handle_t master);

Arguments
master The master devfs entry.

Description
Returns the slave which will be unregistered when master is unregistered.

devfs_register_chrdev
Name devfs_register_chrdev — Optionally register a conventional character driver. Synopsis
int devfs_register_chrdev (unsigned int major, const char * name, struct file_operations * fops);

135

Chapter 6. The Device File System

Arguments
major The major number for the driver. name The name of the driver (as seen in /proc/devices). fops The &file_operations structure pointer.

Description
This function will register a character driver provided the “devfs=only” option was not provided at boot time. Returns 0 on success, else a negative error code on failure.

devfs_register_blkdev
Name devfs_register_blkdev — Optionally register a conventional block driver. Synopsis
int devfs_register_blkdev (unsigned int major, const char * name, struct block_device_operations * bdops);

Arguments
major The major number for the driver. name The name of the driver (as seen in /proc/devices).

136

Chapter 6. The Device File System

bdops The &block_device_operations structure pointer.

Description
This function will register a block driver provided the “devfs=only” option was not provided at boot time. Returns 0 on success, else a negative error code on failure.

devfs_unregister_chrdev
Name devfs_unregister_chrdev — Optionally unregister a conventional character driver. Synopsis
int devfs_unregister_chrdev (unsigned int major, const char * name);

Arguments
major – undescribed – name – undescribed –

major
The major number for the driver.

name
The name of the driver (as seen in /proc/devices).

137

Description This function will unregister a block driver provided the “devfs=only” option was not provided at boot time. else a negative error code on failure. const char * name). name The name of the driver (as seen in /proc/devices). Synopsis int devfs_unregister_blkdev (unsigned int major.Chapter 6. 138 . Arguments major The major number for the driver. else a negative error code on failure. The Device File System This function will unregister a character driver provided the “devfs=only” option was not provided at boot time. Returns 0 on success. Returns 0 on success. devfs_unregister_blkdev Name devfs_unregister_blkdev — Optionally unregister a conventional block driver.

A &pm_dev structure is returned on success. pm_callback callback). on failure the return is NULL.Chapter 7. 139 . Power Management pm_register Name pm_register — register a device with power management Synopsis struct pm_dev * pm_register (pm_dev_t type. Arguments type device type id device ID callback callback function Description Add a device to the list of devices that wish to be notified about power management events. unsigned long id.

The dev passed must be a handle previously returned by pm_register. Power Management pm_unregister Name pm_unregister — unregister a device with power management Synopsis void pm_unregister (struct pm_dev * dev). pm_unregister_all Name pm_unregister_all — unregister all devices with matching callback Synopsis void pm_unregister_all (pm_callback callback). Arguments 140 . Arguments dev device to unregister Description Remove a device from the power management notification lists.Chapter 7.

void * data). pm_request_t rqst. pm_send Name pm_send — send request to a single device Synopsis int pm_send (struct pm_dev * dev. Power Management callback callback function pointer Description Unregister every device that would call the callback passed.Chapter 7. This is primarily meant as a helper function for loadable modules. The data field must hold the intended next state. It enables a module to give up all its managed devices without keeping its own private list. The PM_SUSPEND and PM_RESUME events are handled specially. No call is made if the state matches. Arguments dev device to send to rqst power management request data data for the callback Description Issue a power management request to a given device. 141 .

Zero is returned on success. Arguments rqst power management request data data for the callback Description Issue a power management request to a all devices. pm_send_all Name pm_send_all — send request to all managed devices Synopsis int pm_send_all (pm_request_t rqst. If any device vetoes a suspend request then all other devices that have suspended during the processing of this request are restored to their previous state. Any device is permitted to fail a suspend by returning a non zero (error) value from its callback function. If a suspend fails then the status from the device that vetoes the suspend is returned. 142 . void * data). BUGS what stops two power management requests occuring in parallel and conflicting. Power Management BUGS what stops two power management requests occuring in parallel and conflicting.Chapter 7. The PM_SUSPEND events are handled specially.

Arguments type type of device from where to start looking Description Scan the power management list for devices of a specific type. To search from the beginning pass NULL as the from value. Power Management pm_find Name pm_find — find a device Synopsis struct pm_dev * pm_find (pm_dev_t type. A NULL indicates the end of the list. The return value for a matching device may be passed to further calls to this function to find further matches.Chapter 7. 143 . struct pm_dev * from).

Miscellaneous Devices misc_register Name misc_register — register a miscellaneous device Synopsis int misc_register (struct miscdevice * misc). misc_deregister Name misc_deregister — unregister a miscellaneous device 144 . A zero is returned on success and a negative errno code for failure. For other cases the minor number requested is used. Arguments misc device structure Description Register a miscellaneous device with the kernel. If the minor number is set to MISC_DYNAMIC_MINOR a minor number is assigned and placed in the minor field of the structure.Chapter 8. The structure passed is linked into the kernel and may not be destroyed until it has been unregistered.

Arguments misc device to unregister Description Unregister a miscellaneous device that was previously successfully registered with misc_register. Success is indicated by a zero return. Miscellaneous Devices Synopsis int misc_deregister (struct miscdevice * misc). 145 .Chapter 8. a negative errno code indicates an error.

A teletext device VFL_TYPE_VBI .3.Chapter 9. Arguments vfd video device structure we want to register type type of device to register FIXME needs a semaphore on 2.x The registration code assigns minor numbers based on the type requested. int type). Video4Linux video_register_device Name video_register_device — register video4linux devices Synopsis int video_register_device (struct video_device * vfd. Zero is returned on success. -ENFILE is returned in all the device slots for this category are full.A radio card 146 . If not then the minor field is set and the driver initialize function is called (if non NULL).Vertical blank data (undecoded) VFL_TYPE_RADIO . Valid types are VFL_TYPE_GRABBER .A frame grabber VFL_TYPE_VTX .

Future open calls will be met with errors. Arguments vfd the device to unregister Description This unregisters the passed device and deassigns the minor number. Video4Linux video_unregister_device Name video_unregister_device — unregister a video4linux device Synopsis void video_unregister_device (struct video_device * vfd).Chapter 9. 147 .

int unit). On failure a negative error code is returned. register_sound_mixer Name register_sound_mixer — register a mixer device 148 .Chapter 10. The allocated number is returned on succes. Sound Devices register_sound_special Name register_sound_special — register a special sound node Synopsis int register_sound_special (struct file_operations * fops. Arguments fops File operations for the driver unit Unit number to allocate Description Allocate a special sound device by minor number from the sound subsystem.

On success the allocated number is returned. Pass -1 to request the next free mixer unit. on failure a negative error code is returned. register_sound_midi Name register_sound_midi — register a midi device Synopsis int register_sound_midi (struct file_operations * fops. Arguments fops File operations for the driver 149 . Sound Devices Synopsis int register_sound_mixer (struct file_operations * fops. Unit is the number of the mixer requested. int dev). Arguments fops File operations for the driver dev Unit number to allocate Description Allocate a mixer device.Chapter 10. int dev).

register_sound_dsp Name register_sound_dsp — register a DSP device Synopsis int register_sound_dsp (struct file_operations * fops. Arguments fops File operations for the driver dev Unit number to allocate Description Allocate a DSP device. Pass -1 to request the next free midi unit.eg dsp3/audio3 150 . Unit is the number of the midi device requested. Sound Devices dev Unit number to allocate Description Allocate a midi device. on failure a negative error code is returned. On success the allocated number is returned. On success the allocated number is returned. int dev). Pass -1 to request the next free DSP unit. Unit is the number of the DSP requested.Chapter 10. on failure a negative error code is returned. This function allocates both the audio and dsp device entries together and will always allocate them as a matching pair .

Sound Devices register_sound_synth Name register_sound_synth — register a synth device Synopsis int register_sound_synth (struct file_operations * fops. int dev). Arguments fops File operations for the driver dev Unit number to allocate Description Allocate a synth device. Unit is the number of the synth device requested. unregister_sound_special Name unregister_sound_special — unregister a special sound device Synopsis void unregister_sound_special (int unit). Pass -1 to request the next free synth unit. On success the allocated number is returned.Chapter 10. 151 . on failure a negative error code is returned.

unregister_sound_mixer Name unregister_sound_mixer — unregister a mixer Synopsis void unregister_sound_mixer (int unit). The unit passed is the return value from the register function. The unit passed is the return value from the register function.Chapter 10. 152 . Sound Devices Arguments unit unit number to allocate Description Release a sound device that was allocated with register_sound_special . Arguments unit unit number to allocate Description Release a sound device that was allocated with register_sound_mixer .

Arguments unit unit number to allocate Description Release a sound device that was allocated with register_sound_midi . unregister_sound_dsp Name unregister_sound_dsp — unregister a DSP device Synopsis void unregister_sound_dsp (int unit). Sound Devices unregister_sound_midi Name unregister_sound_midi — unregister a midi device Synopsis void unregister_sound_midi (int unit). The unit passed is the return value from the register function. Arguments 153 .Chapter 10.

Chapter 10. Both of the allocated units are released together automatically. Arguments unit unit number to allocate Description Release a sound device that was allocated with register_sound_synth . unregister_sound_synth Name unregister_sound_synth — unregister a synth device Synopsis void unregister_sound_synth (int unit). The unit passed is the return value from the register function. The unit passed is the return value from the register function. Sound Devices unit unit number to allocate Description Release a sound device that was allocated with register_sound_dsp . 154 .

Chapter 11. The port is then probed and if neccessary the IRQ is autodetected If this fails an error is returned. Arguments req request structure Description Configure the serial port specified by the request. 16x50 UART Driver register_serial Name register_serial — configure a 16x50 serial port at runtime Synopsis int register_serial (struct serial_struct * req). If the port is not currently in the table it is added. On success the port is ready to use and the line number is returned. If the port exists and is in use an error is returned. unregister_serial Name unregister_serial — deconfigure a 16x50 serial port 155 .

156 .Chapter 11. Arguments line line to deconfigure Description The port specified is deconfigured and its resources are freed. 16x50 UART Driver Synopsis void unregister_serial (int line). Line is the port number returned by register_serial . Any user of the port is disconnected as if carrier was dropped.

Arguments irq Interrupt number dev_id The Z8530 device that is interrupting. regs unused Description A Z85[2]30 device has stuck its hand in the air for attention. We scan both the channels on the chip for events and then call the channel specific call backs for each channel that has events. Z85230 Support Library z8530_interrupt Name z8530_interrupt — Handle an interrupt from a Z8530 Synopsis void z8530_interrupt (int irq.Chapter 12. 157 . struct pt_regs * regs). We have to use callback functions because the two channels can be in different modes. void * dev_id.

struct z8530_channel * c).Chapter 12. struct z8530_channel * c). z8530_sync_close Name z8530_sync_close — Close a PIO Z8530 channel Synopsis int z8530_sync_close (struct net_device * dev. We raise the RTS/DTR and commence network operation. 158 . Arguments dev The network interface we are using c The Z8530 channel to open in synchronous PIO mode Description Switch a Z8530 into synchronous mode without DMA assist. Z85230 Support Library z8530_sync_open Name z8530_sync_open — Open a Z8530 channel for PIO Synopsis int z8530_sync_open (struct net_device * dev.

Arguments dev The network device to attach c The Z8530 channel to configure in sync DMA mode.Chapter 12. z8530_sync_dma_open Name z8530_sync_dma_open — Open a Z8530 for DMA I/O Synopsis int z8530_sync_dma_open (struct net_device * dev. Z85230 Support Library Arguments dev Network device to close c Z8530 channel to disassociate and move to idle Description Close down a Z8530 interface and switch its interrupt handlers to discard future events. struct z8530_channel * c). Description 159 .

We assume ISA DMA driven I/O and PC limits on access. z8530_sync_dma_close Name z8530_sync_dma_close — Close down DMA I/O Synopsis int z8530_sync_dma_close (struct net_device * dev. Halt the DMA. and free the buffers. Two ISA DMA channels must be available for this to work. Arguments dev Network device to detach c Z8530 channel to move into discard mode Description Shut down a DMA mode synchronous interface. Z85230 Support Library Set up a Z85x30 device for synchronous DMA in both directions. struct z8530_channel * c). z8530_sync_txdma_open Name z8530_sync_txdma_open — Open a Z8530 for TX driven DMA 160 .Chapter 12.

Description Set up a Z85x30 device for synchronous DMA tranmission. struct z8530_channel * c). z8530_sync_txdma_close Name z8530_sync_txdma_close — Close down a TX driven DMA channel Synopsis int z8530_sync_txdma_close (struct net_device * dev. struct z8530_channel * c). but then it has the bigger FIFO. The receive side is run in PIO mode. Z85230 Support Library Synopsis int z8530_sync_txdma_open (struct net_device * dev. Arguments dev Network device to detach 161 .Chapter 12. Arguments dev The network device to attach c The Z8530 channel to configure in sync DMA mode. One ISA DMA channel must be available for this to work.

Arguments dev Z8530 device to describe mapping string holding mapping type (eg “I/O” or “Mem”) io the port value in question Description Describe a Z8530 in a standard format. 162 . char * mapping. unsigned long io). Halt the DMA. and free the buffers.Chapter 12. z8530_describe Name z8530_describe — Uniformly describe a Z8530 port Synopsis void z8530_describe (struct z8530_dev * dev. The main reason for this function is to try and get a common format of report. We must pass the I/O as the port offset isnt predictable. Z85230 Support Library c Z8530 channel to move into discard mode Description Shut down a DMA/PIO split mode synchronous interface.

or a negative value indicating the problem in errno form. 163 .Chapter 12. We set the interrupt handler up to discard any events. Description Configure up a Z8530/Z85C30 or Z85230 chip. Z85230 Support Library z8530_init Name z8530_init — Initialise a Z8530 device Synopsis int z8530_init (struct z8530_dev * dev). in case we get them during reset or setp. We check the device is present. Return 0 for success. a Z8530 in the wrong state will sometimes get into stupid modes generating 10Khz interrupt streams and the like. Arguments dev Z8530 device to initialise. This matters a lot. identify the type and then program it to hopefully keep quite and behave. z8530_shutdown Name z8530_shutdown — Shutdown a Z8530 device Synopsis int z8530_shutdown (struct z8530_dev * dev).

Z85230 Support Library Arguments dev The Z8530 chip to shutdown Description We set the interrupt handlers to silence any interrupts. Arguments c Z8530 channel to configure rtable table of register.Chapter 12. 164 . The value 255 terminates the table. value pairs FIXME ioctl to allow user uploaded tables Load a Z8530 channel up from the system data. We use +16 to indicate the “prime” registers. z8530_channel_load Name z8530_channel_load — Load channel data Synopsis int z8530_channel_load (struct z8530_channel * c. u8 * rtable). We then reset the chip and wait 100uS to be sure the reset completed. Just in case the caller then tries to do stuff.

Instead of syncppp processing the frames we get to throw them away. 165 . struct sk_buff * skb). struct sk_buff * skb). Arguments c The channel the packet arrived on skb The buffer Description We point the receive handler at this function when idle. Z85230 Support Library z8530_null_rx Name z8530_null_rx — Discard a packet Synopsis void z8530_null_rx (struct z8530_channel * c. z8530_queue_xmit Name z8530_queue_xmit — Queue a packet Synopsis int z8530_queue_xmit (struct z8530_channel * c.Chapter 12.

Arguments c The channel to use Description Get the statistics block. z8530_get_stats Name z8530_get_stats — Get network statistics Synopsis struct net_device_stats * z8530_get_stats (struct z8530_channel * c).Chapter 12. Z85230 Support Library Arguments c The channel to use skb The packet to kick down the channel Description Queue a packet for transmission. Because we have rather hard to hit interrupt latencies for the Z85230 per packet even in DMA mode we do the flip to DMA buffer if needed here not in the IRQ. 166 . We keep the statistics in software as the chip doesn’t do it for us.

Sign up to vote on this title
UsefulNot useful