1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998 |
- /*++
- Copyright (c) 2013 Minoca Corp. All Rights Reserved
- Module Name:
- atl1chw.c
- Abstract:
- This module implements the portion of the ATL1c driver that actually
- interacts with the hardware.
- Author:
- Evan Green 18-Apr-2013
- Environment:
- Kernel
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <minoca/kernel/driver.h>
- #include <minoca/net/netdrv.h>
- #include "atl1c.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Define the maximum amount of packets that ATL will keep queued before it
- // starts to drop packets.
- //
- //
- #define ATL_MAX_TRANSMIT_PACKET_LIST_COUNT (ATL1C_TRANSMIT_DESCRIPTOR_COUNT * 2)
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- VOID
- AtlpReapCompletedTransmitDescriptors (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpSendPendingPackets (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpReapReceivedFrames (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpDisableL0sAndL1 (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpResetPhy (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpApplyChipReset (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpStopController (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpStopMac (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpStopQueue (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpSetupReceiveFilters (
- PATL1C_DEVICE Device
- );
- KSTATUS
- AtlpEnableDevice (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpStartQueue (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpConfigureMac (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpReadPhyDebugRegister (
- PATL1C_DEVICE Device,
- USHORT Register,
- PUSHORT Data
- );
- BOOL
- AtlpWritePhyDebugRegister (
- PATL1C_DEVICE Device,
- USHORT Register,
- USHORT Data
- );
- BOOL
- AtlpPerformPhyRegisterIo (
- PATL1C_DEVICE Device,
- BOOL Write,
- BOOL Extension,
- UCHAR Address,
- USHORT Register,
- PUSHORT Data
- );
- ULONG
- AtlpWaitForIdleUnit (
- PATL1C_DEVICE Device,
- ULONG BitsToBecomeClear
- );
- BOOL
- AtlpReadMacAddress (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpDoesEepromExist (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpReadCurrentMacAddress (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpDisableDeviceInterrupts (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpEnableDeviceInterrupts (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpSetActiveStatePowerManagement (
- PATL1C_DEVICE Device,
- ATL_SPEED Speed
- );
- VOID
- AtlpResetTransmitRing (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpResetReceiveRing (
- PATL1C_DEVICE Device
- );
- BOOL
- AtlpGetLinkCharacteristics (
- PATL1C_DEVICE Device,
- PATL_SPEED Speed,
- PATL_DUPLEX_MODE Duplex
- );
- ULONG
- AtlpHashAddress (
- PUCHAR MacAddress
- );
- RUNLEVEL
- AtlpAcquireInterruptLock (
- PATL1C_DEVICE Device
- );
- VOID
- AtlpReleaseInterruptLock (
- PATL1C_DEVICE Device,
- RUNLEVEL OldRunLevel
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- BOOL AtlDisablePacketDropping = FALSE;
- //
- // ------------------------------------------------------------------ Functions
- //
- KSTATUS
- AtlSend (
- PVOID DeviceContext,
- PNET_PACKET_LIST PacketList
- )
- /*++
- Routine Description:
- This routine sends data through the network.
- Arguments:
- DeviceContext - Supplies a pointer to the device context associated with
- the link down which this data is to be sent.
- PacketList - Supplies a pointer to a list of network packets to send. Data
- in these packets may be modified by this routine, but must not be used
- once this routine returns.
- Return Value:
- STATUS_SUCCESS if all packets were sent.
- STATUS_RESOURCE_IN_USE if some or all of the packets were dropped due to
- the hardware being backed up with too many packets to send.
- Other failure codes indicate that none of the packets were sent.
- --*/
- {
- PATL1C_DEVICE Device;
- UINTN PacketListCount;
- KSTATUS Status;
- ASSERT(KeGetRunLevel() == RunLevelLow);
- Device = (PATL1C_DEVICE)DeviceContext;
- KeAcquireQueuedLock(Device->TransmitLock);
- if (Device->LinkActive == FALSE) {
- Status = STATUS_NO_NETWORK_CONNECTION;
- goto SendEnd;
- }
- //
- // If there is any room in the packet list (or dropping packets is
- // disabled), add all of the packets to the list waiting to be sent.
- //
- PacketListCount = Device->TransmitPacketList.Count;
- if ((PacketListCount < ATL_MAX_TRANSMIT_PACKET_LIST_COUNT) ||
- (AtlDisablePacketDropping != FALSE)) {
- NET_APPEND_PACKET_LIST(PacketList, &(Device->TransmitPacketList));
- AtlpSendPendingPackets(Device);
- Status = STATUS_SUCCESS;
- //
- // Otherwise report that the resource is use as it is too busy to handle
- // more packets.
- //
- } else {
- Status = STATUS_RESOURCE_IN_USE;
- }
- SendEnd:
- KeReleaseQueuedLock(Device->TransmitLock);
- return Status;
- }
- KSTATUS
- AtlGetSetInformation (
- PVOID DeviceContext,
- NET_LINK_INFORMATION_TYPE InformationType,
- PVOID Data,
- PUINTN DataSize,
- BOOL Set
- )
- /*++
- Routine Description:
- This routine gets or sets the network device layer's link information.
- Arguments:
- DeviceContext - Supplies a pointer to the device context associated with
- the link for which information is being set or queried.
- InformationType - Supplies the type of information being queried or set.
- Data - Supplies a pointer to the data buffer where the data is either
- returned for a get operation or given for a set operation.
- DataSize - Supplies a pointer that on input contains the size of the data
- buffer. On output, contains the required size of the data buffer.
- Set - Supplies a boolean indicating if this is a get operation (FALSE) or a
- set operation (TRUE).
- Return Value:
- Status code.
- --*/
- {
- PULONG Flags;
- KSTATUS Status;
- switch (InformationType) {
- case NetLinkInformationChecksumOffload:
- if (*DataSize != sizeof(ULONG)) {
- return STATUS_INVALID_PARAMETER;
- }
- if (Set != FALSE) {
- return STATUS_NOT_SUPPORTED;
- }
- Flags = (PULONG)Data;
- *Flags = 0;
- break;
- default:
- Status = STATUS_NOT_SUPPORTED;
- break;
- }
- return Status;
- }
- KSTATUS
- AtlpInitializeDeviceStructures (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine performs housekeeping preparation for resetting and enabling
- an ATL1c device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- Status code.
- --*/
- {
- ULONG AllocationSize;
- ULONG IoBufferFlags;
- PHYSICAL_ADDRESS PhysicalAddress;
- ULONG Size;
- ULONG SlotIndex;
- KSTATUS Status;
- KeInitializeSpinLock(&(Device->InterruptLock));
- Device->Speed = AtlSpeedOff;
- Device->Duplex = AtlDuplexInvalid;
- Device->EnabledInterrupts = ATL_INTERRUPT_DEFAULT_MASK;
- //
- // Allocate the transmit and receive locks.
- //
- Device->TransmitLock = KeCreateQueuedLock();
- if (Device->TransmitLock == NULL) {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto InitializeDeviceStructuresEnd;
- }
- Device->ReceiveLock = KeCreateQueuedLock();
- if (Device->ReceiveLock == NULL) {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto InitializeDeviceStructuresEnd;
- }
- //
- // Allocate the descriptor buffer to hold the transmit descriptors,
- // transmit buffer array, receive slot array, received packet status array,
- // and the received frame data itself. The transmit queue has one extra
- // descriptor for the empty high priority queue.
- //
- AllocationSize = ((ATL1C_TRANSMIT_DESCRIPTOR_COUNT + 1) *
- sizeof(ATL1C_TRANSMIT_DESCRIPTOR)) +
- (ATL1C_TRANSMIT_DESCRIPTOR_COUNT * sizeof(PVOID)) +
- (ATL1C_RECEIVE_FRAME_COUNT *
- (sizeof(ATL1C_RECEIVE_SLOT) +
- sizeof(ATL1C_RECEIVED_PACKET) +
- ATL1C_RECEIVE_FRAME_DATA_SIZE));
- ASSERT(Device->DescriptorIoBuffer == NULL);
- IoBufferFlags = IO_BUFFER_FLAG_PHYSICALLY_CONTIGUOUS;
- Device->DescriptorIoBuffer = MmAllocateNonPagedIoBuffer(0,
- MAX_ULONG,
- 8,
- AllocationSize,
- IoBufferFlags);
- if (Device->DescriptorIoBuffer == NULL) {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto InitializeDeviceStructuresEnd;
- }
- ASSERT(Device->DescriptorIoBuffer->FragmentCount == 1);
- //
- // Zero out everything except the receive packet data buffers.
- //
- Size = AllocationSize -
- (ATL1C_RECEIVE_FRAME_DATA_SIZE * ATL1C_RECEIVE_FRAME_COUNT);
- RtlZeroMemory(Device->DescriptorIoBuffer->Fragment[0].VirtualAddress, Size);
- //
- // Carve up the buffer and give each array its piece.
- //
- Device->TransmitDescriptor =
- Device->DescriptorIoBuffer->Fragment[0].VirtualAddress;
- Device->TransmitBuffer =
- (PNET_PACKET_BUFFER *)(Device->TransmitDescriptor +
- (ATL1C_TRANSMIT_DESCRIPTOR_COUNT + 1));
- Device->ReceiveSlot =
- (PATL1C_RECEIVE_SLOT)(Device->TransmitBuffer +
- ATL1C_TRANSMIT_DESCRIPTOR_COUNT);
- Device->ReceivedPacket =
- (PATL1C_RECEIVED_PACKET)(Device->ReceiveSlot +
- ATL1C_RECEIVE_FRAME_COUNT);
- Device->ReceivedPacketData =
- (PVOID)(Device->ReceivedPacket + ATL1C_RECEIVE_FRAME_COUNT);
- //
- // Initialize the receive slots.
- //
- PhysicalAddress = Device->DescriptorIoBuffer->Fragment[0].PhysicalAddress +
- AllocationSize -
- (ATL1C_RECEIVE_FRAME_COUNT *
- ATL1C_RECEIVE_FRAME_DATA_SIZE);
- for (SlotIndex = 0; SlotIndex < ATL1C_RECEIVE_FRAME_COUNT; SlotIndex += 1) {
- Device->ReceiveSlot[SlotIndex].PhysicalAddress = PhysicalAddress;
- PhysicalAddress += ATL1C_RECEIVE_FRAME_DATA_SIZE;
- }
- NET_INITIALIZE_PACKET_LIST(&(Device->TransmitPacketList));
- Device->ReceiveNextToClean = 0;
- Device->TransmitNextToClean = 0;
- Device->TransmitNextToUse = 0;
- Status = STATUS_SUCCESS;
- InitializeDeviceStructuresEnd:
- if (!KSUCCESS(Status)) {
- if (Device->DescriptorIoBuffer != NULL) {
- MmFreeIoBuffer(Device->DescriptorIoBuffer);
- Device->TransmitDescriptor = NULL;
- Device->TransmitBuffer = NULL;
- Device->ReceiveSlot = NULL;
- Device->ReceivedPacket = NULL;
- }
- }
- return Status;
- }
- KSTATUS
- AtlpResetDevice (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine resets the ATL1c device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- Status code.
- --*/
- {
- PHYSICAL_ADDRESS PhysicalAddress;
- BOOL Result;
- KSTATUS Status;
- ULONG Value;
- ASSERT(KeGetRunLevel() == RunLevelLow);
- Status = STATUS_DEVICE_IO_ERROR;
- Device->Speed = AtlSpeedOff;
- Device->Duplex = AtlDuplexInvalid;
- //
- // Clear any lingering PCI express protocol errors.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterPexUncErrSev);
- Value &= ~(ATL_PEX_UNC_ERR_SEV_DLP | ATL_PEX_UNC_ERR_SEV_FCP);
- ATL_WRITE_REGISTER32(Device, AtlRegisterPexUncErrSev, Value);
- //
- // Reset the Link Training and Status State Machine.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterLtssmIdControl);
- Value &= ~ATL_LTSSM_ID_ENABLE_WRO;
- ATL_WRITE_REGISTER32(Device, AtlRegisterLtssmIdControl, Value);
- Value = ATL_READ_REGISTER32(Device, AtlRegisterPhyMiscellaneous);
- Value |= ATL_PHY_MISCELLANEOUS_FORCE_RECEIVE_DETECT;
- ATL_WRITE_REGISTER32(Device, AtlRegisterPhyMiscellaneous, Value);
- AtlpDisableL0sAndL1(Device);
- Result = AtlpResetPhy(Device);
- if (Result == FALSE) {
- goto ResetDeviceEnd;
- }
- //
- // Stop anything currently going on.
- //
- Result = AtlpStopController(Device);
- if (Result == FALSE) {
- goto ResetDeviceEnd;
- }
- //
- // Apply a reset to the master control register to get the chip in a
- // known state.
- //
- Result = AtlpApplyChipReset(Device);
- if (Result == FALSE) {
- goto ResetDeviceEnd;
- }
- Result = AtlpReadMacAddress(Device);
- if (Result == FALSE) {
- goto ResetDeviceEnd;
- }
- //
- // Notify the networking core of this new link now that the device is ready
- // to send and receive data, pending media being present.
- //
- if (Device->NetworkLink == NULL) {
- Status = AtlpAddNetworkDevice(Device);
- if (!KSUCCESS(Status)) {
- goto ResetDeviceEnd;
- }
- }
- KeAcquireQueuedLock(Device->ReceiveLock);
- AtlpResetReceiveRing(Device);
- KeReleaseQueuedLock(Device->ReceiveLock);
- KeAcquireQueuedLock(Device->TransmitLock);
- AtlpResetTransmitRing(Device);
- KeReleaseQueuedLock(Device->TransmitLock);
- //
- // Enable all clocks and disable WOL (which would interfere with normal
- // operation).
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterClockGatingControl, 0);
- ATL_READ_REGISTER32(Device, AtlRegisterWakeOnLanControl);
- ATL_WRITE_REGISTER32(Device, AtlRegisterWakeOnLanControl, 0);
- //
- // Configure the descriptor rings, starting with the transmit queue. The
- // normal priority queue (priority 0) gets all the descriptors. The high
- // priority queue, which is unused, gets a single descriptor to pacify it.
- //
- PhysicalAddress = Device->DescriptorIoBuffer->Fragment[0].PhysicalAddress;
- ATL_WRITE_REGISTER32(
- Device,
- AtlRegisterTransmitBaseAddressHigh,
- (ULONG)(PhysicalAddress >> ATL_RING_HIGH_ADDRESS_SHIFT));
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterTransmitBaseAddressLow,
- (ULONG)PhysicalAddress);
- PhysicalAddress += sizeof(ATL1C_TRANSMIT_DESCRIPTOR) *
- ATL1C_TRANSMIT_DESCRIPTOR_COUNT;
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterTransmitBaseAddressLowHighPriority,
- 0);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterTransmitRingSize,
- ATL1C_TRANSMIT_DESCRIPTOR_COUNT);
- //
- // Set up the Receive Free Descriptor ring. Only the first queue is used.
- //
- PhysicalAddress += sizeof(ATL1C_TRANSMIT_DESCRIPTOR) +
- (sizeof(PVOID) * ATL1C_TRANSMIT_DESCRIPTOR_COUNT);
- ATL_WRITE_REGISTER32(
- Device,
- AtlRegisterReceiveBaseAddressHigh,
- (ULONG)(PhysicalAddress >> ATL_RING_HIGH_ADDRESS_SHIFT));
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveBaseAddressLow,
- (ULONG)PhysicalAddress);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceive1BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceive2BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceive3BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveSlotRingSize,
- ATL1C_RECEIVE_FRAME_COUNT);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveBufferSize,
- ATL1C_RECEIVE_FRAME_DATA_SIZE);
- //
- // Set up the Received Packet Status ring.
- //
- PhysicalAddress += sizeof(ATL1C_RECEIVE_SLOT) * ATL1C_RECEIVE_FRAME_COUNT;
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveRingBaseAddressLow,
- (ULONG)PhysicalAddress);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveRing1BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveRing2BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveRing3BaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveStatusRingSize,
- ATL1C_RECEIVE_FRAME_COUNT);
- //
- // The CMB and SMB pointers aren't used.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterCmbBaseAddressLow, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterSmbBaseAddressHigh, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterSmbBaseAddressLow, 0);
- //
- // Officially load all those ring pointers into the device.
- //
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterLoadRingPointers,
- ATL_LOAD_POINTERS_COMMAND_GO);
- //
- // Set up the interrupt moderator timer.
- //
- Value = ((ATL_MICROSECONDS(ATL_TRANSMIT_INTERRUPT_TIMER_VALUE) &
- ATL_INTERRUPT_TIMER_TRANSMIT_MASK) <<
- ATL_INTERRUPT_TIMER_TRANSMIT_SHIFT) |
- ((ATL_MICROSECONDS(ATL_RECEIVE_INTERRUPT_TIMER_VALUE) &
- ATL_INTERRUPT_TIMER_RECEIVE_MASK) <<
- ATL_INTERRUPT_TIMER_RECEIVE_SHIFT);
- ATL_WRITE_REGISTER32(Device, AtlRegisterInterruptTimers, Value);
- //
- // Set the timers to be enabled, and disable interrupt status clear on
- // read.
- //
- Value = ATL_MASTER_CONTROL_SYSTEM_ALIVE_TIMER |
- ATL_MASTER_CONTROL_TRANSMIT_ITIMER_ENABLE |
- ATL_MASTER_CONTROL_RECEIVE_ITIMER_ENABLE;
- ATL_WRITE_REGISTER32(Device, AtlRegisterMasterControl, Value);
- //
- // Disable the interrupt retrigger timer to prevent unserviced interrupts
- // from coming back.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterInterruptRetriggerTimer, 0);
- //
- // Disable the CMB and SMB timers.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterCmbTransmitTimer, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterSmbStatTimer, 0);
- //
- // Set the Maximum Transmission Unit.
- //
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterMaximumTransmissionUnit,
- ATL_L2CB_MAX_TRANSMIT_LENGTH);
- ATL_WRITE_REGISTER32(Device, AtlRegisterHdsControl, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterIpgIfgControl, ATL_IPG_IFG_VALUE);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterHalfDuplexControl,
- ATL_HALF_DUPLEX_CONTROL_VALUE);
- //
- // Set up the transmit parameters.
- //
- Value = (ATL_TRANSMIT_TCP_SEGMENTATION_OFFSET_FRAME_SIZE >>
- ATL_TCP_SEGMENTATION_OFFLOAD_THRESHOLD_DOWNSHIFT) &
- ATL_TCP_SEGMENTATION_OFFLOAD_THRESHOLD_MASK;
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterTcpSegmentationOffloadThreshold,
- Value);
- Value = ((ATL_TRANSMIT_DESCRIPTOR_BURST_COUNT &
- ATL_TRANSMIT_QUEUE_CONTROL_BURST_MASK) <<
- ATL_TRANSMIT_QUEUE_CONTROL_BURST_SHIFT) |
- ATL_TRANSMIT_QUEUE_CONTROL_ENHANCED_MODE |
- ((ATL_L2CB_TRANSMIT_TXF_BURST_PREF &
- ATL_TRANSMIT_QUEUE_CONTROL_BURST_NUMBER_MASK) <<
- ATL_TRANSMIT_QUEUE_CONTROL_BURST_NUMBER_SHIFT);
- ATL_WRITE_REGISTER32(Device, AtlRegisterTransmitQueueControl, Value);
- //
- // Configure receive free slot pre-fetching.
- //
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveFreeThreshold,
- ATL_RECEIVE_FREE_THRESHOLD_VALUE);
- //
- // Disable RSS.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterRssIdtTable0, 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterRssCpu, 0);
- //
- // Configure the receive queue.
- //
- Value = ((ATL_RECEIVE_DESCRIPTOR_BURST_COUNT &
- ATL_RECEIVE_QUEUE_CONTROL_BURST_MASK) <<
- ATL_RECEIVE_QUEUE_CONTROL_BURST_SHIFT);
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveQueueControl, Value);
- //
- // Configure DMA.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterDmaControl, ATL_DMA_CONTROL_VALUE);
- //
- // Configure the MAC. The speed/duplex settings get reconfigured a bit once
- // the link is determined to be established.
- //
- Value = ATL_MAC_CONTROL_ADD_CRC | ATL_MAC_CONTROL_PAD |
- ATL_MAC_CONTROL_DUPLEX |
- ((ATL_PREAMBLE_LENGTH &
- ATL_MAC_CONTROL_PREAMBLE_LENGTH_MASK) <<
- ATL_MAC_CONTROL_PREAMBLE_LENGTH_SHIFT) |
- (ATL_MAC_CONTROL_SPEED_10_100 << ATL_MAC_CONTROL_SPEED_SHIFT);
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- AtlpSetupReceiveFilters(Device);
- //
- // Disable hardware stripping of the VLAN tag. If VLAN support is added,
- // this bit would need to be set here.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMacControl);
- Value &= ~ATL_MAC_CONTROL_STRIP_VLAN;
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- //
- // Write the current producer index of the transmit ring.
- //
- ATL_WRITE_REGISTER16(Device,
- AtlRegisterTransmitNextIndex,
- Device->TransmitNextToClean);
- //
- // Clear any pending interrupts.
- //
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterInterruptStatus,
- ATL_INTERRUPT_MASK);
- //
- // Everything's set up, re-enable interrupts and fire up the device.
- //
- Status = AtlpEnableDevice(Device);
- if (!KSUCCESS(Status)) {
- goto ResetDeviceEnd;
- }
- AtlpEnableDeviceInterrupts(Device);
- ResetDeviceEnd:
- return Status;
- }
- INTERRUPT_STATUS
- AtlpInterruptService (
- PVOID Context
- )
- /*++
- Routine Description:
- This routine implements the ATL1c interrupt service routine.
- Arguments:
- Context - Supplies the context pointer given to the system when the
- interrupt was connected. In this case, this points to the ATL1c device
- structure.
- Return Value:
- Interrupt status.
- --*/
- {
- PATL1C_DEVICE Device;
- INTERRUPT_STATUS InterruptStatus;
- ULONG PendingBits;
- USHORT Value;
- Device = (PATL1C_DEVICE)Context;
- InterruptStatus = InterruptStatusNotClaimed;
- //
- // Read the status register, and if nothing is set then return immediately.
- //
- PendingBits = ATL_READ_REGISTER32(Device, AtlRegisterInterruptStatus);
- if (((PendingBits & Device->EnabledInterrupts) == 0) ||
- ((PendingBits & ATL_INTERRUPT_DISABLE) != 0)) {
- return InterruptStatus;
- }
- InterruptStatus = InterruptStatusClaimed;
- //
- // There are interrupt bits set, so mark this interrupt as claimed.
- //
- KeAcquireSpinLock(&(Device->InterruptLock));
- RtlAtomicOr32(&(Device->PendingInterrupts), PendingBits);
- //
- // The GPHY bit cannot be masked or cleared by the controller directly.
- // Read the PHY interrupt status register to clear the interrupt.
- //
- if ((PendingBits & ATL_INTERRUPT_GPHY) != 0) {
- AtlpPerformPhyRegisterIo(Device,
- FALSE,
- FALSE,
- 0,
- ATL_PHY_MII_INTERRUPT_STATUS,
- &Value);
- }
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterInterruptStatus,
- PendingBits | ATL_INTERRUPT_DISABLE);
- KeReleaseSpinLock(&(Device->InterruptLock));
- return InterruptStatus;
- }
- INTERRUPT_STATUS
- AtlpInterruptServiceWorker (
- PVOID Parameter
- )
- /*++
- Routine Description:
- This routine processes interrupts for the ATL1c controller at low level.
- Arguments:
- Parameter - Supplies an optional parameter passed in by the creator of the
- work item.
- Return Value:
- Interrupt Status.
- --*/
- {
- PATL1C_DEVICE Device;
- ULONG PendingBits;
- INTERRUPT_STATUS Status;
- Device = (PATL1C_DEVICE)(Parameter);
- ASSERT(KeGetRunLevel() == RunLevelLow);
- //
- // Clear out the pending bits.
- //
- PendingBits = RtlAtomicExchange32(&(Device->PendingInterrupts), 0);
- if (PendingBits == 0) {
- Status = InterruptStatusNotClaimed;
- goto InterruptServiceWorkerEnd;
- }
- Status = InterruptStatusClaimed;
- if ((PendingBits & ATL_INTERRUPT_BUFFER_ERROR_MASK) != 0) {
- RtlDebugPrint("ATL: Buffer Error 0x%08x.\n", PendingBits);
- }
- //
- // If the interrupt indicates new packets are coming in, grab them.
- //
- if ((PendingBits & ATL_INTERRUPT_RECEIVE_PACKET_MASK) != 0) {
- AtlpReapReceivedFrames(Device);
- }
- //
- // If packets were sent out, reap the completed transmissions.
- //
- if ((PendingBits & ATL_INTERRUPT_TRANSMIT_PACKET) != 0) {
- AtlpReapCompletedTransmitDescriptors(Device);
- }
- //
- // If an error occurred, reset the MAC.
- //
- if ((PendingBits & ATL_INTERRUPT_ERROR_MASK) != 0) {
- NetSetLinkState(Device->NetworkLink, FALSE, 0);
- AtlpStopController(Device);
- AtlpEnableDevice(Device);
- }
- //
- // Handle a link event change.
- //
- if ((PendingBits & (ATL_INTERRUPT_MANUAL | ATL_INTERRUPT_GPHY)) != 0) {
- AtlpDisableDeviceInterrupts(Device);
- AtlpEnableDevice(Device);
- AtlpEnableDeviceInterrupts(Device);
- }
- InterruptServiceWorkerEnd:
- ATL_WRITE_REGISTER32(Device, AtlRegisterInterruptStatus, 0);
- return Status;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- VOID
- AtlpReapCompletedTransmitDescriptors (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine cleans out any transmit descriptors that have already been
- handled by the controller. This routine must be called at low level and
- assumes the transmit lock is already held.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- USHORT CurrentIndex;
- PATL1C_TRANSMIT_DESCRIPTOR Descriptor;
- BOOL DescriptorReaped;
- USHORT HardwareIndex;
- KeAcquireQueuedLock(Device->TransmitLock);
- HardwareIndex = ATL_READ_REGISTER16(Device,
- AtlRegisterTransmitCurrentIndex);
- DescriptorReaped = FALSE;
- if (Device->TransmitNextToClean != HardwareIndex) {
- DescriptorReaped = TRUE;
- }
- while (Device->TransmitNextToClean != HardwareIndex) {
- CurrentIndex = Device->TransmitNextToClean;
- Descriptor = &(Device->TransmitDescriptor[CurrentIndex]);
- ASSERT(Device->TransmitBuffer[CurrentIndex] != NULL);
- NetFreeBuffer(Device->TransmitBuffer[CurrentIndex]);
- Device->TransmitBuffer[CurrentIndex] = NULL;
- Descriptor->PhysicalAddress = 0;
- Descriptor->BufferLength = 0;
- Device->TransmitNextToClean += 1;
- if (Device->TransmitNextToClean == ATL1C_TRANSMIT_DESCRIPTOR_COUNT) {
- Device->TransmitNextToClean = 0;
- }
- }
- //
- // If space was freed up, signal the event unblocking any parties waiting
- // for transmit descriptors.
- //
- if (DescriptorReaped != FALSE) {
- AtlpSendPendingPackets(Device);
- }
- KeReleaseQueuedLock(Device->TransmitLock);
- return;
- }
- VOID
- AtlpSendPendingPackets (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine sends as many packets as can fit in the hardware descriptor
- buffer. This routine assumes the transmit lock is already held.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- PATL1C_TRANSMIT_DESCRIPTOR Descriptor;
- ULONG DescriptorIndex;
- PNET_PACKET_BUFFER Packet;
- BOOL PacketQueued;
- ASSERT(KeIsQueuedLockHeld(Device->TransmitLock) != FALSE);
- //
- // Fill up the open descriptors with as many pending packets as possible.
- //
- PacketQueued = FALSE;
- while (NET_PACKET_LIST_EMPTY(&(Device->TransmitPacketList)) == FALSE) {
- Packet = LIST_VALUE(Device->TransmitPacketList.Head.Next,
- NET_PACKET_BUFFER,
- ListEntry);
- DescriptorIndex = Device->TransmitNextToUse;
- Descriptor = &(Device->TransmitDescriptor[DescriptorIndex]);
- //
- // If the length isn't zero, this is an active or unreaped entry.
- // Quit to try another day. The active packets should interrupt on
- // completion and drive more packets to be send.
- //
- if (Descriptor->BufferLength != 0) {
- break;
- }
- NET_REMOVE_PACKET_FROM_LIST(Packet, &(Device->TransmitPacketList));
- //
- // Success, a free transmit descriptor. Let's fill it out!
- //
- ASSERT(Device->TransmitBuffer[DescriptorIndex] == NULL);
- Device->TransmitBuffer[DescriptorIndex] = Packet;
- Descriptor->BufferLength = Packet->FooterOffset - Packet->DataOffset;
- Descriptor->PhysicalAddress = Packet->BufferPhysicalAddress +
- Packet->DataOffset;
- Descriptor->Flags = ATL_TRANSMIT_DESCRIPTOR_END_OF_PACKET;
- //
- // Advance the list past this entry.
- //
- Device->TransmitNextToUse += 1;
- if (Device->TransmitNextToUse == ATL1C_TRANSMIT_DESCRIPTOR_COUNT) {
- Device->TransmitNextToUse = 0;
- }
- PacketQueued = TRUE;
- }
- //
- // If some packets were queued, then send them now.
- //
- if (PacketQueued != FALSE) {
- RtlMemoryBarrier();
- ATL_WRITE_REGISTER16(Device,
- AtlRegisterTransmitNextIndex,
- Device->TransmitNextToUse);
- }
- return;
- }
- VOID
- AtlpReapReceivedFrames (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine processes any received frames from the network.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- USHORT CurrentIndex;
- ULONG ErrorFlags;
- ULONG FramesProcessed;
- USHORT FreeIndex;
- USHORT OriginalNextToClean;
- NET_PACKET_BUFFER Packet;
- PATL1C_RECEIVED_PACKET ReceivedPacket;
- ULONG Value;
- ASSERT(KeGetRunLevel() == RunLevelLow);
- //
- // Loop grabbing completed frames.
- //
- FramesProcessed = 0;
- Packet.Flags = 0;
- KeAcquireQueuedLock(Device->ReceiveLock);
- OriginalNextToClean = Device->ReceiveNextToClean;
- while (TRUE) {
- CurrentIndex = Device->ReceiveNextToClean;
- ReceivedPacket = &(Device->ReceivedPacket[CurrentIndex]);
- //
- // If the packet is not valid, then stop.
- //
- if ((ReceivedPacket->FlagsAndLength &
- ATL_RECIEVED_PACKET_FLAG_VALID) == 0) {
- break;
- }
- //
- // This is a valid packet that needs to be reaped. Currently only
- // single packets are supported.
- //
- ASSERT(((ReceivedPacket->FreeIndex >>
- ATL_RECEIVED_PACKET_COUNT_SHIFT) &
- ATL_RECEIVED_PACKET_COUNT_MASK) == 1);
- //
- // Process the packet, unless the error flags are set.
- //
- ErrorFlags = ATL_RECEIVED_PACKET_FLAG_802_3_LENGTH_ERROR |
- ATL_RECEIVED_PACKET_FLAG_CHECKSUM_ERROR;
- if ((ReceivedPacket->FlagsAndLength & ErrorFlags) == 0) {
- FreeIndex = (ReceivedPacket->FreeIndex >>
- ATL_RECEIVED_PACKET_FREE_INDEX_SHIFT) &
- ATL_RECEIVED_PACKET_FREE_INDEX_MASK;
- ASSERT(FreeIndex < ATL1C_RECEIVE_FRAME_COUNT);
- Packet.Buffer = Device->ReceivedPacketData +
- (FreeIndex * ATL1C_RECEIVE_FRAME_DATA_SIZE);
- Packet.BufferPhysicalAddress =
- Device->ReceiveSlot[FreeIndex].PhysicalAddress;
- Packet.BufferSize = ReceivedPacket->FlagsAndLength &
- ATL_RECEIVED_PACKET_SIZE_MASK;
- Packet.DataSize = Packet.BufferSize;
- Packet.DataOffset = 0;
- Packet.FooterOffset = Packet.DataSize;
- NetProcessReceivedPacket(Device->NetworkLink, &Packet);
- }
- //
- // Clear the flag set by the hardware and move the index forward.
- //
- FramesProcessed += 1;
- ReceivedPacket->FlagsAndLength &= ~ATL_RECIEVED_PACKET_FLAG_VALID;
- Device->ReceiveNextToClean += 1;
- if (Device->ReceiveNextToClean == ATL1C_RECEIVE_FRAME_COUNT) {
- Device->ReceiveNextToClean = 0;
- }
- }
- //
- // If progress was made, let the controller know.
- //
- if (FramesProcessed != 0) {
- ASSERT(Device->ReceiveNextToClean != OriginalNextToClean);
- if (Device->ReceiveNextToClean == 0) {
- Value = ATL1C_RECEIVE_FRAME_COUNT - 1;
- } else {
- Value = Device->ReceiveNextToClean - 1;
- }
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveFrameIndex, Value);
- }
- KeReleaseQueuedLock(Device->ReceiveLock);
- return;
- }
- VOID
- AtlpDisableL0sAndL1 (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine disables the L0s and L1 link states.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- //
- // Read the power management register and clear out the bits that are going
- // to be set by this function.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterPowerManagementControl);
- Value &= ~((ATL_POWER_MANAGEMENT_CONTROL_L1_ENTRY_TIME_MASK <<
- ATL_POWER_MANAGEMENT_CONTROL_L1_ENTRY_TIME_SHIFT) |
- ATL_POWER_MANAGEMENT_CONTROL_CLK_SWH_L1 |
- ATL_POWER_MANAGEMENT_CONTROL_L0S_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_ASPM_MAC_CHECK |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_PD_EX_L1);
- Value |= ATL_POWER_MANAGEMENT_CONTROL_SERDES_BUFS_RECEIVE_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_PLL_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_L1_ENABLE;
- ATL_WRITE_REGISTER32(Device, AtlRegisterPowerManagementControl, Value);
- return;
- }
- BOOL
- AtlpResetPhy (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine resets the ATL1c device PHY.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- RUNLEVEL OldRunLevel;
- USHORT PhyValue;
- BOOL Result;
- USHORT ShortValue;
- ULONG Value;
- Value = ATL_PHY_CONTROL_SEL_ANA_RESET;
- ATL_WRITE_REGISTER16(Device, AtlRegisterPhyControl, Value);
- ATL_READ_REGISTER16(Device, AtlRegisterPhyControl);
- HlBusySpin(10000);
- Value = ATL_PHY_CONTROL_EXT_RESET | ATL_PHY_CONTROL_SEL_ANA_RESET;
- ATL_WRITE_REGISTER16(Device, AtlRegisterPhyControl, Value);
- ATL_READ_REGISTER16(Device, AtlRegisterPhyControl);
- HlBusySpin(10000);
- OldRunLevel = AtlpAcquireInterruptLock(Device);
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_LEGCYPS_REGISTER,
- ATL_PHY_DEBUG_LEGCYPS_VALUE);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue = ATL_PHY_TST10BTCFG_LOOP_SEL_10BT |
- ATL_PHY_TST10BTCFG_EN_MASK_TB |
- ATL_PHY_TST10BTCFG_EN_10BT_IDLE |
- ATL_PHY_TST10BTCFG_INTERVAL_SEL_TIMER_VALUE;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_TST10BTCFG_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue = ATL_PHY_SRDSYSMOD_SERDES_CDR_BW_VALUE |
- ATL_PHY_SRDSYSMOD_SERDES_EN_DEEM |
- ATL_PHY_SRDSYSMOD_SERDES_SEL_HSP |
- ATL_PHY_SRDSYSMOD_SERDES_ENABLE_PLL |
- ATL_PHY_SRDSYSMOD_SERDES_EN_LCKDT;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_SRDSYSMOD_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue = ATL_PHY_TST100BTCFG_LONG_CABLE_TH_100_VALUE |
- ATL_PHY_TST100BTCFG_SHORT_CABLE_TH_100_VALUE |
- ATL_PHY_TST100BTCFG_BP_BAD_LINK_ACCUM |
- ATL_PHY_TST100BTCFG_BP_SMALL_BW;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_TST100BTCFG_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue = ATL_PHY_SYSMODCTRL_IECHO_ADJ_3_VALUE |
- ATL_PHY_SYSMODCTRL_IECHO_ADJ_2_VALUE |
- ATL_PHY_SYSMODCTRL_IECHO_ADJ_1_VALUE |
- ATL_PHY_SYSMODCTRL_IECHO_ADJ_0_VALUE;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_SYSMODCTRL_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue = ATL_PHY_ANA_CONTROL_MANUAL_SWITCH_ON_VALUE |
- ATL_PHY_ANA_CONTROL_RESTART_CAL |
- ATL_PHY_ANA_CONTROL_MAN_ENABLE | ATL_PHY_ANA_CONTROL_SEL_HSP |
- ATL_PHY_ANA_CONTROL_EN_HB | ATL_PHY_ANA_CONTROL_OEN_125M;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_ANA_CONTROL_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- HlBusySpin(1000);
- //
- // Disable hibernation.
- //
- Result = AtlpReadPhyDebugRegister(Device,
- ATL_PHY_DEBUG_LEGCYPS_REGISTER,
- &PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue &= ~ATL_PHY_ANA_CONTROL_SEL_CLK125M_DSP;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_LEGCYPS_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- Result = AtlpReadPhyDebugRegister(Device,
- ATL_PHY_DEBUG_HIBNEG_REGISTER,
- &PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- PhyValue &= ~ATL_PHY_HIBNEG_PSHIB_ENABLE;
- Result = AtlpWritePhyDebugRegister(Device,
- ATL_PHY_DEBUG_HIBNEG_REGISTER,
- PhyValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- //
- // Enable interrupts from the PHY whenever the link changes.
- //
- ShortValue = ATL_PHY_INTERRUPT_ENABLE_LINK_UP |
- ATL_PHY_INTERRUPT_ENABLE_LINK_DOWN;
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_INTERRUPT_ENABLE_REGISTER,
- &ShortValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- //
- // Try some other things too.
- //
- ShortValue = ATL_PHY_ADVERTISE_PAUSE | ATL_PHY_ADVERTISE_ASYMMETRIC_PAUSE |
- ATL_PHY_ADVERTISE_10_HALF | ATL_PHY_ADVERTISE_10_FULL |
- ATL_PHY_ADVERTISE_100_HALF | ATL_PHY_ADVERTISE_100_FULL;
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_ADVERTISE_REGISTER,
- &ShortValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- ShortValue = 0;
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_GIGABIT_CONTROL_REGISTER,
- &ShortValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- ShortValue = ATL_PHY_AUTONEGOTIATE_RESTART | ATL_PHY_AUTONEGOTIATE_ENABLE;
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_BASIC_MODE_CONTROL_REGISTER,
- &ShortValue);
- if (Result == FALSE) {
- goto ResetPhyEnd;
- }
- Result = TRUE;
- ResetPhyEnd:
- AtlpReleaseInterruptLock(Device, OldRunLevel);
- return TRUE;
- }
- BOOL
- AtlpApplyChipReset (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine applies a reset to the ATL1c controller.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMasterControl) & 0xFFFF;
- Value |= ATL_MASTER_CONTROL_OOB_DISABLE | ATL_MASTER_CONTROL_SOFT_RESET;
- ATL_WRITE_REGISTER32(Device, AtlRegisterMasterControl, Value);
- HlBusySpin(10000);
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMasterControl);
- if ((Value & ATL_MASTER_CONTROL_SOFT_RESET) != 0) {
- return FALSE;
- }
- if (AtlpWaitForIdleUnit(Device, ATL_IDLE_IO_MASK) != 0) {
- return FALSE;
- }
- return TRUE;
- }
- BOOL
- AtlpStopController (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine stops the ATL1c ethernet controller.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- BOOL Result;
- ULONG Value;
- AtlpDisableDeviceInterrupts(Device);
- Result = AtlpStopQueue(Device);
- if (Result == FALSE) {
- return FALSE;
- }
- //
- // Disable DMA.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterDmaControl);
- Value &= ~(ATL_DMA_CONTROL_CMB_ENABLE | ATL_DMA_CONTROL_SMB_ENABLE);
- ATL_WRITE_REGISTER32(Device, AtlRegisterDmaControl, Value);
- HlBusySpin(1000);
- //
- // Stop the MAC.
- //
- Result = AtlpStopMac(Device);
- if (Result == FALSE) {
- return FALSE;
- }
- //
- // Disable interrupts one more time in case the work item came through
- // and re-enabled them.
- //
- AtlpDisableDeviceInterrupts(Device);
- return TRUE;
- }
- BOOL
- AtlpStopMac (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine disables the MAC.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMacControl);
- Value &= ~(ATL_MAC_CONTROL_TRANSMIT_ENABLED |
- ATL_MAC_CONTROL_RECEIVE_ENABLED);
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- if (AtlpWaitForIdleUnit(Device, ATL_IDLE_IO_MASK) != 0) {
- return FALSE;
- }
- return TRUE;
- }
- BOOL
- AtlpStopQueue (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine disables the ethernet controller transmit and receive
- queues.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterReceiveQueueControl);
- Value &= ~ATL_RECEIVE_QUEUE_CONTROL_ENABLED;
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveQueueControl, Value);
- Value = ATL_READ_REGISTER32(Device, AtlRegisterTransmitQueueControl);
- Value &= ~ATL_TRANSMIT_QUEUE_CONTROL_ENABLED;
- ATL_WRITE_REGISTER32(Device, AtlRegisterTransmitQueueControl, Value);
- if (AtlpWaitForIdleUnit(Device, ATL_IDLE_IO_MASK) != 0) {
- return FALSE;
- }
- return TRUE;
- }
- VOID
- AtlpSetupReceiveFilters (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine sets up the hardware receive filters, including promiscuous
- mode and multicast setup.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMacControl);
- Value &= ~(ATL_MAC_CONTROL_ALL_MULTICAST_ENABLE |
- ATL_MAC_CONTROL_PROMISCUOUS_MODE_ENABLE);
- Value |= ATL_MAC_CONTROL_BROADCAST_ENABLED;
- //
- // If there were multiple addresses to receive, this would be the place
- // to set the hash bits for each one. For now, just zero them out to only
- // receive at the current station address.
- //
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveHashTable, 0);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterReceiveHashTable + sizeof(ULONG),
- 0);
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- return;
- }
- KSTATUS
- AtlpEnableDevice (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine brings up the ATL1c device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- Status code.
- --*/
- {
- ATL_DUPLEX_MODE Duplex;
- ULONGLONG LinkSpeed;
- RUNLEVEL OldRunLevel;
- BOOL Result;
- USHORT ShortValue;
- ATL_SPEED Speed;
- KSTATUS Status;
- ULONG Value;
- ASSERT(KeGetRunLevel() == RunLevelLow);
- Status = STATUS_DEVICE_IO_ERROR;
- //
- // Read the PHY status register, twice.
- //
- ShortValue = 0;
- OldRunLevel = AtlpAcquireInterruptLock(Device);
- AtlpPerformPhyRegisterIo(Device,
- FALSE,
- FALSE,
- 0,
- ATL_PHY_BASIC_MODE_STATUS_REGISTER,
- &ShortValue);
- Result = AtlpPerformPhyRegisterIo(Device,
- FALSE,
- FALSE,
- 0,
- ATL_PHY_BASIC_MODE_STATUS_REGISTER,
- &ShortValue);
- AtlpReleaseInterruptLock(Device, OldRunLevel);
- if (Result == FALSE) {
- RtlDebugPrint("ATL1c: Failed to read Basic Mode Status Register.\n");
- goto EnableDeviceEnd;
- }
- //
- // Tear things down if the link is down.
- //
- if ((ShortValue & ATL_PHY_BASIC_MODE_STATUS_LINK_UP) == 0) {
- NetSetLinkState(Device->NetworkLink, FALSE, 0);
- Result = AtlpStopController(Device);
- if (Result == FALSE) {
- goto EnableDeviceEnd;
- }
- AtlpSetActiveStatePowerManagement(Device, AtlSpeedOff);
- //
- // Reset the descriptor rings.
- //
- KeAcquireQueuedLock(Device->TransmitLock);
- Device->LinkActive = FALSE;
- AtlpResetTransmitRing(Device);
- KeReleaseQueuedLock(Device->TransmitLock);
- KeAcquireQueuedLock(Device->ReceiveLock);
- AtlpResetReceiveRing(Device);
- KeReleaseQueuedLock(Device->ReceiveLock);
- //
- // Go on, the link is up!
- //
- } else {
- Result = AtlpGetLinkCharacteristics(Device, &Speed, &Duplex);
- if (Result == FALSE) {
- RtlDebugPrint("ATL1c: Link up, but failed to get speed/duplex "
- "information.\n");
- goto EnableDeviceEnd;
- }
- Device->LinkActive = TRUE;
- Device->Speed = Speed;
- Device->Duplex = Duplex;
- AtlpSetActiveStatePowerManagement(Device, Speed);
- switch (Device->Speed) {
- case AtlSpeed10:
- LinkSpeed = NET_SPEED_10_MBPS;
- break;
- case AtlSpeed100:
- LinkSpeed = NET_SPEED_100_MBPS;
- break;
- case AtlSpeed1000:
- LinkSpeed = NET_SPEED_1000_MBPS;
- break;
- default:
- ASSERT(FALSE);
- LinkSpeed = 0;
- break;
- }
- NetSetLinkState(Device->NetworkLink, TRUE, LinkSpeed);
- AtlpStartQueue(Device);
- AtlpConfigureMac(Device);
- //
- // Start the MAC, it's go time.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMacControl);
- Value |= ATL_MAC_CONTROL_RECEIVE_ENABLED |
- ATL_MAC_CONTROL_TRANSMIT_ENABLED;
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- }
- Status = STATUS_SUCCESS;
- EnableDeviceEnd:
- return Status;
- }
- VOID
- AtlpStartQueue (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine starts the device's transmit and receive queues.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterReceiveQueueControl);
- Value |= ATL_RECEIVE_QUEUE_CONTROL_ENABLED0;
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveQueueControl, Value);
- Value = ATL_READ_REGISTER32(Device, AtlRegisterTransmitQueueControl);
- Value |= ATL_TRANSMIT_QUEUE_CONTROL_ENABLED;
- ATL_WRITE_REGISTER32(Device, AtlRegisterTransmitQueueControl, Value);
- return;
- }
- VOID
- AtlpConfigureMac (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine configures the MAC after a link has been established with the
- correct speed and duplex settings.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMacControl);
- Value &= ~(ATL_MAC_CONTROL_DUPLEX |
- ATL_MAC_CONTROL_RECEIVE_FLOW_ENABLED |
- ATL_MAC_CONTROL_TRANSMIT_FLOW_ENABLED |
- (ATL_MAC_CONTROL_SPEED_MASK << ATL_MAC_CONTROL_SPEED_SHIFT));
- switch (Device->Speed) {
- case AtlSpeedOff:
- break;
- case AtlSpeed10:
- case AtlSpeed100:
- Value |= ATL_MAC_CONTROL_SPEED_10_100 << ATL_MAC_CONTROL_SPEED_SHIFT;
- break;
- case AtlSpeed1000:
- Value |= ATL_MAC_CONTROL_SPEED_1000 << ATL_MAC_CONTROL_SPEED_SHIFT;
- break;
- default:
- ASSERT(FALSE);
- return;
- }
- if (Device->Duplex == AtlDuplexFull) {
- Value |= ATL_MAC_CONTROL_DUPLEX |
- ATL_MAC_CONTROL_RECEIVE_FLOW_ENABLED |
- ATL_MAC_CONTROL_TRANSMIT_FLOW_ENABLED;
- }
- ATL_WRITE_REGISTER32(Device, AtlRegisterMacControl, Value);
- return;
- }
- BOOL
- AtlpReadPhyDebugRegister (
- PATL1C_DEVICE Device,
- USHORT Register,
- PUSHORT Data
- )
- /*++
- Routine Description:
- This routine reads a PHY debug register.
- Arguments:
- Device - Supplies a pointer to the device.
- Register - Supplies the register to read.
- Data - Supplies a pointer where the data will be returned.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- BOOL Result;
- *Data = 0;
- //
- // Write the address register.
- //
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_DEBUG_ADDRESS,
- &Register);
- if (Result == FALSE) {
- return FALSE;
- }
- //
- // Read the data register.
- //
- Result = AtlpPerformPhyRegisterIo(Device,
- FALSE,
- FALSE,
- 0,
- ATL_PHY_DEBUG_DATA,
- Data);
- return Result;
- }
- BOOL
- AtlpWritePhyDebugRegister (
- PATL1C_DEVICE Device,
- USHORT Register,
- USHORT Data
- )
- /*++
- Routine Description:
- This routine writes to a PHY debug register.
- Arguments:
- Device - Supplies a pointer to the device.
- Register - Supplies the register to write.
- Data - Supplies the data to write.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- BOOL Result;
- //
- // Write the address register.
- //
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_DEBUG_ADDRESS,
- &Register);
- if (Result == FALSE) {
- return FALSE;
- }
- //
- // Write the data register.
- //
- Result = AtlpPerformPhyRegisterIo(Device,
- TRUE,
- FALSE,
- 0,
- ATL_PHY_DEBUG_DATA,
- &Data);
- return Result;
- }
- BOOL
- AtlpPerformPhyRegisterIo (
- PATL1C_DEVICE Device,
- BOOL Write,
- BOOL Extension,
- UCHAR Address,
- USHORT Register,
- PUSHORT Data
- )
- /*++
- Routine Description:
- This routine performs a PHY register read or write using the MDIO register.
- Arguments:
- Device - Supplies a pointer to the device.
- Write - Supplies TRUE if this is a write operation or FALSE if this is a
- read operation.
- Extension - Supplies a boolean indicating whether or not this access is an
- extension register.
- Address - Supplies the address of the device (usually 0).
- Register - Supplies the register to access on the device.
- Data - Supplies a pointer that for writes supplies the data to write and
- for writes contains the value to write.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- USHORT ClockSelect;
- ULONG LoopIndex;
- ULONG MdioValue;
- BOOL Result;
- ULONG Value;
- ASSERT(KeIsSpinLockHeld(&(Device->InterruptLock)) != FALSE);
- ASSERT(KeGetRunLevel() >= RunLevelDispatch);
- //
- // Set up the MDIO control register, and potentially the extension register
- // for an extended register read.
- //
- ClockSelect = ATL_MDIO_CONTROL_CLOCK_25MHZ_DIVIDE_4;
- MdioValue = ATL_MDIO_CONTROL_SPRES_PRMBL |
- ((ClockSelect & ATL_MDIO_CONTROL_CLOCK_SELECT_MASK) <<
- ATL_MDIO_CONTROL_CLOCK_SELECT_SHIFT) |
- ATL_MDIO_CONTROL_START;
- if (Extension != FALSE) {
- MdioValue |= ATL_MDIO_CONTROL_EXTENSION_MODE;
- Value = ((Address & ATL_MDIO_EXTENSION_DEVICE_ADDRESS_MASK) <<
- ATL_MDIO_EXTENSION_DEVICE_ADDRESS_SHIFT) |
- ((Register & ATL_MDIO_EXTENSION_REGISTER_MASK) <<
- ATL_MDIO_EXTENSION_REGISTER_SHIFT);
- ATL_WRITE_REGISTER32(Device, AtlRegisterMdioExtension, Value);
- } else {
- MdioValue |= (Register & ATL_MDIO_CONTROL_REGISTER_MASK) <<
- ATL_MDIO_CONTROL_REGISTER_SHIFT;
- }
- if (Write != FALSE) {
- MdioValue |= (*Data & ATL_MDIO_CONTROL_DATA_MASK) <<
- ATL_MDIO_CONTROL_DATA_SHIFT;
- } else {
- MdioValue |= ATL_MDIO_CONTROL_READ_OPERATION;
- }
- ATL_WRITE_REGISTER32(Device, AtlRegisterMdioControl, MdioValue);
- //
- // Wait for the MDIO module to become idle again.
- //
- for (LoopIndex = 0; LoopIndex < ATL_MDIO_WAIT_LOOP_COUNT; LoopIndex += 1) {
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMdioControl);
- if ((Value & (ATL_MDIO_CONTROL_BUSY | ATL_MDIO_CONTROL_START)) == 0) {
- break;
- }
- HlBusySpin(ATL_MDIO_WAIT_LOOP_DELAY);
- }
- if (LoopIndex == ATL_MDIO_WAIT_LOOP_COUNT) {
- Result = FALSE;
- goto PerformPhyRegisterIoEnd;
- }
- //
- // Read the result out if this is a read.
- //
- if (Write == FALSE) {
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMdioControl);
- *Data = (USHORT)((Value >> ATL_MDIO_CONTROL_DATA_SHIFT) &
- ATL_MDIO_CONTROL_DATA_MASK);
- }
- Result = TRUE;
- PerformPhyRegisterIoEnd:
- return Result;
- }
- ULONG
- AtlpWaitForIdleUnit (
- PATL1C_DEVICE Device,
- ULONG BitsToBecomeClear
- )
- /*++
- Routine Description:
- This routine attempts to wait for the device to become idle.
- Arguments:
- Device - Supplies a pointer to the device.
- BitsToBecomeClear - Supplies the bitmask of bits in the idle status register
- to read until they clear.
- Return Value:
- 0 if all the specified bits cleared.
- Returns the bitmask of bits that are stuck on if the operation timed out.
- --*/
- {
- ULONG IdleRegister;
- ULONG LoopIndex;
- IdleRegister = 0;
- for (LoopIndex = 0; LoopIndex < ATL_IDLE_WAIT_LOOP_COUNT; LoopIndex += 1) {
- IdleRegister = ATL_READ_REGISTER32(Device, AtlRegisterIdleStatus);
- if ((IdleRegister & BitsToBecomeClear) == 0) {
- return 0;
- }
- HlBusySpin(ATL_IDLE_WAIT_LOOP_DELAY);
- }
- return IdleRegister;
- }
- BOOL
- AtlpReadMacAddress (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine reads the MAC address from the device.
- Arguments:
- Device - Supplies a pointer to the device. The MAC address will be set in
- the device structure.
- Return Value:
- TRUE on success.
- FALSE on failure.
- --*/
- {
- ULONG LoopIndex;
- ULONG OtpControl;
- ULONG TwsiControl;
- //
- // First check the current address to see if a valid MAC address is already
- // programmed in. If so, use it. It may have been set by the BIOS.
- //
- if (AtlpReadCurrentMacAddress(Device) != FALSE) {
- return TRUE;
- }
- OtpControl = ATL_READ_REGISTER32(Device, AtlRegisterOtpControl);
- if (AtlpDoesEepromExist(Device) != FALSE) {
- //
- // Enable the OTP clock if it's not already on.
- //
- if ((OtpControl & ATL_OTP_CONTROL_CLOCK_ENABLE) == 0) {
- OtpControl |= ATL_OTP_CONTROL_CLOCK_ENABLE;
- ATL_WRITE_REGISTER32(Device, AtlRegisterOtpControl, OtpControl);
- HlBusySpin(1000);
- }
- TwsiControl = ATL_READ_REGISTER32(Device, AtlRegisterTwsiControl);
- TwsiControl |= ATL_TWSI_CONTROL_SOFTWARE_LOAD_START;
- ATL_WRITE_REGISTER32(Device, AtlRegisterTwsiControl, TwsiControl);
- for (LoopIndex = 0;
- LoopIndex < ATL_TWSI_EEPROM_LOOP_COUNT;
- LoopIndex += 1) {
- HlBusySpin(ATL_TWSI_EEPROM_LOOP_DELAY);
- TwsiControl = ATL_READ_REGISTER32(Device, AtlRegisterTwsiControl);
- if ((TwsiControl & ATL_TWSI_CONTROL_SOFTWARE_LOAD_START) == 0) {
- break;
- }
- }
- if (LoopIndex == ATL_TWSI_EEPROM_LOOP_COUNT) {
- return FALSE;
- }
- }
- //
- // Disable the OTP clock.
- //
- OtpControl &= ~ATL_OTP_CONTROL_CLOCK_ENABLE;
- ATL_WRITE_REGISTER32(Device, AtlRegisterOtpControl, OtpControl);
- HlBusySpin(1000);
- //
- // Now check to see if the current address is loaded.
- //
- if (AtlpReadCurrentMacAddress(Device) != FALSE) {
- return TRUE;
- }
- return FALSE;
- }
- BOOL
- AtlpDoesEepromExist (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine determines if there is an EEPROM attached to the ethernet
- device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- TRUE if an EEPROM is present.
- FALSE if no EEPROM is connected.
- --*/
- {
- ULONG Value;
- Value = ATL_READ_REGISTER32(Device, AtlRegisterTwsiDebug);
- if ((Value & ATL_TWSI_DEBUG_DEVICE_EXISTS) != 0) {
- return TRUE;
- }
- Value = ATL_READ_REGISTER32(Device, AtlRegisterMasterControl);
- if ((Value & ATL_MASTER_CONTROL_OTP_SEL) != 0) {
- return TRUE;
- }
- return FALSE;
- }
- BOOL
- AtlpReadCurrentMacAddress (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine reads the current MAC address programmed into the device and
- if valid, saves it into the device structure.
- Arguments:
- Device - Supplies a pointer to the device. If the current MAC address is
- valid, it will be saved into this structure.
- Return Value:
- TRUE if the current address was valid.
- FALSE if the address was not programmed (was an invalid address).
- --*/
- {
- ULONG Address1;
- USHORT Address2;
- BOOL InvalidAddress;
- Address1 = ATL_READ_REGISTER32(Device, AtlRegisterMacAddress1);
- Address2 = (USHORT)ATL_READ_REGISTER32(Device, AtlRegisterMacAddress2);
- InvalidAddress = FALSE;
- if ((Address1 == MAX_ULONG) && (Address2 == MAX_USHORT)) {
- InvalidAddress = TRUE;
- }
- if ((Address1 == 0) && (Address2 == 0)) {
- InvalidAddress = TRUE;
- }
- if (InvalidAddress == FALSE) {
- Address1 = CPU_TO_NETWORK32(Address1);
- Address2 = CPU_TO_NETWORK16(Address2);
- RtlCopyMemory(Device->EepromMacAddress, &Address2, sizeof(USHORT));
- RtlCopyMemory(&(Device->EepromMacAddress[sizeof(USHORT)]),
- &Address1,
- sizeof(ULONG));
- return TRUE;
- }
- return FALSE;
- }
- VOID
- AtlpDisableDeviceInterrupts (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine disables interrupt generation for the device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ATL_WRITE_REGISTER32(Device, AtlRegisterInterruptMask, 0);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterInterruptStatus,
- ATL_INTERRUPT_DISABLE);
- return;
- }
- VOID
- AtlpEnableDeviceInterrupts (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine enables interrupt generation for the device.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterInterruptStatus,
- ATL_INTERRUPT_MASK);
- ATL_WRITE_REGISTER32(Device,
- AtlRegisterInterruptMask,
- Device->EnabledInterrupts);
- return;
- }
- VOID
- AtlpSetActiveStatePowerManagement (
- PATL1C_DEVICE Device,
- ATL_SPEED Speed
- )
- /*++
- Routine Description:
- This routine sets the PCI Express Active State Power Management
- configuration for the device based on the link speed.
- Arguments:
- Device - Supplies a pointer to the device.
- Speed - Supplies the speed of the link.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- //
- // Read the power management register and clear out the bits that are going
- // to be set by this function.
- //
- Value = ATL_READ_REGISTER32(Device, AtlRegisterPowerManagementControl);
- Value &= ~((ATL_POWER_MANAGEMENT_CONTROL_L1_ENTRY_TIME_MASK <<
- ATL_POWER_MANAGEMENT_CONTROL_L1_ENTRY_TIME_SHIFT) |
- ATL_POWER_MANAGEMENT_CONTROL_L0S_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_ASPM_MAC_CHECK);
- //
- // Enable L0s and/or L1.
- //
- if (Speed != AtlSpeedOff) {
- Value |= ATL_POWER_MANAGEMENT_CONTROL_SERDES_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_PLL_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_BUFS_RECEIVE_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_ASPM_MAC_CHECK;
- Value &= ~(ATL_POWER_MANAGEMENT_CONTROL_SERDES_PD_EX_L1 |
- ATL_POWER_MANAGEMENT_CONTROL_CLK_SWH_L1 |
- ATL_POWER_MANAGEMENT_CONTROL_L0S_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_L1_ENABLE);
- //
- // The link is down.
- //
- } else {
- Value |= ATL_POWER_MANAGEMENT_CONTROL_CLK_SWH_L1;
- Value &= ~(ATL_POWER_MANAGEMENT_CONTROL_SERDES_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_PLL_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_SERDES_BUFS_RECEIVE_L1_ENABLE |
- ATL_POWER_MANAGEMENT_CONTROL_L0S_ENABLE);
- }
- ATL_WRITE_REGISTER32(Device, AtlRegisterPowerManagementControl, Value);
- return;
- }
- VOID
- AtlpResetTransmitRing (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine clears out and resets the transmit descriptor ring. This
- routine assumes the transmit lock is already held (or doesn't need to be).
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- USHORT CurrentIndex;
- USHORT DescriptorIndex;
- ASSERT(KeIsQueuedLockHeld(Device->TransmitLock) != FALSE);
- //
- // Clean out and free all descriptors.
- //
- for (DescriptorIndex = 0;
- DescriptorIndex < ATL1C_TRANSMIT_DESCRIPTOR_COUNT;
- DescriptorIndex += 1) {
- if (Device->TransmitBuffer[DescriptorIndex] != NULL) {
- ASSERT(Device->TransmitDescriptor[DescriptorIndex].BufferLength !=
- 0);
- NetFreeBuffer(Device->TransmitBuffer[DescriptorIndex]);
- Device->TransmitBuffer[DescriptorIndex] = NULL;
- }
- }
- //
- // Clean out the pending transmit descriptors.
- //
- RtlZeroMemory(Device->TransmitDescriptor,
- sizeof(ATL1C_TRANSMIT_DESCRIPTOR) *
- (ATL1C_TRANSMIT_DESCRIPTOR_COUNT + 1));
- //
- // Destroy the list of packets waiting to be sent.
- //
- NetDestroyBufferList(&(Device->TransmitPacketList));
- //
- // Reset the counters in software and hardware based on the current index.
- // The current index cannot be reset by software.
- //
- CurrentIndex = ATL_READ_REGISTER16(Device,
- AtlRegisterTransmitCurrentIndex);
- Device->TransmitNextToUse = CurrentIndex;
- Device->TransmitNextToClean = CurrentIndex;
- ATL_WRITE_REGISTER16(Device,
- AtlRegisterTransmitNextIndex,
- Device->TransmitNextToUse);
- return;
- }
- VOID
- AtlpResetReceiveRing (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine clears out the receive descriptor ring, discarding any
- packets that had come in but not been processed. This routine does not
- acquire the receive lock, it is assumed that the receive lock is already
- held or does not need to be.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- None.
- --*/
- {
- ULONG Value;
- RtlZeroMemory(Device->ReceivedPacket,
- sizeof(ATL1C_RECEIVED_PACKET) * ATL1C_RECEIVE_FRAME_COUNT);
- if (Device->ReceiveNextToClean == 0) {
- Value = ATL1C_RECEIVE_FRAME_COUNT - 1;
- } else {
- Value = Device->ReceiveNextToClean - 1;
- }
- ATL_WRITE_REGISTER32(Device, AtlRegisterReceiveFrameIndex, Value);
- return;
- }
- BOOL
- AtlpGetLinkCharacteristics (
- PATL1C_DEVICE Device,
- PATL_SPEED Speed,
- PATL_DUPLEX_MODE Duplex
- )
- /*++
- Routine Description:
- This routine gets the link information, including link speed and duplex
- status.
- Arguments:
- Device - Supplies a pointer to the device with the link to query.
- Speed - Supplies a pointer where the link speed will be returned.
- Duplex - Supplies a pointer where the link duplex status will be returned.
- Return Value:
- TRUE on success.
- FALSE if the link could not be queried.
- --*/
- {
- RUNLEVEL OldRunLevel;
- BOOL Result;
- USHORT Value;
- OldRunLevel = AtlpAcquireInterruptLock(Device);
- Result = AtlpPerformPhyRegisterIo(Device,
- FALSE,
- FALSE,
- 0,
- ATL_PHY_GIGA_PSSR_REGISTER,
- &Value);
- AtlpReleaseInterruptLock(Device, OldRunLevel);
- if (Result == FALSE) {
- return FALSE;
- }
- if ((Value & ATL_PHY_GIGA_PSSR_SPEED_AND_DUPLEX_RESOLVED) == 0) {
- return FALSE;
- }
- switch (Value & ATL_PHY_GIGA_PSSR_SPEED_MASK) {
- case ATL_PHY_GIGA_PSSR_SPEED_1000:
- *Speed = AtlSpeed1000;
- break;
- case ATL_PHY_GIGA_PSSR_SPEED_100:
- *Speed = AtlSpeed100;
- break;
- case ATL_PHY_GIGA_PSSR_SPEED_10:
- *Speed = AtlSpeed10;
- break;
- default:
- return FALSE;
- }
- if ((Value & ATL_PHY_GIGA_PSSR_DUPLEX) != 0) {
- *Duplex = AtlDuplexFull;
- } else {
- *Duplex = AtlDuplexHalf;
- }
- return TRUE;
- }
- ULONG
- AtlpHashAddress (
- PUCHAR MacAddress
- )
- /*++
- Routine Description:
- This routine computes the value to put in a device's hash table for the
- given MAC address.
- Arguments:
- MacAddress - Supplies a pointer to the six byte MAC address.
- Return Value:
- Returns the hashed value.
- --*/
- {
- ULONG BitIndex;
- ULONG Crc32;
- ULONG Hash;
- Hash = 0;
- //
- // The hash is the CRC32, but with all the bits reversed.
- //
- Crc32 = RtlComputeCrc32(0, MacAddress, 6);
- for (BitIndex = 0;
- BitIndex < (sizeof(ULONG) * BITS_PER_BYTE);
- BitIndex += 1) {
- Hash |= ((Crc32 >> BitIndex) & 0x1) <<
- ((sizeof(ULONG) * BITS_PER_BYTE) - 1 - BitIndex);
- }
- return Hash;
- }
- RUNLEVEL
- AtlpAcquireInterruptLock (
- PATL1C_DEVICE Device
- )
- /*++
- Routine Description:
- This routine acquires the interrupt lock from outside the interrupt
- handler.
- Arguments:
- Device - Supplies a pointer to the device.
- Return Value:
- Returns the original run-level.
- --*/
- {
- RUNLEVEL OldRunLevel;
- ASSERT(KeGetRunLevel() <= RunLevelDispatch);
- if (Device->InterruptHandle != INVALID_HANDLE) {
- OldRunLevel = IoRaiseToInterruptRunLevel(Device->InterruptHandle);
- } else {
- OldRunLevel = KeRaiseRunLevel(RunLevelDispatch);
- }
- KeAcquireSpinLock(&(Device->InterruptLock));
- return OldRunLevel;
- }
- VOID
- AtlpReleaseInterruptLock (
- PATL1C_DEVICE Device,
- RUNLEVEL OldRunLevel
- )
- /*++
- Routine Description:
- This routine releases the interrupt lock from outside the interrupt
- handler.
- Arguments:
- Device - Supplies a pointer to the device.
- OldRunLevel - Supplies the original run-level returned by the acquire
- function.
- Return Value:
- None.
- --*/
- {
- ASSERT(KeGetRunLevel() >= RunLevelDispatch);
- KeReleaseSpinLock(&(Device->InterruptLock));
- KeLowerRunLevel(OldRunLevel);
- return;
- }
|