aic79xx_proc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 scsi_device *sdev);
  52. static int ahd_proc_write_seeprom(struct ahd_softc *ahd,
  53. char *buffer, int length);
  54. /*
  55. * Table of syncrates that don't follow the "divisible by 4"
  56. * rule. This table will be expanded in future SCSI specs.
  57. */
  58. static struct {
  59. u_int period_factor;
  60. u_int period; /* in 100ths of ns */
  61. } scsi_syncrates[] = {
  62. { 0x08, 625 }, /* FAST-160 */
  63. { 0x09, 1250 }, /* FAST-80 */
  64. { 0x0a, 2500 }, /* FAST-40 40MHz */
  65. { 0x0b, 3030 }, /* FAST-40 33MHz */
  66. { 0x0c, 5000 } /* FAST-20 */
  67. };
  68. /*
  69. * Return the frequency in kHz corresponding to the given
  70. * sync period factor.
  71. */
  72. static u_int
  73. ahd_calc_syncsrate(u_int period_factor)
  74. {
  75. int i;
  76. int num_syncrates;
  77. num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
  78. /* See if the period is in the "exception" table */
  79. for (i = 0; i < num_syncrates; i++) {
  80. if (period_factor == scsi_syncrates[i].period_factor) {
  81. /* Period in kHz */
  82. return (100000000 / scsi_syncrates[i].period);
  83. }
  84. }
  85. /*
  86. * Wasn't in the table, so use the standard
  87. * 4 times conversion.
  88. */
  89. return (10000000 / (period_factor * 4 * 10));
  90. }
  91. static void
  92. copy_mem_info(struct info_str *info, char *data, int len)
  93. {
  94. if (info->pos + len > info->offset + info->length)
  95. len = info->offset + info->length - info->pos;
  96. if (info->pos + len < info->offset) {
  97. info->pos += len;
  98. return;
  99. }
  100. if (info->pos < info->offset) {
  101. off_t partial;
  102. partial = info->offset - info->pos;
  103. data += partial;
  104. info->pos += partial;
  105. len -= partial;
  106. }
  107. if (len > 0) {
  108. memcpy(info->buffer, data, len);
  109. info->pos += len;
  110. info->buffer += len;
  111. }
  112. }
  113. static int
  114. copy_info(struct info_str *info, char *fmt, ...)
  115. {
  116. va_list args;
  117. char buf[256];
  118. int len;
  119. va_start(args, fmt);
  120. len = vsprintf(buf, fmt, args);
  121. va_end(args);
  122. copy_mem_info(info, buf, len);
  123. return (len);
  124. }
  125. void
  126. ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
  127. {
  128. u_int speed;
  129. u_int freq;
  130. u_int mb;
  131. if (tinfo->period == AHD_PERIOD_UNKNOWN) {
  132. copy_info(info, "Renegotiation Pending\n");
  133. return;
  134. }
  135. speed = 3300;
  136. freq = 0;
  137. if (tinfo->offset != 0) {
  138. freq = ahd_calc_syncsrate(tinfo->period);
  139. speed = freq;
  140. }
  141. speed *= (0x01 << tinfo->width);
  142. mb = speed / 1000;
  143. if (mb > 0)
  144. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  145. else
  146. copy_info(info, "%dKB/s transfers", speed);
  147. if (freq != 0) {
  148. int printed_options;
  149. printed_options = 0;
  150. copy_info(info, " (%d.%03dMHz", freq / 1000, freq % 1000);
  151. if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
  152. copy_info(info, " RDSTRM");
  153. printed_options++;
  154. }
  155. if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
  156. copy_info(info, "%s", printed_options ? "|DT" : " DT");
  157. printed_options++;
  158. }
  159. if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  160. copy_info(info, "%s", printed_options ? "|IU" : " IU");
  161. printed_options++;
  162. }
  163. if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
  164. copy_info(info, "%s",
  165. printed_options ? "|RTI" : " RTI");
  166. printed_options++;
  167. }
  168. if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
  169. copy_info(info, "%s",
  170. printed_options ? "|QAS" : " QAS");
  171. printed_options++;
  172. }
  173. }
  174. if (tinfo->width > 0) {
  175. if (freq != 0) {
  176. copy_info(info, ", ");
  177. } else {
  178. copy_info(info, " (");
  179. }
  180. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  181. } else if (freq != 0) {
  182. copy_info(info, ")");
  183. }
  184. copy_info(info, "\n");
  185. }
  186. static void
  187. ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
  188. u_int our_id, char channel, u_int target_id,
  189. u_int target_offset)
  190. {
  191. struct ahd_linux_target *targ;
  192. struct scsi_target *starget;
  193. struct ahd_initiator_tinfo *tinfo;
  194. struct ahd_tmode_tstate *tstate;
  195. int lun;
  196. tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
  197. target_id, &tstate);
  198. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  199. copy_info(info, "\tUser: ");
  200. ahd_format_transinfo(info, &tinfo->user);
  201. starget = ahd->platform_data->starget[target_offset];
  202. if (starget == NULL)
  203. return;
  204. targ = scsi_transport_target_data(starget);
  205. copy_info(info, "\tGoal: ");
  206. ahd_format_transinfo(info, &tinfo->goal);
  207. copy_info(info, "\tCurr: ");
  208. ahd_format_transinfo(info, &tinfo->curr);
  209. for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
  210. struct scsi_device *dev;
  211. dev = targ->sdev[lun];
  212. if (dev == NULL)
  213. continue;
  214. ahd_dump_device_state(info, dev);
  215. }
  216. }
  217. static void
  218. ahd_dump_device_state(struct info_str *info, struct scsi_device *sdev)
  219. {
  220. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  221. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  222. sdev->sdev_target->channel + 'A',
  223. sdev->sdev_target->id, sdev->lun);
  224. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  225. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  226. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  227. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  228. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  229. }
  230. static int
  231. ahd_proc_write_seeprom(struct ahd_softc *ahd, char *buffer, int length)
  232. {
  233. ahd_mode_state saved_modes;
  234. int have_seeprom;
  235. u_long s;
  236. int paused;
  237. int written;
  238. /* Default to failure. */
  239. written = -EINVAL;
  240. ahd_lock(ahd, &s);
  241. paused = ahd_is_paused(ahd);
  242. if (!paused)
  243. ahd_pause(ahd);
  244. saved_modes = ahd_save_modes(ahd);
  245. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  246. if (length != sizeof(struct seeprom_config)) {
  247. printf("ahd_proc_write_seeprom: incorrect buffer size\n");
  248. goto done;
  249. }
  250. have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
  251. if (have_seeprom == 0) {
  252. printf("ahd_proc_write_seeprom: cksum verification failed\n");
  253. goto done;
  254. }
  255. have_seeprom = ahd_acquire_seeprom(ahd);
  256. if (!have_seeprom) {
  257. printf("ahd_proc_write_seeprom: No Serial EEPROM\n");
  258. goto done;
  259. } else {
  260. u_int start_addr;
  261. if (ahd->seep_config == NULL) {
  262. ahd->seep_config = malloc(sizeof(*ahd->seep_config),
  263. M_DEVBUF, M_NOWAIT);
  264. if (ahd->seep_config == NULL) {
  265. printf("aic79xx: Unable to allocate serial "
  266. "eeprom buffer. Write failing\n");
  267. goto done;
  268. }
  269. }
  270. printf("aic79xx: Writing Serial EEPROM\n");
  271. start_addr = 32 * (ahd->channel - 'A');
  272. ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
  273. sizeof(struct seeprom_config)/2);
  274. ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
  275. start_addr, sizeof(struct seeprom_config)/2,
  276. /*ByteStream*/FALSE);
  277. ahd_release_seeprom(ahd);
  278. written = length;
  279. }
  280. done:
  281. ahd_restore_modes(ahd, saved_modes);
  282. if (!paused)
  283. ahd_unpause(ahd);
  284. ahd_unlock(ahd, &s);
  285. return (written);
  286. }
  287. /*
  288. * Return information to handle /proc support for the driver.
  289. */
  290. int
  291. ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  292. off_t offset, int length, int inout)
  293. {
  294. struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
  295. struct info_str info;
  296. char ahd_info[256];
  297. u_int max_targ;
  298. u_int i;
  299. int retval;
  300. /* Has data been written to the file? */
  301. if (inout == TRUE) {
  302. retval = ahd_proc_write_seeprom(ahd, buffer, length);
  303. goto done;
  304. }
  305. if (start)
  306. *start = buffer;
  307. info.buffer = buffer;
  308. info.length = length;
  309. info.offset = offset;
  310. info.pos = 0;
  311. copy_info(&info, "Adaptec AIC79xx driver version: %s\n",
  312. AIC79XX_DRIVER_VERSION);
  313. copy_info(&info, "%s\n", ahd->description);
  314. ahd_controller_info(ahd, ahd_info);
  315. copy_info(&info, "%s\n", ahd_info);
  316. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  317. ahd->scb_data.numscbs, AHD_NSEG);
  318. max_targ = 15;
  319. if (ahd->seep_config == NULL)
  320. copy_info(&info, "No Serial EEPROM\n");
  321. else {
  322. copy_info(&info, "Serial EEPROM:\n");
  323. for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
  324. if (((i % 8) == 0) && (i != 0)) {
  325. copy_info(&info, "\n");
  326. }
  327. copy_info(&info, "0x%.4x ",
  328. ((uint16_t*)ahd->seep_config)[i]);
  329. }
  330. copy_info(&info, "\n");
  331. }
  332. copy_info(&info, "\n");
  333. if ((ahd->features & AHD_WIDE) == 0)
  334. max_targ = 7;
  335. for (i = 0; i <= max_targ; i++) {
  336. ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
  337. /*target_id*/i, /*target_offset*/i);
  338. }
  339. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  340. done:
  341. return (retval);
  342. }