aic7xxx_proc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. /*
  56. * Table of syncrates that don't follow the "divisible by 4"
  57. * rule. This table will be expanded in future SCSI specs.
  58. */
  59. static struct {
  60. u_int period_factor;
  61. u_int period; /* in 100ths of ns */
  62. } scsi_syncrates[] = {
  63. { 0x08, 625 }, /* FAST-160 */
  64. { 0x09, 1250 }, /* FAST-80 */
  65. { 0x0a, 2500 }, /* FAST-40 40MHz */
  66. { 0x0b, 3030 }, /* FAST-40 33MHz */
  67. { 0x0c, 5000 } /* FAST-20 */
  68. };
  69. /*
  70. * Return the frequency in kHz corresponding to the given
  71. * sync period factor.
  72. */
  73. static u_int
  74. ahc_calc_syncsrate(u_int period_factor)
  75. {
  76. int i;
  77. int num_syncrates;
  78. num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
  79. /* See if the period is in the "exception" table */
  80. for (i = 0; i < num_syncrates; i++) {
  81. if (period_factor == scsi_syncrates[i].period_factor) {
  82. /* Period in kHz */
  83. return (100000000 / scsi_syncrates[i].period);
  84. }
  85. }
  86. /*
  87. * Wasn't in the table, so use the standard
  88. * 4 times conversion.
  89. */
  90. return (10000000 / (period_factor * 4 * 10));
  91. }
  92. static void
  93. copy_mem_info(struct info_str *info, char *data, int len)
  94. {
  95. if (info->pos + len > info->offset + info->length)
  96. len = info->offset + info->length - info->pos;
  97. if (info->pos + len < info->offset) {
  98. info->pos += len;
  99. return;
  100. }
  101. if (info->pos < info->offset) {
  102. off_t partial;
  103. partial = info->offset - info->pos;
  104. data += partial;
  105. info->pos += partial;
  106. len -= partial;
  107. }
  108. if (len > 0) {
  109. memcpy(info->buffer, data, len);
  110. info->pos += len;
  111. info->buffer += len;
  112. }
  113. }
  114. static int
  115. copy_info(struct info_str *info, char *fmt, ...)
  116. {
  117. va_list args;
  118. char buf[256];
  119. int len;
  120. va_start(args, fmt);
  121. len = vsprintf(buf, fmt, args);
  122. va_end(args);
  123. copy_mem_info(info, buf, len);
  124. return (len);
  125. }
  126. void
  127. ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
  128. {
  129. u_int speed;
  130. u_int freq;
  131. u_int mb;
  132. speed = 3300;
  133. freq = 0;
  134. if (tinfo->offset != 0) {
  135. freq = ahc_calc_syncsrate(tinfo->period);
  136. speed = freq;
  137. }
  138. speed *= (0x01 << tinfo->width);
  139. mb = speed / 1000;
  140. if (mb > 0)
  141. copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
  142. else
  143. copy_info(info, "%dKB/s transfers", speed);
  144. if (freq != 0) {
  145. copy_info(info, " (%d.%03dMHz%s, offset %d",
  146. freq / 1000, freq % 1000,
  147. (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
  148. ? " DT" : "", tinfo->offset);
  149. }
  150. if (tinfo->width > 0) {
  151. if (freq != 0) {
  152. copy_info(info, ", ");
  153. } else {
  154. copy_info(info, " (");
  155. }
  156. copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
  157. } else if (freq != 0) {
  158. copy_info(info, ")");
  159. }
  160. copy_info(info, "\n");
  161. }
  162. static void
  163. ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
  164. u_int our_id, char channel, u_int target_id,
  165. u_int target_offset)
  166. {
  167. struct ahc_linux_target *targ;
  168. struct scsi_target *starget;
  169. struct ahc_initiator_tinfo *tinfo;
  170. struct ahc_tmode_tstate *tstate;
  171. int lun;
  172. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  173. target_id, &tstate);
  174. if ((ahc->features & AHC_TWIN) != 0)
  175. copy_info(info, "Channel %c ", channel);
  176. copy_info(info, "Target %d Negotiation Settings\n", target_id);
  177. copy_info(info, "\tUser: ");
  178. ahc_format_transinfo(info, &tinfo->user);
  179. starget = ahc->platform_data->starget[target_offset];
  180. if (!starget)
  181. return;
  182. targ = scsi_transport_target_data(starget);
  183. copy_info(info, "\tGoal: ");
  184. ahc_format_transinfo(info, &tinfo->goal);
  185. copy_info(info, "\tCurr: ");
  186. ahc_format_transinfo(info, &tinfo->curr);
  187. for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
  188. struct scsi_device *sdev;
  189. sdev = targ->sdev[lun];
  190. if (sdev == NULL)
  191. continue;
  192. ahc_dump_device_state(info, sdev);
  193. }
  194. }
  195. static void
  196. ahc_dump_device_state(struct info_str *info, struct scsi_device *sdev)
  197. {
  198. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  199. copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
  200. sdev->sdev_target->channel + 'A',
  201. sdev->sdev_target->id, sdev->lun);
  202. copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
  203. copy_info(info, "\t\tCommands Active %d\n", dev->active);
  204. copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
  205. copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
  206. copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
  207. }
  208. static int
  209. ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
  210. {
  211. struct seeprom_descriptor sd;
  212. int have_seeprom;
  213. u_long s;
  214. int paused;
  215. int written;
  216. /* Default to failure. */
  217. written = -EINVAL;
  218. ahc_lock(ahc, &s);
  219. paused = ahc_is_paused(ahc);
  220. if (!paused)
  221. ahc_pause(ahc);
  222. if (length != sizeof(struct seeprom_config)) {
  223. printf("ahc_proc_write_seeprom: incorrect buffer size\n");
  224. goto done;
  225. }
  226. have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
  227. if (have_seeprom == 0) {
  228. printf("ahc_proc_write_seeprom: cksum verification failed\n");
  229. goto done;
  230. }
  231. sd.sd_ahc = ahc;
  232. #if AHC_PCI_CONFIG > 0
  233. if ((ahc->chip & AHC_PCI) != 0) {
  234. sd.sd_control_offset = SEECTL;
  235. sd.sd_status_offset = SEECTL;
  236. sd.sd_dataout_offset = SEECTL;
  237. if (ahc->flags & AHC_LARGE_SEEPROM)
  238. sd.sd_chip = C56_66;
  239. else
  240. sd.sd_chip = C46;
  241. sd.sd_MS = SEEMS;
  242. sd.sd_RDY = SEERDY;
  243. sd.sd_CS = SEECS;
  244. sd.sd_CK = SEECK;
  245. sd.sd_DO = SEEDO;
  246. sd.sd_DI = SEEDI;
  247. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  248. } else
  249. #endif
  250. if ((ahc->chip & AHC_VL) != 0) {
  251. sd.sd_control_offset = SEECTL_2840;
  252. sd.sd_status_offset = STATUS_2840;
  253. sd.sd_dataout_offset = STATUS_2840;
  254. sd.sd_chip = C46;
  255. sd.sd_MS = 0;
  256. sd.sd_RDY = EEPROM_TF;
  257. sd.sd_CS = CS_2840;
  258. sd.sd_CK = CK_2840;
  259. sd.sd_DO = DO_2840;
  260. sd.sd_DI = DI_2840;
  261. have_seeprom = TRUE;
  262. } else {
  263. printf("ahc_proc_write_seeprom: unsupported adapter type\n");
  264. goto done;
  265. }
  266. if (!have_seeprom) {
  267. printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
  268. goto done;
  269. } else {
  270. u_int start_addr;
  271. if (ahc->seep_config == NULL) {
  272. ahc->seep_config = malloc(sizeof(*ahc->seep_config),
  273. M_DEVBUF, M_NOWAIT);
  274. if (ahc->seep_config == NULL) {
  275. printf("aic7xxx: Unable to allocate serial "
  276. "eeprom buffer. Write failing\n");
  277. goto done;
  278. }
  279. }
  280. printf("aic7xxx: Writing Serial EEPROM\n");
  281. start_addr = 32 * (ahc->channel - 'A');
  282. ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
  283. sizeof(struct seeprom_config)/2);
  284. ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
  285. start_addr, sizeof(struct seeprom_config)/2);
  286. #if AHC_PCI_CONFIG > 0
  287. if ((ahc->chip & AHC_VL) == 0)
  288. ahc_release_seeprom(&sd);
  289. #endif
  290. written = length;
  291. }
  292. done:
  293. if (!paused)
  294. ahc_unpause(ahc);
  295. ahc_unlock(ahc, &s);
  296. return (written);
  297. }
  298. /*
  299. * Return information to handle /proc support for the driver.
  300. */
  301. int
  302. ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
  303. off_t offset, int length, int inout)
  304. {
  305. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  306. struct info_str info;
  307. char ahc_info[256];
  308. u_int max_targ;
  309. u_int i;
  310. int retval;
  311. /* Has data been written to the file? */
  312. if (inout == TRUE) {
  313. retval = ahc_proc_write_seeprom(ahc, buffer, length);
  314. goto done;
  315. }
  316. if (start)
  317. *start = buffer;
  318. info.buffer = buffer;
  319. info.length = length;
  320. info.offset = offset;
  321. info.pos = 0;
  322. copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
  323. AIC7XXX_DRIVER_VERSION);
  324. copy_info(&info, "%s\n", ahc->description);
  325. ahc_controller_info(ahc, ahc_info);
  326. copy_info(&info, "%s\n", ahc_info);
  327. copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
  328. ahc->scb_data->numscbs, AHC_NSEG);
  329. if (ahc->seep_config == NULL)
  330. copy_info(&info, "No Serial EEPROM\n");
  331. else {
  332. copy_info(&info, "Serial EEPROM:\n");
  333. for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
  334. if (((i % 8) == 0) && (i != 0)) {
  335. copy_info(&info, "\n");
  336. }
  337. copy_info(&info, "0x%.4x ",
  338. ((uint16_t*)ahc->seep_config)[i]);
  339. }
  340. copy_info(&info, "\n");
  341. }
  342. copy_info(&info, "\n");
  343. max_targ = 15;
  344. if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
  345. max_targ = 7;
  346. for (i = 0; i <= max_targ; i++) {
  347. u_int our_id;
  348. u_int target_id;
  349. char channel;
  350. channel = 'A';
  351. our_id = ahc->our_id;
  352. target_id = i;
  353. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  354. channel = 'B';
  355. our_id = ahc->our_id_b;
  356. target_id = i % 8;
  357. }
  358. ahc_dump_target_state(ahc, &info, our_id,
  359. channel, target_id, i);
  360. }
  361. retval = info.pos > info.offset ? info.pos - info.offset : 0;
  362. done:
  363. return (retval);
  364. }