aic79xx_proc.c 8.9 KB

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