Deleted Added
full compact
firewire.c (119289) firewire.c (120660)
1/*
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 17 unchanged lines hidden (view full) ---

26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
1/*
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 17 unchanged lines hidden (view full) ---

26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 * $FreeBSD: head/sys/dev/firewire/firewire.c 119289 2003-08-22 07:30:41Z simokawa $
34 * $FreeBSD: head/sys/dev/firewire/firewire.c 120660 2003-10-02 04:06:56Z simokawa $
35 *
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/types.h>
41
42#include <sys/kernel.h>

--- 93 unchanged lines hidden (view full) ---

136struct fw_device *
137fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
138{
139 struct fw_device *fwdev;
140 int s;
141
142 s = splfw();
143 STAILQ_FOREACH(fwdev, &fc->devices, link)
35 *
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/types.h>
41
42#include <sys/kernel.h>

--- 93 unchanged lines hidden (view full) ---

136struct fw_device *
137fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
138{
139 struct fw_device *fwdev;
140 int s;
141
142 s = splfw();
143 STAILQ_FOREACH(fwdev, &fc->devices, link)
144 if (fwdev->dst == dst)
144 if (fwdev->dst == dst && fwdev->status != FWDEVINVAL)
145 break;
146 splx(s);
147
145 break;
146 splx(s);
147
148 if(fwdev == NULL) return NULL;
149 if(fwdev->status == FWDEVINVAL) return NULL;
150 return fwdev;
151}
152
153/*
154 * Lookup fwdev by EUI64.
155 */
156struct fw_device *
157fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)

--- 21 unchanged lines hidden (view full) ---

179 int err = 0;
180 struct fw_xferq *xferq;
181 int tl = 0, len;
182 struct fw_pkt *fp;
183 int tcode;
184 struct tcode_info *info;
185
186 if(xfer == NULL) return EINVAL;
148 return fwdev;
149}
150
151/*
152 * Lookup fwdev by EUI64.
153 */
154struct fw_device *
155fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)

--- 21 unchanged lines hidden (view full) ---

177 int err = 0;
178 struct fw_xferq *xferq;
179 int tl = 0, len;
180 struct fw_pkt *fp;
181 int tcode;
182 struct tcode_info *info;
183
184 if(xfer == NULL) return EINVAL;
187 if(xfer->send.len > MAXREC(fc->maxrec)){
188 printf("send.len > maxrec\n");
189 return EINVAL;
190 }
191 if(xfer->act.hand == NULL){
192 printf("act.hand == NULL\n");
193 return EINVAL;
194 }
185 if(xfer->act.hand == NULL){
186 printf("act.hand == NULL\n");
187 return EINVAL;
188 }
195 fp = (struct fw_pkt *)xfer->send.buf;
189 fp = &xfer->send.hdr;
196
197 tcode = fp->mode.common.tcode & 0xf;
198 info = &fc->tcode[tcode];
199 if (info->flag == 0) {
200 printf("invalid tcode=%d\n", tcode);
201 return EINVAL;
202 }
203 if (info->flag & FWTI_REQ)
204 xferq = fc->atq;
205 else
206 xferq = fc->ats;
207 len = info->hdr_len;
190
191 tcode = fp->mode.common.tcode & 0xf;
192 info = &fc->tcode[tcode];
193 if (info->flag == 0) {
194 printf("invalid tcode=%d\n", tcode);
195 return EINVAL;
196 }
197 if (info->flag & FWTI_REQ)
198 xferq = fc->atq;
199 else
200 xferq = fc->ats;
201 len = info->hdr_len;
202 if (xfer->send.pay_len > MAXREC(fc->maxrec)) {
203 printf("send.pay_len > maxrec\n");
204 return EINVAL;
205 }
208 if (info->flag & FWTI_BLOCK_STR)
206 if (info->flag & FWTI_BLOCK_STR)
209 len += fp->mode.stream.len;
207 len = fp->mode.stream.len;
210 else if (info->flag & FWTI_BLOCK_ASY)
208 else if (info->flag & FWTI_BLOCK_ASY)
211 len += fp->mode.rresb.len;
212 if( len > xfer->send.len ){
213 printf("len(%d) > send.len(%d) (tcode=%d)\n",
214 len, xfer->send.len, tcode);
209 len = fp->mode.rresb.len;
210 else
211 len = 0;
212 if (len != xfer->send.pay_len){
213 printf("len(%d) != send.pay_len(%d) (tcode=%d)\n",
214 len, xfer->send.pay_len, tcode);
215 return EINVAL;
216 }
215 return EINVAL;
216 }
217 xfer->send.len = len;
218
219 if(xferq->start == NULL){
220 printf("xferq->start == NULL\n");
221 return EINVAL;
222 }
223 if(!(xferq->queued < xferq->maxq)){
224 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
225 xferq->queued);
226 return EINVAL;
227 }
228
217
218 if(xferq->start == NULL){
219 printf("xferq->start == NULL\n");
220 return EINVAL;
221 }
222 if(!(xferq->queued < xferq->maxq)){
223 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
224 xferq->queued);
225 return EINVAL;
226 }
227
229
228 microtime(&xfer->tv);
230 if (info->flag & FWTI_TLABEL) {
231 if((tl = fw_get_tlabel(fc, xfer)) == -1 )
232 return EIO;
233 fp->mode.hdr.tlrt = tl << 2;
234 }
235
236 xfer->tl = tl;
237 xfer->resp = 0;

--- 71 unchanged lines hidden (view full) ---

