Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  *                  QLOGIC LINUX SOFTWARE
  3  *
  4  * QLogic ISP2x00 device driver for Linux 2.6.x
  5  * Copyright (C) 2003-2004 QLogic Corporation
  6  * (www.qlogic.com)
  7  *
  8  * This program is free software; you can redistribute it and/or modify it
  9  * under the terms of the GNU General Public License as published by the
 10  * Free Software Foundation; either version 2, or (at your option) any
 11  * later version.
 12  *
 13  * This program is distributed in the hope that it will be useful, but
 14  * WITHOUT ANY WARRANTY; without even the implied warranty of
 15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16  * General Public License for more details.
 17  *
 18  */
 19 
 20 
 21 static __inline__ uint16_t qla2x00_debounce_register(volatile uint16_t __iomem *);
 22 /*
 23  * qla2x00_debounce_register
 24  *      Debounce register.
 25  *
 26  * Input:
 27  *      port = register address.
 28  *
 29  * Returns:
 30  *      register value.
 31  */
 32 static __inline__ uint16_t
 33 qla2x00_debounce_register(volatile uint16_t __iomem *addr) 
 34 {
 35         volatile uint16_t first;
 36         volatile uint16_t second;
 37 
 38         do {
 39                 first = RD_REG_WORD(addr);
 40                 barrier();
 41                 cpu_relax();
 42                 second = RD_REG_WORD(addr);
 43         } while (first != second);
 44 
 45         return (first);
 46 }
 47 
 48 static __inline__ int qla2x00_normalize_dma_addr(
 49     dma_addr_t *e_addr,  uint32_t *e_len,
 50     dma_addr_t *ne_addr, uint32_t *ne_len);
 51 
 52 /**
 53  * qla2x00_normalize_dma_addr() - Normalize an DMA address.
 54  * @e_addr: Raw DMA address
 55  * @e_len: Raw DMA length
 56  * @ne_addr: Normalized second DMA address
 57  * @ne_len: Normalized second DMA length
 58  *
 59  * If the address does not span a 4GB page boundary, the contents of @ne_addr
 60  * and @ne_len are undefined.  @e_len is updated to reflect a normalization.
 61  *
 62  * Example:
 63  *
 64  *      ffffabc0ffffeeee        (e_addr) start of DMA address
 65  *      0000000020000000        (e_len)  length of DMA transfer
 66  *      ffffabc11fffeeed        end of DMA transfer
 67  *
 68  * Is the 4GB boundary crossed?
 69  *
 70  *      ffffabc0ffffeeee        (e_addr)
 71  *      ffffabc11fffeeed        (e_addr + e_len - 1)
 72  *      00000001e0000003        ((e_addr ^ (e_addr + e_len - 1))
 73  *      0000000100000000        ((e_addr ^ (e_addr + e_len - 1)) & ~(0xffffffff)
 74  *
 75  * Compute start of second DMA segment:
 76  *
 77  *      ffffabc0ffffeeee        (e_addr)
 78  *      ffffabc1ffffeeee        (0x100000000 + e_addr)
 79  *      ffffabc100000000        (0x100000000 + e_addr) & ~(0xffffffff)
 80  *      ffffabc100000000        (ne_addr)
 81  *      
 82  * Compute length of second DMA segment:
 83  *
 84  *      00000000ffffeeee        (e_addr & 0xffffffff)
 85  *      0000000000001112        (0x100000000 - (e_addr & 0xffffffff))
 86  *      000000001fffeeee        (e_len - (0x100000000 - (e_addr & 0xffffffff))
 87  *      000000001fffeeee        (ne_len)
 88  *
 89  * Adjust length of first DMA segment
 90  *
 91  *      0000000020000000        (e_len)
 92  *      0000000000001112        (e_len - ne_len)
 93  *      0000000000001112        (e_len)
 94  *
 95  * Returns non-zero if the specified address was normalized, else zero.
 96  */
 97 static __inline__ int
 98 qla2x00_normalize_dma_addr(
 99     dma_addr_t *e_addr,  uint32_t *e_len,
100     dma_addr_t *ne_addr, uint32_t *ne_len)
101 {
102         int normalized;
103 
104         normalized = 0;
105         if ((*e_addr ^ (*e_addr + *e_len - 1)) & ~(0xFFFFFFFFULL)) {
106                 /* Compute normalized crossed address and len */
107                 *ne_addr = (0x100000000ULL + *e_addr) & ~(0xFFFFFFFFULL);
108                 *ne_len = *e_len - (0x100000000ULL - (*e_addr & 0xFFFFFFFFULL));
109                 *e_len -= *ne_len;
110 
111                 normalized++;
112         }
113         return (normalized);
114 }
115 
116 static __inline__ void qla2x00_poll(scsi_qla_host_t *);
117 static inline void 
118 qla2x00_poll(scsi_qla_host_t *ha)
119 {
120         if (IS_QLA2100(ha) || IS_QLA2200(ha))
121                 qla2100_intr_handler(0, ha, NULL);
122         else
123                 qla2300_intr_handler(0, ha, NULL);
124 }
125 
126 
127 static __inline__ void qla2x00_enable_intrs(scsi_qla_host_t *);
128 static __inline__ void qla2x00_disable_intrs(scsi_qla_host_t *);
129 
130 static inline void 
131 qla2x00_enable_intrs(scsi_qla_host_t *ha)
132 {
133         unsigned long flags = 0;
134         device_reg_t __iomem *reg = ha->iobase;
135 
136         spin_lock_irqsave(&ha->hardware_lock, flags);
137         ha->interrupts_on = 1;
138         /* enable risc and host interrupts */
139         WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
140         RD_REG_WORD(&reg->ictrl);
141         spin_unlock_irqrestore(&ha->hardware_lock, flags);
142 
143 }
144 
145 static inline void 
146 qla2x00_disable_intrs(scsi_qla_host_t *ha)
147 {
148         unsigned long flags = 0;
149         device_reg_t __iomem *reg = ha->iobase;
150 
151         spin_lock_irqsave(&ha->hardware_lock, flags);
152         ha->interrupts_on = 0;
153         /* disable risc and host interrupts */
154         WRT_REG_WORD(&reg->ictrl, 0);
155         RD_REG_WORD(&reg->ictrl);
156         spin_unlock_irqrestore(&ha->hardware_lock, flags);
157 }
158 
159 
160 static __inline__ int qla2x00_is_wwn_zero(uint8_t *);
161 
162 /*
163  * qla2x00_is_wwn_zero - Check for zero node name
164  *
165  * Input:
166  *      wwn = Pointer to WW name to check
167  *
168  * Returns:
169  *      1 if name is 0x00 else 0
170  *
171  * Context:
172  *      Kernel context.
173  */
174 static __inline__ int
175 qla2x00_is_wwn_zero(uint8_t *wwn)
176 {
177         int cnt;
178 
179         for (cnt = 0; cnt < WWN_SIZE ; cnt++, wwn++) {
180                 if (*wwn != 0)
181                         break;
182         }
183         /* if zero return 1 */
184         if (cnt == WWN_SIZE)
185                 return (1);
186         else
187                 return (0);
188 }
189 
190 static __inline__ uint8_t
191 qla2x00_suspend_lun(scsi_qla_host_t *, os_lun_t *, int, int);
192 static __inline__ uint8_t
193 qla2x00_delay_lun(scsi_qla_host_t *, os_lun_t *, int);
194 
195 static __inline__ uint8_t
196 qla2x00_suspend_lun(scsi_qla_host_t *ha, os_lun_t *lq, int time, int count)
197 {
198         return (__qla2x00_suspend_lun(ha, lq, time, count, 0));
199 }
200 
201 static __inline__ uint8_t
202 qla2x00_delay_lun(scsi_qla_host_t *ha, os_lun_t *lq, int time)
203 {
204         return (__qla2x00_suspend_lun(ha, lq, time, 1, 1));
205 }
206 
207 static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *);
208 /*
209  * This routine will wait for fabric devices for
210  * the reset delay.
211  */
212 static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha) 
213 {
214         uint16_t        fw_state;
215 
216         qla2x00_get_firmware_state(ha, &fw_state);
217 }
218 
219 /**
220  * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
221  * @ha: HA context
222  * @ha_locked: is function called with the hardware lock
223  *
224  * Returns non-zero if a failure occured, else zero.
225  */
226 static inline int
227 qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked)
228 {
229         /* Send marker if required */
230         if (ha->marker_needed != 0) {
231                 if (ha_locked) {
232                         if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
233                             QLA_SUCCESS)
234                                 return (QLA_FUNCTION_FAILED);
235                 } else {
236                         if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
237                             QLA_SUCCESS)
238                                 return (QLA_FUNCTION_FAILED);
239                 }
240                 ha->marker_needed = 0;
241         }
242         return (QLA_SUCCESS);
243 }
244 
245 static __inline__ void qla2x00_add_timer_to_cmd(srb_t *, int);
246 static __inline__ void qla2x00_delete_timer_from_cmd(srb_t *);
247 
248 /**************************************************************************
249 *   qla2x00_add_timer_to_cmd
250 *
251 * Description:
252 *       Creates a timer for the specified command. The timeout is usually
253 *       the command time from kernel minus 2 secs.
254 *
255 * Input:
256 *     sp - pointer to validate
257 *
258 * Returns:
259 *     None.
260 **************************************************************************/
261 static inline void
262 qla2x00_add_timer_to_cmd(srb_t *sp, int timeout)
263 {
264         init_timer(&sp->timer);
265         sp->timer.expires = jiffies + timeout * HZ;
266         sp->timer.data = (unsigned long) sp;
267         sp->timer.function = (void (*) (unsigned long))qla2x00_cmd_timeout;
268         add_timer(&sp->timer);
269 }
270 
271 /**************************************************************************
272 *   qla2x00_delete_timer_from_cmd
273 *
274 * Description:
275 *       Delete the timer for the specified command.
276 *
277 * Input:
278 *     sp - pointer to validate
279 *
280 * Returns:
281 *     None.
282 **************************************************************************/
283 static inline void 
284 qla2x00_delete_timer_from_cmd(srb_t *sp)
285 {
286         if (sp->timer.function != NULL) {
287                 del_timer(&sp->timer);
288                 sp->timer.function =  NULL;
289                 sp->timer.data = (unsigned long) NULL;
290         }
291 }
292 
293 
  This page was automatically generated by the LXR engine.