1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
14 * FBI board dependent Driver for SMT and LLC
20 #include "h/supern_2.h"
21 #include "h/skfbiinc.h"
22 #include <linux/bitrev.h>
23 #include <linux/pci.h>
30 #define LED_Y_ON 0x11 /* Used for ring up/down indication */
31 #define LED_Y_OFF 0x10
34 #define MS2BCLK(x) ((x)*12500L)
37 * valid configuration values are:
44 * | --------------------- the patched POS_ID of the Adapter
45 * | xxxx = (Vendor ID low byte,
46 * | Vendor ID high byte,
47 * | Device ID low byte,
48 * | Device ID high byte)
49 * +------------------------------ the patched oem_id must be
50 * 'S' for SK or 'I' for IBM
51 * this is a short id for the driver.
55 const u_char oem_id[] = "xPOS_ID:xxxx" ;
56 #else /* OEM_CONCEPT */
57 const u_char oem_id[] = OEM_ID ;
58 #endif /* OEM_CONCEPT */
60 #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
62 const struct s_oem_ids oem_ids[] = {
66 #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
69 /* Prototypes of external functions */
71 extern int AIX_vpdReadByte() ;
75 /* Prototype of a local function. */
76 static void smt_stop_watchdog(struct s_smc *smc);
81 static void card_start(struct s_smc *smc)
89 smt_stop_watchdog(smc) ;
93 * make sure no transfer activity is pending
95 outpw(FM_A(FM_MDREG1),FM_MINIT) ;
96 outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
97 hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
99 * now reset everything
101 outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
102 i = (int) inp(ADDR(B0_CTRL)) ; /* do dummy read */
103 SK_UNUSED(i) ; /* Make LINT happy. */
104 outp(ADDR(B0_CTRL), CTRL_RST_CLR) ;
107 * Reset all bits in the PCI STATUS register
109 outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_ON) ; /* enable for writes */
110 word = inpw(PCI_C(PCI_STATUS)) ;
111 outpw(PCI_C(PCI_STATUS), word | PCI_STATUS_ERROR_BITS);
112 outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_OFF) ; /* disable writes */
115 * Release the reset of all the State machines
116 * Release Master_Reset
117 * Release HPI_SM_Reset
119 outp(ADDR(B0_CTRL), CTRL_MRST_CLR|CTRL_HPI_CLR) ;
122 * determine the adapter type
123 * Note: Do it here, because some drivers may call card_start() once
124 * at very first before any other initialization functions is
127 rev_id = inp(PCI_C(PCI_REVISION_ID)) ;
128 if ((rev_id & 0xf0) == SK_ML_ID_1 || (rev_id & 0xf0) == SK_ML_ID_2) {
129 smc->hw.hw_is_64bit = TRUE ;
131 smc->hw.hw_is_64bit = FALSE ;
135 * Watermark initialization
137 if (!smc->hw.hw_is_64bit) {
138 outpd(ADDR(B4_R1_F), RX_WATERMARK) ;
139 outpd(ADDR(B5_XA_F), TX_WATERMARK) ;
140 outpd(ADDR(B5_XS_F), TX_WATERMARK) ;
143 outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* clear the reset chips */
144 outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_ON|LED_GB_OFF) ; /* ye LED on */
146 /* init the timer value for the watch dog 2,5 minutes */
147 outpd(ADDR(B2_WDOG_INI),0x6FC23AC0) ;
149 /* initialize the ISR mask */
150 smc->hw.is_imask = ISR_MASK ;
151 smc->hw.hw_state = STOPPED ;
153 GET_PAGE(0) ; /* necessary for BOOT */
156 void card_stop(struct s_smc *smc)
158 smt_stop_watchdog(smc) ;
159 smc->hw.mac_ring_is_up = 0 ; /* ring down */
163 * make sure no transfer activity is pending
165 outpw(FM_A(FM_MDREG1),FM_MINIT) ;
166 outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
167 hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
169 * now reset everything
171 outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
172 outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* reset for all chips */
173 outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_OFF|LED_GB_OFF) ; /* all LEDs off */
174 smc->hw.hw_state = STOPPED ;
177 /*--------------------------- ISR handling ----------------------------------*/
179 void mac1_irq(struct s_smc *smc, u_short stu, u_short stl)
185 * parity error: note encoding error is not possible in tag mode
187 if (stl & (FM_SPCEPDS | /* parity err. syn.q.*/
188 FM_SPCEPDA0 | /* parity err. a.q.0 */
189 FM_SPCEPDA1)) { /* parity err. a.q.1 */
190 SMT_PANIC(smc,SMT_E0134, SMT_E0134_MSG) ;
193 * buffer underrun: can only occur if a tx threshold is specified
195 if (stl & (FM_STBURS | /* tx buffer underrun syn.q.*/
196 FM_STBURA0 | /* tx buffer underrun a.q.0 */
197 FM_STBURA1)) { /* tx buffer underrun a.q.2 */
198 SMT_PANIC(smc,SMT_E0133, SMT_E0133_MSG) ;
201 if ( (stu & (FM_SXMTABT | /* transmit abort */
202 FM_STXABRS | /* syn. tx abort */
203 FM_STXABRA0)) || /* asyn. tx abort */
204 (stl & (FM_SQLCKS | /* lock for syn. q. */
205 FM_SQLCKA0)) ) { /* lock for asyn. q. */
206 formac_tx_restart(smc) ; /* init tx */
208 stu = inpw(FM_A(FM_ST1U)) ;
209 stl = inpw(FM_A(FM_ST1L)) ;
210 stu &= ~ (FM_STECFRMA0 | FM_STEFRMA0 | FM_STEFRMS) ;
215 if (stu & (FM_STEFRMA0 | /* end of asyn tx */
216 FM_STEFRMS)) { /* end of sync tx */
221 llc_restart_tx(smc) ;
225 * interrupt source= plc1
226 * this function is called in nwfbisr.asm
228 void plc1_irq(struct s_smc *smc)
230 u_short st = inpw(PLC(PB,PL_INTR_EVENT)) ;
236 * interrupt source= plc2
237 * this function is called in nwfbisr.asm
239 void plc2_irq(struct s_smc *smc)
241 u_short st = inpw(PLC(PA,PL_INTR_EVENT)) ;
248 * interrupt source= timer
250 void timer_irq(struct s_smc *smc)
253 smc->hw.t_stop = smc->hw.t_start;
254 smt_timer_done(smc) ;
258 * return S-port (PA or PB)
260 int pcm_get_s_port(struct s_smc *smc)
267 * Station Label = "FDDI-XYZ" where
273 #define STATION_LABEL_CONNECTOR_OFFSET 5
274 #define STATION_LABEL_PMD_OFFSET 6
275 #define STATION_LABEL_PORT_OFFSET 7
277 void read_address(struct s_smc *smc, u_char *mac_addr)
284 for (i = 0; i < 6; i++) { /* read mac address from board */
285 smc->hw.fddi_phys_addr.a[i] =
286 bitrev8(inp(ADDR(B2_MAC_0+i)));
290 ConnectorType = inp(ADDR(B2_CONN_TYP)) ;
291 PmdType = inp(ADDR(B2_PMD_TYP)) ;
293 smc->y[PA].pmd_type[PMD_SK_CONN] =
294 smc->y[PB].pmd_type[PMD_SK_CONN] = ConnectorType ;
295 smc->y[PA].pmd_type[PMD_SK_PMD ] =
296 smc->y[PB].pmd_type[PMD_SK_PMD ] = PmdType ;
299 for (i = 0; i < 6 ;i++) {
300 smc->hw.fddi_canon_addr.a[i] = mac_addr[i] ;
301 smc->hw.fddi_home_addr.a[i] = bitrev8(mac_addr[i]);
305 smc->hw.fddi_home_addr = smc->hw.fddi_phys_addr ;
307 for (i = 0; i < 6 ;i++) {
308 smc->hw.fddi_canon_addr.a[i] =
309 bitrev8(smc->hw.fddi_phys_addr.a[i]);
314 * FDDI card soft reset
316 void init_board(struct s_smc *smc, u_char *mac_addr)
319 read_address(smc,mac_addr) ;
321 if (!(inp(ADDR(B0_DAS)) & DAS_AVAIL))
322 smc->s.sas = SMT_SAS ; /* Single att. station */
324 smc->s.sas = SMT_DAS ; /* Dual att. station */
326 if (!(inp(ADDR(B0_DAS)) & DAS_BYP_ST))
327 smc->mib.fddiSMTBypassPresent = 0 ;
328 /* without opt. bypass */
330 smc->mib.fddiSMTBypassPresent = 1 ;
331 /* with opt. bypass */
335 * insert or deinsert optical bypass (called by ECM)
337 void sm_pm_bypass_req(struct s_smc *smc, int mode)
339 DB_ECMN(1, "ECM : sm_pm_bypass_req(%s)",
340 mode == BP_INSERT ? "BP_INSERT" : "BP_DEINSERT");
342 if (smc->s.sas != SMT_DAS)
348 outp(ADDR(B0_DAS),DAS_BYP_INS) ; /* insert station */
351 outp(ADDR(B0_DAS),DAS_BYP_RMV) ; /* bypass station */
358 * check if bypass connected
360 int sm_pm_bypass_present(struct s_smc *smc)
362 return (inp(ADDR(B0_DAS)) & DAS_BYP_ST) ? TRUE : FALSE;
365 void plc_clear_irq(struct s_smc *smc, int p)
374 * led_indication called by rmt_indication() and
380 * 0 Only switch green LEDs according to their respective PCM state
381 * LED_Y_OFF just switch yellow LED off
382 * LED_Y_ON just switch yello LED on
384 static void led_indication(struct s_smc *smc, int led_event)
386 /* use smc->hw.mac_ring_is_up == TRUE
387 * as indication for Ring Operational
391 struct fddi_mib_p *mib_a ;
392 struct fddi_mib_p *mib_b ;
402 /* Ring up = yellow led OFF*/
403 if (led_event == LED_Y_ON) {
404 led_state |= LED_MY_ON ;
406 else if (led_event == LED_Y_OFF) {
407 led_state |= LED_MY_OFF ;
409 else { /* PCM state changed */
410 /* Link at Port A/S = green led A ON */
411 if (mib_a->fddiPORTPCMState == PC8_ACTIVE) {
412 led_state |= LED_GA_ON ;
415 led_state |= LED_GA_OFF ;
418 /* Link at Port B = green led B ON */
419 if (mib_b->fddiPORTPCMState == PC8_ACTIVE) {
420 led_state |= LED_GB_ON ;
423 led_state |= LED_GB_OFF ;
427 outp(ADDR(B0_LED), led_state) ;
433 void pcm_state_change(struct s_smc *smc, int plc, int p_state)
436 * the current implementation of pcm_state_change() in the driver
437 * parts must be renamed to drv_pcm_state_change() which will be called
438 * now after led_indication.
440 DRV_PCM_STATE_CHANGE(smc,plc,p_state) ;
442 led_indication(smc,0) ;
446 void rmt_indication(struct s_smc *smc, int i)
448 /* Call a driver special function if defined */
449 DRV_RMT_INDICATION(smc,i) ;
451 led_indication(smc, i ? LED_Y_OFF : LED_Y_ON) ;
456 * llc_recover_tx called by init_tx (fplus.c)
458 void llc_recover_tx(struct s_smc *smc)
461 extern int load_gen_flag ;
466 smc->hw.n_a_send= 0 ;
473 static int is_equal_num(char comp1[], char comp2[], int num)
477 for (i = 0 ; i < num ; i++) {
478 if (comp1[i] != comp2[i])
486 * set the OEM ID defaults, and test the contents of the OEM data base
487 * The default OEM is the first ACTIVE entry in the OEM data base
490 * 1 error in data base
494 int set_oi_id_def(struct s_smc *smc)
502 act_entries = FALSE ;
504 smc->hw.oem_min_status = OI_STAT_ACTIVE ;
506 /* check OEM data base */
507 while (oem_ids[i].oi_status) {
508 switch (oem_ids[i].oi_status) {
510 act_entries = TRUE ; /* we have active IDs */
512 sel_id = i ; /* save the first active ID */
514 case OI_STAT_PRESENT:
516 break ; /* entry ok */
518 return 1; /* invalid oi_status */
527 /* ok, we have a valid OEM data base with an active entry */
528 smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[sel_id] ;
531 #endif /* MULT_OEM */
533 void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr)
537 for (i = 0 ; i < 6 ; i++)
538 bia_addr->a[i] = bitrev8(smc->hw.fddi_phys_addr.a[i]);
541 void smt_start_watchdog(struct s_smc *smc)
543 SK_UNUSED(smc) ; /* Make LINT happy. */
548 if (smc->hw.wdog_used) {
549 outpw(ADDR(B2_WDOG_CRTL),TIM_START) ; /* Start timer. */
556 static void smt_stop_watchdog(struct s_smc *smc)
558 SK_UNUSED(smc) ; /* Make LINT happy. */
562 if (smc->hw.wdog_used) {
563 outpw(ADDR(B2_WDOG_CRTL),TIM_STOP) ; /* Stop timer. */
572 void mac_do_pci_fix(struct s_smc *smc)