309firewire_xfer_timeout(struct firewire_comm *fc)
310{
311 struct fw_xfer *xfer;
312 struct tlabel *tl;
313 struct timeval tv;
314 struct timeval split_timeout;
315 int i, s;
316
229 if (info->flag & FWTI_TLABEL) {
230 if((tl = fw_get_tlabel(fc, xfer)) == -1 )
231 return EIO;
232 fp->mode.hdr.tlrt = tl << 2;
233 }
234
235 xfer->tl = tl;
236 xfer->resp = 0;

--- 71 unchanged lines hidden (view full) ---

308firewire_xfer_timeout(struct firewire_comm *fc)
309{
310 struct fw_xfer *xfer;
311 struct tlabel *tl;
312 struct timeval tv;
313 struct timeval split_timeout;
314 int i, s;
315
317 split_timeout.tv_sec = 6;
318 split_timeout.tv_usec = 0;
316 split_timeout.tv_sec = 0;
317 split_timeout.tv_usec = 200 * 1000; /* 200 msec */
319
320 microtime(&tv);
321 timevalsub(&tv, &split_timeout);
322
323 s = splfw();
324 for (i = 0; i < 0x40; i ++) {
325 while ((tl = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
326 xfer = tl->xfer;
327 if (timevalcmp(&xfer->tv, &tv, >))
328 /* the rests are newer than this */
329 break;
330 device_printf(fc->bdev,
331 "split transaction timeout dst=0x%x tl=0x%x state=%d\n",
318
319 microtime(&tv);
320 timevalsub(&tv, &split_timeout);
321
322 s = splfw();
323 for (i = 0; i < 0x40; i ++) {
324 while ((tl = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
325 xfer = tl->xfer;
326 if (timevalcmp(&xfer->tv, &tv, >))
327 /* the rests are newer than this */
328 break;
329 device_printf(fc->bdev,
330 "split transaction timeout dst=0x%x tl=0x%x state=%d\n",
332 xfer->dst, i, xfer->state);
331 xfer->send.hdr.mode.hdr.dst, i, xfer->state);
333 xfer->resp = ETIMEDOUT;
334 STAILQ_REMOVE_HEAD(&fc->tlabels[i], link);
335 fw_xfer_done(xfer);
336 }
337 }
338 splx(s);
339}
340
341static void
342firewire_watchdog(void *arg)
343{
344 struct firewire_comm *fc;
345
346 fc = (struct firewire_comm *)arg;
347 firewire_xfer_timeout(fc);
348 fc->timeout(fc);
332 xfer->resp = ETIMEDOUT;
333 STAILQ_REMOVE_HEAD(&fc->tlabels[i], link);
334 fw_xfer_done(xfer);
335 }
336 }
337 splx(s);
338}
339
340static void
341firewire_watchdog(void *arg)
342{
343 struct firewire_comm *fc;
344
345 fc = (struct firewire_comm *)arg;
346 firewire_xfer_timeout(fc);
347 fc->timeout(fc);
349 callout_reset(&fc->timeout_callout, hz,
348 callout_reset(&fc->timeout_callout, hz / 10,
350 (void *)firewire_watchdog, (void *)fc);
351}
352
353/*
354 * The attach routine.
355 */
356static int
357firewire_attach(device_t dev)

--- 413 unchanged lines hidden (view full) ---

771 fwb->start_hi = 0x2;
772 fwb->start_lo = 0;
773 fwb->addrlen = 0xffffffff;
774 fwb->xfer = xfer;
775 fw_bindadd(fc, fwb);
776#endif
777}
778
349 (void *)firewire_watchdog, (void *)fc);
350}
351
352/*
353 * The attach routine.
354 */
355static int
356firewire_attach(device_t dev)

--- 413 unchanged lines hidden (view full) ---

770 fwb->start_hi = 0x2;
771 fwb->start_lo = 0;
772 fwb->addrlen = 0xffffffff;
773 fwb->xfer = xfer;
774 fw_bindadd(fc, fwb);
775#endif
776}
777
778#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)?-1:\
779 ((fwb)->end < (addr))?1:0)
780
779/*
780 * To lookup binded process from IEEE1394 address.
781 */
782struct fw_bind *
781/*
782 * To lookup binded process from IEEE1394 address.
783 */
784struct fw_bind *
783fw_bindlookup(struct firewire_comm *fc, u_int32_t dest_hi, u_int32_t dest_lo)
785fw_bindlookup(struct firewire_comm *fc, u_int16_t dest_hi, u_int32_t dest_lo)
784{
786{
787 u_int64_t addr;
785 struct fw_bind *tfw;
788 struct fw_bind *tfw;
786 for(tfw = STAILQ_FIRST(&fc->binds) ; tfw != NULL ;
787 tfw = STAILQ_NEXT(tfw, fclist)){
788 if (tfw->act_type != FWACT_NULL &&
789 tfw->start_hi == dest_hi &&
790 tfw->start_lo <= dest_lo &&
791 (tfw->start_lo + tfw->addrlen) > dest_lo){
789
790 addr = ((u_int64_t)dest_hi << 32) | dest_lo;
791 STAILQ_FOREACH(tfw, &fc->binds, fclist)
792 if (tfw->act_type != FWACT_NULL && BIND_CMP(addr, tfw) == 0)
792 return(tfw);
793 return(tfw);
793 }
794 }
795 return(NULL);
796}
797
798/*
799 * To bind IEEE1394 address block to process.
800 */
801int
802fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
803{
794 return(NULL);
795}
796
797/*
798 * To bind IEEE1394 address block to process.
799 */
800int
801fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
802{
804 struct fw_bind *tfw, *tfw2 = NULL;
805 int err = 0;
806 tfw = STAILQ_FIRST(&fc->binds);
807 if(tfw == NULL){
803 struct fw_bind *tfw, *prev = NULL;
804
805 if (fwb->start > fwb->end) {
806 printf("%s: invalid range\n", __FUNCTION__);
807 return EINVAL;
808 }
809
810 STAILQ_FOREACH(tfw, &fc->binds, fclist) {
811 if (fwb->end < tfw->start)
812 break;
813 prev = tfw;
814 }
815 if (prev == NULL) {
808 STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
809 goto out;
810 }
816 STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
817 goto out;
818 }
811 if((tfw->start_hi > fwb->start_hi) ||
812 (tfw->start_hi == fwb->start_hi &&
813 (tfw->start_lo > (fwb->start_lo + fwb->addrlen)))){
814 STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
819 if (prev->end < fwb->start) {
820 STAILQ_INSERT_AFTER(&fc->binds, prev, fwb, fclist);
815 goto out;
816 }
821 goto out;
822 }
817 for(; tfw != NULL; tfw = STAILQ_NEXT(tfw, fclist)){
818 if((tfw->start_hi < fwb->start_hi) ||
819 (tfw->start_hi == fwb->start_hi &&
820 (tfw->start_lo + tfw->addrlen) < fwb->start_lo)){
821 tfw2 = STAILQ_NEXT(tfw, fclist);
822 if(tfw2 == NULL)
823 break;
824 if((tfw2->start_hi > fwb->start_hi) ||
825 (tfw2->start_hi == fwb->start_hi &&
826 tfw2->start_lo > (fwb->start_lo + fwb->addrlen))){
827 break;
828 }else{
829 err = EBUSY;
830 goto out;
831 }
832 }
833 }
834 if(tfw != NULL){
835 STAILQ_INSERT_AFTER(&fc->binds, tfw, fwb, fclist);
836 }else{
837 STAILQ_INSERT_TAIL(&fc->binds, fwb, fclist);
838 }
823
824 printf("%s: bind failed\n", __FUNCTION__);
825 return (EBUSY);
826
839out:
827out:
840 if (!err && fwb->act_type == FWACT_CH)
828 if (fwb->act_type == FWACT_CH)
841 STAILQ_INSERT_HEAD(&fc->ir[fwb->sub]->binds, fwb, chlist);
829 STAILQ_INSERT_HEAD(&fc->ir[fwb->sub]->binds, fwb, chlist);
842 return err;
830 return (0);
843}
844
845/*
846 * To free IEEE1394 address block.
847 */
848int
849fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
850{
831}
832
833/*
834 * To free IEEE1394 address block.
835 */
836int
837fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
838{
851 int s;
839#if 0
852 struct fw_xfer *xfer, *next;
840 struct fw_xfer *xfer, *next;
841#endif
842 struct fw_bind *tfw;
843 int s;
853
854 s = splfw();
844
845 s = splfw();
855 /* shall we check the existance? */
856 STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
846 STAILQ_FOREACH(tfw, &fc->binds, fclist)
847 if (tfw == fwb) {
848 STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
849 goto found;
850 }
851
852 printf("%s: no such bind\n", __FUNCTION__);
853 splx(s);
854 return (1);
855found:
856#if 0
857 /* shall we do this? */
858 for (xfer = STAILQ_FIRST(&fwb->xferlist); xfer != NULL; xfer = next) {
859 next = STAILQ_NEXT(xfer, link);
860 fw_xfer_free(xfer);
861 }
862 STAILQ_INIT(&fwb->xferlist);
857 /* shall we do this? */
858 for (xfer = STAILQ_FIRST(&fwb->xferlist); xfer != NULL; xfer = next) {
859 next = STAILQ_NEXT(xfer, link);
860 fw_xfer_free(xfer);
861 }
862 STAILQ_INIT(&fwb->xferlist);
863#endif
863
864 splx(s);
865 return 0;
866}
867
868/*
869 * To free transaction label.
870 */

--- 23 unchanged lines hidden (view full) ---

894fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel)
895{
896 struct fw_xfer *xfer;
897 struct tlabel *tl;
898 int s = splfw();
899
900 for( tl = STAILQ_FIRST(&fc->tlabels[tlabel]); tl != NULL;
901 tl = STAILQ_NEXT(tl, link)){
864
865 splx(s);
866 return 0;
867}
868
869/*
870 * To free transaction label.
871 */

--- 23 unchanged lines hidden (view full) ---

895fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel)
896{
897 struct fw_xfer *xfer;
898 struct tlabel *tl;
899 int s = splfw();
900
901 for( tl = STAILQ_FIRST(&fc->tlabels[tlabel]); tl != NULL;
902 tl = STAILQ_NEXT(tl, link)){
902 if(tl->xfer->dst == node){
903 if(tl->xfer->send.hdr.mode.hdr.dst == node){
903 xfer = tl->xfer;
904 splx(s);
905 if (firewire_debug > 2)
906 printf("fw_tl2xfer: found tl=%d\n", tlabel);
907 return(xfer);
908 }
909 }
910 if (firewire_debug > 1)

--- 9 unchanged lines hidden (view full) ---

920fw_xfer_alloc(struct malloc_type *type)
921{
922 struct fw_xfer *xfer;
923
924 xfer = malloc(sizeof(struct fw_xfer), type, M_NOWAIT | M_ZERO);
925 if (xfer == NULL)
926 return xfer;
927
904 xfer = tl->xfer;
905 splx(s);
906 if (firewire_debug > 2)
907 printf("fw_tl2xfer: found tl=%d\n", tlabel);
908 return(xfer);
909 }
910 }
911 if (firewire_debug > 1)

--- 9 unchanged lines hidden (view full) ---

921fw_xfer_alloc(struct malloc_type *type)
922{
923 struct fw_xfer *xfer;
924
925 xfer = malloc(sizeof(struct fw_xfer), type, M_NOWAIT | M_ZERO);
926 if (xfer == NULL)
927 return xfer;
928
928 microtime(&xfer->tv);
929 xfer->malloc = type;
930
931 return xfer;
932}
933
934struct fw_xfer *
935fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
936{
937 struct fw_xfer *xfer;
938
939 xfer = fw_xfer_alloc(type);
929 xfer->malloc = type;
930
931 return xfer;
932}
933
934struct fw_xfer *
935fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
936{
937 struct fw_xfer *xfer;
938
939 xfer = fw_xfer_alloc(type);
940 xfer->send.len = send_len;
941 xfer->recv.len = recv_len;
940 xfer->send.pay_len = send_len;
941 xfer->recv.pay_len = recv_len;
942 if (xfer == NULL)
943 return(NULL);
942 if (xfer == NULL)
943 return(NULL);
944 if (send_len) {
945 xfer->send.buf = malloc(send_len, type, M_NOWAIT | M_ZERO);
946 if (xfer->send.buf == NULL) {
944 if (send_len > 0) {
945 xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
946 if (xfer->send.payload == NULL) {
947 fw_xfer_free(xfer);
948 return(NULL);
949 }
950 }
947 fw_xfer_free(xfer);
948 return(NULL);
949 }
950 }
951 if (recv_len) {
952 xfer->recv.buf = malloc(recv_len, type, M_NOWAIT);
953 if (xfer->recv.buf == NULL) {
954 if (xfer->send.buf != NULL)
955 free(xfer->send.buf, type);
951 if (recv_len > 0) {
952 xfer->recv.payload = malloc(recv_len, type, M_NOWAIT);
953 if (xfer->recv.payload == NULL) {
954 if (xfer->send.payload != NULL)
955 free(xfer->send.payload, type);
956 fw_xfer_free(xfer);
957 return(NULL);
958 }
959 }
960 return(xfer);
961}
962
963/*

--- 46 unchanged lines hidden (view full) ---

1010 xfer->state = FWXF_INIT;
1011 xfer->resp = 0;
1012 xfer->retry = 0;
1013}
1014/*
1015 * To free IEEE1394 XFER structure.
1016 */
1017void
956 fw_xfer_free(xfer);
957 return(NULL);
958 }
959 }
960 return(xfer);
961}
962
963/*

--- 46 unchanged lines hidden (view full) ---

1010 xfer->state = FWXF_INIT;
1011 xfer->resp = 0;
1012 xfer->retry = 0;
1013}
1014/*
1015 * To free IEEE1394 XFER structure.
1016 */
1017void
1018fw_xfer_free( struct fw_xfer* xfer)
1018fw_xfer_free_buf( struct fw_xfer* xfer)
1019{
1019{
1020 if(xfer == NULL ) return;
1020 if (xfer == NULL) {
1021 printf("%s: xfer == NULL\n", __FUNCTION__);
1022 return;
1023 }
1021 fw_xfer_unload(xfer);
1024 fw_xfer_unload(xfer);
1022 if(xfer->send.buf != NULL){
1023 free(xfer->send.buf, xfer->malloc);
1025 if(xfer->send.payload != NULL){
1026 free(xfer->send.payload, xfer->malloc);
1024 }
1027 }
1025 if(xfer->recv.buf != NULL){
1026 free(xfer->recv.buf, xfer->malloc);
1028 if(xfer->recv.payload != NULL){
1029 free(xfer->recv.payload, xfer->malloc);
1027 }
1028 free(xfer, xfer->malloc);
1029}
1030
1030 }
1031 free(xfer, xfer->malloc);
1032}
1033
1031static void
1034void
1035fw_xfer_free( struct fw_xfer* xfer)
1036{
1037 if (xfer == NULL) {
1038 printf("%s: xfer == NULL\n", __FUNCTION__);
1039 return;
1040 }
1041 fw_xfer_unload(xfer);
1042 free(xfer, xfer->malloc);
1043}
1044
1045void
1032fw_asy_callback_free(struct fw_xfer *xfer)
1033{
1034#if 0
1035 printf("asyreq done state=%d resp=%d\n",
1036 xfer->state, xfer->resp);
1037#endif
1038 fw_xfer_free(xfer);
1039}

