esas2r.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. /*
  2. * linux/drivers/scsi/esas2r/esas2r.h
  3. * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
  4. *
  5. * Copyright (c) 2001-2013 ATTO Technology, Inc.
  6. * (mailto:linuxdrivers@attotech.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. *
  29. * DISCLAIMER OF LIABILITY
  30. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, write to the Free Software
  40. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  41. * USA.
  42. */
  43. #include <linux/kernel.h>
  44. #include <linux/delay.h>
  45. #include <linux/pci.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/module.h>
  50. #include <linux/vmalloc.h>
  51. #include <scsi/scsi.h>
  52. #include <scsi/scsi_host.h>
  53. #include <scsi/scsi_cmnd.h>
  54. #include <scsi/scsi_device.h>
  55. #include <scsi/scsi_eh.h>
  56. #include <scsi/scsi_tcq.h>
  57. #include "esas2r_log.h"
  58. #include "atioctl.h"
  59. #include "atvda.h"
  60. #ifndef ESAS2R_H
  61. #define ESAS2R_H
  62. /* Global Variables */
  63. extern struct esas2r_adapter *esas2r_adapters[];
  64. extern u8 *esas2r_buffered_ioctl;
  65. extern dma_addr_t esas2r_buffered_ioctl_addr;
  66. extern u32 esas2r_buffered_ioctl_size;
  67. extern struct pci_dev *esas2r_buffered_ioctl_pcid;
  68. #define SGL_PG_SZ_MIN 64
  69. #define SGL_PG_SZ_MAX 1024
  70. extern int sgl_page_size;
  71. #define NUM_SGL_MIN 8
  72. #define NUM_SGL_MAX 2048
  73. extern int num_sg_lists;
  74. #define NUM_REQ_MIN 4
  75. #define NUM_REQ_MAX 256
  76. extern int num_requests;
  77. #define NUM_AE_MIN 2
  78. #define NUM_AE_MAX 8
  79. extern int num_ae_requests;
  80. extern int cmd_per_lun;
  81. extern int can_queue;
  82. extern int esas2r_max_sectors;
  83. extern int sg_tablesize;
  84. extern int interrupt_mode;
  85. extern int num_io_requests;
  86. /* Macro defintions */
  87. #define ESAS2R_MAX_ID 255
  88. #define MAX_ADAPTERS 32
  89. #define ESAS2R_DRVR_NAME "esas2r"
  90. #define ESAS2R_LONGNAME "ATTO ExpressSAS 6GB RAID Adapter"
  91. #define ESAS2R_MAX_DEVICES 32
  92. #define ATTONODE_NAME "ATTONode"
  93. #define ESAS2R_MAJOR_REV 1
  94. #define ESAS2R_MINOR_REV 00
  95. #define ESAS2R_VERSION_STR DEFINED_NUM_TO_STR(ESAS2R_MAJOR_REV) "." \
  96. DEFINED_NUM_TO_STR(ESAS2R_MINOR_REV)
  97. #define ESAS2R_COPYRIGHT_YEARS "2001-2013"
  98. #define ESAS2R_DEFAULT_SGL_PAGE_SIZE 384
  99. #define ESAS2R_DEFAULT_CMD_PER_LUN 64
  100. #define ESAS2R_DEFAULT_NUM_SG_LISTS 1024
  101. #define DEFINED_NUM_TO_STR(num) NUM_TO_STR(num)
  102. #define NUM_TO_STR(num) #num
  103. #define ESAS2R_SGL_ALIGN 16
  104. #define ESAS2R_LIST_ALIGN 16
  105. #define ESAS2R_LIST_EXTRA ESAS2R_NUM_EXTRA
  106. #define ESAS2R_DATA_BUF_LEN 256
  107. #define ESAS2R_DEFAULT_TMO 5000
  108. #define ESAS2R_DISC_BUF_LEN 512
  109. #define ESAS2R_FWCOREDUMP_SZ 0x80000
  110. #define ESAS2R_NUM_PHYS 8
  111. #define ESAS2R_TARG_ID_INV 0xFFFF
  112. #define ESAS2R_INT_STS_MASK MU_INTSTAT_MASK
  113. #define ESAS2R_INT_ENB_MASK MU_INTSTAT_MASK
  114. #define ESAS2R_INT_DIS_MASK 0
  115. #define ESAS2R_MAX_TARGETS 256
  116. #define ESAS2R_KOBJ_NAME_LEN 20
  117. /* u16 (WORD) component macros */
  118. #define LOBYTE(w) ((u8)(u16)(w))
  119. #define HIBYTE(w) ((u8)(((u16)(w)) >> 8))
  120. #define MAKEWORD(lo, hi) ((u16)((u8)(lo) | ((u16)(u8)(hi) << 8)))
  121. /* u32 (DWORD) component macros */
  122. #define LOWORD(d) ((u16)(u32)(d))
  123. #define HIWORD(d) ((u16)(((u32)(d)) >> 16))
  124. #define MAKEDWORD(lo, hi) ((u32)((u16)(lo) | ((u32)(u16)(hi) << 16)))
  125. /* macro to get the lowest nonzero bit of a value */
  126. #define LOBIT(x) ((x) & (0 - (x)))
  127. /* These functions are provided to access the chip's control registers.
  128. * The register is specified by its byte offset from the register base
  129. * for the adapter.
  130. */
  131. #define esas2r_read_register_dword(a, reg) \
  132. readl((void __iomem *)a->regs + (reg) + MW_REG_OFFSET_HWREG)
  133. #define esas2r_write_register_dword(a, reg, data) \
  134. writel(data, (void __iomem *)(a->regs + (reg) + MW_REG_OFFSET_HWREG))
  135. #define esas2r_flush_register_dword(a, r) esas2r_read_register_dword(a, r)
  136. /* This function is provided to access the chip's data window. The
  137. * register is specified by its byte offset from the window base
  138. * for the adapter.
  139. */
  140. #define esas2r_read_data_byte(a, reg) \
  141. readb((void __iomem *)a->data_window + (reg))
  142. /* ATTO vendor and device Ids */
  143. #define ATTO_VENDOR_ID 0x117C
  144. #define ATTO_DID_INTEL_IOP348 0x002C
  145. #define ATTO_DID_MV_88RC9580 0x0049
  146. #define ATTO_DID_MV_88RC9580TS 0x0066
  147. #define ATTO_DID_MV_88RC9580TSE 0x0067
  148. #define ATTO_DID_MV_88RC9580TL 0x0068
  149. /* ATTO subsystem device Ids */
  150. #define ATTO_SSDID_TBT 0x4000
  151. #define ATTO_TSSC_3808 0x4066
  152. #define ATTO_TSSC_3808E 0x4067
  153. #define ATTO_TLSH_1068 0x4068
  154. #define ATTO_ESAS_R680 0x0049
  155. #define ATTO_ESAS_R608 0x004A
  156. #define ATTO_ESAS_R60F 0x004B
  157. #define ATTO_ESAS_R6F0 0x004C
  158. #define ATTO_ESAS_R644 0x004D
  159. #define ATTO_ESAS_R648 0x004E
  160. /*
  161. * flash definitions & structures
  162. * define the code types
  163. */
  164. #define FBT_CPYR 0xAA00
  165. #define FBT_SETUP 0xAA02
  166. #define FBT_FLASH_VER 0xAA04
  167. /* offsets to various locations in flash */
  168. #define FLS_OFFSET_BOOT (u32)(0x00700000)
  169. #define FLS_OFFSET_NVR (u32)(0x007C0000)
  170. #define FLS_OFFSET_CPYR FLS_OFFSET_NVR
  171. #define FLS_LENGTH_BOOT (FLS_OFFSET_CPYR - FLS_OFFSET_BOOT)
  172. #define FLS_BLOCK_SIZE (u32)(0x00020000)
  173. #define FI_NVR_2KB 0x0800
  174. #define FI_NVR_8KB 0x2000
  175. #define FM_BUF_SZ 0x800
  176. /*
  177. * marvell frey (88R9580) register definitions
  178. * chip revision identifiers
  179. */
  180. #define MVR_FREY_B2 0xB2
  181. /*
  182. * memory window definitions. window 0 is the data window with definitions
  183. * of MW_DATA_XXX. window 1 is the register window with definitions of
  184. * MW_REG_XXX.
  185. */
  186. #define MW_REG_WINDOW_SIZE (u32)(0x00040000)
  187. #define MW_REG_OFFSET_HWREG (u32)(0x00000000)
  188. #define MW_REG_OFFSET_PCI (u32)(0x00008000)
  189. #define MW_REG_PCI_HWREG_DELTA (MW_REG_OFFSET_PCI - MW_REG_OFFSET_HWREG)
  190. #define MW_DATA_WINDOW_SIZE (u32)(0x00020000)
  191. #define MW_DATA_ADDR_SER_FLASH (u32)(0xEC000000)
  192. #define MW_DATA_ADDR_SRAM (u32)(0xF4000000)
  193. #define MW_DATA_ADDR_PAR_FLASH (u32)(0xFC000000)
  194. /*
  195. * the following registers are for the communication
  196. * list interface (AKA message unit (MU))
  197. */
  198. #define MU_IN_LIST_ADDR_LO (u32)(0x00004000)
  199. #define MU_IN_LIST_ADDR_HI (u32)(0x00004004)
  200. #define MU_IN_LIST_WRITE (u32)(0x00004018)
  201. #define MU_ILW_TOGGLE (u32)(0x00004000)
  202. #define MU_IN_LIST_READ (u32)(0x0000401C)
  203. #define MU_ILR_TOGGLE (u32)(0x00004000)
  204. #define MU_ILIC_LIST (u32)(0x0000000F)
  205. #define MU_ILIC_LIST_F0 (u32)(0x00000000)
  206. #define MU_ILIC_DEST (u32)(0x00000F00)
  207. #define MU_ILIC_DEST_DDR (u32)(0x00000200)
  208. #define MU_IN_LIST_IFC_CONFIG (u32)(0x00004028)
  209. #define MU_IN_LIST_CONFIG (u32)(0x0000402C)
  210. #define MU_ILC_ENABLE (u32)(0x00000001)
  211. #define MU_ILC_ENTRY_MASK (u32)(0x000000F0)
  212. #define MU_ILC_ENTRY_4_DW (u32)(0x00000020)
  213. #define MU_ILC_DYNAMIC_SRC (u32)(0x00008000)
  214. #define MU_ILC_NUMBER_MASK (u32)(0x7FFF0000)
  215. #define MU_ILC_NUMBER_SHIFT 16
  216. #define MU_OUT_LIST_ADDR_LO (u32)(0x00004050)
  217. #define MU_OUT_LIST_ADDR_HI (u32)(0x00004054)
  218. #define MU_OUT_LIST_COPY_PTR_LO (u32)(0x00004058)
  219. #define MU_OUT_LIST_COPY_PTR_HI (u32)(0x0000405C)
  220. #define MU_OUT_LIST_WRITE (u32)(0x00004068)
  221. #define MU_OLW_TOGGLE (u32)(0x00004000)
  222. #define MU_OUT_LIST_COPY (u32)(0x0000406C)
  223. #define MU_OLC_TOGGLE (u32)(0x00004000)
  224. #define MU_OLC_WRT_PTR (u32)(0x00003FFF)
  225. #define MU_OUT_LIST_IFC_CONFIG (u32)(0x00004078)
  226. #define MU_OLIC_LIST (u32)(0x0000000F)
  227. #define MU_OLIC_LIST_F0 (u32)(0x00000000)
  228. #define MU_OLIC_SOURCE (u32)(0x00000F00)
  229. #define MU_OLIC_SOURCE_DDR (u32)(0x00000200)
  230. #define MU_OUT_LIST_CONFIG (u32)(0x0000407C)
  231. #define MU_OLC_ENABLE (u32)(0x00000001)
  232. #define MU_OLC_ENTRY_MASK (u32)(0x000000F0)
  233. #define MU_OLC_ENTRY_4_DW (u32)(0x00000020)
  234. #define MU_OLC_NUMBER_MASK (u32)(0x7FFF0000)
  235. #define MU_OLC_NUMBER_SHIFT 16
  236. #define MU_OUT_LIST_INT_STAT (u32)(0x00004088)
  237. #define MU_OLIS_INT (u32)(0x00000001)
  238. #define MU_OUT_LIST_INT_MASK (u32)(0x0000408C)
  239. #define MU_OLIS_MASK (u32)(0x00000001)
  240. /*
  241. * the maximum size of the communication lists is two greater than the
  242. * maximum amount of VDA requests. the extra are to prevent queue overflow.
  243. */
  244. #define ESAS2R_MAX_NUM_REQS 256
  245. #define ESAS2R_NUM_EXTRA 2
  246. #define ESAS2R_MAX_COMM_LIST_SIZE (ESAS2R_MAX_NUM_REQS + ESAS2R_NUM_EXTRA)
  247. /*
  248. * the following registers are for the CPU interface
  249. */
  250. #define MU_CTL_STATUS_IN (u32)(0x00010108)
  251. #define MU_CTL_IN_FULL_RST (u32)(0x00000020)
  252. #define MU_CTL_STATUS_IN_B2 (u32)(0x00010130)
  253. #define MU_CTL_IN_FULL_RST2 (u32)(0x80000000)
  254. #define MU_DOORBELL_IN (u32)(0x00010460)
  255. #define DRBL_RESET_BUS (u32)(0x00000002)
  256. #define DRBL_PAUSE_AE (u32)(0x00000004)
  257. #define DRBL_RESUME_AE (u32)(0x00000008)
  258. #define DRBL_MSG_IFC_DOWN (u32)(0x00000010)
  259. #define DRBL_FLASH_REQ (u32)(0x00000020)
  260. #define DRBL_FLASH_DONE (u32)(0x00000040)
  261. #define DRBL_FORCE_INT (u32)(0x00000080)
  262. #define DRBL_MSG_IFC_INIT (u32)(0x00000100)
  263. #define DRBL_POWER_DOWN (u32)(0x00000200)
  264. #define DRBL_DRV_VER_1 (u32)(0x00010000)
  265. #define DRBL_DRV_VER DRBL_DRV_VER_1
  266. #define MU_DOORBELL_IN_ENB (u32)(0x00010464)
  267. #define MU_DOORBELL_OUT (u32)(0x00010480)
  268. #define DRBL_PANIC_REASON_MASK (u32)(0x00F00000)
  269. #define DRBL_UNUSED_HANDLER (u32)(0x00100000)
  270. #define DRBL_UNDEF_INSTR (u32)(0x00200000)
  271. #define DRBL_PREFETCH_ABORT (u32)(0x00300000)
  272. #define DRBL_DATA_ABORT (u32)(0x00400000)
  273. #define DRBL_JUMP_TO_ZERO (u32)(0x00500000)
  274. #define DRBL_FW_RESET (u32)(0x00080000)
  275. #define DRBL_FW_VER_MSK (u32)(0x00070000)
  276. #define DRBL_FW_VER_0 (u32)(0x00000000)
  277. #define DRBL_FW_VER_1 (u32)(0x00010000)
  278. #define DRBL_FW_VER DRBL_FW_VER_1
  279. #define MU_DOORBELL_OUT_ENB (u32)(0x00010484)
  280. #define DRBL_ENB_MASK (u32)(0x00F803FF)
  281. #define MU_INT_STATUS_OUT (u32)(0x00010200)
  282. #define MU_INTSTAT_POST_OUT (u32)(0x00000010)
  283. #define MU_INTSTAT_DRBL_IN (u32)(0x00000100)
  284. #define MU_INTSTAT_DRBL (u32)(0x00001000)
  285. #define MU_INTSTAT_MASK (u32)(0x00001010)
  286. #define MU_INT_MASK_OUT (u32)(0x0001020C)
  287. /* PCI express registers accessed via window 1 */
  288. #define MVR_PCI_WIN1_REMAP (u32)(0x00008438)
  289. #define MVRPW1R_ENABLE (u32)(0x00000001)
  290. /* structures */
  291. /* inbound list dynamic source entry */
  292. struct esas2r_inbound_list_source_entry {
  293. u64 address;
  294. u32 length;
  295. #define HWILSE_INTERFACE_F0 0x00000000
  296. u32 reserved;
  297. };
  298. /* PCI data structure in expansion ROM images */
  299. struct __packed esas2r_boot_header {
  300. char signature[4];
  301. u16 vendor_id;
  302. u16 device_id;
  303. u16 VPD;
  304. u16 struct_length;
  305. u8 struct_revision;
  306. u8 class_code[3];
  307. u16 image_length;
  308. u16 code_revision;
  309. u8 code_type;
  310. #define CODE_TYPE_PC 0
  311. #define CODE_TYPE_OPEN 1
  312. #define CODE_TYPE_EFI 3
  313. u8 indicator;
  314. #define INDICATOR_LAST 0x80
  315. u8 reserved[2];
  316. };
  317. struct __packed esas2r_boot_image {
  318. u16 signature;
  319. u8 reserved[22];
  320. u16 header_offset;
  321. u16 pnp_offset;
  322. };
  323. struct __packed esas2r_pc_image {
  324. u16 signature;
  325. u8 length;
  326. u8 entry_point[3];
  327. u8 checksum;
  328. u16 image_end;
  329. u16 min_size;
  330. u8 rom_flags;
  331. u8 reserved[12];
  332. u16 header_offset;
  333. u16 pnp_offset;
  334. struct esas2r_boot_header boot_image;
  335. };
  336. struct __packed esas2r_efi_image {
  337. u16 signature;
  338. u16 length;
  339. u32 efi_signature;
  340. #define EFI_ROM_SIG 0x00000EF1
  341. u16 image_type;
  342. #define EFI_IMAGE_APP 10
  343. #define EFI_IMAGE_BSD 11
  344. #define EFI_IMAGE_RTD 12
  345. u16 machine_type;
  346. #define EFI_MACHINE_IA32 0x014c
  347. #define EFI_MACHINE_IA64 0x0200
  348. #define EFI_MACHINE_X64 0x8664
  349. #define EFI_MACHINE_EBC 0x0EBC
  350. u16 compression;
  351. #define EFI_UNCOMPRESSED 0x0000
  352. #define EFI_COMPRESSED 0x0001
  353. u8 reserved[8];
  354. u16 efi_offset;
  355. u16 header_offset;
  356. u16 reserved2;
  357. struct esas2r_boot_header boot_image;
  358. };
  359. struct esas2r_adapter;
  360. struct esas2r_sg_context;
  361. struct esas2r_request;
  362. typedef void (*RQCALLBK) (struct esas2r_adapter *a,
  363. struct esas2r_request *rq);
  364. typedef bool (*RQBUILDSGL) (struct esas2r_adapter *a,
  365. struct esas2r_sg_context *sgc);
  366. struct esas2r_component_header {
  367. u8 img_type;
  368. #define CH_IT_FW 0x00
  369. #define CH_IT_NVR 0x01
  370. #define CH_IT_BIOS 0x02
  371. #define CH_IT_MAC 0x03
  372. #define CH_IT_CFG 0x04
  373. #define CH_IT_EFI 0x05
  374. u8 status;
  375. #define CH_STAT_PENDING 0xff
  376. #define CH_STAT_FAILED 0x00
  377. #define CH_STAT_SUCCESS 0x01
  378. #define CH_STAT_RETRY 0x02
  379. #define CH_STAT_INVALID 0x03
  380. u8 pad[2];
  381. u32 version;
  382. u32 length;
  383. u32 image_offset;
  384. };
  385. #define FI_REL_VER_SZ 16
  386. struct esas2r_flash_img_v0 {
  387. u8 fi_version;
  388. #define FI_VERSION_0 00
  389. u8 status;
  390. u8 adap_typ;
  391. u8 action;
  392. u32 length;
  393. u16 checksum;
  394. u16 driver_error;
  395. u16 flags;
  396. u16 num_comps;
  397. #define FI_NUM_COMPS_V0 5
  398. u8 rel_version[FI_REL_VER_SZ];
  399. struct esas2r_component_header cmp_hdr[FI_NUM_COMPS_V0];
  400. u8 scratch_buf[FM_BUF_SZ];
  401. };
  402. struct esas2r_flash_img {
  403. u8 fi_version;
  404. #define FI_VERSION_1 01
  405. u8 status;
  406. #define FI_STAT_SUCCESS 0x00
  407. #define FI_STAT_FAILED 0x01
  408. #define FI_STAT_REBOOT 0x02
  409. #define FI_STAT_ADAPTYP 0x03
  410. #define FI_STAT_INVALID 0x04
  411. #define FI_STAT_CHKSUM 0x05
  412. #define FI_STAT_LENGTH 0x06
  413. #define FI_STAT_UNKNOWN 0x07
  414. #define FI_STAT_IMG_VER 0x08
  415. #define FI_STAT_BUSY 0x09
  416. #define FI_STAT_DUAL 0x0A
  417. #define FI_STAT_MISSING 0x0B
  418. #define FI_STAT_UNSUPP 0x0C
  419. #define FI_STAT_ERASE 0x0D
  420. #define FI_STAT_FLASH 0x0E
  421. #define FI_STAT_DEGRADED 0x0F
  422. u8 adap_typ;
  423. #define FI_AT_UNKNWN 0xFF
  424. #define FI_AT_SUN_LAKE 0x0B
  425. #define FI_AT_MV_9580 0x0F
  426. u8 action;
  427. #define FI_ACT_DOWN 0x00
  428. #define FI_ACT_UP 0x01
  429. #define FI_ACT_UPSZ 0x02
  430. #define FI_ACT_MAX 0x02
  431. #define FI_ACT_DOWN1 0x80
  432. u32 length;
  433. u16 checksum;
  434. u16 driver_error;
  435. u16 flags;
  436. #define FI_FLG_NVR_DEF 0x0001
  437. u16 num_comps;
  438. #define FI_NUM_COMPS_V1 6
  439. u8 rel_version[FI_REL_VER_SZ];
  440. struct esas2r_component_header cmp_hdr[FI_NUM_COMPS_V1];
  441. u8 scratch_buf[FM_BUF_SZ];
  442. };
  443. /* definitions for flash script (FS) commands */
  444. struct esas2r_ioctlfs_command {
  445. u8 command;
  446. #define ESAS2R_FS_CMD_ERASE 0
  447. #define ESAS2R_FS_CMD_READ 1
  448. #define ESAS2R_FS_CMD_BEGINW 2
  449. #define ESAS2R_FS_CMD_WRITE 3
  450. #define ESAS2R_FS_CMD_COMMIT 4
  451. #define ESAS2R_FS_CMD_CANCEL 5
  452. u8 checksum;
  453. u8 reserved[2];
  454. u32 flash_addr;
  455. u32 length;
  456. u32 image_offset;
  457. };
  458. struct esas2r_ioctl_fs {
  459. u8 version;
  460. #define ESAS2R_FS_VER 0
  461. u8 status;
  462. u8 driver_error;
  463. u8 adap_type;
  464. #define ESAS2R_FS_AT_ESASRAID2 3
  465. #define ESAS2R_FS_AT_TSSASRAID2 4
  466. #define ESAS2R_FS_AT_TSSASRAID2E 5
  467. #define ESAS2R_FS_AT_TLSASHBA 6
  468. u8 driver_ver;
  469. u8 reserved[11];
  470. struct esas2r_ioctlfs_command command;
  471. u8 data[1];
  472. };
  473. struct esas2r_sas_nvram {
  474. u8 signature[4];
  475. u8 version;
  476. #define SASNVR_VERSION_0 0x00
  477. #define SASNVR_VERSION SASNVR_VERSION_0
  478. u8 checksum;
  479. #define SASNVR_CKSUM_SEED 0x5A
  480. u8 max_lun_for_target;
  481. u8 pci_latency;
  482. #define SASNVR_PCILAT_DIS 0x00
  483. #define SASNVR_PCILAT_MIN 0x10
  484. #define SASNVR_PCILAT_MAX 0xF8
  485. u8 options1;
  486. #define SASNVR1_BOOT_DRVR 0x01
  487. #define SASNVR1_BOOT_SCAN 0x02
  488. #define SASNVR1_DIS_PCI_MWI 0x04
  489. #define SASNVR1_FORCE_ORD_Q 0x08
  490. #define SASNVR1_CACHELINE_0 0x10
  491. #define SASNVR1_DIS_DEVSORT 0x20
  492. #define SASNVR1_PWR_MGT_EN 0x40
  493. #define SASNVR1_WIDEPORT 0x80
  494. u8 options2;
  495. #define SASNVR2_SINGLE_BUS 0x01
  496. #define SASNVR2_SLOT_BIND 0x02
  497. #define SASNVR2_EXP_PROG 0x04
  498. #define SASNVR2_CMDTHR_LUN 0x08
  499. #define SASNVR2_HEARTBEAT 0x10
  500. #define SASNVR2_INT_CONNECT 0x20
  501. #define SASNVR2_SW_MUX_CTRL 0x40
  502. #define SASNVR2_DISABLE_NCQ 0x80
  503. u8 int_coalescing;
  504. #define SASNVR_COAL_DIS 0x00
  505. #define SASNVR_COAL_LOW 0x01
  506. #define SASNVR_COAL_MED 0x02
  507. #define SASNVR_COAL_HI 0x03
  508. u8 cmd_throttle;
  509. #define SASNVR_CMDTHR_NONE 0x00
  510. u8 dev_wait_time;
  511. u8 dev_wait_count;
  512. u8 spin_up_delay;
  513. #define SASNVR_SPINUP_MAX 0x14
  514. u8 ssp_align_rate;
  515. u8 sas_addr[8];
  516. u8 phy_speed[16];
  517. #define SASNVR_SPEED_AUTO 0x00
  518. #define SASNVR_SPEED_1_5GB 0x01
  519. #define SASNVR_SPEED_3GB 0x02
  520. #define SASNVR_SPEED_6GB 0x03
  521. #define SASNVR_SPEED_12GB 0x04
  522. u8 phy_mux[16];
  523. #define SASNVR_MUX_DISABLED 0x00
  524. #define SASNVR_MUX_1_5GB 0x01
  525. #define SASNVR_MUX_3GB 0x02
  526. #define SASNVR_MUX_6GB 0x03
  527. u8 phy_flags[16];
  528. #define SASNVR_PHF_DISABLED 0x01
  529. #define SASNVR_PHF_RD_ONLY 0x02
  530. u8 sort_type;
  531. #define SASNVR_SORT_SAS_ADDR 0x00
  532. #define SASNVR_SORT_H308_CONN 0x01
  533. #define SASNVR_SORT_PHY_ID 0x02
  534. #define SASNVR_SORT_SLOT_ID 0x03
  535. u8 dpm_reqcmd_lmt;
  536. u8 dpm_stndby_time;
  537. u8 dpm_active_time;
  538. u8 phy_target_id[16];
  539. #define SASNVR_PTI_DISABLED 0xFF
  540. u8 virt_ses_mode;
  541. #define SASNVR_VSMH_DISABLED 0x00
  542. u8 read_write_mode;
  543. #define SASNVR_RWM_DEFAULT 0x00
  544. u8 link_down_to;
  545. u8 reserved[0xA1];
  546. };
  547. typedef u32 (*PGETPHYSADDR) (struct esas2r_sg_context *sgc, u64 *addr);
  548. struct esas2r_sg_context {
  549. struct esas2r_adapter *adapter;
  550. struct esas2r_request *first_req;
  551. u32 length;
  552. u8 *cur_offset;
  553. PGETPHYSADDR get_phys_addr;
  554. union {
  555. struct {
  556. struct atto_vda_sge *curr;
  557. struct atto_vda_sge *last;
  558. struct atto_vda_sge *limit;
  559. struct atto_vda_sge *chain;
  560. } a64;
  561. struct {
  562. struct atto_physical_region_description *curr;
  563. struct atto_physical_region_description *chain;
  564. u32 sgl_max_cnt;
  565. u32 sge_cnt;
  566. } prd;
  567. } sge;
  568. struct scatterlist *cur_sgel;
  569. u8 *exp_offset;
  570. int num_sgel;
  571. int sgel_count;
  572. };
  573. struct esas2r_target {
  574. u8 flags;
  575. #define TF_PASS_THRU 0x01
  576. #define TF_USED 0x02
  577. u8 new_target_state;
  578. u8 target_state;
  579. u8 buffered_target_state;
  580. #define TS_NOT_PRESENT 0x00
  581. #define TS_PRESENT 0x05
  582. #define TS_LUN_CHANGE 0x06
  583. #define TS_INVALID 0xFF
  584. u32 block_size;
  585. u32 inter_block;
  586. u32 inter_byte;
  587. u16 virt_targ_id;
  588. u16 phys_targ_id;
  589. u8 identifier_len;
  590. u64 sas_addr;
  591. u8 identifier[60];
  592. struct atto_vda_ae_lu lu_event;
  593. };
  594. struct esas2r_request {
  595. struct list_head comp_list;
  596. struct list_head req_list;
  597. union atto_vda_req *vrq;
  598. struct esas2r_mem_desc *vrq_md;
  599. union {
  600. void *data_buf;
  601. union atto_vda_rsp_data *vda_rsp_data;
  602. };
  603. u8 *sense_buf;
  604. struct list_head sg_table_head;
  605. struct esas2r_mem_desc *sg_table;
  606. u32 timeout;
  607. #define RQ_TIMEOUT_S1 0xFFFFFFFF
  608. #define RQ_TIMEOUT_S2 0xFFFFFFFE
  609. #define RQ_MAX_TIMEOUT 0xFFFFFFFD
  610. u16 target_id;
  611. u8 req_type;
  612. #define RT_INI_REQ 0x01
  613. #define RT_DISC_REQ 0x02
  614. u8 sense_len;
  615. union atto_vda_func_rsp func_rsp;
  616. RQCALLBK comp_cb;
  617. RQCALLBK interrupt_cb;
  618. void *interrupt_cx;
  619. u8 flags;
  620. #define RF_1ST_IBLK_BASE 0x04
  621. #define RF_FAILURE_OK 0x08
  622. u8 req_stat;
  623. u16 vda_req_sz;
  624. #define RQ_SIZE_DEFAULT 0
  625. u64 lba;
  626. RQCALLBK aux_req_cb;
  627. void *aux_req_cx;
  628. u32 blk_len;
  629. u32 max_blk_len;
  630. union {
  631. struct scsi_cmnd *cmd;
  632. u8 *task_management_status_ptr;
  633. };
  634. };
  635. struct esas2r_flash_context {
  636. struct esas2r_flash_img *fi;
  637. RQCALLBK interrupt_cb;
  638. u8 *sgc_offset;
  639. u8 *scratch;
  640. u32 fi_hdr_len;
  641. u8 task;
  642. #define FMTSK_ERASE_BOOT 0
  643. #define FMTSK_WRTBIOS 1
  644. #define FMTSK_READBIOS 2
  645. #define FMTSK_WRTMAC 3
  646. #define FMTSK_READMAC 4
  647. #define FMTSK_WRTEFI 5
  648. #define FMTSK_READEFI 6
  649. #define FMTSK_WRTCFG 7
  650. #define FMTSK_READCFG 8
  651. u8 func;
  652. u16 num_comps;
  653. u32 cmp_len;
  654. u32 flsh_addr;
  655. u32 curr_len;
  656. u8 comp_typ;
  657. struct esas2r_sg_context sgc;
  658. };
  659. struct esas2r_disc_context {
  660. u8 disc_evt;
  661. #define DCDE_DEV_CHANGE 0x01
  662. #define DCDE_DEV_SCAN 0x02
  663. u8 state;
  664. #define DCS_DEV_RMV 0x00
  665. #define DCS_DEV_ADD 0x01
  666. #define DCS_BLOCK_DEV_SCAN 0x02
  667. #define DCS_RAID_GRP_INFO 0x03
  668. #define DCS_PART_INFO 0x04
  669. #define DCS_PT_DEV_INFO 0x05
  670. #define DCS_PT_DEV_ADDR 0x06
  671. #define DCS_DISC_DONE 0xFF
  672. u16 flags;
  673. #define DCF_DEV_CHANGE 0x0001
  674. #define DCF_DEV_SCAN 0x0002
  675. #define DCF_POLLED 0x8000
  676. u32 interleave;
  677. u32 block_size;
  678. u16 dev_ix;
  679. u8 part_num;
  680. u8 raid_grp_ix;
  681. char raid_grp_name[16];
  682. struct esas2r_target *curr_targ;
  683. u16 curr_virt_id;
  684. u16 curr_phys_id;
  685. u8 scan_gen;
  686. u8 dev_addr_type;
  687. u64 sas_addr;
  688. };
  689. struct esas2r_mem_desc {
  690. struct list_head next_desc;
  691. void *virt_addr;
  692. u64 phys_addr;
  693. void *pad;
  694. void *esas2r_data;
  695. u32 esas2r_param;
  696. u32 size;
  697. };
  698. enum fw_event_type {
  699. fw_event_null,
  700. fw_event_lun_change,
  701. fw_event_present,
  702. fw_event_not_present,
  703. fw_event_vda_ae
  704. };
  705. struct esas2r_vda_ae {
  706. u32 signature;
  707. #define ESAS2R_VDA_EVENT_SIG 0x4154544F
  708. u8 bus_number;
  709. u8 devfn;
  710. u8 pad[2];
  711. union atto_vda_ae vda_ae;
  712. };
  713. struct esas2r_fw_event_work {
  714. struct list_head list;
  715. struct delayed_work work;
  716. struct esas2r_adapter *a;
  717. enum fw_event_type type;
  718. u8 data[sizeof(struct esas2r_vda_ae)];
  719. };
  720. enum state {
  721. FW_INVALID_ST,
  722. FW_STATUS_ST,
  723. FW_COMMAND_ST
  724. };
  725. struct esas2r_firmware {
  726. enum state state;
  727. struct esas2r_flash_img header;
  728. u8 *data;
  729. u64 phys;
  730. int orig_len;
  731. void *header_buff;
  732. u64 header_buff_phys;
  733. };
  734. struct esas2r_adapter {
  735. struct esas2r_target targetdb[ESAS2R_MAX_TARGETS];
  736. struct esas2r_target *targetdb_end;
  737. unsigned char *regs;
  738. unsigned char *data_window;
  739. long flags;
  740. #define AF_PORT_CHANGE 0
  741. #define AF_CHPRST_NEEDED 1
  742. #define AF_CHPRST_PENDING 2
  743. #define AF_CHPRST_DETECTED 3
  744. #define AF_BUSRST_NEEDED 4
  745. #define AF_BUSRST_PENDING 5
  746. #define AF_BUSRST_DETECTED 6
  747. #define AF_DISABLED 7
  748. #define AF_FLASH_LOCK 8
  749. #define AF_OS_RESET 9
  750. #define AF_FLASHING 10
  751. #define AF_POWER_MGT 11
  752. #define AF_NVR_VALID 12
  753. #define AF_DEGRADED_MODE 13
  754. #define AF_DISC_PENDING 14
  755. #define AF_TASKLET_SCHEDULED 15
  756. #define AF_HEARTBEAT 16
  757. #define AF_HEARTBEAT_ENB 17
  758. #define AF_NOT_PRESENT 18
  759. #define AF_CHPRST_STARTED 19
  760. #define AF_FIRST_INIT 20
  761. #define AF_POWER_DOWN 21
  762. #define AF_DISC_IN_PROG 22
  763. #define AF_COMM_LIST_TOGGLE 23
  764. #define AF_LEGACY_SGE_MODE 24
  765. #define AF_DISC_POLLED 25
  766. long flags2;
  767. #define AF2_SERIAL_FLASH 0
  768. #define AF2_DEV_SCAN 1
  769. #define AF2_DEV_CNT_OK 2
  770. #define AF2_COREDUMP_AVAIL 3
  771. #define AF2_COREDUMP_SAVED 4
  772. #define AF2_VDA_POWER_DOWN 5
  773. #define AF2_THUNDERLINK 6
  774. #define AF2_THUNDERBOLT 7
  775. #define AF2_INIT_DONE 8
  776. #define AF2_INT_PENDING 9
  777. #define AF2_TIMER_TICK 10
  778. #define AF2_IRQ_CLAIMED 11
  779. #define AF2_MSI_ENABLED 12
  780. atomic_t disable_cnt;
  781. atomic_t dis_ints_cnt;
  782. u32 int_stat;
  783. u32 int_mask;
  784. u32 volatile *outbound_copy;
  785. struct list_head avail_request;
  786. spinlock_t request_lock;
  787. spinlock_t sg_list_lock;
  788. spinlock_t queue_lock;
  789. spinlock_t mem_lock;
  790. struct list_head free_sg_list_head;
  791. struct esas2r_mem_desc *sg_list_mds;
  792. struct list_head active_list;
  793. struct list_head defer_list;
  794. struct esas2r_request **req_table;
  795. union {
  796. u16 prev_dev_cnt;
  797. u32 heartbeat_time;
  798. #define ESAS2R_HEARTBEAT_TIME (3000)
  799. };
  800. u32 chip_uptime;
  801. #define ESAS2R_CHP_UPTIME_MAX (60000)
  802. #define ESAS2R_CHP_UPTIME_CNT (20000)
  803. u64 uncached_phys;
  804. u8 *uncached;
  805. struct esas2r_sas_nvram *nvram;
  806. struct esas2r_request general_req;
  807. u8 init_msg;
  808. #define ESAS2R_INIT_MSG_START 1
  809. #define ESAS2R_INIT_MSG_INIT 2
  810. #define ESAS2R_INIT_MSG_GET_INIT 3
  811. #define ESAS2R_INIT_MSG_REINIT 4
  812. u16 cmd_ref_no;
  813. u32 fw_version;
  814. u32 fw_build;
  815. u32 chip_init_time;
  816. #define ESAS2R_CHPRST_TIME (180000)
  817. #define ESAS2R_CHPRST_WAIT_TIME (2000)
  818. u32 last_tick_time;
  819. u32 window_base;
  820. RQBUILDSGL build_sgl;
  821. struct esas2r_request *first_ae_req;
  822. u32 list_size;
  823. u32 last_write;
  824. u32 last_read;
  825. u16 max_vdareq_size;
  826. u16 disc_wait_cnt;
  827. struct esas2r_mem_desc inbound_list_md;
  828. struct esas2r_mem_desc outbound_list_md;
  829. struct esas2r_disc_context disc_ctx;
  830. u8 *disc_buffer;
  831. u32 disc_start_time;
  832. u32 disc_wait_time;
  833. u32 flash_ver;
  834. char flash_rev[16];
  835. char fw_rev[16];
  836. char image_type[16];
  837. struct esas2r_flash_context flash_context;
  838. u32 num_targets_backend;
  839. u32 ioctl_tunnel;
  840. struct tasklet_struct tasklet;
  841. struct pci_dev *pcid;
  842. struct Scsi_Host *host;
  843. unsigned int index;
  844. char name[32];
  845. struct timer_list timer;
  846. struct esas2r_firmware firmware;
  847. wait_queue_head_t nvram_waiter;
  848. int nvram_command_done;
  849. wait_queue_head_t fm_api_waiter;
  850. int fm_api_command_done;
  851. wait_queue_head_t vda_waiter;
  852. int vda_command_done;
  853. u8 *vda_buffer;
  854. u64 ppvda_buffer;
  855. #define VDA_BUFFER_HEADER_SZ (offsetof(struct atto_ioctl_vda, data))
  856. #define VDA_MAX_BUFFER_SIZE (0x40000 + VDA_BUFFER_HEADER_SZ)
  857. wait_queue_head_t fs_api_waiter;
  858. int fs_api_command_done;
  859. u64 ppfs_api_buffer;
  860. u8 *fs_api_buffer;
  861. u32 fs_api_buffer_size;
  862. wait_queue_head_t buffered_ioctl_waiter;
  863. int buffered_ioctl_done;
  864. int uncached_size;
  865. struct workqueue_struct *fw_event_q;
  866. struct list_head fw_event_list;
  867. spinlock_t fw_event_lock;
  868. u8 fw_events_off; /* if '1', then ignore events */
  869. char fw_event_q_name[ESAS2R_KOBJ_NAME_LEN];
  870. /*
  871. * intr_mode stores the interrupt mode currently being used by this
  872. * adapter. it is based on the interrupt_mode module parameter, but
  873. * can be changed based on the ability (or not) to utilize the
  874. * mode requested by the parameter.
  875. */
  876. int intr_mode;
  877. #define INTR_MODE_LEGACY 0
  878. #define INTR_MODE_MSI 1
  879. #define INTR_MODE_MSIX 2
  880. struct esas2r_sg_context fm_api_sgc;
  881. u8 *save_offset;
  882. struct list_head vrq_mds_head;
  883. struct esas2r_mem_desc *vrq_mds;
  884. int num_vrqs;
  885. struct semaphore fm_api_semaphore;
  886. struct semaphore fs_api_semaphore;
  887. struct semaphore nvram_semaphore;
  888. struct atto_ioctl *local_atto_ioctl;
  889. u8 fw_coredump_buff[ESAS2R_FWCOREDUMP_SZ];
  890. unsigned int sysfs_fw_created:1;
  891. unsigned int sysfs_fs_created:1;
  892. unsigned int sysfs_vda_created:1;
  893. unsigned int sysfs_hw_created:1;
  894. unsigned int sysfs_live_nvram_created:1;
  895. unsigned int sysfs_default_nvram_created:1;
  896. };
  897. /*
  898. * Function Declarations
  899. * SCSI functions
  900. */
  901. int esas2r_release(struct Scsi_Host *);
  902. const char *esas2r_info(struct Scsi_Host *);
  903. int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq,
  904. struct esas2r_sas_nvram *data);
  905. int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg);
  906. int esas2r_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
  907. u8 handle_hba_ioctl(struct esas2r_adapter *a,
  908. struct atto_ioctl *ioctl_hba);
  909. int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd);
  910. int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh);
  911. long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
  912. /* SCSI error handler (eh) functions */
  913. int esas2r_eh_abort(struct scsi_cmnd *cmd);
  914. int esas2r_device_reset(struct scsi_cmnd *cmd);
  915. int esas2r_host_reset(struct scsi_cmnd *cmd);
  916. int esas2r_bus_reset(struct scsi_cmnd *cmd);
  917. int esas2r_target_reset(struct scsi_cmnd *cmd);
  918. /* Internal functions */
  919. int esas2r_init_adapter(struct Scsi_Host *host, struct pci_dev *pcid,
  920. int index);
  921. int esas2r_cleanup(struct Scsi_Host *host);
  922. int esas2r_read_fw(struct esas2r_adapter *a, char *buf, long off, int count);
  923. int esas2r_write_fw(struct esas2r_adapter *a, const char *buf, long off,
  924. int count);
  925. int esas2r_read_vda(struct esas2r_adapter *a, char *buf, long off, int count);
  926. int esas2r_write_vda(struct esas2r_adapter *a, const char *buf, long off,
  927. int count);
  928. int esas2r_read_fs(struct esas2r_adapter *a, char *buf, long off, int count);
  929. int esas2r_write_fs(struct esas2r_adapter *a, const char *buf, long off,
  930. int count);
  931. void esas2r_adapter_tasklet(unsigned long context);
  932. irqreturn_t esas2r_interrupt(int irq, void *dev_id);
  933. irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id);
  934. void esas2r_kickoff_timer(struct esas2r_adapter *a);
  935. int esas2r_suspend(struct pci_dev *pcid, pm_message_t state);
  936. int esas2r_resume(struct pci_dev *pcid);
  937. void esas2r_fw_event_off(struct esas2r_adapter *a);
  938. void esas2r_fw_event_on(struct esas2r_adapter *a);
  939. bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
  940. struct esas2r_sas_nvram *nvram);
  941. void esas2r_nvram_get_defaults(struct esas2r_adapter *a,
  942. struct esas2r_sas_nvram *nvram);
  943. void esas2r_complete_request_cb(struct esas2r_adapter *a,
  944. struct esas2r_request *rq);
  945. void esas2r_reset_detected(struct esas2r_adapter *a);
  946. void esas2r_target_state_changed(struct esas2r_adapter *ha, u16 targ_id,
  947. u8 state);
  948. int esas2r_req_status_to_error(u8 req_stat);
  949. void esas2r_kill_adapter(int i);
  950. void esas2r_free_request(struct esas2r_adapter *a, struct esas2r_request *rq);
  951. struct esas2r_request *esas2r_alloc_request(struct esas2r_adapter *a);
  952. u32 esas2r_get_uncached_size(struct esas2r_adapter *a);
  953. bool esas2r_init_adapter_struct(struct esas2r_adapter *a,
  954. void **uncached_area);
  955. bool esas2r_check_adapter(struct esas2r_adapter *a);
  956. bool esas2r_init_adapter_hw(struct esas2r_adapter *a, bool init_poll);
  957. void esas2r_start_request(struct esas2r_adapter *a, struct esas2r_request *rq);
  958. bool esas2r_send_task_mgmt(struct esas2r_adapter *a,
  959. struct esas2r_request *rqaux, u8 task_mgt_func);
  960. void esas2r_do_tasklet_tasks(struct esas2r_adapter *a);
  961. void esas2r_adapter_interrupt(struct esas2r_adapter *a);
  962. void esas2r_do_deferred_processes(struct esas2r_adapter *a);
  963. void esas2r_reset_bus(struct esas2r_adapter *a);
  964. void esas2r_reset_adapter(struct esas2r_adapter *a);
  965. void esas2r_timer_tick(struct esas2r_adapter *a);
  966. const char *esas2r_get_model_name(struct esas2r_adapter *a);
  967. const char *esas2r_get_model_name_short(struct esas2r_adapter *a);
  968. u32 esas2r_stall_execution(struct esas2r_adapter *a, u32 start_time,
  969. u32 *delay);
  970. void esas2r_build_flash_req(struct esas2r_adapter *a,
  971. struct esas2r_request *rq,
  972. u8 sub_func,
  973. u8 cksum,
  974. u32 addr,
  975. u32 length);
  976. void esas2r_build_mgt_req(struct esas2r_adapter *a,
  977. struct esas2r_request *rq,
  978. u8 sub_func,
  979. u8 scan_gen,
  980. u16 dev_index,
  981. u32 length,
  982. void *data);
  983. void esas2r_build_ae_req(struct esas2r_adapter *a, struct esas2r_request *rq);
  984. void esas2r_build_cli_req(struct esas2r_adapter *a,
  985. struct esas2r_request *rq,
  986. u32 length,
  987. u32 cmd_rsp_len);
  988. void esas2r_build_ioctl_req(struct esas2r_adapter *a,
  989. struct esas2r_request *rq,
  990. u32 length,
  991. u8 sub_func);
  992. void esas2r_build_cfg_req(struct esas2r_adapter *a,
  993. struct esas2r_request *rq,
  994. u8 sub_func,
  995. u32 length,
  996. void *data);
  997. void esas2r_power_down(struct esas2r_adapter *a);
  998. bool esas2r_power_up(struct esas2r_adapter *a, bool init_poll);
  999. void esas2r_wait_request(struct esas2r_adapter *a, struct esas2r_request *rq);
  1000. u32 esas2r_map_data_window(struct esas2r_adapter *a, u32 addr_lo);
  1001. bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
  1002. struct esas2r_ioctl_fs *fs,
  1003. struct esas2r_request *rq,
  1004. struct esas2r_sg_context *sgc);
  1005. bool esas2r_read_flash_block(struct esas2r_adapter *a, void *to, u32 from,
  1006. u32 size);
  1007. bool esas2r_read_mem_block(struct esas2r_adapter *a, void *to, u32 from,
  1008. u32 size);
  1009. bool esas2r_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi,
  1010. struct esas2r_request *rq, struct esas2r_sg_context *sgc);
  1011. void esas2r_force_interrupt(struct esas2r_adapter *a);
  1012. void esas2r_local_start_request(struct esas2r_adapter *a,
  1013. struct esas2r_request *rq);
  1014. void esas2r_process_adapter_reset(struct esas2r_adapter *a);
  1015. void esas2r_complete_request(struct esas2r_adapter *a,
  1016. struct esas2r_request *rq);
  1017. void esas2r_dummy_complete(struct esas2r_adapter *a,
  1018. struct esas2r_request *rq);
  1019. void esas2r_ae_complete(struct esas2r_adapter *a, struct esas2r_request *rq);
  1020. void esas2r_start_vda_request(struct esas2r_adapter *a,
  1021. struct esas2r_request *rq);
  1022. bool esas2r_read_flash_rev(struct esas2r_adapter *a);
  1023. bool esas2r_read_image_type(struct esas2r_adapter *a);
  1024. bool esas2r_nvram_read_direct(struct esas2r_adapter *a);
  1025. bool esas2r_nvram_validate(struct esas2r_adapter *a);
  1026. void esas2r_nvram_set_defaults(struct esas2r_adapter *a);
  1027. bool esas2r_print_flash_rev(struct esas2r_adapter *a);
  1028. void esas2r_send_reset_ae(struct esas2r_adapter *a, bool pwr_mgt);
  1029. bool esas2r_init_msgs(struct esas2r_adapter *a);
  1030. bool esas2r_is_adapter_present(struct esas2r_adapter *a);
  1031. void esas2r_nuxi_mgt_data(u8 function, void *data);
  1032. void esas2r_nuxi_cfg_data(u8 function, void *data);
  1033. void esas2r_nuxi_ae_data(union atto_vda_ae *ae);
  1034. void esas2r_reset_chip(struct esas2r_adapter *a);
  1035. void esas2r_log_request_failure(struct esas2r_adapter *a,
  1036. struct esas2r_request *rq);
  1037. void esas2r_polled_interrupt(struct esas2r_adapter *a);
  1038. bool esas2r_ioreq_aborted(struct esas2r_adapter *a, struct esas2r_request *rq,
  1039. u8 status);
  1040. bool esas2r_build_sg_list_sge(struct esas2r_adapter *a,
  1041. struct esas2r_sg_context *sgc);
  1042. bool esas2r_build_sg_list_prd(struct esas2r_adapter *a,
  1043. struct esas2r_sg_context *sgc);
  1044. void esas2r_targ_db_initialize(struct esas2r_adapter *a);
  1045. void esas2r_targ_db_remove_all(struct esas2r_adapter *a, bool notify);
  1046. void esas2r_targ_db_report_changes(struct esas2r_adapter *a);
  1047. struct esas2r_target *esas2r_targ_db_add_raid(struct esas2r_adapter *a,
  1048. struct esas2r_disc_context *dc);
  1049. struct esas2r_target *esas2r_targ_db_add_pthru(struct esas2r_adapter *a,
  1050. struct esas2r_disc_context *dc,
  1051. u8 *ident,
  1052. u8 ident_len);
  1053. void esas2r_targ_db_remove(struct esas2r_adapter *a, struct esas2r_target *t);
  1054. struct esas2r_target *esas2r_targ_db_find_by_sas_addr(struct esas2r_adapter *a,
  1055. u64 *sas_addr);
  1056. struct esas2r_target *esas2r_targ_db_find_by_ident(struct esas2r_adapter *a,
  1057. void *identifier,
  1058. u8 ident_len);
  1059. u16 esas2r_targ_db_find_next_present(struct esas2r_adapter *a, u16 target_id);
  1060. struct esas2r_target *esas2r_targ_db_find_by_virt_id(struct esas2r_adapter *a,
  1061. u16 virt_id);
  1062. u16 esas2r_targ_db_get_tgt_cnt(struct esas2r_adapter *a);
  1063. void esas2r_disc_initialize(struct esas2r_adapter *a);
  1064. void esas2r_disc_start_waiting(struct esas2r_adapter *a);
  1065. void esas2r_disc_check_for_work(struct esas2r_adapter *a);
  1066. void esas2r_disc_check_complete(struct esas2r_adapter *a);
  1067. void esas2r_disc_queue_event(struct esas2r_adapter *a, u8 disc_evt);
  1068. bool esas2r_disc_start_port(struct esas2r_adapter *a);
  1069. void esas2r_disc_local_start_request(struct esas2r_adapter *a,
  1070. struct esas2r_request *rq);
  1071. bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str);
  1072. bool esas2r_process_vda_ioctl(struct esas2r_adapter *a,
  1073. struct atto_ioctl_vda *vi,
  1074. struct esas2r_request *rq,
  1075. struct esas2r_sg_context *sgc);
  1076. void esas2r_queue_fw_event(struct esas2r_adapter *a,
  1077. enum fw_event_type type,
  1078. void *data,
  1079. int data_sz);
  1080. /* Inline functions */
  1081. /* Allocate a chip scatter/gather list entry */
  1082. static inline struct esas2r_mem_desc *esas2r_alloc_sgl(struct esas2r_adapter *a)
  1083. {
  1084. unsigned long flags;
  1085. struct list_head *sgl;
  1086. struct esas2r_mem_desc *result = NULL;
  1087. spin_lock_irqsave(&a->sg_list_lock, flags);
  1088. if (likely(!list_empty(&a->free_sg_list_head))) {
  1089. sgl = a->free_sg_list_head.next;
  1090. result = list_entry(sgl, struct esas2r_mem_desc, next_desc);
  1091. list_del_init(sgl);
  1092. }
  1093. spin_unlock_irqrestore(&a->sg_list_lock, flags);
  1094. return result;
  1095. }
  1096. /* Initialize a scatter/gather context */
  1097. static inline void esas2r_sgc_init(struct esas2r_sg_context *sgc,
  1098. struct esas2r_adapter *a,
  1099. struct esas2r_request *rq,
  1100. struct atto_vda_sge *first)
  1101. {
  1102. sgc->adapter = a;
  1103. sgc->first_req = rq;
  1104. /*
  1105. * set the limit pointer such that an SGE pointer above this value
  1106. * would be the first one to overflow the SGL.
  1107. */
  1108. sgc->sge.a64.limit = (struct atto_vda_sge *)((u8 *)rq->vrq
  1109. + (sizeof(union
  1110. atto_vda_req) /
  1111. 8)
  1112. - sizeof(struct
  1113. atto_vda_sge));
  1114. if (first) {
  1115. sgc->sge.a64.last =
  1116. sgc->sge.a64.curr = first;
  1117. rq->vrq->scsi.sg_list_offset = (u8)
  1118. ((u8 *)first -
  1119. (u8 *)rq->vrq);
  1120. } else {
  1121. sgc->sge.a64.last =
  1122. sgc->sge.a64.curr = &rq->vrq->scsi.u.sge[0];
  1123. rq->vrq->scsi.sg_list_offset =
  1124. (u8)offsetof(struct atto_vda_scsi_req, u.sge);
  1125. }
  1126. sgc->sge.a64.chain = NULL;
  1127. }
  1128. static inline void esas2r_rq_init_request(struct esas2r_request *rq,
  1129. struct esas2r_adapter *a)
  1130. {
  1131. union atto_vda_req *vrq = rq->vrq;
  1132. INIT_LIST_HEAD(&rq->sg_table_head);
  1133. rq->data_buf = (void *)(vrq + 1);
  1134. rq->interrupt_cb = NULL;
  1135. rq->comp_cb = esas2r_complete_request_cb;
  1136. rq->flags = 0;
  1137. rq->timeout = 0;
  1138. rq->req_stat = RS_PENDING;
  1139. rq->req_type = RT_INI_REQ;
  1140. /* clear the outbound response */
  1141. rq->func_rsp.dwords[0] = 0;
  1142. rq->func_rsp.dwords[1] = 0;
  1143. /*
  1144. * clear the size of the VDA request. esas2r_build_sg_list() will
  1145. * only allow the size of the request to grow. there are some
  1146. * management requests that go through there twice and the second
  1147. * time through sets a smaller request size. if this is not modified
  1148. * at all we'll set it to the size of the entire VDA request.
  1149. */
  1150. rq->vda_req_sz = RQ_SIZE_DEFAULT;
  1151. /* req_table entry should be NULL at this point - if not, halt */
  1152. if (a->req_table[LOWORD(vrq->scsi.handle)])
  1153. esas2r_bugon();
  1154. /* fill in the table for this handle so we can get back to the
  1155. * request.
  1156. */
  1157. a->req_table[LOWORD(vrq->scsi.handle)] = rq;
  1158. /*
  1159. * add a reference number to the handle to make it unique (until it
  1160. * wraps of course) while preserving the least significant word
  1161. */
  1162. vrq->scsi.handle = (a->cmd_ref_no++ << 16) | (u16)vrq->scsi.handle;
  1163. /*
  1164. * the following formats a SCSI request. the caller can override as
  1165. * necessary. clear_vda_request can be called to clear the VDA
  1166. * request for another type of request.
  1167. */
  1168. vrq->scsi.function = VDA_FUNC_SCSI;
  1169. vrq->scsi.sense_len = SENSE_DATA_SZ;
  1170. /* clear out sg_list_offset and chain_offset */
  1171. vrq->scsi.sg_list_offset = 0;
  1172. vrq->scsi.chain_offset = 0;
  1173. vrq->scsi.flags = 0;
  1174. vrq->scsi.reserved = 0;
  1175. /* set the sense buffer to be the data payload buffer */
  1176. vrq->scsi.ppsense_buf
  1177. = cpu_to_le64(rq->vrq_md->phys_addr +
  1178. sizeof(union atto_vda_req));
  1179. }
  1180. static inline void esas2r_rq_free_sg_lists(struct esas2r_request *rq,
  1181. struct esas2r_adapter *a)
  1182. {
  1183. unsigned long flags;
  1184. if (list_empty(&rq->sg_table_head))
  1185. return;
  1186. spin_lock_irqsave(&a->sg_list_lock, flags);
  1187. list_splice_tail_init(&rq->sg_table_head, &a->free_sg_list_head);
  1188. spin_unlock_irqrestore(&a->sg_list_lock, flags);
  1189. }
  1190. static inline void esas2r_rq_destroy_request(struct esas2r_request *rq,
  1191. struct esas2r_adapter *a)
  1192. {
  1193. esas2r_rq_free_sg_lists(rq, a);
  1194. a->req_table[LOWORD(rq->vrq->scsi.handle)] = NULL;
  1195. rq->data_buf = NULL;
  1196. }
  1197. static inline bool esas2r_is_tasklet_pending(struct esas2r_adapter *a)
  1198. {
  1199. return test_bit(AF_BUSRST_NEEDED, &a->flags) ||
  1200. test_bit(AF_BUSRST_DETECTED, &a->flags) ||
  1201. test_bit(AF_CHPRST_NEEDED, &a->flags) ||
  1202. test_bit(AF_CHPRST_DETECTED, &a->flags) ||
  1203. test_bit(AF_PORT_CHANGE, &a->flags);
  1204. }
  1205. /*
  1206. * Build the scatter/gather list for an I/O request according to the
  1207. * specifications placed in the esas2r_sg_context. The caller must initialize
  1208. * struct esas2r_sg_context prior to the initial call by calling
  1209. * esas2r_sgc_init()
  1210. */
  1211. static inline bool esas2r_build_sg_list(struct esas2r_adapter *a,
  1212. struct esas2r_request *rq,
  1213. struct esas2r_sg_context *sgc)
  1214. {
  1215. if (unlikely(le32_to_cpu(rq->vrq->scsi.length) == 0))
  1216. return true;
  1217. return (*a->build_sgl)(a, sgc);
  1218. }
  1219. static inline void esas2r_disable_chip_interrupts(struct esas2r_adapter *a)
  1220. {
  1221. if (atomic_inc_return(&a->dis_ints_cnt) == 1)
  1222. esas2r_write_register_dword(a, MU_INT_MASK_OUT,
  1223. ESAS2R_INT_DIS_MASK);
  1224. }
  1225. static inline void esas2r_enable_chip_interrupts(struct esas2r_adapter *a)
  1226. {
  1227. if (atomic_dec_return(&a->dis_ints_cnt) == 0)
  1228. esas2r_write_register_dword(a, MU_INT_MASK_OUT,
  1229. ESAS2R_INT_ENB_MASK);
  1230. }
  1231. /* Schedule a TASKLET to perform non-interrupt tasks that may require delays
  1232. * or long completion times.
  1233. */
  1234. static inline void esas2r_schedule_tasklet(struct esas2r_adapter *a)
  1235. {
  1236. /* make sure we don't schedule twice */
  1237. if (!test_and_set_bit(AF_TASKLET_SCHEDULED, &a->flags))
  1238. tasklet_hi_schedule(&a->tasklet);
  1239. }
  1240. static inline void esas2r_enable_heartbeat(struct esas2r_adapter *a)
  1241. {
  1242. if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
  1243. !test_bit(AF_CHPRST_PENDING, &a->flags) &&
  1244. (a->nvram->options2 & SASNVR2_HEARTBEAT))
  1245. set_bit(AF_HEARTBEAT_ENB, &a->flags);
  1246. else
  1247. clear_bit(AF_HEARTBEAT_ENB, &a->flags);
  1248. }
  1249. static inline void esas2r_disable_heartbeat(struct esas2r_adapter *a)
  1250. {
  1251. clear_bit(AF_HEARTBEAT_ENB, &a->flags);
  1252. clear_bit(AF_HEARTBEAT, &a->flags);
  1253. }
  1254. /* Set the initial state for resetting the adapter on the next pass through
  1255. * esas2r_do_deferred.
  1256. */
  1257. static inline void esas2r_local_reset_adapter(struct esas2r_adapter *a)
  1258. {
  1259. esas2r_disable_heartbeat(a);
  1260. set_bit(AF_CHPRST_NEEDED, &a->flags);
  1261. set_bit(AF_CHPRST_PENDING, &a->flags);
  1262. set_bit(AF_DISC_PENDING, &a->flags);
  1263. }
  1264. /* See if an interrupt is pending on the adapter. */
  1265. static inline bool esas2r_adapter_interrupt_pending(struct esas2r_adapter *a)
  1266. {
  1267. u32 intstat;
  1268. if (a->int_mask == 0)
  1269. return false;
  1270. intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
  1271. if ((intstat & a->int_mask) == 0)
  1272. return false;
  1273. esas2r_disable_chip_interrupts(a);
  1274. a->int_stat = intstat;
  1275. a->int_mask = 0;
  1276. return true;
  1277. }
  1278. static inline u16 esas2r_targ_get_id(struct esas2r_target *t,
  1279. struct esas2r_adapter *a)
  1280. {
  1281. return (u16)(uintptr_t)(t - a->targetdb);
  1282. }
  1283. /* Build and start an asynchronous event request */
  1284. static inline void esas2r_start_ae_request(struct esas2r_adapter *a,
  1285. struct esas2r_request *rq)
  1286. {
  1287. unsigned long flags;
  1288. esas2r_build_ae_req(a, rq);
  1289. spin_lock_irqsave(&a->queue_lock, flags);
  1290. esas2r_start_vda_request(a, rq);
  1291. spin_unlock_irqrestore(&a->queue_lock, flags);
  1292. }
  1293. static inline void esas2r_comp_list_drain(struct esas2r_adapter *a,
  1294. struct list_head *comp_list)
  1295. {
  1296. struct esas2r_request *rq;
  1297. struct list_head *element, *next;
  1298. list_for_each_safe(element, next, comp_list) {
  1299. rq = list_entry(element, struct esas2r_request, comp_list);
  1300. list_del_init(element);
  1301. esas2r_complete_request(a, rq);
  1302. }
  1303. }
  1304. /* sysfs handlers */
  1305. extern struct bin_attribute bin_attr_fw;
  1306. extern struct bin_attribute bin_attr_fs;
  1307. extern struct bin_attribute bin_attr_vda;
  1308. extern struct bin_attribute bin_attr_hw;
  1309. extern struct bin_attribute bin_attr_live_nvram;
  1310. extern struct bin_attribute bin_attr_default_nvram;
  1311. #endif /* ESAS2R_H */