aic7xxx_proc.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Copyright (c) 2000-2001 Adaptec Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions, and the following disclaimer,
  10. * without modification.
  11. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  12. * substantially similar to the "NO WARRANTY" disclaimer below
  13. * ("Disclaimer") and any redistribution must be conditioned upon
  14. * including a substantially similar Disclaimer requirement for further
  15. * binary redistribution.
  16. * 3. Neither the names of the above-listed copyright holders nor the names
  17. * of any contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * NO WARRANTY
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  34. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGES.
  36. *
  37. * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
  38. * sym driver.
  39. *
  40. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#29 $
  41. */
  42. #include "aic7xxx_osm.h"
  43. #include "aic7xxx_inline.h"
  44. #include "aic7xxx_93cx6.h"
  45. static void copy_mem_info(struct info_str *info, char *data, int len);
  46. static int copy_info(struct info_str *info, char *fmt, ...);
  47. static void ahc_dump_target_state(struct ahc_softc *ahc,
  48. struct info_str *info,
  49. u_int our_id, char channel,
  50. u_int target_id, u_int target_offset);
  51. static void ahc_dump_device_state(struct info_str *info,
  52. struct scsi_device *dev);
  53. static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
  54. char *buffer, int length);
  55. static void
  56. copy_mem_info(struct info_str *info, char *data, int len)
  57. {
  58. if (info->pos + len > info->offset + info->length)
  59. len = info->offset + info->length - info->pos;
  60. if (info->pos + len < info->offset) {
  61. info->pos += len;
  62. return;
  63. }
  64. if (info->pos < info->offset) {
  65. off_t partial;
  66. partial = info->offset - info->pos;
  67. data += partial;
  68. info->pos += partial;
  69. len -= partial;
  70. }
  71. if (len > 0) {
  72. memcpy(info->buffer, data, len);
  73. info->pos += len;
  74. info->buffer += len;
  75. }
  76. }
  77. static int
  78. copy_info(struct info_str *info, char *fmt, ...)
  79. {
  80. va_list args;
  81. char buf[256];
  82. int len;
  83. va_start(args, fmt);
  84. len = vsprintf(buf, fmt, args);
  85. va_end(args);
  86. copy_mem_info(info, buf, len);
  87. return (len);
  88. }
  89. void
  90. ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
  91. {
  92. u_int speed;
  93. u_int freq;
  94. u_int mb;
  95. speed = 3300;
  96. freq = 0;
  97. if (tinfo->offset != 0) {
  98. freq = aic_calc_syncsrate(tinfo->period);
  99. speed = freq;
  100. }
  101. speed *= (0x01 << tinfo->width);
  102. mb = speed / 1000;
  103. if (mb > 0)
  104. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  105. else
  106. copy_info(info, "%dKB/s transfers", speed);
  107. if (freq != 0) {
  108. copy_info(info, " (%d.%03dMHz%s, offset %d",
  109. freq / 1000, freq % 1000,
  110. (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
  111. ? " DT" : "", tinfo->offset);
  112. }
  113. if (tinfo->width > 0) {
  114. if (freq != 0) {
  115. copy_info(info, ", ");
  116. } else {
  117. copy_info(info, " (");
  118. }
  119. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  120. } else if (freq != 0) {
  121. copy_info(info, ")");
  122. }
  123. copy_info(info, "\n");
  124. }
  125. static void
  126. ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
  127. u_int our_id, char channel, u_int target_id,
  128. u_int target_offset)
  129. {
  130. struct ahc_linux_target *targ;
  131. struct scsi_target *starget;
  132. struct ahc_initiator_tinfo *tinfo;
  133. struct ahc_tmode_tstate *tstate;
  134. int lun;
  135. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  136. target_id, &tstate);
  137. if ((ahc->features & AHC_TWIN) != 0)
  138. copy_info(info, "Channel %c ", channel);
  139. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  140. copy_info(info, "\tUser: ");
  141. ahc_format_transinfo(info, &tinfo->user);
  142. starget = ahc->platform_data->starget[target_offset];
  143. targ = scsi_transport_target_data(starget);
  144. if (targ == NULL)
  145. return;
  146. copy_info(info, "\tGoal: ");
  147. ahc_format_transinfo(info, &tinfo->goal);
  148. copy_info(info, "\tCurr: ");
  149. ahc_format_transinfo(info, &tinfo->curr);
  150. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  151. struct scsi_device *sdev;
  152. sdev = targ->sdev[lun];
  153. if (sdev == NULL)
  154. continue;
  155. ahc_dump_device_state(info, sdev);
  156. }
  157. }
  158. static void
  159. ahc_dump_device_state(struct info_str *info, struct scsi_device *sdev)
  160. {
  161. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  162. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  163. sdev->sdev_target->channel + 'A',
  164. sdev->sdev_target->id, sdev->lun);
  165. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  166. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  167. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  168. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  169. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  170. }
  171. static int
  172. ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
  173. {
  174. struct seeprom_descriptor sd;
  175. int have_seeprom;
  176. u_long s;
  177. int paused;
  178. int written;
  179. /* Default to failure. */
  180. written = -EINVAL;
  181. ahc_lock(ahc, &s);
  182. paused = ahc_is_paused(ahc);
  183. if (!paused)
  184. ahc_pause(ahc);
  185. if (length != sizeof(struct seeprom_config)) {
  186. printf("ahc_proc_write_seeprom: incorrect buffer size\n");
  187. goto done;
  188. }
  189. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  190. if (have_seeprom == 0) {
  191. printf("ahc_proc_write_seeprom: cksum verification failed\n");
  192. goto done;
  193. }
  194. sd.sd_ahc = ahc;
  195. #if AHC_PCI_CONFIG > 0
  196. if ((ahc->chip & AHC_PCI) != 0) {
  197. sd.sd_control_offset = SEECTL;
  198. sd.sd_status_offset = SEECTL;
  199. sd.sd_dataout_offset = SEECTL;
  200. if (ahc->flags & AHC_LARGE_SEEPROM)
  201. sd.sd_chip = C56_66;
  202. else
  203. sd.sd_chip = C46;
  204. sd.sd_MS = SEEMS;
  205. sd.sd_RDY = SEERDY;
  206. sd.sd_CS = SEECS;
  207. sd.sd_CK = SEECK;
  208. sd.sd_DO = SEEDO;
  209. sd.sd_DI = SEEDI;
  210. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  211. } else
  212. #endif
  213. if ((ahc->chip & AHC_VL) != 0) {
  214. sd.sd_control_offset = SEECTL_2840;
  215. sd.sd_status_offset = STATUS_2840;
  216. sd.sd_dataout_offset = STATUS_2840;
  217. sd.sd_chip = C46;
  218. sd.sd_MS = 0;
  219. sd.sd_RDY = EEPROM_TF;
  220. sd.sd_CS = CS_2840;
  221. sd.sd_CK = CK_2840;
  222. sd.sd_DO = DO_2840;
  223. sd.sd_DI = DI_2840;
  224. have_seeprom = TRUE;
  225. } else {
  226. printf("ahc_proc_write_seeprom: unsupported adapter type\n");
  227. goto done;
  228. }
  229. if (!have_seeprom) {
  230. printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
  231. goto done;
  232. } else {
  233. u_int start_addr;
  234. if (ahc->seep_config == NULL) {
  235. ahc->seep_config = malloc(sizeof(*ahc->seep_config),
  236. M_DEVBUF, M_NOWAIT);
  237. if (ahc->seep_config == NULL) {
  238. printf("aic7xxx: Unable to allocate serial "
  239. "eeprom buffer. Write failing\n");
  240. goto done;
  241. }
  242. }
  243. printf("aic7xxx: Writing Serial EEPROM\n");
  244. start_addr = 32 * (ahc->channel - 'A');
  245. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  246. sizeof(struct seeprom_config)/2);
  247. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  248. start_addr, sizeof(struct seeprom_config)/2);
  249. #if AHC_PCI_CONFIG > 0
  250. if ((ahc->chip & AHC_VL) == 0)
  251. ahc_release_seeprom(&sd);
  252. #endif
  253. written = length;
  254. }
  255. done:
  256. if (!paused)
  257. ahc_unpause(ahc);
  258. ahc_unlock(ahc, &s);
  259. return (written);
  260. }
  261. /*
  262. * Return information to handle /proc support for the driver.
  263. */
  264. int
  265. ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  266. off_t offset, int length, int inout)
  267. {
  268. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  269. struct info_str info;
  270. char ahc_info[256];
  271. u_int max_targ;
  272. u_int i;
  273. int retval;
  274. /* Has data been written to the file? */
  275. if (inout == TRUE) {
  276. retval = ahc_proc_write_seeprom(ahc, buffer, length);
  277. goto done;
  278. }
  279. if (start)
  280. *start = buffer;
  281. info.buffer = buffer;
  282. info.length = length;
  283. info.offset = offset;
  284. info.pos = 0;
  285. copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
  286. AIC7XXX_DRIVER_VERSION);
  287. copy_info(&info, "%s\n", ahc->description);
  288. ahc_controller_info(ahc, ahc_info);
  289. copy_info(&info, "%s\n", ahc_info);
  290. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  291. ahc->scb_data->numscbs, AHC_NSEG);
  292. if (ahc->seep_config == NULL)
  293. copy_info(&info, "No Serial EEPROM\n");
  294. else {
  295. copy_info(&info, "Serial EEPROM:\n");
  296. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  297. if (((i % 8) == 0) && (i != 0)) {
  298. copy_info(&info, "\n");
  299. }
  300. copy_info(&info, "0x%.4x ",
  301. ((uint16_t*)ahc->seep_config)[i]);
  302. }
  303. copy_info(&info, "\n");
  304. }
  305. copy_info(&info, "\n");
  306. max_targ = 15;
  307. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  308. max_targ = 7;
  309. for (i = 0; i <= max_targ; i++) {
  310. u_int our_id;
  311. u_int target_id;
  312. char channel;
  313. channel = 'A';
  314. our_id = ahc->our_id;
  315. target_id = i;
  316. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  317. channel = 'B';
  318. our_id = ahc->our_id_b;
  319. target_id = i % 8;
  320. }
  321. ahc_dump_target_state(ahc, &info, our_id,
  322. channel, target_id, i);
  323. }
  324. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  325. done:
  326. return (retval);
  327. }