--- 4 unchanged lines hidden (view full) ---

1044static void
1045fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1046{
1047 struct fw_xfer *xfer;
1048 struct fw_pkt *fp;
1049
1050 fc->status = FWBUSPHYCONF;
1051
1046fw_asy_callback_free(struct fw_xfer *xfer)
1047{
1048#if 0
1049 printf("asyreq done state=%d resp=%d\n",
1050 xfer->state, xfer->resp);
1051#endif
1052 fw_xfer_free(xfer);
1053}

--- 4 unchanged lines hidden (view full) ---

1058static void
1059fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1060{
1061 struct fw_xfer *xfer;
1062 struct fw_pkt *fp;
1063
1064 fc->status = FWBUSPHYCONF;
1065
1052 xfer = fw_xfer_alloc_buf(M_FWXFER, 12, 0);
1066 xfer = fw_xfer_alloc(M_FWXFER);
1053 if (xfer == NULL)
1054 return;
1055 xfer->fc = fc;
1056 xfer->retry_req = fw_asybusy;
1057 xfer->act.hand = fw_asy_callback_free;
1058
1067 if (xfer == NULL)
1068 return;
1069 xfer->fc = fc;
1070 xfer->retry_req = fw_asybusy;
1071 xfer->act.hand = fw_asy_callback_free;
1072
1059 fp = (struct fw_pkt *)xfer->send.buf;
1073 fp = &xfer->send.hdr;
1060 fp->mode.ld[1] = 0;
1061 if (root_node >= 0)
1062 fp->mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
1063 if (gap_count >= 0)
1064 fp->mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
1065 fp->mode.ld[2] = ~fp->mode.ld[1];
1066/* XXX Dangerous, how to pass PHY packet to device driver */
1067 fp->mode.common.tcode |= FWTCODE_PHY;

--- 264 unchanged lines hidden (view full) ---

1332 }
1333dorequest:
1334#if 0
1335 xfer = asyreqq(fc, FWSPD_S100, 0, 0,
1336 ((FWLOCALBUS | fc->ongonode) << 16) | 0xffff , addr,
1337 fw_bus_explore_callback);
1338 if(xfer == NULL) goto done;
1339#else
1074 fp->mode.ld[1] = 0;
1075 if (root_node >= 0)
1076 fp->mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
1077 if (gap_count >= 0)
1078 fp->mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
1079 fp->mode.ld[2] = ~fp->mode.ld[1];
1080/* XXX Dangerous, how to pass PHY packet to device driver */
1081 fp->mode.common.tcode |= FWTCODE_PHY;

--- 264 unchanged lines hidden (view full) ---

1346 }
1347dorequest:
1348#if 0
1349 xfer = asyreqq(fc, FWSPD_S100, 0, 0,
1350 ((FWLOCALBUS | fc->ongonode) << 16) | 0xffff , addr,
1351 fw_bus_explore_callback);
1352 if(xfer == NULL) goto done;
1353#else
1340 xfer = fw_xfer_alloc_buf(M_FWXFER, 16, 16);
1354 xfer = fw_xfer_alloc(M_FWXFER);
1341 if(xfer == NULL){
1342 goto done;
1343 }
1355 if(xfer == NULL){
1356 goto done;
1357 }
1344 xfer->spd = 0;
1345 fp = (struct fw_pkt *)xfer->send.buf;
1358 xfer->send.spd = 0;
1359 fp = &xfer->send.hdr;
1346 fp->mode.rreqq.dest_hi = 0xffff;
1347 fp->mode.rreqq.tlrt = 0;
1348 fp->mode.rreqq.tcode = FWTCODE_RREQQ;
1349 fp->mode.rreqq.pri = 0;
1350 fp->mode.rreqq.src = 0;
1360 fp->mode.rreqq.dest_hi = 0xffff;
1361 fp->mode.rreqq.tlrt = 0;
1362 fp->mode.rreqq.tcode = FWTCODE_RREQQ;
1363 fp->mode.rreqq.pri = 0;
1364 fp->mode.rreqq.src = 0;
1351 xfer->dst = FWLOCALBUS | fc->ongonode;
1352 fp->mode.rreqq.dst = xfer->dst;
1365 fp->mode.rreqq.dst = FWLOCALBUS | fc->ongonode;
1353 fp->mode.rreqq.dest_lo = addr;
1354 xfer->act.hand = fw_bus_explore_callback;
1355
1356 if (firewire_debug)
1357 printf("node%d: explore addr=0x%x\n",
1358 fc->ongonode, fc->ongoaddr);
1359 err = fw_asyreq(fc, -1, xfer);
1360 if(err){

--- 17 unchanged lines hidden (view full) ---

1378asyreqq(struct firewire_comm *fc, u_int8_t spd, u_int8_t tl, u_int8_t rt,
1379 u_int32_t addr_hi, u_int32_t addr_lo,
1380 void (*hand) __P((struct fw_xfer*)))
1381{
1382 struct fw_xfer *xfer;
1383 struct fw_pkt *fp;
1384 int err;
1385
1366 fp->mode.rreqq.dest_lo = addr;
1367 xfer->act.hand = fw_bus_explore_callback;
1368
1369 if (firewire_debug)
1370 printf("node%d: explore addr=0x%x\n",
1371 fc->ongonode, fc->ongoaddr);
1372 err = fw_asyreq(fc, -1, xfer);
1373 if(err){

--- 17 unchanged lines hidden (view full) ---

1391asyreqq(struct firewire_comm *fc, u_int8_t spd, u_int8_t tl, u_int8_t rt,
1392 u_int32_t addr_hi, u_int32_t addr_lo,
1393 void (*hand) __P((struct fw_xfer*)))
1394{
1395 struct fw_xfer *xfer;
1396 struct fw_pkt *fp;
1397 int err;
1398
1386 xfer = fw_xfer_alloc_buf(M_FWXFER, 16, 16);
1399 xfer = fw_xfer_alloc(M_FWXFER);
1387 if (xfer == NULL)
1388 return NULL;
1389
1400 if (xfer == NULL)
1401 return NULL;
1402
1390 xfer->spd = spd; /* XXX:min(spd, fc->spd) */
1391 fp = (struct fw_pkt *)xfer->send.buf;
1403 xfer->send.spd = spd; /* XXX:min(spd, fc->spd) */
1404 fp = &xfer->send.hdr;
1392 fp->mode.rreqq.dest_hi = addr_hi & 0xffff;
1393 if(tl & FWP_TL_VALID){
1394 fp->mode.rreqq.tlrt = (tl & 0x3f) << 2;
1395 }else{
1396 fp->mode.rreqq.tlrt = 0;
1397 }
1398 fp->mode.rreqq.tlrt |= rt & 0x3;
1399 fp->mode.rreqq.tcode = FWTCODE_RREQQ;
1400 fp->mode.rreqq.pri = 0;
1401 fp->mode.rreqq.src = 0;
1405 fp->mode.rreqq.dest_hi = addr_hi & 0xffff;
1406 if(tl & FWP_TL_VALID){
1407 fp->mode.rreqq.tlrt = (tl & 0x3f) << 2;
1408 }else{
1409 fp->mode.rreqq.tlrt = 0;
1410 }
1411 fp->mode.rreqq.tlrt |= rt & 0x3;
1412 fp->mode.rreqq.tcode = FWTCODE_RREQQ;
1413 fp->mode.rreqq.pri = 0;
1414 fp->mode.rreqq.src = 0;
1402 xfer->dst = addr_hi >> 16;
1403 fp->mode.rreqq.dst = xfer->dst;
1415 fp->mode.rreqq.dst = addr_hi >> 16;
1404 fp->mode.rreqq.dest_lo = addr_lo;
1405 xfer->act.hand = hand;
1406
1407 err = fw_asyreq(fc, -1, xfer);
1408 if(err){
1409 fw_xfer_free( xfer);
1410 return NULL;
1411 }

--- 25 unchanged lines hidden (view full) ---

1437 fc->ongonode, fc->ongoaddr);
1438
1439 if(xfer->resp != 0){
1440 printf("node%d: resp=%d addr=0x%x\n",
1441 fc->ongonode, xfer->resp, fc->ongoaddr);
1442 goto errnode;
1443 }
1444
1416 fp->mode.rreqq.dest_lo = addr_lo;
1417 xfer->act.hand = hand;
1418
1419 err = fw_asyreq(fc, -1, xfer);
1420 if(err){
1421 fw_xfer_free( xfer);
1422 return NULL;
1423 }

--- 25 unchanged lines hidden (view full) ---

1449 fc->ongonode, fc->ongoaddr);
1450
1451 if(xfer->resp != 0){
1452 printf("node%d: resp=%d addr=0x%x\n",
1453 fc->ongonode, xfer->resp, fc->ongoaddr);
1454 goto errnode;
1455 }
1456
1445 if(xfer->send.buf == NULL){
1446 printf("node%d: send.buf=NULL addr=0x%x\n",
1447 fc->ongonode, fc->ongoaddr);
1448 goto errnode;
1449 }
1450 sfp = (struct fw_pkt *)xfer->send.buf;
1451
1452 if(xfer->recv.buf == NULL){
1453 printf("node%d: recv.buf=NULL addr=0x%x\n",
1454 fc->ongonode, fc->ongoaddr);
1455 goto errnode;
1456 }
1457 rfp = (struct fw_pkt *)xfer->recv.buf;
1457 sfp = &xfer->send.hdr;
1458 rfp = &xfer->recv.hdr;
1458#if 0
1459 {
1460 u_int32_t *qld;
1461 int i;
1462 qld = (u_int32_t *)xfer->recv.buf;
1463 printf("len:%d\n", xfer->recv.len);
1464 for( i = 0 ; i <= xfer->recv.len && i < 32; i+= 4){
1465 printf("0x%08x ", rfp->mode.ld[i/4]);

--- 179 unchanged lines hidden (view full) ---

1645 int s;
1646 static u_int32_t label = 0;
1647
1648 s = splfw();
1649 for( i = 0 ; i < 0x40 ; i ++){
1650 label = (label + 1) & 0x3f;
1651 for(tmptl = STAILQ_FIRST(&fc->tlabels[label]);
1652 tmptl != NULL; tmptl = STAILQ_NEXT(tmptl, link)){
1459#if 0
1460 {
1461 u_int32_t *qld;
1462 int i;
1463 qld = (u_int32_t *)xfer->recv.buf;
1464 printf("len:%d\n", xfer->recv.len);
1465 for( i = 0 ; i <= xfer->recv.len && i < 32; i+= 4){
1466 printf("0x%08x ", rfp->mode.ld[i/4]);

--- 179 unchanged lines hidden (view full) ---

1646 int s;
1647 static u_int32_t label = 0;
1648
1649 s = splfw();
1650 for( i = 0 ; i < 0x40 ; i ++){
1651 label = (label + 1) & 0x3f;
1652 for(tmptl = STAILQ_FIRST(&fc->tlabels[label]);
1653 tmptl != NULL; tmptl = STAILQ_NEXT(tmptl, link)){
1653 if(tmptl->xfer->dst == xfer->dst) break;
1654 if (tmptl->xfer->send.hdr.mode.hdr.dst ==
1655 xfer->send.hdr.mode.hdr.dst)
1656 break;
1654 }
1655 if(tmptl == NULL) {
1656 tl = malloc(sizeof(struct tlabel),M_FW,M_NOWAIT);
1657 if (tl == NULL) {
1658 splx(s);
1659 return (-1);
1660 }
1661 tl->xfer = xfer;
1662 STAILQ_INSERT_TAIL(&fc->tlabels[label], tl, link);
1663 splx(s);
1664 if (firewire_debug > 1)
1665 printf("fw_get_tlabel: dst=%d tl=%d\n",
1657 }
1658 if(tmptl == NULL) {
1659 tl = malloc(sizeof(struct tlabel),M_FW,M_NOWAIT);
1660 if (tl == NULL) {
1661 splx(s);
1662 return (-1);
1663 }
1664 tl->xfer = xfer;
1665 STAILQ_INSERT_TAIL(&fc->tlabels[label], tl, link);
1666 splx(s);
1667 if (firewire_debug > 1)
1668 printf("fw_get_tlabel: dst=%d tl=%d\n",
1666 xfer->dst, label);
1669 xfer->send.hdr.mode.hdr.dst, label);
1667 return(label);
1668 }
1669 }
1670 splx(s);
1671
1672 printf("fw_get_tlabel: no free tlabel\n");
1673 return(-1);
1674}
1675
1676static void
1670 return(label);
1671 }
1672 }
1673 splx(s);
1674
1675 printf("fw_get_tlabel: no free tlabel\n");
1676 return(-1);
1677}
1678
1679static void
1677fw_rcv_copy(struct fw_xfer *xfer, struct iovec *vec, int nvec)
1680fw_rcv_copy(struct fw_rcv_buf *rb)
1678{
1681{
1679 char *p;
1680 int res, i, len;
1682 struct fw_pkt *pkt;
1683 u_char *p;
1684 struct tcode_info *tinfo;
1685 u_int res, i, len, plen;
1681
1686
1682 p = xfer->recv.buf;
1683 res = xfer->recv.len;
1684 for (i = 0; i < nvec; i++, vec++) {
1685 len = vec->iov_len;
1687 rb->xfer->recv.spd -= rb->spd;
1688
1689 pkt = (struct fw_pkt *)rb->vec->iov_base;
1690 tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
1691
1692 /* Copy header */
1693 p = (u_char *)&rb->xfer->recv.hdr;
1694 bcopy(rb->vec->iov_base, p, tinfo->hdr_len);
1695 (u_char *)rb->vec->iov_base += tinfo->hdr_len;
1696 rb->vec->iov_len -= tinfo->hdr_len;
1697
1698 /* Copy payload */
1699 p = (u_char *)rb->xfer->recv.payload;
1700 res = rb->xfer->recv.pay_len;
1701
1702 /* special handling for RRESQ */
1703 if (pkt->mode.hdr.tcode == FWTCODE_RRESQ &&
1704 p != NULL && res >= sizeof(u_int32_t)) {
1705 *(u_int32_t *)p = pkt->mode.rresq.data;
1706 rb->xfer->recv.pay_len = sizeof(u_int32_t);
1707 return;
1708 }
1709
1710 if ((tinfo->flag & FWTI_BLOCK_ASY) == 0)
1711 return;
1712
1713 plen = pkt->mode.rresb.len;
1714
1715 for (i = 0; i < rb->nvec; i++, rb->vec++) {
1716 len = MIN(rb->vec->iov_len, plen);
1686 if (res < len) {
1687 printf("rcv buffer(%d) is %d bytes short.\n",
1717 if (res < len) {
1718 printf("rcv buffer(%d) is %d bytes short.\n",
1688 xfer->recv.len, len - res);
1719 rb->xfer->recv.pay_len, len - res);
1689 len = res;
1690 }
1720 len = res;
1721 }
1691 bcopy(vec->iov_base, p, len);
1722 bcopy(rb->vec->iov_base, p, len);
1692 p += len;
1693 res -= len;
1723 p += len;
1724 res -= len;
1694 if (res <= 0)
1725 plen -= len;
1726 if (res == 0 || plen == 0)
1695 break;
1696 }
1727 break;
1728 }
1697 xfer->recv.len -= res;
1729 rb->xfer->recv.pay_len -= res;
1730
1698}
1699
1700/*
1701 * Generic packet receving process.
1702 */
1703void
1731}
1732
1733/*
1734 * Generic packet receving process.
1735 */
1736void
1704fw_rcv(struct firewire_comm *fc, struct iovec *vec, int nvec, u_int sub, u_int spd)
1737fw_rcv(struct fw_rcv_buf *rb)
1705{
1706 struct fw_pkt *fp, *resfp;
1738{
1739 struct fw_pkt *fp, *resfp;
1707 struct fw_xfer *xfer;
1708 struct fw_bind *bind;
1740 struct fw_bind *bind;
1709 struct firewire_softc *sc;
1710 int tcode, s;
1711 int i, len, oldstate;
1712#if 0
1713 {
1714 u_int32_t *qld;
1715 int i;
1716 qld = (u_int32_t *)buf;
1717 printf("spd %d len:%d\n", spd, len);
1718 for( i = 0 ; i <= len && i < 32; i+= 4){
1719 printf("0x%08x ", ntohl(qld[i/4]));
1720 if((i % 16) == 15) printf("\n");
1721 }
1722 if((i % 16) != 15) printf("\n");
1723 }
1724#endif
1741 int tcode, s;
1742 int i, len, oldstate;
1743#if 0
1744 {
1745 u_int32_t *qld;
1746 int i;
1747 qld = (u_int32_t *)buf;
1748 printf("spd %d len:%d\n", spd, len);
1749 for( i = 0 ; i <= len && i < 32; i+= 4){
1750 printf("0x%08x ", ntohl(qld[i/4]));
1751 if((i % 16) == 15) printf("\n");
1752 }
1753 if((i % 16) != 15) printf("\n");
1754 }
1755#endif
1725 fp = (struct fw_pkt *)vec[0].iov_base;
1756 fp = (struct fw_pkt *)rb->vec[0].iov_base;
1726 tcode = fp->mode.common.tcode;
1757 tcode = fp->mode.common.tcode;
1727#if 0 /* XXX this check is not valid for RRESQ and WREQQ */
1728 if (vec[0].iov_len < fc->tcode[tcode].hdr_len) {
1729#if __FreeBSD_version >= 500000
1730 printf("fw_rcv: iov_len(%zu) is less than"
1731#else
1732 printf("fw_rcv: iov_len(%u) is less than"
1733#endif
1734 " hdr_len(%d:tcode=%d)\n", vec[0].iov_len,
1735 fc->tcode[tcode].hdr_len, tcode);
1736 }
1737#endif
1738 switch (tcode) {
1739 case FWTCODE_WRES:
1740 case FWTCODE_RRESQ:
1741 case FWTCODE_RRESB:
1742 case FWTCODE_LRES:
1758 switch (tcode) {
1759 case FWTCODE_WRES:
1760 case FWTCODE_RRESQ:
1761 case FWTCODE_RRESB:
1762 case FWTCODE_LRES:
1743 xfer = fw_tl2xfer(fc, fp->mode.hdr.src,
1763 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1744 fp->mode.hdr.tlrt >> 2);
1764 fp->mode.hdr.tlrt >> 2);
1745 if(xfer == NULL) {
1765 if(rb->xfer == NULL) {
1746 printf("fw_rcv: unknown response "
1747 "tcode=%d src=0x%x tl=0x%x rt=%d data=0x%x\n",
1748 tcode,
1749 fp->mode.hdr.src,
1750 fp->mode.hdr.tlrt >> 2,
1751 fp->mode.hdr.tlrt & 3,
1752 fp->mode.rresq.data);
1753#if 1
1754 printf("try ad-hoc work around!!\n");
1766 printf("fw_rcv: unknown response "
1767 "tcode=%d src=0x%x tl=0x%x rt=%d data=0x%x\n",
1768 tcode,
1769 fp->mode.hdr.src,
1770 fp->mode.hdr.tlrt >> 2,
1771 fp->mode.hdr.tlrt & 3,
1772 fp->mode.rresq.data);
1773#if 1
1774 printf("try ad-hoc work around!!\n");
1755 xfer = fw_tl2xfer(fc, fp->mode.hdr.src,
1775 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1756 (fp->mode.hdr.tlrt >> 2)^3);
1776 (fp->mode.hdr.tlrt >> 2)^3);
1757 if (xfer == NULL) {
1777 if (rb->xfer == NULL) {
1758 printf("no use...\n");
1759 goto err;
1760 }
1761#else
1762 goto err;
1763#endif
1764 }
1778 printf("no use...\n");
1779 goto err;
1780 }
1781#else
1782 goto err;
1783#endif
1784 }
1765 fw_rcv_copy(xfer, vec, nvec);
1766 xfer->resp = 0;
1785 fw_rcv_copy(rb);
1786 if (rb->xfer->recv.hdr.mode.wres.rtcode != RESP_CMP)
1787 rb->xfer->resp = EIO;
1788 else
1789 rb->xfer->resp = 0;
1767 /* make sure the packet is drained in AT queue */
1790 /* make sure the packet is drained in AT queue */
1768 oldstate = xfer->state;
1769 xfer->state = FWXF_RCVD;
1791 oldstate = rb->xfer->state;
1792 rb->xfer->state = FWXF_RCVD;
1770 switch (oldstate) {
1771 case FWXF_SENT:
1793 switch (oldstate) {
1794 case FWXF_SENT:
1772 fw_xfer_done(xfer);
1795 fw_xfer_done(rb->xfer);
1773 break;
1774 case FWXF_START:
1775#if 0
1776 if (firewire_debug)
1796 break;
1797 case FWXF_START:
1798#if 0
1799 if (firewire_debug)
1777 printf("not sent yet tl=%x\n", xfer->tl);
1800 printf("not sent yet tl=%x\n", rb->xfer->tl);
1778#endif
1779 break;
1780 default:
1801#endif
1802 break;
1803 default:
1781 printf("unexpected state %d\n", xfer->state);
1804 printf("unexpected state %d\n", rb->xfer->state);
1782 }
1783 return;
1784 case FWTCODE_WREQQ:
1785 case FWTCODE_WREQB:
1786 case FWTCODE_RREQQ:
1787 case FWTCODE_RREQB:
1788 case FWTCODE_LREQ:
1805 }
1806 return;
1807 case FWTCODE_WREQQ:
1808 case FWTCODE_WREQB:
1809 case FWTCODE_RREQQ:
1810 case FWTCODE_RREQB:
1811 case FWTCODE_LREQ:
1789 bind = fw_bindlookup(fc, fp->mode.rreqq.dest_hi,
1812 bind = fw_bindlookup(rb->fc, fp->mode.rreqq.dest_hi,
1790 fp->mode.rreqq.dest_lo);
1791 if(bind == NULL){
1792#if __FreeBSD_version >= 500000
1813 fp->mode.rreqq.dest_lo);
1814 if(bind == NULL){
1815#if __FreeBSD_version >= 500000
1793 printf("Unknown service addr 0x%08x:0x%08x tcode=%x src=0x%x data=%x\n",
1816 printf("Unknown service addr 0x%04x:0x%08x tcode=%x src=0x%x data=%x\n",
1794#else
1817#else
1795 printf("Unknown service addr 0x%08x:0x%08x tcode=%x src=0x%x data=%lx\n",
1818 printf("Unknown service addr 0x%04x:0x%08x tcode=%x src=0x%x data=%lx\n",
1796#endif
1797 fp->mode.wreqq.dest_hi,
1798 fp->mode.wreqq.dest_lo,
1799 tcode,
1800 fp->mode.hdr.src,
1801 ntohl(fp->mode.wreqq.data));
1819#endif
1820 fp->mode.wreqq.dest_hi,
1821 fp->mode.wreqq.dest_lo,
1822 tcode,
1823 fp->mode.hdr.src,
1824 ntohl(fp->mode.wreqq.data));
1802 if (fc->status == FWBUSRESET) {
1825 if (rb->fc->status == FWBUSRESET) {
1803 printf("fw_rcv: cannot respond(bus reset)!\n");
1804 goto err;
1805 }
1826 printf("fw_rcv: cannot respond(bus reset)!\n");
1827 goto err;
1828 }
1806 xfer = fw_xfer_alloc_buf(M_FWXFER, 16, 0);
1807 if(xfer == NULL){
1829 rb->xfer = fw_xfer_alloc(M_FWXFER);
1830 if(rb->xfer == NULL){
1808 return;
1809 }
1831 return;
1832 }
1810 xfer->spd = spd;
1811 resfp = (struct fw_pkt *)xfer->send.buf;
1833 rb->xfer->send.spd = rb->spd;
1834 rb->xfer->send.pay_len = 0;
1835 resfp = &rb->xfer->send.hdr;
1812 switch (tcode) {
1813 case FWTCODE_WREQQ:
1814 case FWTCODE_WREQB:
1815 resfp->mode.hdr.tcode = FWTCODE_WRES;
1836 switch (tcode) {
1837 case FWTCODE_WREQQ:
1838 case FWTCODE_WREQB:
1839 resfp->mode.hdr.tcode = FWTCODE_WRES;
1816 xfer->send.len = 12;
1817 break;
1818 case FWTCODE_RREQQ:
1819 resfp->mode.hdr.tcode = FWTCODE_RRESQ;
1840 break;
1841 case FWTCODE_RREQQ:
1842 resfp->mode.hdr.tcode = FWTCODE_RRESQ;
1820 xfer->send.len = 16;
1821 break;
1822 case FWTCODE_RREQB:
1823 resfp->mode.hdr.tcode = FWTCODE_RRESB;
1843 break;
1844 case FWTCODE_RREQB:
1845 resfp->mode.hdr.tcode = FWTCODE_RRESB;
1824 xfer->send.len = 16;
1825 break;
1826 case FWTCODE_LREQ:
1827 resfp->mode.hdr.tcode = FWTCODE_LRES;
1846 break;
1847 case FWTCODE_LREQ:
1848 resfp->mode.hdr.tcode = FWTCODE_LRES;
1828 xfer->send.len = 16;
1829 break;
1830 }
1831 resfp->mode.hdr.dst = fp->mode.hdr.src;
1832 resfp->mode.hdr.tlrt = fp->mode.hdr.tlrt;
1833 resfp->mode.hdr.pri = fp->mode.hdr.pri;
1849 break;
1850 }
1851 resfp->mode.hdr.dst = fp->mode.hdr.src;
1852 resfp->mode.hdr.tlrt = fp->mode.hdr.tlrt;
1853 resfp->mode.hdr.pri = fp->mode.hdr.pri;
1834 resfp->mode.rresb.rtcode = 7;
1854 resfp->mode.rresb.rtcode = RESP_ADDRESS_ERROR;
1835 resfp->mode.rresb.extcode = 0;
1836 resfp->mode.rresb.len = 0;
1837/*
1855 resfp->mode.rresb.extcode = 0;
1856 resfp->mode.rresb.len = 0;
1857/*
1838 xfer->act.hand = fw_asy_callback;
1858 rb->xfer->act.hand = fw_asy_callback;
1839*/
1859*/
1840 xfer->act.hand = fw_xfer_free;
1841 if(fw_asyreq(fc, -1, xfer)){
1842 fw_xfer_free( xfer);
1860 rb->xfer->act.hand = fw_xfer_free;
1861 if(fw_asyreq(rb->fc, -1, rb->xfer)){
1862 fw_xfer_free(rb->xfer);
1843 return;
1844 }
1845 goto err;
1846 }
1847 len = 0;
1863 return;
1864 }
1865 goto err;
1866 }
1867 len = 0;
1848 for (i = 0; i < nvec; i ++)
1849 len += vec[i].iov_len;
1868 for (i = 0; i < rb->nvec; i ++)
1869 len += rb->vec[i].iov_len;
1850 switch(bind->act_type){
1851 case FWACT_XFER:
1852 /* splfw()?? */
1870 switch(bind->act_type){
1871 case FWACT_XFER:
1872 /* splfw()?? */
1853 xfer = STAILQ_FIRST(&bind->xferlist);
1854 if (xfer == NULL) {
1873 rb->xfer = STAILQ_FIRST(&bind->xferlist);
1874 if (rb->xfer == NULL) {
1855 printf("Discard a packet for this bind.\n");
1856 goto err;
1857 }
1858 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
1875 printf("Discard a packet for this bind.\n");
1876 goto err;
1877 }
1878 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
1859 fw_rcv_copy(xfer, vec, nvec);
1860 xfer->spd = spd;
1861 if (fc->status != FWBUSRESET)
1862 xfer->act.hand(xfer);
1879 fw_rcv_copy(rb);
1880 if (rb->fc->status != FWBUSRESET)
1881 rb->xfer->act.hand(rb->xfer);
1863 else
1882 else
1864 STAILQ_INSERT_TAIL(&fc->pending, xfer, link);
1883 STAILQ_INSERT_TAIL(&rb->fc->pending,
1884 rb->xfer, link);
1865 return;
1866 break;
1867 case FWACT_CH:
1885 return;
1886 break;
1887 case FWACT_CH:
1868 if(fc->ir[bind->sub]->queued >=
1869 fc->ir[bind->sub]->maxq){
1870 device_printf(fc->bdev,
1888 if(rb->fc->ir[bind->sub]->queued >=
1889 rb->fc->ir[bind->sub]->maxq){
1890 device_printf(rb->fc->bdev,
1871 "Discard a packet %x %d\n",
1872 bind->sub,
1891 "Discard a packet %x %d\n",
1892 bind->sub,
1873 fc->ir[bind->sub]->queued);
1893 rb->fc->ir[bind->sub]->queued);
1874 goto err;
1875 }
1894 goto err;
1895 }
1876 xfer = STAILQ_FIRST(&bind->xferlist);
1877 if (xfer == NULL) {
1896 rb->xfer = STAILQ_FIRST(&bind->xferlist);
1897 if (rb->xfer == NULL) {
1878 printf("Discard packet for this bind\n");
1879 goto err;
1880 }
1881 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
1898 printf("Discard packet for this bind\n");
1899 goto err;
1900 }
1901 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
1882 fw_rcv_copy(xfer, vec, nvec);
1883 xfer->spd = spd;
1902 fw_rcv_copy(rb);
1884 s = splfw();
1903 s = splfw();
1885 fc->ir[bind->sub]->queued++;
1886 STAILQ_INSERT_TAIL(&fc->ir[bind->sub]->q, xfer, link);
1904 rb->fc->ir[bind->sub]->queued++;
1905 STAILQ_INSERT_TAIL(&rb->fc->ir[bind->sub]->q,
1906 rb->xfer, link);
1887 splx(s);
1888
1907 splx(s);
1908
1889 wakeup((caddr_t)fc->ir[bind->sub]);
1909 wakeup((caddr_t)rb->fc->ir[bind->sub]);
1890
1891 return;
1892 break;
1893 default:
1894 goto err;
1895 break;
1896 }
1897 break;
1910
1911 return;
1912 break;
1913 default:
1914 goto err;
1915 break;
1916 }
1917 break;
1918#if 0 /* shouldn't happen ?? or for GASP */
1898 case FWTCODE_STREAM:
1899 {
1900 struct fw_xferq *xferq;
1901
1919 case FWTCODE_STREAM:
1920 {
1921 struct fw_xferq *xferq;
1922
1902 xferq = fc->ir[sub];
1923 xferq = rb->fc->ir[sub];
1903#if 0
1904 printf("stream rcv dma %d len %d off %d spd %d\n",
1905 sub, len, off, spd);
1906#endif
1907 if(xferq->queued >= xferq->maxq) {
1908 printf("receive queue is full\n");
1909 goto err;
1910 }
1911 /* XXX get xfer from xfer queue, we don't need copy for
1912 per packet mode */
1924#if 0
1925 printf("stream rcv dma %d len %d off %d spd %d\n",
1926 sub, len, off, spd);
1927#endif
1928 if(xferq->queued >= xferq->maxq) {
1929 printf("receive queue is full\n");
1930 goto err;
1931 }
1932 /* XXX get xfer from xfer queue, we don't need copy for
1933 per packet mode */
1913 xfer = fw_xfer_alloc_buf(M_FWXFER, 0, /* XXX */
1934 rb->xfer = fw_xfer_alloc_buf(M_FWXFER, 0, /* XXX */
1914 vec[0].iov_len);
1935 vec[0].iov_len);
1915 if(xfer == NULL) goto err;
1916 fw_rcv_copy(xfer, vec, nvec);
1917 xfer->spd = spd;
1936 if (rb->xfer == NULL) goto err;
1937 fw_rcv_copy(rb)
1918 s = splfw();
1919 xferq->queued++;
1938 s = splfw();
1939 xferq->queued++;
1920 STAILQ_INSERT_TAIL(&xferq->q, xfer, link);
1940 STAILQ_INSERT_TAIL(&xferq->q, rb->xfer, link);
1921 splx(s);
1941 splx(s);
1922 sc = device_get_softc(fc->bdev);
1942 sc = device_get_softc(rb->fc->bdev);
1923#if __FreeBSD_version >= 500000
1924 if (SEL_WAITING(&xferq->rsel))
1925#else
1926 if (&xferq->rsel.si_pid != 0)
1927#endif
1928 selwakeup(&xferq->rsel);
1929 if (xferq->flag & FWXFERQ_WAKEUP) {
1930 xferq->flag &= ~FWXFERQ_WAKEUP;
1931 wakeup((caddr_t)xferq);
1932 }
1933 if (xferq->flag & FWXFERQ_HANDLER) {
1934 xferq->hand(xferq);
1935 }
1936 return;
1937 break;
1938 }
1943#if __FreeBSD_version >= 500000
1944 if (SEL_WAITING(&xferq->rsel))
1945#else
1946 if (&xferq->rsel.si_pid != 0)
1947#endif
1948 selwakeup(&xferq->rsel);
1949 if (xferq->flag & FWXFERQ_WAKEUP) {
1950 xferq->flag &= ~FWXFERQ_WAKEUP;
1951 wakeup((caddr_t)xferq);
1952 }
1953 if (xferq->flag & FWXFERQ_HANDLER) {
1954 xferq->hand(xferq);
1955 }
1956 return;
1957 break;
1958 }
1959#endif
1939 default:
1940 printf("fw_rcv: unknow tcode %d\n", tcode);
1941 break;
1942 }
1943err:
1944 return;
1945}
1946
1947/*
1948 * Post process for Bus Manager election process.
1949 */
1950static void
1951fw_try_bmr_callback(struct fw_xfer *xfer)
1952{
1960 default:
1961 printf("fw_rcv: unknow tcode %d\n", tcode);
1962 break;
1963 }
1964err:
1965 return;
1966}
1967
1968/*
1969 * Post process for Bus Manager election process.
1970 */
1971static void
1972fw_try_bmr_callback(struct fw_xfer *xfer)
1973{
1953 struct fw_pkt *rfp;
1954 struct firewire_comm *fc;
1955 int bmr;
1956
1957 if (xfer == NULL)
1958 return;
1959 fc = xfer->fc;
1960 if (xfer->resp != 0)
1961 goto error;
1974 struct firewire_comm *fc;
1975 int bmr;
1976
1977 if (xfer == NULL)
1978 return;
1979 fc = xfer->fc;
1980 if (xfer->resp != 0)
1981 goto error;
1962 if (xfer->send.buf == NULL)
1982 if (xfer->recv.payload == NULL)
1963 goto error;
1983 goto error;
1964 if (xfer->recv.buf == NULL)
1984 if (xfer->recv.hdr.mode.lres.rtcode != FWRCODE_COMPLETE)
1965 goto error;
1985 goto error;
1966 rfp = (struct fw_pkt *)xfer->recv.buf;
1967 if (rfp->mode.lres.rtcode != FWRCODE_COMPLETE)
1968 goto error;
1969
1986
1970 bmr = ntohl(rfp->mode.lres.payload[0]);
1987 bmr = ntohl(xfer->recv.payload[0]);
1971 if (bmr == 0x3f)
1972 bmr = fc->nodeid;
1973
1974 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, bmr & 0x3f);
1988 if (bmr == 0x3f)
1989 bmr = fc->nodeid;
1990
1991 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, bmr & 0x3f);
1975 fw_xfer_free(xfer);
1992 fw_xfer_free_buf(xfer);
1976 fw_bmr(fc);
1977 return;
1978
1979error:
1980 device_printf(fc->bdev, "bus manager election failed\n");
1993 fw_bmr(fc);
1994 return;
1995
1996error:
1997 device_printf(fc->bdev, "bus manager election failed\n");
1981 fw_xfer_free(xfer);
1998 fw_xfer_free_buf(xfer);
1982}
1983
1984
1985/*
1986 * To candidate Bus Manager election process.
1987 */
1988static void
1989fw_try_bmr(void *arg)
1990{
1991 struct fw_xfer *xfer;
1992 struct firewire_comm *fc = (struct firewire_comm *)arg;
1993 struct fw_pkt *fp;
1994 int err = 0;
1995
1999}
2000
2001
2002/*
2003 * To candidate Bus Manager election process.
2004 */
2005static void
2006fw_try_bmr(void *arg)
2007{
2008 struct fw_xfer *xfer;
2009 struct firewire_comm *fc = (struct firewire_comm *)arg;
2010 struct fw_pkt *fp;
2011 int err = 0;
2012
1996 xfer = fw_xfer_alloc_buf(M_FWXFER, 24, 20);
2013 xfer = fw_xfer_alloc_buf(M_FWXFER, 8, 4);
1997 if(xfer == NULL){
1998 return;
1999 }
2014 if(xfer == NULL){
2015 return;
2016 }
2000 xfer->spd = 0;
2017 xfer->send.spd = 0;
2001 fc->status = FWBUSMGRELECT;
2002
2018 fc->status = FWBUSMGRELECT;
2019
2003 fp = (struct fw_pkt *)xfer->send.buf;
2020 fp = &xfer->send.hdr;
2004 fp->mode.lreq.dest_hi = 0xffff;
2005 fp->mode.lreq.tlrt = 0;
2006 fp->mode.lreq.tcode = FWTCODE_LREQ;
2007 fp->mode.lreq.pri = 0;
2008 fp->mode.lreq.src = 0;
2009 fp->mode.lreq.len = 8;
2021 fp->mode.lreq.dest_hi = 0xffff;
2022 fp->mode.lreq.tlrt = 0;
2023 fp->mode.lreq.tcode = FWTCODE_LREQ;
2024 fp->mode.lreq.pri = 0;
2025 fp->mode.lreq.src = 0;
2026 fp->mode.lreq.len = 8;
2010 fp->mode.lreq.extcode = FW_LREQ_CMPSWAP;
2011 xfer->dst = FWLOCALBUS | fc->irm;
2012 fp->mode.lreq.dst = xfer->dst;
2027 fp->mode.lreq.extcode = EXTCODE_CMP_SWAP;
2028 fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
2013 fp->mode.lreq.dest_lo = 0xf0000000 | BUS_MGR_ID;
2029 fp->mode.lreq.dest_lo = 0xf0000000 | BUS_MGR_ID;
2014 fp->mode.lreq.payload[0] = htonl(0x3f);
2015 fp->mode.lreq.payload[1] = htonl(fc->nodeid);
2030 xfer->send.payload[0] = htonl(0x3f);
2031 xfer->send.payload[1] = htonl(fc->nodeid);
2016 xfer->act.hand = fw_try_bmr_callback;
2017
2018 err = fw_asyreq(fc, -1, xfer);
2019 if(err){
2032 xfer->act.hand = fw_try_bmr_callback;
2033
2034 err = fw_asyreq(fc, -1, xfer);
2035 if(err){
2020 fw_xfer_free( xfer);
2036 fw_xfer_free_buf(xfer);
2021 return;
2022 }
2023 return;
2024}
2025
2026#ifdef FW_VMACCESS
2027/*
2028 * Software implementation for physical memory block access.

--- 90 unchanged lines hidden (view full) ---

2119}
2120
2121static int
2122fw_bmr(struct firewire_comm *fc)
2123{
2124 struct fw_device fwdev;
2125 union fw_self_id *self_id;
2126 int cmstr;
2037 return;
2038 }
2039 return;
2040}
2041
2042#ifdef FW_VMACCESS
2043/*
2044 * Software implementation for physical memory block access.

--- 90 unchanged lines hidden (view full) ---

2135}
2136
2137static int
2138fw_bmr(struct firewire_comm *fc)
2139{
2140 struct fw_device fwdev;
2141 union fw_self_id *self_id;
2142 int cmstr;
2143 u_int32_t quad;
2127
2128 /* Check to see if the current root node is cycle master capable */
2129 self_id = &fc->topology_map->self_id[fc->max_node];
2130 if (fc->max_node > 0) {
2131 /* XXX check cmc bit of businfo block rather than contender */
2132 if (self_id->p0.link_active && self_id->p0.contender)
2133 cmstr = fc->max_node;
2134 else {

--- 23 unchanged lines hidden (view full) ---

2158 /* Bus probe has not finished, make dummy fwdev for cmstr */
2159 bzero(&fwdev, sizeof(fwdev));
2160 fwdev.fc = fc;
2161 fwdev.dst = cmstr;
2162 fwdev.speed = 0;
2163 fwdev.maxrec = 8; /* 512 */
2164 fwdev.status = FWDEVINIT;
2165 /* Set cmstr bit on the cycle master */
2144
2145 /* Check to see if the current root node is cycle master capable */
2146 self_id = &fc->topology_map->self_id[fc->max_node];
2147 if (fc->max_node > 0) {
2148 /* XXX check cmc bit of businfo block rather than contender */
2149 if (self_id->p0.link_active && self_id->p0.contender)
2150 cmstr = fc->max_node;
2151 else {

--- 23 unchanged lines hidden (view full) ---

2175 /* Bus probe has not finished, make dummy fwdev for cmstr */
2176 bzero(&fwdev, sizeof(fwdev));
2177 fwdev.fc = fc;
2178 fwdev.dst = cmstr;
2179 fwdev.speed = 0;
2180 fwdev.maxrec = 8; /* 512 */
2181 fwdev.status = FWDEVINIT;
2182 /* Set cmstr bit on the cycle master */
2183 quad = htonl(1 << 8);
2166 fwmem_write_quad(&fwdev, NULL, 0/*spd*/,
2184 fwmem_write_quad(&fwdev, NULL, 0/*spd*/,
2167 0xffff, 0xf0000000 | STATE_SET, htonl(1 << 8),
2168 fw_asy_callback_free);
2185 0xffff, 0xf0000000 | STATE_SET, &quad, fw_asy_callback_free);
2169
2170 return 0;
2171}
2172
2173static int
2174fw_modevent(module_t mode, int type, void *data)
2175{
2176 int err = 0;

--- 26 unchanged lines hidden ---
2186
2187 return 0;
2188}
2189
2190static int
2191fw_modevent(module_t mode, int type, void *data)
2192{
2193 int err = 0;

--- 26 unchanged lines hidden ---