aic7xxx_proc.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 ahc_linux_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 ahc_initiator_tinfo *tinfo;
  132. struct ahc_tmode_tstate *tstate;
  133. int lun;
  134. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  135. target_id, &tstate);
  136. if ((ahc->features & AHC_TWIN) != 0)
  137. copy_info(info, "Channel %c ", channel);
  138. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  139. copy_info(info, "\tUser: ");
  140. ahc_format_transinfo(info, &tinfo->user);
  141. targ = ahc->platform_data->targets[target_offset];
  142. if (targ == NULL)
  143. return;
  144. copy_info(info, "\tGoal: ");
  145. ahc_format_transinfo(info, &tinfo->goal);
  146. copy_info(info, "\tCurr: ");
  147. ahc_format_transinfo(info, &tinfo->curr);
  148. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  149. struct ahc_linux_device *dev;
  150. dev = targ->devices[lun];
  151. if (dev == NULL)
  152. continue;
  153. ahc_dump_device_state(info, dev);
  154. }
  155. }
  156. static void
  157. ahc_dump_device_state(struct info_str *info, struct ahc_linux_device *dev)
  158. {
  159. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  160. dev->target->channel + 'A', dev->target->target, dev->lun);
  161. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  162. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  163. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  164. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  165. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  166. }
  167. static int
  168. ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
  169. {
  170. struct seeprom_descriptor sd;
  171. int have_seeprom;
  172. u_long s;
  173. int paused;
  174. int written;
  175. /* Default to failure. */
  176. written = -EINVAL;
  177. ahc_lock(ahc, &s);
  178. paused = ahc_is_paused(ahc);
  179. if (!paused)
  180. ahc_pause(ahc);
  181. if (length != sizeof(struct seeprom_config)) {
  182. printf("ahc_proc_write_seeprom: incorrect buffer size\n");
  183. goto done;
  184. }
  185. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  186. if (have_seeprom == 0) {
  187. printf("ahc_proc_write_seeprom: cksum verification failed\n");
  188. goto done;
  189. }
  190. sd.sd_ahc = ahc;
  191. #if AHC_PCI_CONFIG > 0
  192. if ((ahc->chip & AHC_PCI) != 0) {
  193. sd.sd_control_offset = SEECTL;
  194. sd.sd_status_offset = SEECTL;
  195. sd.sd_dataout_offset = SEECTL;
  196. if (ahc->flags & AHC_LARGE_SEEPROM)
  197. sd.sd_chip = C56_66;
  198. else
  199. sd.sd_chip = C46;
  200. sd.sd_MS = SEEMS;
  201. sd.sd_RDY = SEERDY;
  202. sd.sd_CS = SEECS;
  203. sd.sd_CK = SEECK;
  204. sd.sd_DO = SEEDO;
  205. sd.sd_DI = SEEDI;
  206. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  207. } else
  208. #endif
  209. if ((ahc->chip & AHC_VL) != 0) {
  210. sd.sd_control_offset = SEECTL_2840;
  211. sd.sd_status_offset = STATUS_2840;
  212. sd.sd_dataout_offset = STATUS_2840;
  213. sd.sd_chip = C46;
  214. sd.sd_MS = 0;
  215. sd.sd_RDY = EEPROM_TF;
  216. sd.sd_CS = CS_2840;
  217. sd.sd_CK = CK_2840;
  218. sd.sd_DO = DO_2840;
  219. sd.sd_DI = DI_2840;
  220. have_seeprom = TRUE;
  221. } else {
  222. printf("ahc_proc_write_seeprom: unsupported adapter type\n");
  223. goto done;
  224. }
  225. if (!have_seeprom) {
  226. printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
  227. goto done;
  228. } else {
  229. u_int start_addr;
  230. if (ahc->seep_config == NULL) {
  231. ahc->seep_config = malloc(sizeof(*ahc->seep_config),
  232. M_DEVBUF, M_NOWAIT);
  233. if (ahc->seep_config == NULL) {
  234. printf("aic7xxx: Unable to allocate serial "
  235. "eeprom buffer. Write failing\n");
  236. goto done;
  237. }
  238. }
  239. printf("aic7xxx: Writing Serial EEPROM\n");
  240. start_addr = 32 * (ahc->channel - 'A');
  241. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  242. sizeof(struct seeprom_config)/2);
  243. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  244. start_addr, sizeof(struct seeprom_config)/2);
  245. #if AHC_PCI_CONFIG > 0
  246. if ((ahc->chip & AHC_VL) == 0)
  247. ahc_release_seeprom(&sd);
  248. #endif
  249. written = length;
  250. }
  251. done:
  252. if (!paused)
  253. ahc_unpause(ahc);
  254. ahc_unlock(ahc, &s);
  255. return (written);
  256. }
  257. /*
  258. * Return information to handle /proc support for the driver.
  259. */
  260. int
  261. ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  262. off_t offset, int length, int inout)
  263. {
  264. struct ahc_softc *ahc;
  265. struct info_str info;
  266. char ahc_info[256];
  267. u_long s;
  268. u_int max_targ;
  269. u_int i;
  270. int retval;
  271. retval = -EINVAL;
  272. ahc_list_lock(&s);
  273. ahc = ahc_find_softc(*(struct ahc_softc **)shost->hostdata);
  274. if (ahc == NULL)
  275. goto done;
  276. /* Has data been written to the file? */
  277. if (inout == TRUE) {
  278. retval = ahc_proc_write_seeprom(ahc, buffer, length);
  279. goto done;
  280. }
  281. if (start)
  282. *start = buffer;
  283. info.buffer = buffer;
  284. info.length = length;
  285. info.offset = offset;
  286. info.pos = 0;
  287. copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
  288. AIC7XXX_DRIVER_VERSION);
  289. copy_info(&info, "%s\n", ahc->description);
  290. ahc_controller_info(ahc, ahc_info);
  291. copy_info(&info, "%s\n", ahc_info);
  292. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  293. ahc->scb_data->numscbs, AHC_NSEG);
  294. if (ahc->seep_config == NULL)
  295. copy_info(&info, "No Serial EEPROM\n");
  296. else {
  297. copy_info(&info, "Serial EEPROM:\n");
  298. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  299. if (((i % 8) == 0) && (i != 0)) {
  300. copy_info(&info, "\n");
  301. }
  302. copy_info(&info, "0x%.4x ",
  303. ((uint16_t*)ahc->seep_config)[i]);
  304. }
  305. copy_info(&info, "\n");
  306. }
  307. copy_info(&info, "\n");
  308. max_targ = 15;
  309. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  310. max_targ = 7;
  311. for (i = 0; i <= max_targ; i++) {
  312. u_int our_id;
  313. u_int target_id;
  314. char channel;
  315. channel = 'A';
  316. our_id = ahc->our_id;
  317. target_id = i;
  318. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  319. channel = 'B';
  320. our_id = ahc->our_id_b;
  321. target_id = i % 8;
  322. }
  323. ahc_dump_target_state(ahc, &info, our_id,
  324. channel, target_id, i);
  325. }
  326. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  327. done:
  328. ahc_list_unlock(&s);
  329. return (retval);
  330. }