aic79xx_proc.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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/aic79xx_proc.c#19 $
  41. */
  42. #include "aic79xx_osm.h"
  43. #include "aic79xx_inline.h"
  44. static void copy_mem_info(struct info_str *info, char *data, int len);
  45. static int copy_info(struct info_str *info, char *fmt, ...);
  46. static void ahd_dump_target_state(struct ahd_softc *ahd,
  47. struct info_str *info,
  48. u_int our_id, char channel,
  49. u_int target_id, u_int target_offset);
  50. static void ahd_dump_device_state(struct info_str *info,
  51. struct ahd_linux_device *dev);
  52. static int ahd_proc_write_seeprom(struct ahd_softc *ahd,
  53. char *buffer, int length);
  54. static void
  55. copy_mem_info(struct info_str *info, char *data, int len)
  56. {
  57. if (info->pos + len > info->offset + info->length)
  58. len = info->offset + info->length - info->pos;
  59. if (info->pos + len < info->offset) {
  60. info->pos += len;
  61. return;
  62. }
  63. if (info->pos < info->offset) {
  64. off_t partial;
  65. partial = info->offset - info->pos;
  66. data += partial;
  67. info->pos += partial;
  68. len -= partial;
  69. }
  70. if (len > 0) {
  71. memcpy(info->buffer, data, len);
  72. info->pos += len;
  73. info->buffer += len;
  74. }
  75. }
  76. static int
  77. copy_info(struct info_str *info, char *fmt, ...)
  78. {
  79. va_list args;
  80. char buf[256];
  81. int len;
  82. va_start(args, fmt);
  83. len = vsprintf(buf, fmt, args);
  84. va_end(args);
  85. copy_mem_info(info, buf, len);
  86. return (len);
  87. }
  88. void
  89. ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
  90. {
  91. u_int speed;
  92. u_int freq;
  93. u_int mb;
  94. if (tinfo->period == AHD_PERIOD_UNKNOWN) {
  95. copy_info(info, "Renegotiation Pending\n");
  96. return;
  97. }
  98. speed = 3300;
  99. freq = 0;
  100. if (tinfo->offset != 0) {
  101. freq = aic_calc_syncsrate(tinfo->period);
  102. speed = freq;
  103. }
  104. speed *= (0x01 << tinfo->width);
  105. mb = speed / 1000;
  106. if (mb > 0)
  107. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  108. else
  109. copy_info(info, "%dKB/s transfers", speed);
  110. if (freq != 0) {
  111. int printed_options;
  112. printed_options = 0;
  113. copy_info(info, " (%d.%03dMHz", freq / 1000, freq % 1000);
  114. if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
  115. copy_info(info, " RDSTRM");
  116. printed_options++;
  117. }
  118. if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
  119. copy_info(info, "%s", printed_options ? "|DT" : " DT");
  120. printed_options++;
  121. }
  122. if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  123. copy_info(info, "%s", printed_options ? "|IU" : " IU");
  124. printed_options++;
  125. }
  126. if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
  127. copy_info(info, "%s",
  128. printed_options ? "|RTI" : " RTI");
  129. printed_options++;
  130. }
  131. if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
  132. copy_info(info, "%s",
  133. printed_options ? "|QAS" : " QAS");
  134. printed_options++;
  135. }
  136. }
  137. if (tinfo->width > 0) {
  138. if (freq != 0) {
  139. copy_info(info, ", ");
  140. } else {
  141. copy_info(info, " (");
  142. }
  143. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  144. } else if (freq != 0) {
  145. copy_info(info, ")");
  146. }
  147. copy_info(info, "\n");
  148. }
  149. static void
  150. ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
  151. u_int our_id, char channel, u_int target_id,
  152. u_int target_offset)
  153. {
  154. struct ahd_linux_target *targ;
  155. struct ahd_initiator_tinfo *tinfo;
  156. struct ahd_tmode_tstate *tstate;
  157. int lun;
  158. tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
  159. target_id, &tstate);
  160. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  161. copy_info(info, "\tUser: ");
  162. ahd_format_transinfo(info, &tinfo->user);
  163. targ = ahd->platform_data->targets[target_offset];
  164. if (targ == NULL)
  165. return;
  166. copy_info(info, "\tGoal: ");
  167. ahd_format_transinfo(info, &tinfo->goal);
  168. copy_info(info, "\tCurr: ");
  169. ahd_format_transinfo(info, &tinfo->curr);
  170. copy_info(info, "\tTransmission Errors %ld\n", targ->errors_detected);
  171. for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
  172. struct ahd_linux_device *dev;
  173. dev = targ->devices[lun];
  174. if (dev == NULL)
  175. continue;
  176. ahd_dump_device_state(info, dev);
  177. }
  178. }
  179. static void
  180. ahd_dump_device_state(struct info_str *info, struct ahd_linux_device *dev)
  181. {
  182. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  183. dev->target->channel + 'A', dev->target->target, dev->lun);
  184. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  185. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  186. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  187. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  188. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  189. }
  190. static int
  191. ahd_proc_write_seeprom(struct ahd_softc *ahd, char *buffer, int length)
  192. {
  193. ahd_mode_state saved_modes;
  194. int have_seeprom;
  195. u_long s;
  196. int paused;
  197. int written;
  198. /* Default to failure. */
  199. written = -EINVAL;
  200. ahd_lock(ahd, &s);
  201. paused = ahd_is_paused(ahd);
  202. if (!paused)
  203. ahd_pause(ahd);
  204. saved_modes = ahd_save_modes(ahd);
  205. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  206. if (length != sizeof(struct seeprom_config)) {
  207. printf("ahd_proc_write_seeprom: incorrect buffer size\n");
  208. goto done;
  209. }
  210. have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
  211. if (have_seeprom == 0) {
  212. printf("ahd_proc_write_seeprom: cksum verification failed\n");
  213. goto done;
  214. }
  215. have_seeprom = ahd_acquire_seeprom(ahd);
  216. if (!have_seeprom) {
  217. printf("ahd_proc_write_seeprom: No Serial EEPROM\n");
  218. goto done;
  219. } else {
  220. u_int start_addr;
  221. if (ahd->seep_config == NULL) {
  222. ahd->seep_config = malloc(sizeof(*ahd->seep_config),
  223. M_DEVBUF, M_NOWAIT);
  224. if (ahd->seep_config == NULL) {
  225. printf("aic79xx: Unable to allocate serial "
  226. "eeprom buffer. Write failing\n");
  227. goto done;
  228. }
  229. }
  230. printf("aic79xx: Writing Serial EEPROM\n");
  231. start_addr = 32 * (ahd->channel - 'A');
  232. ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
  233. sizeof(struct seeprom_config)/2);
  234. ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
  235. start_addr, sizeof(struct seeprom_config)/2,
  236. /*ByteStream*/FALSE);
  237. ahd_release_seeprom(ahd);
  238. written = length;
  239. }
  240. done:
  241. ahd_restore_modes(ahd, saved_modes);
  242. if (!paused)
  243. ahd_unpause(ahd);
  244. ahd_unlock(ahd, &s);
  245. return (written);
  246. }
  247. /*
  248. * Return information to handle /proc support for the driver.
  249. */
  250. int
  251. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
  252. ahd_linux_proc_info(char *buffer, char **start, off_t offset,
  253. int length, int hostno, int inout)
  254. #else
  255. ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  256. off_t offset, int length, int inout)
  257. #endif
  258. {
  259. struct ahd_softc *ahd;
  260. struct info_str info;
  261. char ahd_info[256];
  262. u_long l;
  263. u_int max_targ;
  264. u_int i;
  265. int retval;
  266. retval = -EINVAL;
  267. ahd_list_lock(&l);
  268. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
  269. TAILQ_FOREACH(ahd, &ahd_tailq, links) {
  270. if (ahd->platform_data->host->host_no == hostno)
  271. break;
  272. }
  273. #else
  274. ahd = ahd_find_softc(*(struct ahd_softc **)shost->hostdata);
  275. #endif
  276. if (ahd == NULL)
  277. goto done;
  278. /* Has data been written to the file? */
  279. if (inout == TRUE) {
  280. retval = ahd_proc_write_seeprom(ahd, buffer, length);
  281. goto done;
  282. }
  283. if (start)
  284. *start = buffer;
  285. info.buffer = buffer;
  286. info.length = length;
  287. info.offset = offset;
  288. info.pos = 0;
  289. copy_info(&info, "Adaptec AIC79xx driver version: %s\n",
  290. AIC79XX_DRIVER_VERSION);
  291. copy_info(&info, "%s\n", ahd->description);
  292. ahd_controller_info(ahd, ahd_info);
  293. copy_info(&info, "%s\n", ahd_info);
  294. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  295. ahd->scb_data.numscbs, AHD_NSEG);
  296. max_targ = 15;
  297. if (ahd->seep_config == NULL)
  298. copy_info(&info, "No Serial EEPROM\n");
  299. else {
  300. copy_info(&info, "Serial EEPROM:\n");
  301. for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
  302. if (((i % 8) == 0) && (i != 0)) {
  303. copy_info(&info, "\n");
  304. }
  305. copy_info(&info, "0x%.4x ",
  306. ((uint16_t*)ahd->seep_config)[i]);
  307. }
  308. copy_info(&info, "\n");
  309. }
  310. copy_info(&info, "\n");
  311. if ((ahd->features & AHD_WIDE) == 0)
  312. max_targ = 7;
  313. for (i = 0; i <= max_targ; i++) {
  314. ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
  315. /*target_id*/i, /*target_offset*/i);
  316. }
  317. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  318. done:
  319. ahd_list_unlock(&l);
  320. return (retval);
  321. }