aic7xxx_osm.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. /*
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * Copyright (c) 1994 John Aycock
  5. * The University of Calgary Department of Computer Science.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Copyright (c) 2000-2003 Adaptec Inc.
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the above copyright
  28. * notice, this list of conditions, and the following disclaimer,
  29. * without modification.
  30. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  31. * substantially similar to the "NO WARRANTY" disclaimer below
  32. * ("Disclaimer") and any redistribution must be conditioned upon
  33. * including a substantially similar Disclaimer requirement for further
  34. * binary redistribution.
  35. * 3. Neither the names of the above-listed copyright holders nor the names
  36. * of any contributors may be used to endorse or promote products derived
  37. * from this software without specific prior written permission.
  38. *
  39. * Alternatively, this software may be distributed under the terms of the
  40. * GNU General Public License ("GPL") version 2 as published by the Free
  41. * Software Foundation.
  42. *
  43. * NO WARRANTY
  44. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  45. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  47. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  48. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  49. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  50. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  52. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  53. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. * POSSIBILITY OF SUCH DAMAGES.
  55. *
  56. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#151 $
  57. *
  58. */
  59. #ifndef _AIC7XXX_LINUX_H_
  60. #define _AIC7XXX_LINUX_H_
  61. #include <linux/types.h>
  62. #include <linux/blkdev.h>
  63. #include <linux/delay.h>
  64. #include <linux/ioport.h>
  65. #include <linux/pci.h>
  66. #include <linux/smp_lock.h>
  67. #include <linux/version.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/module.h>
  70. #include <asm/byteorder.h>
  71. #include <asm/io.h>
  72. #include <linux/config.h>
  73. #include <linux/slab.h>
  74. /* Core SCSI definitions */
  75. #define AIC_LIB_PREFIX ahc
  76. #include "scsi.h"
  77. #include <scsi/scsi_host.h>
  78. /* Name space conflict with BSD queue macros */
  79. #ifdef LIST_HEAD
  80. #undef LIST_HEAD
  81. #endif
  82. #include "cam.h"
  83. #include "queue.h"
  84. #include "scsi_message.h"
  85. #include "aiclib.h"
  86. /*********************************** Debugging ********************************/
  87. #ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
  88. #ifdef CONFIG_AIC7XXX_DEBUG_MASK
  89. #define AHC_DEBUG 1
  90. #define AHC_DEBUG_OPTS CONFIG_AIC7XXX_DEBUG_MASK
  91. #else
  92. /*
  93. * Compile in debugging code, but do not enable any printfs.
  94. */
  95. #define AHC_DEBUG 1
  96. #endif
  97. /* No debugging code. */
  98. #endif
  99. /************************* Forward Declarations *******************************/
  100. struct ahc_softc;
  101. typedef struct pci_dev *ahc_dev_softc_t;
  102. typedef Scsi_Cmnd *ahc_io_ctx_t;
  103. /******************************* Byte Order ***********************************/
  104. #define ahc_htobe16(x) cpu_to_be16(x)
  105. #define ahc_htobe32(x) cpu_to_be32(x)
  106. #define ahc_htobe64(x) cpu_to_be64(x)
  107. #define ahc_htole16(x) cpu_to_le16(x)
  108. #define ahc_htole32(x) cpu_to_le32(x)
  109. #define ahc_htole64(x) cpu_to_le64(x)
  110. #define ahc_be16toh(x) be16_to_cpu(x)
  111. #define ahc_be32toh(x) be32_to_cpu(x)
  112. #define ahc_be64toh(x) be64_to_cpu(x)
  113. #define ahc_le16toh(x) le16_to_cpu(x)
  114. #define ahc_le32toh(x) le32_to_cpu(x)
  115. #define ahc_le64toh(x) le64_to_cpu(x)
  116. #ifndef LITTLE_ENDIAN
  117. #define LITTLE_ENDIAN 1234
  118. #endif
  119. #ifndef BIG_ENDIAN
  120. #define BIG_ENDIAN 4321
  121. #endif
  122. #ifndef BYTE_ORDER
  123. #if defined(__BIG_ENDIAN)
  124. #define BYTE_ORDER BIG_ENDIAN
  125. #endif
  126. #if defined(__LITTLE_ENDIAN)
  127. #define BYTE_ORDER LITTLE_ENDIAN
  128. #endif
  129. #endif /* BYTE_ORDER */
  130. /************************* Configuration Data *********************************/
  131. extern u_int aic7xxx_no_probe;
  132. extern u_int aic7xxx_allow_memio;
  133. extern int aic7xxx_detect_complete;
  134. extern Scsi_Host_Template aic7xxx_driver_template;
  135. /***************************** Bus Space/DMA **********************************/
  136. typedef uint32_t bus_size_t;
  137. typedef enum {
  138. BUS_SPACE_MEMIO,
  139. BUS_SPACE_PIO
  140. } bus_space_tag_t;
  141. typedef union {
  142. u_long ioport;
  143. volatile uint8_t __iomem *maddr;
  144. } bus_space_handle_t;
  145. typedef struct bus_dma_segment
  146. {
  147. dma_addr_t ds_addr;
  148. bus_size_t ds_len;
  149. } bus_dma_segment_t;
  150. struct ahc_linux_dma_tag
  151. {
  152. bus_size_t alignment;
  153. bus_size_t boundary;
  154. bus_size_t maxsize;
  155. };
  156. typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
  157. struct ahc_linux_dmamap
  158. {
  159. dma_addr_t bus_addr;
  160. };
  161. typedef struct ahc_linux_dmamap* bus_dmamap_t;
  162. typedef int bus_dma_filter_t(void*, dma_addr_t);
  163. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  164. #define BUS_DMA_WAITOK 0x0
  165. #define BUS_DMA_NOWAIT 0x1
  166. #define BUS_DMA_ALLOCNOW 0x2
  167. #define BUS_DMA_LOAD_SEGS 0x4 /*
  168. * Argument is an S/G list not
  169. * a single buffer.
  170. */
  171. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  172. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  173. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  174. int ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
  175. bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  176. dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
  177. bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  178. bus_size_t /*maxsize*/, int /*nsegments*/,
  179. bus_size_t /*maxsegsz*/, int /*flags*/,
  180. bus_dma_tag_t */*dma_tagp*/);
  181. void ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
  182. int ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  183. void** /*vaddr*/, int /*flags*/,
  184. bus_dmamap_t* /*mapp*/);
  185. void ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  186. void* /*vaddr*/, bus_dmamap_t /*map*/);
  187. void ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
  188. bus_dmamap_t /*map*/);
  189. int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
  190. bus_dmamap_t /*map*/, void * /*buf*/,
  191. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  192. void */*callback_arg*/, int /*flags*/);
  193. int ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
  194. /*
  195. * Operations performed by ahc_dmamap_sync().
  196. */
  197. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  198. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  199. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  200. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  201. /*
  202. * XXX
  203. * ahc_dmamap_sync is only used on buffers allocated with
  204. * the pci_alloc_consistent() API. Although I'm not sure how
  205. * this works on architectures with a write buffer, Linux does
  206. * not have an API to sync "coherent" memory. Perhaps we need
  207. * to do an mb()?
  208. */
  209. #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
  210. /************************** Timer DataStructures ******************************/
  211. typedef struct timer_list ahc_timer_t;
  212. /********************************** Includes **********************************/
  213. #ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
  214. #define AIC_DEBUG_REGISTERS 1
  215. #else
  216. #define AIC_DEBUG_REGISTERS 0
  217. #endif
  218. #include "aic7xxx.h"
  219. /***************************** Timer Facilities *******************************/
  220. #define ahc_timer_init init_timer
  221. #define ahc_timer_stop del_timer_sync
  222. typedef void ahc_linux_callback_t (u_long);
  223. static __inline void ahc_timer_reset(ahc_timer_t *timer, int usec,
  224. ahc_callback_t *func, void *arg);
  225. static __inline void ahc_scb_timer_reset(struct scb *scb, u_int usec);
  226. static __inline void
  227. ahc_timer_reset(ahc_timer_t *timer, int usec, ahc_callback_t *func, void *arg)
  228. {
  229. struct ahc_softc *ahc;
  230. ahc = (struct ahc_softc *)arg;
  231. del_timer(timer);
  232. timer->data = (u_long)arg;
  233. timer->expires = jiffies + (usec * HZ)/1000000;
  234. timer->function = (ahc_linux_callback_t*)func;
  235. add_timer(timer);
  236. }
  237. static __inline void
  238. ahc_scb_timer_reset(struct scb *scb, u_int usec)
  239. {
  240. mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
  241. }
  242. /***************************** SMP support ************************************/
  243. #include <linux/spinlock.h>
  244. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) || defined(SCSI_HAS_HOST_LOCK))
  245. #define AHC_SCSI_HAS_HOST_LOCK 1
  246. #else
  247. #define AHC_SCSI_HAS_HOST_LOCK 0
  248. #endif
  249. #define AIC7XXX_DRIVER_VERSION "6.2.36"
  250. /**************************** Front End Queues ********************************/
  251. /*
  252. * Data structure used to cast the Linux struct scsi_cmnd to something
  253. * that allows us to use the queue macros. The linux structure has
  254. * plenty of space to hold the links fields as required by the queue
  255. * macros, but the queue macors require them to have the correct type.
  256. */
  257. struct ahc_cmd_internal {
  258. /* Area owned by the Linux scsi layer. */
  259. uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
  260. union {
  261. STAILQ_ENTRY(ahc_cmd) ste;
  262. LIST_ENTRY(ahc_cmd) le;
  263. TAILQ_ENTRY(ahc_cmd) tqe;
  264. } links;
  265. uint32_t end;
  266. };
  267. struct ahc_cmd {
  268. union {
  269. struct ahc_cmd_internal icmd;
  270. struct scsi_cmnd scsi_cmd;
  271. } un;
  272. };
  273. #define acmd_icmd(cmd) ((cmd)->un.icmd)
  274. #define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
  275. #define acmd_links un.icmd.links
  276. /*************************** Device Data Structures ***************************/
  277. /*
  278. * A per probed device structure used to deal with some error recovery
  279. * scenarios that the Linux mid-layer code just doesn't know how to
  280. * handle. The structure allocated for a device only becomes persistent
  281. * after a successfully completed inquiry command to the target when
  282. * that inquiry data indicates a lun is present.
  283. */
  284. TAILQ_HEAD(ahc_busyq, ahc_cmd);
  285. typedef enum {
  286. AHC_DEV_UNCONFIGURED = 0x01,
  287. AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  288. AHC_DEV_TIMER_ACTIVE = 0x04, /* Our timer is active */
  289. AHC_DEV_ON_RUN_LIST = 0x08, /* Queued to be run later */
  290. AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
  291. AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
  292. AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
  293. AHC_DEV_SLAVE_CONFIGURED = 0x80 /* slave_configure() has been called */
  294. } ahc_linux_dev_flags;
  295. struct ahc_linux_target;
  296. struct ahc_linux_device {
  297. TAILQ_ENTRY(ahc_linux_device) links;
  298. /*
  299. * The number of transactions currently
  300. * queued to the device.
  301. */
  302. int active;
  303. /*
  304. * The currently allowed number of
  305. * transactions that can be queued to
  306. * the device. Must be signed for
  307. * conversion from tagged to untagged
  308. * mode where the device may have more
  309. * than one outstanding active transaction.
  310. */
  311. int openings;
  312. /*
  313. * A positive count indicates that this
  314. * device's queue is halted.
  315. */
  316. u_int qfrozen;
  317. /*
  318. * Cumulative command counter.
  319. */
  320. u_long commands_issued;
  321. /*
  322. * The number of tagged transactions when
  323. * running at our current opening level
  324. * that have been successfully received by
  325. * this device since the last QUEUE FULL.
  326. */
  327. u_int tag_success_count;
  328. #define AHC_TAG_SUCCESS_INTERVAL 50
  329. ahc_linux_dev_flags flags;
  330. /*
  331. * Per device timer.
  332. */
  333. struct timer_list timer;
  334. /*
  335. * The high limit for the tags variable.
  336. */
  337. u_int maxtags;
  338. /*
  339. * The computed number of tags outstanding
  340. * at the time of the last QUEUE FULL event.
  341. */
  342. u_int tags_on_last_queuefull;
  343. /*
  344. * How many times we have seen a queue full
  345. * with the same number of tags. This is used
  346. * to stop our adaptive queue depth algorithm
  347. * on devices with a fixed number of tags.
  348. */
  349. u_int last_queuefull_same_count;
  350. #define AHC_LOCK_TAGS_COUNT 50
  351. /*
  352. * How many transactions have been queued
  353. * without the device going idle. We use
  354. * this statistic to determine when to issue
  355. * an ordered tag to prevent transaction
  356. * starvation. This statistic is only updated
  357. * if the AHC_DEV_PERIODIC_OTAG flag is set
  358. * on this device.
  359. */
  360. u_int commands_since_idle_or_otag;
  361. #define AHC_OTAG_THRESH 500
  362. int lun;
  363. Scsi_Device *scsi_device;
  364. struct ahc_linux_target *target;
  365. };
  366. struct ahc_linux_target {
  367. struct ahc_linux_device *devices[AHC_NUM_LUNS];
  368. int channel;
  369. int target;
  370. int refcount;
  371. struct ahc_transinfo last_tinfo;
  372. struct ahc_softc *ahc;
  373. };
  374. /********************* Definitions Required by the Core ***********************/
  375. /*
  376. * Number of SG segments we require. So long as the S/G segments for
  377. * a particular transaction are allocated in a physically contiguous
  378. * manner and are allocated below 4GB, the number of S/G segments is
  379. * unrestricted.
  380. */
  381. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
  382. /*
  383. * We dynamically adjust the number of segments in pre-2.5 kernels to
  384. * avoid fragmentation issues in the SCSI mid-layer's private memory
  385. * allocator. See aic7xxx_osm.c ahc_linux_size_nseg() for details.
  386. */
  387. extern u_int ahc_linux_nseg;
  388. #define AHC_NSEG ahc_linux_nseg
  389. #define AHC_LINUX_MIN_NSEG 64
  390. #else
  391. #define AHC_NSEG 128
  392. #endif
  393. /*
  394. * Per-SCB OSM storage.
  395. */
  396. typedef enum {
  397. AHC_UP_EH_SEMAPHORE = 0x1
  398. } ahc_linux_scb_flags;
  399. struct scb_platform_data {
  400. struct ahc_linux_device *dev;
  401. dma_addr_t buf_busaddr;
  402. uint32_t xfer_len;
  403. uint32_t sense_resid; /* Auto-Sense residual */
  404. ahc_linux_scb_flags flags;
  405. };
  406. /*
  407. * Define a structure used for each host adapter. All members are
  408. * aligned on a boundary >= the size of the member to honor the
  409. * alignment restrictions of the various platforms supported by
  410. * this driver.
  411. */
  412. typedef enum {
  413. AHC_RUN_CMPLT_Q_TIMER = 0x10
  414. } ahc_linux_softc_flags;
  415. TAILQ_HEAD(ahc_completeq, ahc_cmd);
  416. struct ahc_platform_data {
  417. /*
  418. * Fields accessed from interrupt context.
  419. */
  420. struct ahc_linux_target *targets[AHC_NUM_TARGETS];
  421. TAILQ_HEAD(, ahc_linux_device) device_runq;
  422. struct ahc_completeq completeq;
  423. spinlock_t spin_lock;
  424. u_int qfrozen;
  425. pid_t dv_pid;
  426. struct timer_list completeq_timer;
  427. struct timer_list reset_timer;
  428. struct semaphore eh_sem;
  429. struct semaphore dv_sem;
  430. struct semaphore dv_cmd_sem; /* XXX This needs to be in
  431. * the target struct
  432. */
  433. struct scsi_device *dv_scsi_dev;
  434. struct Scsi_Host *host; /* pointer to scsi host */
  435. #define AHC_LINUX_NOIRQ ((uint32_t)~0)
  436. uint32_t irq; /* IRQ for this adapter */
  437. uint32_t bios_address;
  438. uint32_t mem_busaddr; /* Mem Base Addr */
  439. uint64_t hw_dma_mask;
  440. ahc_linux_softc_flags flags;
  441. };
  442. /************************** OS Utility Wrappers *******************************/
  443. #define printf printk
  444. #define M_NOWAIT GFP_ATOMIC
  445. #define M_WAITOK 0
  446. #define malloc(size, type, flags) kmalloc(size, flags)
  447. #define free(ptr, type) kfree(ptr)
  448. static __inline void ahc_delay(long);
  449. static __inline void
  450. ahc_delay(long usec)
  451. {
  452. /*
  453. * udelay on Linux can have problems for
  454. * multi-millisecond waits. Wait at most
  455. * 1024us per call.
  456. */
  457. while (usec > 0) {
  458. udelay(usec % 1024);
  459. usec -= 1024;
  460. }
  461. }
  462. /***************************** Low Level I/O **********************************/
  463. static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
  464. static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
  465. static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
  466. uint8_t *, int count);
  467. static __inline void ahc_insb(struct ahc_softc * ahc, long port,
  468. uint8_t *, int count);
  469. static __inline uint8_t
  470. ahc_inb(struct ahc_softc * ahc, long port)
  471. {
  472. uint8_t x;
  473. if (ahc->tag == BUS_SPACE_MEMIO) {
  474. x = readb(ahc->bsh.maddr + port);
  475. } else {
  476. x = inb(ahc->bsh.ioport + port);
  477. }
  478. mb();
  479. return (x);
  480. }
  481. static __inline void
  482. ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
  483. {
  484. if (ahc->tag == BUS_SPACE_MEMIO) {
  485. writeb(val, ahc->bsh.maddr + port);
  486. } else {
  487. outb(val, ahc->bsh.ioport + port);
  488. }
  489. mb();
  490. }
  491. static __inline void
  492. ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  493. {
  494. int i;
  495. /*
  496. * There is probably a more efficient way to do this on Linux
  497. * but we don't use this for anything speed critical and this
  498. * should work.
  499. */
  500. for (i = 0; i < count; i++)
  501. ahc_outb(ahc, port, *array++);
  502. }
  503. static __inline void
  504. ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  505. {
  506. int i;
  507. /*
  508. * There is probably a more efficient way to do this on Linux
  509. * but we don't use this for anything speed critical and this
  510. * should work.
  511. */
  512. for (i = 0; i < count; i++)
  513. *array++ = ahc_inb(ahc, port);
  514. }
  515. /**************************** Initialization **********************************/
  516. int ahc_linux_register_host(struct ahc_softc *,
  517. Scsi_Host_Template *);
  518. uint64_t ahc_linux_get_memsize(void);
  519. /*************************** Pretty Printing **********************************/
  520. struct info_str {
  521. char *buffer;
  522. int length;
  523. off_t offset;
  524. int pos;
  525. };
  526. void ahc_format_transinfo(struct info_str *info,
  527. struct ahc_transinfo *tinfo);
  528. /******************************** Locking *************************************/
  529. /* Lock protecting internal data structures */
  530. static __inline void ahc_lockinit(struct ahc_softc *);
  531. static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
  532. static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
  533. /* Lock acquisition and release of the above lock in midlayer entry points. */
  534. static __inline void ahc_midlayer_entrypoint_lock(struct ahc_softc *,
  535. unsigned long *flags);
  536. static __inline void ahc_midlayer_entrypoint_unlock(struct ahc_softc *,
  537. unsigned long *flags);
  538. /* Lock held during command compeletion to the upper layer */
  539. static __inline void ahc_done_lockinit(struct ahc_softc *);
  540. static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
  541. static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
  542. /* Lock held during ahc_list manipulation and ahc softc frees */
  543. extern spinlock_t ahc_list_spinlock;
  544. static __inline void ahc_list_lockinit(void);
  545. static __inline void ahc_list_lock(unsigned long *flags);
  546. static __inline void ahc_list_unlock(unsigned long *flags);
  547. static __inline void
  548. ahc_lockinit(struct ahc_softc *ahc)
  549. {
  550. spin_lock_init(&ahc->platform_data->spin_lock);
  551. }
  552. static __inline void
  553. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  554. {
  555. spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
  556. }
  557. static __inline void
  558. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  559. {
  560. spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
  561. }
  562. static __inline void
  563. ahc_midlayer_entrypoint_lock(struct ahc_softc *ahc, unsigned long *flags)
  564. {
  565. /*
  566. * In 2.5.X and some 2.4.X versions, the midlayer takes our
  567. * lock just before calling us, so we avoid locking again.
  568. * For other kernel versions, the io_request_lock is taken
  569. * just before our entry point is called. In this case, we
  570. * trade the io_request_lock for our per-softc lock.
  571. */
  572. #if AHC_SCSI_HAS_HOST_LOCK == 0
  573. spin_unlock(&io_request_lock);
  574. spin_lock(&ahc->platform_data->spin_lock);
  575. #endif
  576. }
  577. static __inline void
  578. ahc_midlayer_entrypoint_unlock(struct ahc_softc *ahc, unsigned long *flags)
  579. {
  580. #if AHC_SCSI_HAS_HOST_LOCK == 0
  581. spin_unlock(&ahc->platform_data->spin_lock);
  582. spin_lock(&io_request_lock);
  583. #endif
  584. }
  585. static __inline void
  586. ahc_done_lockinit(struct ahc_softc *ahc)
  587. {
  588. /*
  589. * In 2.5.X, our own lock is held during completions.
  590. * In previous versions, the io_request_lock is used.
  591. * In either case, we can't initialize this lock again.
  592. */
  593. }
  594. static __inline void
  595. ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
  596. {
  597. #if AHC_SCSI_HAS_HOST_LOCK == 0
  598. spin_lock_irqsave(&io_request_lock, *flags);
  599. #endif
  600. }
  601. static __inline void
  602. ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
  603. {
  604. #if AHC_SCSI_HAS_HOST_LOCK == 0
  605. spin_unlock_irqrestore(&io_request_lock, *flags);
  606. #endif
  607. }
  608. static __inline void
  609. ahc_list_lockinit(void)
  610. {
  611. spin_lock_init(&ahc_list_spinlock);
  612. }
  613. static __inline void
  614. ahc_list_lock(unsigned long *flags)
  615. {
  616. spin_lock_irqsave(&ahc_list_spinlock, *flags);
  617. }
  618. static __inline void
  619. ahc_list_unlock(unsigned long *flags)
  620. {
  621. spin_unlock_irqrestore(&ahc_list_spinlock, *flags);
  622. }
  623. /******************************* PCI Definitions ******************************/
  624. /*
  625. * PCIM_xxx: mask to locate subfield in register
  626. * PCIR_xxx: config register offset
  627. * PCIC_xxx: device class
  628. * PCIS_xxx: device subclass
  629. * PCIP_xxx: device programming interface
  630. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  631. * PCID_xxx: device ID
  632. */
  633. #define PCIR_DEVVENDOR 0x00
  634. #define PCIR_VENDOR 0x00
  635. #define PCIR_DEVICE 0x02
  636. #define PCIR_COMMAND 0x04
  637. #define PCIM_CMD_PORTEN 0x0001
  638. #define PCIM_CMD_MEMEN 0x0002
  639. #define PCIM_CMD_BUSMASTEREN 0x0004
  640. #define PCIM_CMD_MWRICEN 0x0010
  641. #define PCIM_CMD_PERRESPEN 0x0040
  642. #define PCIM_CMD_SERRESPEN 0x0100
  643. #define PCIR_STATUS 0x06
  644. #define PCIR_REVID 0x08
  645. #define PCIR_PROGIF 0x09
  646. #define PCIR_SUBCLASS 0x0a
  647. #define PCIR_CLASS 0x0b
  648. #define PCIR_CACHELNSZ 0x0c
  649. #define PCIR_LATTIMER 0x0d
  650. #define PCIR_HEADERTYPE 0x0e
  651. #define PCIM_MFDEV 0x80
  652. #define PCIR_BIST 0x0f
  653. #define PCIR_CAP_PTR 0x34
  654. /* config registers for header type 0 devices */
  655. #define PCIR_MAPS 0x10
  656. #define PCIR_SUBVEND_0 0x2c
  657. #define PCIR_SUBDEV_0 0x2e
  658. extern struct pci_driver aic7xxx_pci_driver;
  659. typedef enum
  660. {
  661. AHC_POWER_STATE_D0,
  662. AHC_POWER_STATE_D1,
  663. AHC_POWER_STATE_D2,
  664. AHC_POWER_STATE_D3
  665. } ahc_power_state;
  666. /**************************** VL/EISA Routines ********************************/
  667. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) \
  668. && (defined(__i386__) || defined(__alpha__)) \
  669. && (!defined(CONFIG_EISA)))
  670. #define CONFIG_EISA
  671. #endif
  672. #ifdef CONFIG_EISA
  673. extern uint32_t aic7xxx_probe_eisa_vl;
  674. int ahc_linux_eisa_init(void);
  675. void ahc_linux_eisa_exit(void);
  676. int aic7770_map_registers(struct ahc_softc *ahc,
  677. u_int port);
  678. int aic7770_map_int(struct ahc_softc *ahc, u_int irq);
  679. #else
  680. static inline int ahc_linux_eisa_init(void) {
  681. return -ENODEV;
  682. }
  683. static inline void ahc_linux_eisa_exit(void) {
  684. }
  685. #endif
  686. /******************************* PCI Routines *********************************/
  687. #ifdef CONFIG_PCI
  688. int ahc_linux_pci_init(void);
  689. void ahc_linux_pci_exit(void);
  690. int ahc_pci_map_registers(struct ahc_softc *ahc);
  691. int ahc_pci_map_int(struct ahc_softc *ahc);
  692. static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
  693. int reg, int width);
  694. static __inline uint32_t
  695. ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
  696. {
  697. switch (width) {
  698. case 1:
  699. {
  700. uint8_t retval;
  701. pci_read_config_byte(pci, reg, &retval);
  702. return (retval);
  703. }
  704. case 2:
  705. {
  706. uint16_t retval;
  707. pci_read_config_word(pci, reg, &retval);
  708. return (retval);
  709. }
  710. case 4:
  711. {
  712. uint32_t retval;
  713. pci_read_config_dword(pci, reg, &retval);
  714. return (retval);
  715. }
  716. default:
  717. panic("ahc_pci_read_config: Read size too big");
  718. /* NOTREACHED */
  719. return (0);
  720. }
  721. }
  722. static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
  723. int reg, uint32_t value,
  724. int width);
  725. static __inline void
  726. ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
  727. {
  728. switch (width) {
  729. case 1:
  730. pci_write_config_byte(pci, reg, value);
  731. break;
  732. case 2:
  733. pci_write_config_word(pci, reg, value);
  734. break;
  735. case 4:
  736. pci_write_config_dword(pci, reg, value);
  737. break;
  738. default:
  739. panic("ahc_pci_write_config: Write size too big");
  740. /* NOTREACHED */
  741. }
  742. }
  743. static __inline int ahc_get_pci_function(ahc_dev_softc_t);
  744. static __inline int
  745. ahc_get_pci_function(ahc_dev_softc_t pci)
  746. {
  747. return (PCI_FUNC(pci->devfn));
  748. }
  749. static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
  750. static __inline int
  751. ahc_get_pci_slot(ahc_dev_softc_t pci)
  752. {
  753. return (PCI_SLOT(pci->devfn));
  754. }
  755. static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
  756. static __inline int
  757. ahc_get_pci_bus(ahc_dev_softc_t pci)
  758. {
  759. return (pci->bus->number);
  760. }
  761. #else
  762. static inline int ahc_linux_pci_init(void) {
  763. return 0;
  764. }
  765. static inline void ahc_linux_pci_exit(void) {
  766. }
  767. #endif
  768. static __inline void ahc_flush_device_writes(struct ahc_softc *);
  769. static __inline void
  770. ahc_flush_device_writes(struct ahc_softc *ahc)
  771. {
  772. /* XXX Is this sufficient for all architectures??? */
  773. ahc_inb(ahc, INTSTAT);
  774. }
  775. /**************************** Proc FS Support *********************************/
  776. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
  777. int ahc_linux_proc_info(char *, char **, off_t, int, int, int);
  778. #else
  779. int ahc_linux_proc_info(struct Scsi_Host *, char *, char **,
  780. off_t, int, int);
  781. #endif
  782. /*************************** Domain Validation ********************************/
  783. /*********************** Transaction Access Wrappers *************************/
  784. static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
  785. static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
  786. static __inline void ahc_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
  787. static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
  788. static __inline uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd);
  789. static __inline uint32_t ahc_get_transaction_status(struct scb *);
  790. static __inline uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd);
  791. static __inline uint32_t ahc_get_scsi_status(struct scb *);
  792. static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
  793. static __inline u_long ahc_get_transfer_length(struct scb *);
  794. static __inline int ahc_get_transfer_dir(struct scb *);
  795. static __inline void ahc_set_residual(struct scb *, u_long);
  796. static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
  797. static __inline u_long ahc_get_residual(struct scb *);
  798. static __inline u_long ahc_get_sense_residual(struct scb *);
  799. static __inline int ahc_perform_autosense(struct scb *);
  800. static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
  801. struct scb *);
  802. static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
  803. struct ahc_devinfo *);
  804. static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
  805. struct scb *scb);
  806. static __inline void ahc_freeze_scb(struct scb *scb);
  807. static __inline
  808. void ahc_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
  809. {
  810. cmd->result &= ~(CAM_STATUS_MASK << 16);
  811. cmd->result |= status << 16;
  812. }
  813. static __inline
  814. void ahc_set_transaction_status(struct scb *scb, uint32_t status)
  815. {
  816. ahc_cmd_set_transaction_status(scb->io_ctx,status);
  817. }
  818. static __inline
  819. void ahc_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
  820. {
  821. cmd->result &= ~0xFFFF;
  822. cmd->result |= status;
  823. }
  824. static __inline
  825. void ahc_set_scsi_status(struct scb *scb, uint32_t status)
  826. {
  827. ahc_cmd_set_scsi_status(scb->io_ctx, status);
  828. }
  829. static __inline
  830. uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd)
  831. {
  832. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  833. }
  834. static __inline
  835. uint32_t ahc_get_transaction_status(struct scb *scb)
  836. {
  837. return (ahc_cmd_get_transaction_status(scb->io_ctx));
  838. }
  839. static __inline
  840. uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd)
  841. {
  842. return (cmd->result & 0xFFFF);
  843. }
  844. static __inline
  845. uint32_t ahc_get_scsi_status(struct scb *scb)
  846. {
  847. return (ahc_cmd_get_scsi_status(scb->io_ctx));
  848. }
  849. static __inline
  850. void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  851. {
  852. /*
  853. * Nothing to do for linux as the incoming transaction
  854. * has no concept of tag/non tagged, etc.
  855. */
  856. }
  857. static __inline
  858. u_long ahc_get_transfer_length(struct scb *scb)
  859. {
  860. return (scb->platform_data->xfer_len);
  861. }
  862. static __inline
  863. int ahc_get_transfer_dir(struct scb *scb)
  864. {
  865. return (scb->io_ctx->sc_data_direction);
  866. }
  867. static __inline
  868. void ahc_set_residual(struct scb *scb, u_long resid)
  869. {
  870. scb->io_ctx->resid = resid;
  871. }
  872. static __inline
  873. void ahc_set_sense_residual(struct scb *scb, u_long resid)
  874. {
  875. scb->platform_data->sense_resid = resid;
  876. }
  877. static __inline
  878. u_long ahc_get_residual(struct scb *scb)
  879. {
  880. return (scb->io_ctx->resid);
  881. }
  882. static __inline
  883. u_long ahc_get_sense_residual(struct scb *scb)
  884. {
  885. return (scb->platform_data->sense_resid);
  886. }
  887. static __inline
  888. int ahc_perform_autosense(struct scb *scb)
  889. {
  890. /*
  891. * We always perform autosense in Linux.
  892. * On other platforms this is set on a
  893. * per-transaction basis.
  894. */
  895. return (1);
  896. }
  897. static __inline uint32_t
  898. ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
  899. {
  900. return (sizeof(struct scsi_sense_data));
  901. }
  902. static __inline void
  903. ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
  904. struct ahc_devinfo *devinfo)
  905. {
  906. /* Nothing to do here for linux */
  907. }
  908. static __inline void
  909. ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
  910. {
  911. ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
  912. }
  913. int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
  914. void ahc_platform_free(struct ahc_softc *ahc);
  915. void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  916. static __inline void
  917. ahc_freeze_scb(struct scb *scb)
  918. {
  919. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  920. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  921. scb->platform_data->dev->qfrozen++;
  922. }
  923. }
  924. void ahc_platform_set_tags(struct ahc_softc *ahc,
  925. struct ahc_devinfo *devinfo, ahc_queue_alg);
  926. int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
  927. char channel, int lun, u_int tag,
  928. role_t role, uint32_t status);
  929. irqreturn_t
  930. ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
  931. void ahc_platform_flushwork(struct ahc_softc *ahc);
  932. int ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
  933. void ahc_done(struct ahc_softc*, struct scb*);
  934. void ahc_send_async(struct ahc_softc *, char channel,
  935. u_int target, u_int lun, ac_code, void *);
  936. void ahc_print_path(struct ahc_softc *, struct scb *);
  937. void ahc_platform_dump_card_state(struct ahc_softc *ahc);
  938. #ifdef CONFIG_PCI
  939. #define AHC_PCI_CONFIG 1
  940. #else
  941. #define AHC_PCI_CONFIG 0
  942. #endif
  943. #define bootverbose aic7xxx_verbose
  944. extern u_int aic7xxx_verbose;
  945. #endif /* _AIC7XXX_LINUX_H_ */